(builder, text, style, startStyle, endStyle)
| 3994 | |
| 3995 | var tokenSpecialChars = /[\t\u0000-\u0019\u200b\u2028\u2029\uFEFF]/g; |
| 3996 | function buildToken(builder, text, style, startStyle, endStyle) { |
| 3997 | if (!text) return; |
| 3998 | if (!tokenSpecialChars.test(text)) { |
| 3999 | builder.col += text.length; |
| 4000 | var content = document.createTextNode(text); |
| 4001 | } else { |
| 4002 | var content = document.createDocumentFragment(), pos = 0; |
| 4003 | while (true) { |
| 4004 | tokenSpecialChars.lastIndex = pos; |
| 4005 | var m = tokenSpecialChars.exec(text); |
| 4006 | var skipped = m ? m.index - pos : text.length - pos; |
| 4007 | if (skipped) { |
| 4008 | content.appendChild(document.createTextNode(text.slice(pos, pos + skipped))); |
| 4009 | builder.col += skipped; |
| 4010 | } |
| 4011 | if (!m) break; |
| 4012 | pos += skipped + 1; |
| 4013 | if (m[0] == "\t") { |
| 4014 | var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize; |
| 4015 | content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab")); |
| 4016 | builder.col += tabWidth; |
| 4017 | } else { |
| 4018 | var token = elt("span", "\u2022", "cm-invalidchar"); |
| 4019 | token.title = "\\u" + m[0].charCodeAt(0).toString(16); |
| 4020 | content.appendChild(token); |
| 4021 | builder.col += 1; |
| 4022 | } |
| 4023 | } |
| 4024 | } |
| 4025 | if (style || startStyle || endStyle || builder.measure) { |
| 4026 | var fullStyle = style || ""; |
| 4027 | if (startStyle) fullStyle += startStyle; |
| 4028 | if (endStyle) fullStyle += endStyle; |
| 4029 | return builder.pre.appendChild(elt("span", [content], fullStyle)); |
| 4030 | } |
| 4031 | builder.pre.appendChild(content); |
| 4032 | } |
| 4033 | |
| 4034 | function buildTokenMeasure(builder, text, style, startStyle, endStyle) { |
| 4035 | for (var i = 0; i < text.length; ++i) { |
no test coverage detected