in backend/app/utils/HtmlToPlainText.scala [100:132]
private def append(text: String) = {
if (text.startsWith("\n")) width = 0 // reset counter if starts with a newline. only from formats above, not in natural text
if (text == " " && (accum.isEmpty || StringUtil.in(accum.substring(accum.length - 1), " ", "\n"))) {
// do nothing
} else if (text.length + width > FormattingVisitor.maxWidth) { // won't fit, needs to wrap
val words = text.split("\\s+")
var i = 0
while ( {
i < words.length
}) {
var word = words(i)
val last = i == words.length - 1
if (!last) { // insert a space if not the last word
word = word + " "
}
if (word.length + width > FormattingVisitor.maxWidth) { // wrap and reset counter
accum.append("\n").append(word)
width = word.length
}
else {
accum.append(word)
width += word.length
}
{
i += 1; i - 1
}
}
} else { // fits as is, without need to wrap text
accum.append(text)
width += text.length
}
}