Support data-mx-bg-color attribute on <font> tags in formatted messages.

Signed-off-by: Kestrel Williams-King <ethereal@ethv.net>
This commit is contained in:
ethereal 2020-09-07 00:57:54 -04:00
parent f019e4a246
commit 5fbcf348f5
2 changed files with 9 additions and 1 deletions

View file

@ -41,6 +41,7 @@ Build 🧱:
Other changes:
- Use File extension functions to make code more concise (#1996)
- Create a script to import SAS strings (#1909)
- Support `data-mx-bg-color` attribute on `<font>` tags.
Changes in Element 1.0.5 (2020-08-21)
===================================================

View file

@ -17,6 +17,7 @@ package im.vector.app.features.html
import android.graphics.Color
import android.text.style.ForegroundColorSpan
import android.text.style.BackgroundColorSpan
import io.noties.markwon.MarkwonConfiguration
import io.noties.markwon.RenderProps
import io.noties.markwon.html.HtmlTag
@ -31,7 +32,13 @@ class FontTagHandler : SimpleTagHandler() {
override fun getSpans(configuration: MarkwonConfiguration, renderProps: RenderProps, tag: HtmlTag): Any? {
val colorString = tag.attributes()["color"]?.let { parseColor(it) } ?: Color.BLACK
return ForegroundColorSpan(colorString)
val bgColor = tag.attributes()["data-mx-bg-color"]
if(bgColor == null) {
return ForegroundColorSpan(colorString)
}
else {
return arrayOf(ForegroundColorSpan(colorString), BackgroundColorSpan(bgColor.let { parseColor(it) }))
}
}
private fun parseColor(colorName: String): Int {