From a53ad39e1adcf1b799d864f26f3818c616ceb1f7 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 4 Jul 2022 01:07:38 +1200 Subject: [PATCH] Add comments for the EventHtmlRenderer file --- .../app/features/html/EventHtmlRenderer.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 8ea8bf1762..ed6b68e04a 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 @@ -14,6 +14,15 @@ * limitations under the License. */ +/* + * This file renders the formatted_body of an event to a formatted Android Spannable. + * The core of this work is done with Markwon, a general-purpose Markdown+HTML formatter. + * Since formatted_body is HTML only, Markwon is configured to only handle HTML, not Markdown. + * The EventHtmlRenderer class is next used in the method buildFormattedTextItem + * in the file MessageItemFactory.kt. + * Effectively, this is used in the chat messages view and the room list message previews. + */ + package im.vector.app.features.html import android.content.Context @@ -30,6 +39,7 @@ import io.noties.markwon.PrecomputedFutureTextSetterCompat import io.noties.markwon.ext.latex.JLatexMathPlugin import io.noties.markwon.ext.latex.JLatexMathTheme import io.noties.markwon.html.HtmlPlugin +import io.noties.markwon.inlineparser.EntityInlineProcessor import io.noties.markwon.inlineparser.HtmlInlineProcessor import io.noties.markwon.inlineparser.MarkwonInlineParser import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin @@ -54,8 +64,10 @@ class EventHtmlRenderer @Inject constructor( .usePlugin(HtmlPlugin.create(htmlConfigure)) private val markwon = if (vectorPreferences.latexMathsIsEnabled()) { + // If latex maths is enabled in app preferences, refomat it so Markwon recognises it + // It needs to be in this specific format: https://noties.io/Markwon/docs/v4/ext-latex builder - .usePlugin(object : AbstractMarkwonPlugin() { // Markwon expects maths to be in a specific format: https://noties.io/Markwon/docs/v4/ext-latex + .usePlugin(object : AbstractMarkwonPlugin() { override fun processMarkdown(markdown: String): String { return markdown .replace(Regex(""".*?""")) { matchResult -> @@ -86,6 +98,9 @@ class EventHtmlRenderer @Inject constructor( ) .usePlugin(object : AbstractMarkwonPlugin() { override fun configureParser(builder: Parser.Builder) { + /* Configuring the Markwon block formatting processor. + * Default settings are all Markdown blocks. Turn those off. + */ builder.enabledBlockTypes(kotlin.collections.emptySet()) } })