MCPcopy Create free account
hub / github.com/TruthHun/BookStack / runMode

Function runMode

static/editor.md/lib/codemirror/lib/codemirror.js:6588–6623  ·  view source on GitHub ↗
(cm, text, mode, state, f, lineClasses, forceToEnd)

Source from the content-addressed store, hash-verified

6586
6587 // Run the given mode's parser over a line, calling f for each token.
6588 function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
6589 var flattenSpans = mode.flattenSpans;
6590 if (flattenSpans == null) flattenSpans = cm.options.flattenSpans;
6591 var curStart = 0, curStyle = null;
6592 var stream = new StringStream(text, cm.options.tabSize), style;
6593 var inner = cm.options.addModeClass && [null];
6594 if (text == "") extractLineClasses(callBlankLine(mode, state), lineClasses);
6595 while (!stream.eol()) {
6596 if (stream.pos > cm.options.maxHighlightLength) {
6597 flattenSpans = false;
6598 if (forceToEnd) processLine(cm, text, state, stream.pos);
6599 stream.pos = text.length;
6600 style = null;
6601 } else {
6602 style = extractLineClasses(readToken(mode, stream, state, inner), lineClasses);
6603 }
6604 if (inner) {
6605 var mName = inner[0].name;
6606 if (mName) style = "m-" + (style ? mName + " " + style : mName);
6607 }
6608 if (!flattenSpans || curStyle != style) {
6609 while (curStart < stream.start) {
6610 curStart = Math.min(stream.start, curStart + 50000);
6611 f(curStart, curStyle);
6612 }
6613 curStyle = style;
6614 }
6615 stream.start = stream.pos;
6616 }
6617 while (curStart < stream.pos) {
6618 // Webkit seems to refuse to render text nodes longer than 57444 characters
6619 var pos = Math.min(stream.pos, curStart + 50000);
6620 f(pos, curStyle);
6621 curStart = pos;
6622 }
6623 }
6624
6625 // Compute a style array (an array starting with a mode generation
6626 // -- for invalidation -- followed by pairs of end positions and

Callers 1

highlightLineFunction · 0.70

Calls 5

extractLineClassesFunction · 0.70
callBlankLineFunction · 0.70
processLineFunction · 0.70
readTokenFunction · 0.70
fFunction · 0.50

Tested by

no test coverage detected