match intended mastodon presentation (#557)

strip out <span="invisible">blah</span>
append ellipsis to <span="ellipsis">blah</span>
This commit is contained in:
Gareth Simpson 2023-01-31 08:02:01 +00:00 committed by GitHub
parent 0695fd5733
commit 0a0e985e33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,16 @@ public struct HTMLString: Decodable, Equatable, Hashable {
htmlValue = regex.stringByReplacingMatches(in: htmlValue, options: [], range: NSRange(location: 0, length: htmlValue.count), withTemplate: "\\\\$1")
}
// match intended mastodon presentation
// strip out <span="invisible">blah</span>
// append ellipsis to <span="ellipsis">blah</span>
if let regex = try? NSRegularExpression(pattern: "(<span class=\"invisible\">.*?</span>)", options: .caseInsensitive) {
htmlValue = regex.stringByReplacingMatches(in: htmlValue, options: [], range: NSRange(location: 0, length: htmlValue.count), withTemplate: "")
}
if let regex = try? NSRegularExpression(pattern: "(<span class=\"ellipsis\">(.*?)</span>)", options: .caseInsensitive) {
htmlValue = regex.stringByReplacingMatches(in: htmlValue, options: [], range: NSRange(location: 0, length: htmlValue.count), withTemplate: "$2…")
}
do {
asMarkdown = try HTMLParser().parse(html: htmlValue)
.toMarkdown()