This commit is contained in:
Thomas Ricouard 2023-02-07 07:40:48 +01:00
commit ff3fb534c5
4 changed files with 11 additions and 8 deletions

View file

@ -154,7 +154,7 @@
"settings.haptic.buttons" = "Knopfdruck"; "settings.haptic.buttons" = "Knopfdruck";
"settings.display.section.ipad" = "iPad"; "settings.display.section.ipad" = "iPad";
"settings.display.show-ipad-column" = "Enable secondary column"; "settings.display.show-ipad-column" = "Zweite Spalte aktivieren";
"enum.expand-media.show" = "Alle zeigen"; "enum.expand-media.show" = "Alle zeigen";
"enum.expand-media.hide" = "Alle ausblenden"; "enum.expand-media.hide" = "Alle ausblenden";

View file

@ -157,7 +157,7 @@
"settings.haptic.buttons" = "Appui bouton"; "settings.haptic.buttons" = "Appui bouton";
"settings.display.section.ipad" = "iPad"; "settings.display.section.ipad" = "iPad";
"settings.display.show-ipad-column" = "Enable secondary column"; "settings.display.show-ipad-column" = "Activer la colonne secondaire";
// MARK: Tabs // MARK: Tabs
"tab.explore" = "Explorer"; "tab.explore" = "Explorer";

View file

@ -157,7 +157,7 @@
"settings.haptic.buttons" = "Naciśnięcie przycisku"; "settings.haptic.buttons" = "Naciśnięcie przycisku";
"settings.display.section.ipad" = "iPad"; "settings.display.section.ipad" = "iPad";
"settings.display.show-ipad-column" = "Enable secondary column"; "settings.display.show-ipad-column" = "Włącz dodatkową kolumnę";
// MARK: Tabs // MARK: Tabs
"tab.explore" = "Odkrywaj"; "tab.explore" = "Odkrywaj";

View file

@ -13,8 +13,8 @@ public struct HTMLString: Codable, Equatable, Hashable {
public var statusesURLs = [URL]() public var statusesURLs = [URL]()
public var asSafeMarkdownAttributedString: AttributedString = .init() public var asSafeMarkdownAttributedString: AttributedString = .init()
private var regex: NSRegularExpression? private var main_regex: NSRegularExpression?
private var underscore_regex: NSRegularExpression?
public init(from decoder: Decoder) { public init(from decoder: Decoder) {
var alreadyDecoded: Bool = false var alreadyDecoded: Bool = false
do { do {
@ -38,7 +38,9 @@ public struct HTMLString: Codable, Equatable, Hashable {
// Pre-escape \ ` _ * and [ as these are the only // Pre-escape \ ` _ * and [ as these are the only
// characters the markdown parser used picks up // characters the markdown parser used picks up
// when it renders to attributed text // when it renders to attributed text
regex = try? NSRegularExpression(pattern: "([\\_\\*\\`\\[\\\\])", options: .caseInsensitive) main_regex = try? NSRegularExpression(pattern: "([\\*\\`\\[\\\\])", options: .caseInsensitive)
// don't escape underscores that are between colons, they are most likely custom emoji
underscore_regex = try? NSRegularExpression(pattern: "(?!\\B:[^:]*)(_)(?![^:]*:\\B)", options: .caseInsensitive)
asMarkdown = "" asMarkdown = ""
do { do {
@ -150,9 +152,10 @@ public struct HTMLString: Codable, Equatable, Hashable {
} else if node.nodeName() == "#text" { } else if node.nodeName() == "#text" {
var txt = node.description var txt = node.description
if let regex { if let underscore_regex, let main_regex {
// This is the markdown escaper // This is the markdown escaper
txt = regex.stringByReplacingMatches(in: txt, options: [], range: NSRange(location: 0, length: txt.count), withTemplate: "\\\\$1") txt = main_regex.stringByReplacingMatches(in: txt, options: [], range: NSRange(location: 0, length: txt.count), withTemplate: "\\\\$1")
txt = underscore_regex.stringByReplacingMatches(in: txt, options: [], range: NSRange(location: 0, length: txt.count), withTemplate: "\\\\$1")
} }
asMarkdown += txt asMarkdown += txt