mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 20:29:10 +03:00
Inline images: Use alt text in room previews and notifications
Change-Id: I6649794d31582c3f5e6ab3e151a866663d4645ee
This commit is contained in:
parent
4ce1137d8e
commit
387d2e12bb
1 changed files with 8 additions and 0 deletions
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue