Fix #4856, fix #4431 - Normalise HTML whitespaces using SwiftSoup's own text()/TextNode.normaliseWhitespace methods

This commit is contained in:
Stefan Ceriu
2026-01-20 16:44:56 +02:00
committed by Stefan Ceriu
parent 7d47a290ee
commit 40b655bde6
16 changed files with 68 additions and 43 deletions
@@ -122,9 +122,9 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
for node in element.getChildNodes() {
if let textNode = node as? TextNode {
// If this node is plain text just append its preformatted contents
// If this node is plain text append the whitespace normalised version
if node.parent() == documentBody {
result.append(NSAttributedString(string: textNode.getWholeText()))
result.append(NSAttributedString(string: textNode.text()))
continue
}
@@ -237,7 +237,7 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
content = attributedString(element: childElement, documentBody: documentBody, preserveFormatting: preserveFormatting, listTag: tag, listIndex: &listIndex, indentLevel: indentLevel + 1)
if indentLevel > 0 {
if indentLevel > 0 || !element.ownText().isEmpty {
content.insert(NSAttributedString("\n"), at: 0)
}