mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
parent
734602f4f7
commit
b40334f7db
3 changed files with 15 additions and 10 deletions
|
@ -22,6 +22,7 @@ Improvements 🙌:
|
|||
Bugfix 🐛:
|
||||
- Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252)
|
||||
- Search Result | scroll jumps after pagination (#2238)
|
||||
- Badly formatted mentions in body (#1506)
|
||||
|
||||
Translations 🗣:
|
||||
-
|
||||
|
|
|
@ -90,8 +90,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||
|
||||
private fun createTextContent(text: CharSequence, autoMarkdown: Boolean): TextContent {
|
||||
if (autoMarkdown) {
|
||||
val source = textPillsUtils.processSpecialSpansToMarkdown(text) ?: text.toString()
|
||||
return markdownParser.parse(source)
|
||||
return markdownParser.parse(text)
|
||||
} else {
|
||||
// Try to detect pills
|
||||
textPillsUtils.processSpecialSpansToHtml(text)?.let {
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.room.send
|
|||
|
||||
import org.commonmark.parser.Parser
|
||||
import org.commonmark.renderer.html.HtmlRenderer
|
||||
import org.matrix.android.sdk.internal.session.room.send.pills.TextPillsUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
|
@ -27,18 +28,21 @@ import javax.inject.Inject
|
|||
*/
|
||||
internal class MarkdownParser @Inject constructor(
|
||||
private val parser: Parser,
|
||||
private val htmlRenderer: HtmlRenderer
|
||||
private val htmlRenderer: HtmlRenderer,
|
||||
private val textPillsUtils: TextPillsUtils
|
||||
) {
|
||||
|
||||
private val mdSpecialChars = "[`_\\-*>.\\[\\]#~]".toRegex()
|
||||
|
||||
fun parse(text: String): TextContent {
|
||||
fun parse(text: CharSequence): TextContent {
|
||||
val source = textPillsUtils.processSpecialSpansToMarkdown(text) ?: text.toString()
|
||||
|
||||
// If no special char are detected, just return plain text
|
||||
if (text.contains(mdSpecialChars).not()) {
|
||||
return TextContent(text)
|
||||
if (source.contains(mdSpecialChars).not()) {
|
||||
return TextContent(source)
|
||||
}
|
||||
|
||||
val document = parser.parse(text)
|
||||
val document = parser.parse(source)
|
||||
val htmlText = htmlRenderer.render(document)
|
||||
|
||||
// Cleanup extra paragraph
|
||||
|
@ -48,13 +52,14 @@ internal class MarkdownParser @Inject constructor(
|
|||
htmlText
|
||||
}
|
||||
|
||||
return if (isFormattedTextPertinent(text, cleanHtmlText)) {
|
||||
return if (isFormattedTextPertinent(source, cleanHtmlText)) {
|
||||
// According to https://matrix.org/docs/spec/client_server/latest#m-room-message-msgtypes:
|
||||
// The plain text version of the HTML should be provided in the body.
|
||||
// But it caused too many problems so it has been removed in #2002
|
||||
TextContent(text, cleanHtmlText.postTreatment())
|
||||
// See #739
|
||||
TextContent(text.toString(), cleanHtmlText.postTreatment())
|
||||
} else {
|
||||
TextContent(text)
|
||||
TextContent(source)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue