mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-12-23 15:40:37 +00:00
Compose: Fix editing, now keep line breaks and link close #602
This commit is contained in:
parent
11b9346b0e
commit
86937e65fe
2 changed files with 12 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue