MCPcopy Index your code
hub / github.com/DHTMLX/gantt / buildToken

Function buildToken

samples/common/codehighlight/codemirror.js:1793–1856  ·  view source on GitHub ↗
(builder, text, style, startStyle, endStyle, css, attributes)

Source from the content-addressed store, hash-verified

1791 // Build up the DOM representation for a single token, and add it to
1792 // the line map. Takes care to render special characters separately.
1793 function buildToken(builder, text, style, startStyle, endStyle, css, attributes) {
1794 if (!text) { return }
1795 var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;
1796 var special = builder.cm.state.specialChars, mustWrap = false;
1797 var content;
1798 if (!special.test(text)) {
1799 builder.col += text.length;
1800 content = document.createTextNode(displayText);
1801 builder.map.push(builder.pos, builder.pos + text.length, content);
1802 if (ie && ie_version < 9) { mustWrap = true; }
1803 builder.pos += text.length;
1804 } else {
1805 content = document.createDocumentFragment();
1806 var pos = 0;
1807 while (true) {
1808 special.lastIndex = pos;
1809 var m = special.exec(text);
1810 var skipped = m ? m.index - pos : text.length - pos;
1811 if (skipped) {
1812 var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
1813 if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])); }
1814 else { content.appendChild(txt); }
1815 builder.map.push(builder.pos, builder.pos + skipped, txt);
1816 builder.col += skipped;
1817 builder.pos += skipped;
1818 }
1819 if (!m) { break }
1820 pos += skipped + 1;
1821 var txt$1 = (void 0);
1822 if (m[0] == "\t") {
1823 var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
1824 txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
1825 txt$1.setAttribute("role", "presentation");
1826 txt$1.setAttribute("cm-text", "\t");
1827 builder.col += tabWidth;
1828 } else if (m[0] == "\r" || m[0] == "\n") {
1829 txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
1830 txt$1.setAttribute("cm-text", m[0]);
1831 builder.col += 1;
1832 } else {
1833 txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);
1834 txt$1.setAttribute("cm-text", m[0]);
1835 if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])); }
1836 else { content.appendChild(txt$1); }
1837 builder.col += 1;
1838 }
1839 builder.map.push(builder.pos, builder.pos + 1, txt$1);
1840 builder.pos++;
1841 }
1842 }
1843 builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;
1844 if (style || startStyle || endStyle || mustWrap || css || attributes) {
1845 var fullStyle = style || "";
1846 if (startStyle) { fullStyle += startStyle; }
1847 if (endStyle) { fullStyle += endStyle; }
1848 var token = elt("span", [content], fullStyle, css);
1849 if (attributes) {
1850 for (var attr in attributes) { if (attributes.hasOwnProperty(attr) && attr != "style" && attr != "class")

Callers

nothing calls this directly

Calls 3

splitSpacesFunction · 0.85
eltFunction · 0.85
spaceStrFunction · 0.85

Tested by

no test coverage detected