From 9f1d3804d972f9816eddc49c8c88b9b0fb8c56b9 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 26 Jan 2023 18:38:20 -0500 Subject: [PATCH] Apply Mastodon's link truncation Closes #344 --- Tusker/HTMLConverter.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tusker/HTMLConverter.swift b/Tusker/HTMLConverter.swift index 32f25c8a..dc0c76d2 100644 --- a/Tusker/HTMLConverter.swift +++ b/Tusker/HTMLConverter.swift @@ -55,7 +55,21 @@ struct HTMLConverter { case let node as Element: let attributed = NSMutableAttributedString(string: "", attributes: [.font: font, .foregroundColor: color]) for child in node.getChildNodes() { + var appendEllipsis = false + if node.tagName() == "a", + let el = child as? Element { + if el.hasClass("invisible") { + continue + } else if el.hasClass("ellipsis") { + appendEllipsis = true + } + } + attributed.append(attributedTextForHTMLNode(child, usePreformattedText: usePreformattedText || node.tagName() == "pre")) + + if appendEllipsis { + attributed.append(NSAttributedString("…")) + } } switch node.tagName() {