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

Function highlightLine

static/mergely/lib/codemirror.js:6834–6870  ·  view source on GitHub ↗
(cm, line, state, forceToEnd)

Source from the content-addressed store, hash-verified

6832 // style strings), which is used to highlight the tokens on the
6833 // line.
6834 function highlightLine(cm, line, state, forceToEnd) {
6835 // A styles array always starts with a number identifying the
6836 // mode/overlays that it is based on (for easy invalidation).
6837 var st = [cm.state.modeGen], lineClasses = {};
6838 // Compute the base array of styles
6839 runMode(cm, line.text, cm.doc.mode, state, function(end, style) {
6840 st.push(end, style);
6841 }, lineClasses, forceToEnd);
6842
6843 // Run overlays, adjust style array.
6844 for (var o = 0; o < cm.state.overlays.length; ++o) {
6845 var overlay = cm.state.overlays[o], i = 1, at = 0;
6846 runMode(cm, line.text, overlay.mode, true, function(end, style) {
6847 var start = i;
6848 // Ensure there's a token end at the current position, and that i points at it
6849 while (at < end) {
6850 var i_end = st[i];
6851 if (i_end > end)
6852 st.splice(i, 1, end, st[i+1], i_end);
6853 i += 2;
6854 at = Math.min(end, i_end);
6855 }
6856 if (!style) return;
6857 if (overlay.opaque) {
6858 st.splice(start, i - start, end, "cm-overlay " + style);
6859 i = start + 2;
6860 } else {
6861 for (; start < i; start += 2) {
6862 var cur = st[start+1];
6863 st[start+1] = (cur ? cur + " " : "") + "cm-overlay " + style;
6864 }
6865 }
6866 }, lineClasses);
6867 }
6868
6869 return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null};
6870 }
6871
6872 function getLineStyles(cm, line, updateFrontier) {
6873 if (!line.styles || line.styles[0] != cm.state.modeGen) {

Callers 2

highlightWorkerFunction · 0.70
getLineStylesFunction · 0.70

Calls 1

runModeFunction · 0.70

Tested by

no test coverage detected