forked from shadowfacts/Tusker
Fix preformatted text not being displayed correctly
This commit is contained in:
parent
b5a41badcc
commit
784c71342d
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue