MCPcopy Index your code
hub / github.com/csev/py4e / buildToken

Function buildToken

tools/pythonauto/static/codemirrorepl/codemirror.js:5713–5761  ·  view source on GitHub ↗
(builder, text, style, startStyle, endStyle, title)

Source from the content-addressed store, hash-verified

5711 // Build up the DOM representation for a single token, and add it to
5712 // the line map. Takes care to render special characters separately.
5713 function buildToken(builder, text, style, startStyle, endStyle, title) {
5714 if (!text) return;
5715 var special = builder.cm.options.specialChars, mustWrap = false;
5716 if (!special.test(text)) {
5717 builder.col += text.length;
5718 var content = document.createTextNode(text);
5719 builder.map.push(builder.pos, builder.pos + text.length, content);
5720 if (ie_upto8) mustWrap = true;
5721 builder.pos += text.length;
5722 } else {
5723 var content = document.createDocumentFragment(), pos = 0;
5724 while (true) {
5725 special.lastIndex = pos;
5726 var m = special.exec(text);
5727 var skipped = m ? m.index - pos : text.length - pos;
5728 if (skipped) {
5729 var txt = document.createTextNode(text.slice(pos, pos + skipped));
5730 if (ie_upto8) content.appendChild(elt("span", [txt]));
5731 else content.appendChild(txt);
5732 builder.map.push(builder.pos, builder.pos + skipped, txt);
5733 builder.col += skipped;
5734 builder.pos += skipped;
5735 }
5736 if (!m) break;
5737 pos += skipped + 1;
5738 if (m[0] == "\t") {
5739 var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
5740 var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
5741 builder.col += tabWidth;
5742 } else {
5743 var txt = builder.cm.options.specialCharPlaceholder(m[0]);
5744 if (ie_upto8) content.appendChild(elt("span", [txt]));
5745 else content.appendChild(txt);
5746 builder.col += 1;
5747 }
5748 builder.map.push(builder.pos, builder.pos + 1, txt);
5749 builder.pos++;
5750 }
5751 }
5752 if (style || startStyle || endStyle || mustWrap) {
5753 var fullStyle = style || "";
5754 if (startStyle) fullStyle += startStyle;
5755 if (endStyle) fullStyle += endStyle;
5756 var token = elt("span", [content], fullStyle);
5757 if (title) token.title = title;
5758 return builder.content.appendChild(token);
5759 }
5760 builder.content.appendChild(content);
5761 }
5762
5763 function buildTokenSplitSpaces(inner) {
5764 function split(old) {

Callers

nothing calls this directly

Calls 4

sliceMethod · 0.80
eltFunction · 0.70
spaceStrFunction · 0.70
appendChildMethod · 0.45

Tested by

no test coverage detected