Skip to content

Commit

Permalink
Resolve escaped characters in a status (#2071)
Browse files Browse the repository at this point in the history
* Resolve escaped characters in a status

Escaped characters are now returned to their original form for
HTMLString.asRawText.

* Unescape the markdown version too

The HTMLString.asMarkdown string is now also unescaped, & and
similar are resolved.

* Fix a internal fallback

If one of the unescape(...) commands fails, the original, unescaped
text is used instead of an empty string.
  • Loading branch information
Havhingstor authored May 13, 2024
1 parent 6ed760a commit 7caf00d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Packages/Models/Sources/Models/Alias/HTMLString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public struct HTMLString: Codable, Equatable, Hashable, @unchecked Sendable {
_ = text.removeLast()
_ = text.removeLast()
}
asRawText = text
asRawText = (try? Entities.unescape(text)) ?? text

if asMarkdown.hasPrefix("\n") {
_ = asMarkdown.removeFirst()
Expand Down Expand Up @@ -175,7 +175,9 @@ public struct HTMLString: Codable, Equatable, Hashable, @unchecked Sendable {
return
} else if node.nodeName() == "#text" {
var txt = node.description


txt = (try? Entities.unescape(txt)) ?? txt

if let underscore_regex, let main_regex {
// This is the markdown escaper
txt = main_regex.stringByReplacingMatches(in: txt, options: [], range: NSRange(location: 0, length: txt.count), withTemplate: "\\\\$1")
Expand Down

0 comments on commit 7caf00d

Please sign in to comment.