(builder, text, style, startStyle, endStyle, title)
| 4575 | } |
| 4576 | |
| 4577 | function buildToken(builder, text, style, startStyle, endStyle, title) { |
| 4578 | if (!text) return; |
| 4579 | var special = builder.cm.options.specialChars; |
| 4580 | if (!special.test(text)) { |
| 4581 | builder.col += text.length; |
| 4582 | var content = document.createTextNode(text); |
| 4583 | } else { |
| 4584 | var content = document.createDocumentFragment(), pos = 0; |
| 4585 | while (true) { |
| 4586 | special.lastIndex = pos; |
| 4587 | var m = special.exec(text); |
| 4588 | var skipped = m ? m.index - pos : text.length - pos; |
| 4589 | if (skipped) { |
| 4590 | content.appendChild(document.createTextNode(text.slice(pos, pos + skipped))); |
| 4591 | builder.col += skipped; |
| 4592 | } |
| 4593 | if (!m) break; |
| 4594 | pos += skipped + 1; |
| 4595 | if (m[0] == "\t") { |
| 4596 | var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize; |
| 4597 | content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab")); |
| 4598 | builder.col += tabWidth; |
| 4599 | } else { |
| 4600 | var token = builder.cm.options.specialCharPlaceholder(m[0]); |
| 4601 | content.appendChild(token); |
| 4602 | builder.col += 1; |
| 4603 | } |
| 4604 | } |
| 4605 | } |
| 4606 | if (style || startStyle || endStyle || builder.measure) { |
| 4607 | var fullStyle = style || ""; |
| 4608 | if (startStyle) fullStyle += startStyle; |
| 4609 | if (endStyle) fullStyle += endStyle; |
| 4610 | var token = elt("span", [content], fullStyle); |
| 4611 | if (title) token.title = title; |
| 4612 | return builder.pre.appendChild(token); |
| 4613 | } |
| 4614 | builder.pre.appendChild(content); |
| 4615 | } |
| 4616 | |
| 4617 | function buildTokenMeasure(builder, text, style, startStyle, endStyle) { |
| 4618 | var wrapping = builder.cm.options.lineWrapping; |
no test coverage detected