Split long spans into multiple spans

If a span has more than 2^16 chars and has the style `white-space: pre` Chrome
won't render it.
This commit is contained in:
probablycorey
2013-10-18 11:44:56 -07:00
parent 069208975c
commit fd062a7c4f

View File

@@ -10,6 +10,8 @@ StartCharacterRegex = /^./
StartDotRegex = /^\.?/
WhitespaceRegex = /\S/
maxTokenLength = 20000
# Private: Represents a single unit of text as selected by a grammar.
module.exports =
class Token
@@ -165,9 +167,18 @@ class Token
endIndex = match.index
html = leadingHtml + @escapeString(html, startIndex, endIndex) + trailingHtml
fragments = [leadingHtml]
html
if @value.length > maxTokenLength
while startIndex < endIndex
fragments.push "<span>" + @escapeString(html, startIndex, startIndex + maxTokenLength) + "</span>"
startIndex += maxTokenLength
else
fragments.push @escapeString(html, startIndex, endIndex)
fragments.push trailingHtml
fragments.join('')
escapeString: (str, startIndex, endIndex) ->
strLength = str.length