Fix preformatted text not being displayed correctly

This commit is contained in:
Shadowfacts 2020-01-18 16:05:44 -05:00
parent b5a41badcc
commit 784c71342d
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 9 additions and 3 deletions

View File

@ -105,14 +105,20 @@ class ContentTextView: LinkTextView {
self.attributedText = mutAttrString
}
func attributedTextForHTMLNode(_ node: Node) -> NSAttributedString {
func attributedTextForHTMLNode(_ node: Node, usePreformattedText: Bool = false) -> NSAttributedString {
switch node {
case let node as TextNode:
return NSAttributedString(string: node.text(), attributes: [.font: defaultFont])
let text: String
if usePreformattedText {
text = node.getWholeText()
} else {
text = node.text()
}
return NSAttributedString(string: text, attributes: [.font: defaultFont])
case let node as Element:
let attributed = NSMutableAttributedString(string: "", attributes: [.font: defaultFont])
for child in node.getChildNodes() {
attributed.append(attributedTextForHTMLNode(child))
attributed.append(attributedTextForHTMLNode(child, usePreformattedText: usePreformattedText || node.tagName() == "pre"))
}
switch node.tagName() {