Inline images: data-mx-emoticon height override

Change-Id: I3f1ab2aff5b17635600d76f4ca41fc539359b1ce
This commit is contained in:
SpiritCroc 2022-05-05 09:54:21 +02:00
parent 3c702b7230
commit 04cc69c206

View file

@ -67,6 +67,11 @@ class EventHtmlRenderer @Inject constructor(
fun afterRender(renderedText: Spannable)
}
private fun String.removeHeightWidthAttrs(): String {
return replace(Regex("""height="([^"]*)""""), "")
.replace(Regex("""width="([^"]*)""""), "")
}
private fun buildMarkwon() = Markwon.builder(context)
.usePlugins(listOf(
HtmlPlugin.create(htmlConfigure),
@ -78,6 +83,15 @@ class EventHtmlRenderer @Inject constructor(
.blockQuoteColor(quoteBarColor)
}
},
object : AbstractMarkwonPlugin() { // Overwrite height for data-mx-emoticon, to ensure emoji-like height
override fun processMarkdown(markdown: String): String {
return markdown
.replace(Regex("""<img\s+([^>]*)data-mx-emoticon([^>]*)>""")) { matchResult ->
"""<img height="1.2em" """ + matchResult.groupValues[1].removeHeightWidthAttrs() +
" data-mx-emoticon" + matchResult.groupValues[2].removeHeightWidthAttrs() + ">"
}
}
},
GlideImagesPlugin.create(object: GlideImagesPlugin.GlideStore {
override fun load(drawable: AsyncDrawable): RequestBuilder<Drawable> {
val url = drawable.destination