(builder, text, style, startStyle, endStyle, title, css)
| 6976 | // Build up the DOM representation for a single token, and add it to |
| 6977 | // the line map. Takes care to render special characters separately. |
| 6978 | function buildToken(builder, text, style, startStyle, endStyle, title, css) { |
| 6979 | if (!text) return; |
| 6980 | var displayText = builder.splitSpaces ? text.replace(/ {3,}/g, splitSpaces) : text; |
| 6981 | var special = builder.cm.state.specialChars, mustWrap = false; |
| 6982 | if (!special.test(text)) { |
| 6983 | builder.col += text.length; |
| 6984 | var content = document.createTextNode(displayText); |
| 6985 | builder.map.push(builder.pos, builder.pos + text.length, content); |
| 6986 | if (ie && ie_version < 9) mustWrap = true; |
| 6987 | builder.pos += text.length; |
| 6988 | } else { |
| 6989 | var content = document.createDocumentFragment(), pos = 0; |
| 6990 | while (true) { |
| 6991 | special.lastIndex = pos; |
| 6992 | var m = special.exec(text); |
| 6993 | var skipped = m ? m.index - pos : text.length - pos; |
| 6994 | if (skipped) { |
| 6995 | var txt = document.createTextNode(displayText.slice(pos, pos + skipped)); |
| 6996 | if (ie && ie_version < 9) content.appendChild(elt("span", [txt])); |
| 6997 | else content.appendChild(txt); |
| 6998 | builder.map.push(builder.pos, builder.pos + skipped, txt); |
| 6999 | builder.col += skipped; |
| 7000 | builder.pos += skipped; |
| 7001 | } |
| 7002 | if (!m) break; |
| 7003 | pos += skipped + 1; |
| 7004 | if (m[0] == "\t") { |
| 7005 | var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize; |
| 7006 | var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab")); |
| 7007 | txt.setAttribute("role", "presentation"); |
| 7008 | txt.setAttribute("cm-text", "\t"); |
| 7009 | builder.col += tabWidth; |
| 7010 | } else if (m[0] == "\r" || m[0] == "\n") { |
| 7011 | var txt = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar")); |
| 7012 | txt.setAttribute("cm-text", m[0]); |
| 7013 | builder.col += 1; |
| 7014 | } else { |
| 7015 | var txt = builder.cm.options.specialCharPlaceholder(m[0]); |
| 7016 | txt.setAttribute("cm-text", m[0]); |
| 7017 | if (ie && ie_version < 9) content.appendChild(elt("span", [txt])); |
| 7018 | else content.appendChild(txt); |
| 7019 | builder.col += 1; |
| 7020 | } |
| 7021 | builder.map.push(builder.pos, builder.pos + 1, txt); |
| 7022 | builder.pos++; |
| 7023 | } |
| 7024 | } |
| 7025 | if (style || startStyle || endStyle || mustWrap || css) { |
| 7026 | var fullStyle = style || ""; |
| 7027 | if (startStyle) fullStyle += startStyle; |
| 7028 | if (endStyle) fullStyle += endStyle; |
| 7029 | var token = elt("span", [content], fullStyle, css); |
| 7030 | if (title) token.title = title; |
| 7031 | return builder.content.appendChild(token); |
| 7032 | } |
| 7033 | builder.content.appendChild(content); |
| 7034 | } |
| 7035 |
nothing calls this directly
no test coverage detected