Use string split instead of regex.

This commit is contained in:
Paulo Reis 2016-08-02 11:59:43 +01:00
parent ff62e50530
commit 01637386bd
2 changed files with 11 additions and 4 deletions

View file

@ -3,13 +3,21 @@ define [
], (App) ->
DEF_MIN_LENGTH = 20
_decodeHTMLEntities = (str) ->
str.replace /&#(\d+);/g, (match, dec) ->
String.fromCharCode dec;
_getWrappedWordsString = (baseStr, wrapperElName, minLength) ->
minLength = minLength || DEF_MIN_LENGTH
words = baseStr.split ' '
findWordsRegEx = new RegExp "\\w{#{minLength},}", "g"
wrappingTemplate = "<#{wrapperElName} class=\"break-word\">$&</#{wrapperElName}>"
wordsWrapped = for word in words
if _decodeHTMLEntities(word).length >= minLength
"<#{wrapperElName} class=\"break-word\">#{word}</#{wrapperElName}>"
else
word
baseStr.replace findWordsRegEx, wrappingTemplate
outputStr = wordsWrapped.join ' '
App.filter "wrapLongWords", () ->

View file

@ -131,7 +131,6 @@
.break-word {
word-break: break-all;
color: red;
}
.editor-dark {