From a31a9ab5219cfab3df6ce9b735253e980cb81631 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 17 Nov 2022 13:32:53 +0300 Subject: [PATCH 1/3] Fix italic text is truncated when bubble mode and markdown is enabled. --- .../im/vector/app/features/html/EventHtmlRenderer.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt index 9e869ecde1..9a2bdc791e 100644 --- a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt @@ -27,6 +27,7 @@ package im.vector.app.features.html import android.content.Context import android.content.res.Resources +import android.graphics.Typeface import android.graphics.drawable.Drawable import android.text.Spannable import androidx.core.text.toSpannable @@ -40,6 +41,7 @@ import im.vector.app.features.settings.VectorPreferences import io.noties.markwon.AbstractMarkwonPlugin import io.noties.markwon.Markwon import io.noties.markwon.MarkwonPlugin +import io.noties.markwon.MarkwonSpansFactory import io.noties.markwon.PrecomputedFutureTextSetterCompat import io.noties.markwon.ext.latex.JLatexMathPlugin import io.noties.markwon.ext.latex.JLatexMathTheme @@ -50,6 +52,8 @@ import io.noties.markwon.inlineparser.EntityInlineProcessor import io.noties.markwon.inlineparser.HtmlInlineProcessor import io.noties.markwon.inlineparser.MarkwonInlineParser import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin +import me.gujun.android.span.style.CustomTypefaceSpan +import org.commonmark.node.Emphasis import org.commonmark.node.Node import org.commonmark.parser.Parser import org.matrix.android.sdk.api.MatrixUrls.isMxcUrl @@ -94,6 +98,12 @@ class EventHtmlRenderer @Inject constructor( // It needs to be in this specific format: https://noties.io/Markwon/docs/v4/ext-latex builder .usePlugin(object : AbstractMarkwonPlugin() { + override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) { + builder.setFactory( + Emphasis::class.java + ) { _, _ -> CustomTypefaceSpan(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC)) } + } + override fun processMarkdown(markdown: String): String { return markdown .replace(Regex(""".*?""")) { matchResult -> From ab94b21807b01c9a30d9214fb1191b0a3db8743e Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 17 Nov 2022 15:58:42 +0300 Subject: [PATCH 2/3] Fix the place of the span factory. --- changelog.d/5679.bugfix | 1 + .../im/vector/app/features/html/EventHtmlRenderer.kt | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 changelog.d/5679.bugfix diff --git a/changelog.d/5679.bugfix b/changelog.d/5679.bugfix new file mode 100644 index 0000000000..0394bc3e5d --- /dev/null +++ b/changelog.d/5679.bugfix @@ -0,0 +1 @@ +Fix italic text is truncated when bubble mode and markdown is enabled diff --git a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt index 9a2bdc791e..21fcbffb03 100644 --- a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt @@ -98,12 +98,6 @@ class EventHtmlRenderer @Inject constructor( // It needs to be in this specific format: https://noties.io/Markwon/docs/v4/ext-latex builder .usePlugin(object : AbstractMarkwonPlugin() { - override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) { - builder.setFactory( - Emphasis::class.java - ) { _, _ -> CustomTypefaceSpan(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC)) } - } - override fun processMarkdown(markdown: String): String { return markdown .replace(Regex(""".*?""")) { matchResult -> @@ -133,6 +127,12 @@ class EventHtmlRenderer @Inject constructor( ) ) .usePlugin(object : AbstractMarkwonPlugin() { + override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) { + builder.setFactory( + Emphasis::class.java + ) { _, _ -> CustomTypefaceSpan(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC)) } + } + override fun configureParser(builder: Parser.Builder) { /* Configuring the Markwon block formatting processor. * Default settings are all Markdown blocks. Turn those off. From 7774f6931760badd4d4d47b6f701e7d177529bd1 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 18 Nov 2022 14:46:03 +0300 Subject: [PATCH 3/3] Fix unit test. --- .../src/androidTest/java/im/vector/app/core/utils/TestSpan.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vector/src/androidTest/java/im/vector/app/core/utils/TestSpan.kt b/vector/src/androidTest/java/im/vector/app/core/utils/TestSpan.kt index 9e23e76f0c..e31dc6942c 100644 --- a/vector/src/androidTest/java/im/vector/app/core/utils/TestSpan.kt +++ b/vector/src/androidTest/java/im/vector/app/core/utils/TestSpan.kt @@ -29,6 +29,7 @@ import io.mockk.verify import io.noties.markwon.core.spans.EmphasisSpan import io.noties.markwon.core.spans.OrderedListItemSpan import io.noties.markwon.core.spans.StrongEmphasisSpan +import me.gujun.android.span.style.CustomTypefaceSpan fun Spannable.toTestSpan(): String { var output = toString() @@ -54,7 +55,7 @@ private fun Any.readTags(): SpanTags { OrderedListItemSpan::class -> SpanTags("[list item]", "[/list item]") HtmlCodeSpan::class -> SpanTags("[code]", "[/code]") StrongEmphasisSpan::class -> SpanTags("[bold]", "[/bold]") - EmphasisSpan::class -> SpanTags("[italic]", "[/italic]") + EmphasisSpan::class, CustomTypefaceSpan::class -> SpanTags("[italic]", "[/italic]") else -> throw IllegalArgumentException("Unknown ${this::class}") } }