|
|
@ -24,7 +24,6 @@ fun Element.textArray(): Array<String> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun tail(node: Node, depth: Int) { |
|
|
|
override fun tail(node: Node, depth: Int) { |
|
|
|
// make sure there is a space between block tags and immediately following text nodes <div>One</div>Two should be "One Two". |
|
|
|
|
|
|
|
if (node is Element) { |
|
|
|
if (node is Element) { |
|
|
|
if (node.isBlock && node.nextSibling() is TextNode && !lastCharIsWhitespace( |
|
|
|
if (node.isBlock && node.nextSibling() is TextNode && !lastCharIsWhitespace( |
|
|
|
accum |
|
|
|
accum |
|
|
@ -37,12 +36,11 @@ fun Element.textArray(): Array<String> { |
|
|
|
return text.splitNotBlank("\n") |
|
|
|
return text.splitNotBlank("\n") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun appendNormalisedText( |
|
|
|
private fun appendNormalisedText(accum: StringBuilder, textNode: TextNode) { |
|
|
|
accum: StringBuilder, |
|
|
|
|
|
|
|
textNode: TextNode |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
val text = textNode.wholeText |
|
|
|
val text = textNode.wholeText |
|
|
|
if (preserveWhitespace(textNode.parentNode()) || textNode is CDataNode) accum.append(text) else StringUtil.appendNormalisedWhitespace( |
|
|
|
if (preserveWhitespace(textNode.parentNode()) || textNode is CDataNode) |
|
|
|
|
|
|
|
accum.append(text) |
|
|
|
|
|
|
|
else StringUtil.appendNormalisedWhitespace( |
|
|
|
accum, |
|
|
|
accum, |
|
|
|
text, |
|
|
|
text, |
|
|
|
lastCharIsWhitespace(accum) |
|
|
|
lastCharIsWhitespace(accum) |
|
|
@ -50,7 +48,6 @@ private fun appendNormalisedText( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun preserveWhitespace(node: Node?): Boolean { |
|
|
|
private fun preserveWhitespace(node: Node?): Boolean { |
|
|
|
// looks only at this element and five levels up, to prevent recursion & needless stack searches |
|
|
|
|
|
|
|
if (node is Element) { |
|
|
|
if (node is Element) { |
|
|
|
var el = node as Element? |
|
|
|
var el = node as Element? |
|
|
|
var i = 0 |
|
|
|
var i = 0 |
|
|
|