From d7bfe5fb8115d8ffc7d5e9990531d94b5537d245 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 15 Jun 2021 17:39:35 +0800 Subject: [PATCH] fix: Kanna not convert line break tag "
" issue --- Mastodon/Helper/MastodonStatusContent.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Mastodon/Helper/MastodonStatusContent.swift b/Mastodon/Helper/MastodonStatusContent.swift index 391519e84..d338615df 100755 --- a/Mastodon/Helper/MastodonStatusContent.swift +++ b/Mastodon/Helper/MastodonStatusContent.swift @@ -17,7 +17,6 @@ enum MastodonStatusContent { static func parse(content: String, emojiDict: EmojiDict) throws -> MastodonStatusContent.ParseResult { let document: String = { var content = content - content = content.replacingOccurrences(of: "
", with: "\n") for (shortcode, url) in emojiDict { let emojiNode = "\(shortcode)" let pattern = ":\(shortcode):" @@ -189,6 +188,14 @@ extension MastodonStatusContent { static func parse(document: String) throws -> MastodonStatusContent.Node { let html = try HTML(html: document, encoding: .utf8) + + // add `\r\n` explicit due to Kanna text missing it after convert to text + // ref: https://github.com/tid-kijyun/Kanna/issues/150 + let brNodes = html.css("br").makeIterator() + while let brNode = brNodes.next() { + brNode.addNextSibling(try! HTML(html: "\r\n", encoding: .utf8).body!) + } + let body = html.body ?? nil let text = body?.text ?? "" let level = 0