(cm, text, mode, context, f, lineClasses, forceToEnd)
| 2680 | |
| 2681 | // Run the given mode's parser over a line, calling f for each token. |
| 2682 | function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) { |
| 2683 | var flattenSpans = mode.flattenSpans |
| 2684 | if (flattenSpans == null) { |
| 2685 | flattenSpans = cm.options.flattenSpans |
| 2686 | } |
| 2687 | var curStart = 0, |
| 2688 | curStyle = null |
| 2689 | var stream = new StringStream(text, cm.options.tabSize, context), |
| 2690 | style |
| 2691 | var inner = cm.options.addModeClass && [null] |
| 2692 | if (text == "") { |
| 2693 | extractLineClasses(callBlankLine(mode, context.state), lineClasses) |
| 2694 | } |
| 2695 | while (!stream.eol()) { |
| 2696 | if (stream.pos > cm.options.maxHighlightLength) { |
| 2697 | flattenSpans = false |
| 2698 | if (forceToEnd) { |
| 2699 | processLine(cm, text, context, stream.pos) |
| 2700 | } |
| 2701 | stream.pos = text.length |
| 2702 | style = null |
| 2703 | } else { |
| 2704 | style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses) |
| 2705 | } |
| 2706 | if (inner) { |
| 2707 | var mName = inner[0].name |
| 2708 | if (mName) { |
| 2709 | style = "m-" + (style ? mName + " " + style : mName) |
| 2710 | } |
| 2711 | } |
| 2712 | if (!flattenSpans || curStyle != style) { |
| 2713 | while (curStart < stream.start) { |
| 2714 | curStart = Math.min(stream.start, curStart + 5000) |
| 2715 | f(curStart, curStyle) |
| 2716 | } |
| 2717 | curStyle = style |
| 2718 | } |
| 2719 | stream.start = stream.pos |
| 2720 | } |
| 2721 | while (curStart < stream.pos) { |
| 2722 | // Webkit seems to refuse to render text nodes longer than 57444 |
| 2723 | // characters, and returns inaccurate measurements in nodes |
| 2724 | // starting around 5000 chars. |
| 2725 | var pos = Math.min(stream.pos, curStart + 5000) |
| 2726 | f(pos, curStyle) |
| 2727 | curStart = pos |
| 2728 | } |
| 2729 | } |
| 2730 | |
| 2731 | // Finds the line to start with when starting a parse. Tries to |
| 2732 | // find a line with a stateAfter, so that it can start with a |
no test coverage detected