Kommentare, Toolbar, Editorfenster

This commit is contained in:
2026-03-21 18:42:53 +01:00
parent 8b57d8ff61
commit da22b50ae4
+20
View File
@@ -0,0 +1,20 @@
import Foundation
extension String {
/// Strips HTML tags and decodes common HTML entities for plain-text display.
var strippingHTML: String {
// Use NSAttributedString to parse HTML handles entities and nested tags correctly
guard let data = data(using: .utf8),
let attributed = try? NSAttributedString(
data: data,
options: [.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue],
documentAttributes: nil)
else {
// Fallback: remove tags with regex
return replacingOccurrences(of: "<[^>]+>", with: "", options: .regularExpression)
.trimmingCharacters(in: .whitespacesAndNewlines)
}
return attributed.string.trimmingCharacters(in: .whitespacesAndNewlines)
}
}