Fix toPlainText representation with formatting spans
This commit is contained in:
parent
2ca981ddfa
commit
02b6a90a95
2 changed files with 11 additions and 4 deletions
|
|
@ -55,8 +55,15 @@ private class PlainTextNodeVisitor : NodeVisitor {
|
|||
private val builder = StringBuilder()
|
||||
|
||||
override fun head(node: Node, depth: Int) {
|
||||
if (node is TextNode && node.text().isNotBlank()) {
|
||||
builder.append(node.text())
|
||||
if (node is TextNode) {
|
||||
// If the text node is blank, only add a single whitespace char if there wasn't already one
|
||||
if (node.text().isBlank()) {
|
||||
if (builder.lastOrNull()?.isWhitespace() == false) {
|
||||
builder.append(" ")
|
||||
}
|
||||
} else {
|
||||
builder.append(node.text())
|
||||
}
|
||||
} else if (node is Element && node.tagName() == "li") {
|
||||
val index = node.elementSiblingIndex() + 1
|
||||
val isOrdered = node.parent()?.nodeName()?.lowercase() == "ol"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue