Skip to content

Commit 13fce9b

Browse files
committed
Bump markwon version and enable LaTeX rendering for messages
1 parent 9298ca9 commit 13fce9b

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

vector/build.gradle

+4-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ dependencies {
283283
def epoxy_version = '4.1.0'
284284
def fragment_version = '1.3.0-beta01'
285285
def arrow_version = "0.8.2"
286-
def markwon_version = '4.1.2'
286+
def coroutines_version = "1.3.8"
287+
def markwon_version = '4.3.0'
287288
def big_image_viewer_version = '1.6.2'
288289
def glide_version = '4.11.0'
289290
def moshi_version = '1.11.0'
@@ -365,6 +366,8 @@ dependencies {
365366
implementation 'com.google.android.material:material:1.3.0-alpha02'
366367
implementation 'me.gujun.android:span:1.7'
367368
implementation "io.noties.markwon:core:$markwon_version"
369+
implementation "io.noties.markwon:ext-latex:$markwon_version"
370+
implementation "io.noties.markwon:inline-parser:$markwon_version"
368371
implementation "io.noties.markwon:html:$markwon_version"
369372
implementation 'com.googlecode.htmlcompressor:htmlcompressor:1.4'
370373
implementation 'me.saket:better-link-movement-method:2.2.0'

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt

+1
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ class MessageItemFactory @Inject constructor(
414414
}
415415
}
416416
.useBigFont(linkifiedBody.length <= MAX_NUMBER_OF_EMOJI_FOR_BIG_FONT * 2 && containsOnlyEmojis(linkifiedBody.toString()))
417+
.markwonPlugins(htmlRenderer.get().plugins)
417418
.searchForPills(isFormatted)
418419
.leftGuideline(avatarSizeProvider.leftGuideline)
419420
.attributes(attributes)

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package im.vector.app.features.home.room.detail.timeline.item
1818

19+
import android.text.Spanned
1920
import android.text.method.MovementMethod
2021
import androidx.appcompat.widget.AppCompatTextView
2122
import androidx.core.text.PrecomputedTextCompat
@@ -24,6 +25,7 @@ import com.airbnb.epoxy.EpoxyAttribute
2425
import com.airbnb.epoxy.EpoxyModelClass
2526
import im.vector.app.R
2627
import im.vector.app.features.home.room.detail.timeline.tools.findPillsAndProcess
28+
import io.noties.markwon.MarkwonPlugin
2729

2830
@EpoxyModelClass(layout = R.layout.item_timeline_event_base)
2931
abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
@@ -39,6 +41,8 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
3941

4042
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
4143
var movementMethod: MovementMethod? = null
44+
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
45+
var markwonPlugins: (List<MarkwonPlugin>)? = null
4246

4347
override fun bind(holder: Holder) {
4448
super.bind(holder)
@@ -54,11 +58,13 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
5458
if (searchForPills) {
5559
message?.findPillsAndProcess(coroutineScope) { it.bind(holder.messageView) }
5660
}
61+
markwonPlugins?.forEach { plugin -> plugin.beforeSetText(holder.messageView, message as Spanned) }
5762
val textFuture = PrecomputedTextCompat.getTextFuture(
5863
message ?: "",
5964
TextViewCompat.getTextMetricsParams(holder.messageView),
6065
null)
6166
holder.messageView.setTextFuture(textFuture)
67+
markwonPlugins?.forEach { plugin -> plugin.afterSetText(holder.messageView) }
6268
}
6369

6470
override fun getViewType() = STUB_ID

vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt

+11
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ import im.vector.app.core.glide.GlideApp
2222
import im.vector.app.core.resources.ColorProvider
2323
import im.vector.app.features.home.AvatarRenderer
2424
import io.noties.markwon.Markwon
25+
import io.noties.markwon.MarkwonPlugin
26+
import io.noties.markwon.ext.latex.JLatexMathPlugin
27+
import io.noties.markwon.ext.latex.JLatexMathTheme
2528
import io.noties.markwon.html.HtmlPlugin
2629
import io.noties.markwon.html.TagHandlerNoOp
30+
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin
2731
import org.commonmark.node.Node
2832
import timber.log.Timber
2933
import javax.inject.Inject
@@ -35,8 +39,15 @@ class EventHtmlRenderer @Inject constructor(context: Context,
3539

3640
private val markwon = Markwon.builder(context)
3741
.usePlugin(HtmlPlugin.create(htmlConfigure))
42+
.usePlugin(MarkwonInlineParserPlugin.create())
43+
.usePlugin(JLatexMathPlugin.create(44F) { builder ->
44+
builder.inlinesEnabled(true)
45+
builder.theme().inlinePadding(JLatexMathTheme.Padding.symmetric(24, 8))
46+
})
3847
.build()
3948

49+
val plugins: List<MarkwonPlugin> = markwon.plugins
50+
4051
fun parse(text: String): Node {
4152
return markwon.parse(text)
4253
}

0 commit comments

Comments
 (0)