(cm, text, mode, state, f, lineClasses, forceToEnd)
| 5542 | |
| 5543 | // Run the given mode's parser over a line, calling f for each token. |
| 5544 | function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) { |
| 5545 | var flattenSpans = mode.flattenSpans; |
| 5546 | if (flattenSpans == null) flattenSpans = cm.options.flattenSpans; |
| 5547 | var curStart = 0, curStyle = null; |
| 5548 | var stream = new StringStream(text, cm.options.tabSize), style; |
| 5549 | if (text == "") extractLineClasses(callBlankLine(mode, state), lineClasses); |
| 5550 | while (!stream.eol()) { |
| 5551 | if (stream.pos > cm.options.maxHighlightLength) { |
| 5552 | flattenSpans = false; |
| 5553 | if (forceToEnd) processLine(cm, text, state, stream.pos); |
| 5554 | stream.pos = text.length; |
| 5555 | style = null; |
| 5556 | } else { |
| 5557 | style = extractLineClasses(mode.token(stream, state), lineClasses); |
| 5558 | } |
| 5559 | if (cm.options.addModeClass) { |
| 5560 | var mName = CodeMirror.innerMode(mode, state).mode.name; |
| 5561 | if (mName) style = "m-" + (style ? mName + " " + style : mName); |
| 5562 | } |
| 5563 | if (!flattenSpans || curStyle != style) { |
| 5564 | if (curStart < stream.start) f(stream.start, curStyle); |
| 5565 | curStart = stream.start; curStyle = style; |
| 5566 | } |
| 5567 | stream.start = stream.pos; |
| 5568 | } |
| 5569 | while (curStart < stream.pos) { |
| 5570 | // Webkit seems to refuse to render text nodes longer than 57444 characters |
| 5571 | var pos = Math.min(stream.pos, curStart + 50000); |
| 5572 | f(pos, curStyle); |
| 5573 | curStart = pos; |
| 5574 | } |
| 5575 | } |
| 5576 | |
| 5577 | // Compute a style array (an array starting with a mode generation |
| 5578 | // -- for invalidation -- followed by pairs of end positions and |
no test coverage detected