mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Reply: remove inner tags when replying
This commit is contained in:
parent
aa5de1896f
commit
794b89c041
3 changed files with 22 additions and 7 deletions
|
@ -178,7 +178,8 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||
permalink,
|
||||
userLink,
|
||||
originalEvent.senderInfo.disambiguatedDisplayName,
|
||||
body.takeFormatted(),
|
||||
// Remove inner mx_reply tags if any
|
||||
body.takeFormatted().replace(MX_REPLY_REGEX, ""),
|
||||
createTextContent(newBodyText, newBodyAutoMarkdown).takeFormatted()
|
||||
)
|
||||
//
|
||||
|
@ -372,7 +373,8 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||
permalink,
|
||||
userLink,
|
||||
userId,
|
||||
body.takeFormatted(),
|
||||
// Remove inner mx_reply tags if any
|
||||
body.takeFormatted().replace(MX_REPLY_REGEX, ""),
|
||||
createTextContent(replyText, autoMarkdown).takeFormatted()
|
||||
)
|
||||
//
|
||||
|
@ -485,5 +487,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||
// </mx-reply>
|
||||
// No whitespace because currently breaks temporary formatted text to Span
|
||||
const val REPLY_PATTERN = """<mx-reply><blockquote><a href="%s">In reply to</a> <a href="%s">%s</a><br />%s</blockquote></mx-reply>%s"""
|
||||
// This is used to replace inner mx-reply tags
|
||||
val MX_REPLY_REGEX = "<mx-reply>.*</mx-reply>".toRegex()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -353,11 +353,11 @@ class MessageItemFactory @Inject constructor(
|
|||
codeVisitor.visit(localFormattedBody)
|
||||
when (codeVisitor.codeKind) {
|
||||
CodeVisitor.Kind.BLOCK -> {
|
||||
val codeFormattedBlock = htmlRenderer.get().render(localFormattedBody)
|
||||
val codeFormattedBlock = htmlRenderer.get().render(localFormattedBody) ?: messageContent.formattedBody!!
|
||||
buildCodeBlockItem(codeFormattedBlock, informationData, highlight, callback, attributes)
|
||||
}
|
||||
CodeVisitor.Kind.INLINE -> {
|
||||
val codeFormatted = htmlRenderer.get().render(localFormattedBody)
|
||||
val codeFormatted = htmlRenderer.get().render(localFormattedBody)?: messageContent.formattedBody!!
|
||||
buildMessageTextItem(codeFormatted, false, informationData, highlight, callback, attributes)
|
||||
}
|
||||
CodeVisitor.Kind.NONE -> {
|
||||
|
|
|
@ -25,6 +25,7 @@ import io.noties.markwon.Markwon
|
|||
import io.noties.markwon.html.HtmlPlugin
|
||||
import io.noties.markwon.html.TagHandlerNoOp
|
||||
import org.commonmark.node.Node
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -41,11 +42,21 @@ class EventHtmlRenderer @Inject constructor(context: Context,
|
|||
}
|
||||
|
||||
fun render(text: String): CharSequence {
|
||||
return markwon.toMarkdown(text)
|
||||
return try {
|
||||
markwon.toMarkdown(text)
|
||||
}catch (failure: Throwable){
|
||||
Timber.v("Fail to render $text to html")
|
||||
text
|
||||
}
|
||||
}
|
||||
|
||||
fun render(node: Node): CharSequence {
|
||||
return markwon.render(node)
|
||||
fun render(node: Node): CharSequence? {
|
||||
return try {
|
||||
markwon.render(node)
|
||||
}catch (failure: Throwable){
|
||||
Timber.v("Fail to render $node to html")
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue