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

Function buildLineContent

static/editor.md/lib/codemirror/lib/codemirror.js:6708–6760  ·  view source on GitHub ↗
(cm, lineView)

Source from the content-addressed store, hash-verified

6706 // The returned object contains the DOM node, this map, and
6707 // information about line-wide styles that were set by the mode.
6708 function buildLineContent(cm, lineView) {
6709 // The padding-right forces the element to have a 'border', which
6710 // is needed on Webkit to be able to get line-level bounding
6711 // rectangles for it (in measureChar).
6712 var content = elt("span", null, null, webkit ? "padding-right: .1px" : null);
6713 var builder = {pre: elt("pre", [content]), content: content, col: 0, pos: 0, cm: cm};
6714 lineView.measure = {};
6715
6716 // Iterate over the logical lines that make up this visual line.
6717 for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
6718 var line = i ? lineView.rest[i - 1] : lineView.line, order;
6719 builder.pos = 0;
6720 builder.addToken = buildToken;
6721 // Optionally wire in some hacks into the token-rendering
6722 // algorithm, to deal with browser quirks.
6723 if ((ie || webkit) && cm.getOption("lineWrapping"))
6724 builder.addToken = buildTokenSplitSpaces(builder.addToken);
6725 if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line)))
6726 builder.addToken = buildTokenBadBidi(builder.addToken, order);
6727 builder.map = [];
6728 var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
6729 insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
6730 if (line.styleClasses) {
6731 if (line.styleClasses.bgClass)
6732 builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "");
6733 if (line.styleClasses.textClass)
6734 builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "");
6735 }
6736
6737 // Ensure at least a single node is present, for measuring.
6738 if (builder.map.length == 0)
6739 builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)));
6740
6741 // Store the map and a cache object for the current logical line
6742 if (i == 0) {
6743 lineView.measure.map = builder.map;
6744 lineView.measure.cache = {};
6745 } else {
6746 (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);
6747 (lineView.measure.caches || (lineView.measure.caches = [])).push({});
6748 }
6749 }
6750
6751 // See issue #2901
6752 if (webkit && /\bcm-tab\b/.test(builder.content.lastChild.className))
6753 builder.content.className = "cm-tab-wrap-hack";
6754
6755 signal(cm, "renderLine", cm, lineView.line, builder.pre);
6756 if (builder.pre.className)
6757 builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
6758
6759 return builder;
6760 }
6761
6762 function defaultSpecialCharPlaceholder(ch) {
6763 var token = elt("span", "\u2022", "cm-invalidchar");

Callers 2

getLineContentFunction · 0.70

Calls 10

eltFunction · 0.70
buildTokenSplitSpacesFunction · 0.70
hasBadBidiRectsFunction · 0.70
getOrderFunction · 0.70
buildTokenBadBidiFunction · 0.70
lineNoFunction · 0.70
insertLineContentFunction · 0.70
getLineStylesFunction · 0.70
joinClassesFunction · 0.70
zeroWidthElementFunction · 0.70

Tested by

no test coverage detected