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

Function buildToken

static/editor.md/lib/codemirror/lib/codemirror.js:6771–6822  ·  view source on GitHub ↗
(builder, text, style, startStyle, endStyle, title, css)

Source from the content-addressed store, hash-verified

6769 // Build up the DOM representation for a single token, and add it to
6770 // the line map. Takes care to render special characters separately.
6771 function buildToken(builder, text, style, startStyle, endStyle, title, css) {
6772 if (!text) return;
6773 var special = builder.cm.options.specialChars, mustWrap = false;
6774 if (!special.test(text)) {
6775 builder.col += text.length;
6776 var content = document.createTextNode(text);
6777 builder.map.push(builder.pos, builder.pos + text.length, content);
6778 if (ie && ie_version < 9) mustWrap = true;
6779 builder.pos += text.length;
6780 } else {
6781 var content = document.createDocumentFragment(), pos = 0;
6782 while (true) {
6783 special.lastIndex = pos;
6784 var m = special.exec(text);
6785 var skipped = m ? m.index - pos : text.length - pos;
6786 if (skipped) {
6787 var txt = document.createTextNode(text.slice(pos, pos + skipped));
6788 if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
6789 else content.appendChild(txt);
6790 builder.map.push(builder.pos, builder.pos + skipped, txt);
6791 builder.col += skipped;
6792 builder.pos += skipped;
6793 }
6794 if (!m) break;
6795 pos += skipped + 1;
6796 if (m[0] == "\t") {
6797 var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
6798 var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
6799 txt.setAttribute("role", "presentation");
6800 txt.setAttribute("cm-text", "\t");
6801 builder.col += tabWidth;
6802 } else {
6803 var txt = builder.cm.options.specialCharPlaceholder(m[0]);
6804 txt.setAttribute("cm-text", m[0]);
6805 if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
6806 else content.appendChild(txt);
6807 builder.col += 1;
6808 }
6809 builder.map.push(builder.pos, builder.pos + 1, txt);
6810 builder.pos++;
6811 }
6812 }
6813 if (style || startStyle || endStyle || mustWrap || css) {
6814 var fullStyle = style || "";
6815 if (startStyle) fullStyle += startStyle;
6816 if (endStyle) fullStyle += endStyle;
6817 var token = elt("span", [content], fullStyle, css);
6818 if (title) token.title = title;
6819 return builder.content.appendChild(token);
6820 }
6821 builder.content.appendChild(content);
6822 }
6823
6824 function buildTokenSplitSpaces(inner) {
6825 function split(old) {

Callers

nothing calls this directly

Calls 3

eltFunction · 0.70
spaceStrFunction · 0.70
setAttributeMethod · 0.45

Tested by

no test coverage detected