Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix italic text is truncated when bubble mode and markdown is enabled (PSG-1006) #7601

Merged
merged 3 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5679.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix italic text is truncated when bubble mode and markdown is enabled
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -123,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.
Expand Down