Add comments for the EventHtmlRenderer file

This commit is contained in:
Cadence Ember 2022-07-04 01:07:38 +12:00
parent 84bb11c1bf
commit a53ad39e1a
1 changed files with 16 additions and 1 deletions

View File

@ -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("""<span\s+data-mx-maths="([^"]*)">.*?</span>""")) { 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())
}
})