From 29123ac726efbf64fa04339246a2f6be5f6a2eb8 Mon Sep 17 00:00:00 2001 From: Leon Schmidt <50419884+MexHigh@users.noreply.github.com> Date: Tue, 1 Sep 2020 22:02:16 +0200 Subject: [PATCH] Bugfix/markdown parsing (#2002) Removed replacing of newlines in already parsed HTML documents Signed-off-by: Leon Schmidt Co-authored-by: Benoit Marty --- CHANGES.md | 1 + .../internal/session/room/send/MarkdownParser.kt | 16 ++-------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9a41f3c4ef..86b796869e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Improvements 🙌: Bugfix 🐛: - Display name not shown under Settings/General (#1926) + - Wrong markdown parsing (#350, #1375, #1939, #1982) - Words containing my name should not trigger notifications (#1781) - Fix changing language issue - Fix FontSize issue (#1483, #1787) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParser.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParser.kt index 3390d9dc79..233ba9bc42 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParser.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParser.kt @@ -33,7 +33,7 @@ internal class MarkdownParser @Inject constructor( private val textContentRenderer: TextContentRenderer ) { - private val mdSpecialChars = "[`_\\-\\*>\\.\\[\\]#~]".toRegex() + private val mdSpecialChars = "[`_\\-*>.\\[\\]#~]".toRegex() fun parse(text: String): TextContent { // If no special char are detected, just return plain text @@ -54,8 +54,7 @@ internal class MarkdownParser @Inject constructor( return if (isFormattedTextPertinent(text, cleanHtmlText)) { // According to https://matrix.org/docs/spec/client_server/latest#m-room-message-msgtypes: // The plain text version of the HTML should be provided in the body. - val plainText = textContentRenderer.render(document) - TextContent(plainText, cleanHtmlText.postTreatment()) + TextContent(text, cleanHtmlText.trim()) } else { TextContent(text) } @@ -63,15 +62,4 @@ internal class MarkdownParser @Inject constructor( private fun isFormattedTextPertinent(text: String, htmlText: String?) = text != htmlText && htmlText != "

${text.trim()}

\n" - - /** - * The parser makes some mistakes, so deal with it here - */ - private fun String.postTreatment(): String { - return this - // Remove extra space before and after the content - .trim() - // There is no need to include new line in an html-like source - .replace("\n", "") - } }