From 784c71342db2355cf146334b34c3a83ead5f8a07 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 18 Jan 2020 16:05:44 -0500 Subject: [PATCH] Fix preformatted text not being displayed correctly --- Tusker/Views/ContentTextView.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Tusker/Views/ContentTextView.swift b/Tusker/Views/ContentTextView.swift index 18a5cf88..5f11aff8 100644 --- a/Tusker/Views/ContentTextView.swift +++ b/Tusker/Views/ContentTextView.swift @@ -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() {