diff --git a/Packages/Models/Sources/Models/Alias/HTMLString.swift b/Packages/Models/Sources/Models/Alias/HTMLString.swift index b69e7cca..9dda2ef3 100644 --- a/Packages/Models/Sources/Models/Alias/HTMLString.swift +++ b/Packages/Models/Sources/Models/Alias/HTMLString.swift @@ -29,7 +29,17 @@ public struct HTMLString: Decodable, Equatable, Hashable { let document: Document = try SwiftSoup.parse(htmlValue) handleNode(node: document) - asRawText = try document.text() + document.outputSettings(OutputSettings().prettyPrint(pretty: false)) + try document.select("br").after("\n") + try document.select("p").after("\n\n") + let html = try document.html() + var text = try SwiftSoup.clean(html, "", Whitelist.none(), OutputSettings().prettyPrint(pretty: false)) ?? "" + // Remove the two last line break added after the last paragraph. + if text.hasSuffix("\n\n") { + _ = text.removeLast() + _ = text.removeLast() + } + asRawText = text } catch { asRawText = htmlValue } diff --git a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift index ed5f4a7d..4d85f0e5 100644 --- a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift +++ b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift @@ -232,7 +232,7 @@ public class StatusEditorViewModel: ObservableObject { selectedRange = .init(location: statusText.string.utf16.count, length: 0) markedTextRange = nil case let .edit(status): - var rawText = NSAttributedString(status.content.asSafeMarkdownAttributedString).string + var rawText = status.content.asRawText for mention in status.mentions { rawText = rawText.replacingOccurrences(of: "@\(mention.username)", with: "@\(mention.acct)") }