Inline images: Use alt text in room previews and notifications

Change-Id: I6649794d31582c3f5e6ab3e151a866663d4645ee
This commit is contained in:
SpiritCroc 2022-06-21 21:30:18 +02:00
parent 4ce1137d8e
commit 387d2e12bb

View file

@ -15,6 +15,7 @@
*/
package org.matrix.android.sdk.api.util
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.internal.util.unescapeHtml
object ContentUtils {
@ -53,6 +54,13 @@ object ContentUtils {
// can capture the spoiler reason for better formatting? ex. { reason = it.value; ">"}
return formattedBody.replace("(?<=<span data-mx-spoiler)=\\\".+?\\\">".toRegex(), ">")
.replace("(?<=<span data-mx-spoiler>).+?(?=</span>)".toRegex()) { SPOILER_CHAR.repeat(it.value.length) }
// Replace inline images with alt text
.replace(Regex("""<img(\s+[^>]*)>""")) { matchResult ->
tryOrNull {
val alt = Regex("""\s+alt="([^"]*)"""").find(matchResult.groupValues[1])
alt?.groupValues?.get(1)
} ?: ""
}
.unescapeHtml()
}