Apply Mastodon's link truncation

Closes #344
This commit is contained in:
Shadowfacts 2023-01-26 18:38:20 -05:00
parent 333295367a
commit 9f1d3804d9
1 changed files with 14 additions and 0 deletions

View File

@ -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() {