mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-26 17:14:59 +01:00
parent
734602f4f7
commit
b40334f7db
@ -22,6 +22,7 @@ Improvements 🙌:
|
|||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
- Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252)
|
- 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)
|
- Search Result | scroll jumps after pagination (#2238)
|
||||||
|
- Badly formatted mentions in body (#1506)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
@ -90,8 +90,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||||||
|
|
||||||
private fun createTextContent(text: CharSequence, autoMarkdown: Boolean): TextContent {
|
private fun createTextContent(text: CharSequence, autoMarkdown: Boolean): TextContent {
|
||||||
if (autoMarkdown) {
|
if (autoMarkdown) {
|
||||||
val source = textPillsUtils.processSpecialSpansToMarkdown(text) ?: text.toString()
|
return markdownParser.parse(text)
|
||||||
return markdownParser.parse(source)
|
|
||||||
} else {
|
} else {
|
||||||
// Try to detect pills
|
// Try to detect pills
|
||||||
textPillsUtils.processSpecialSpansToHtml(text)?.let {
|
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.parser.Parser
|
||||||
import org.commonmark.renderer.html.HtmlRenderer
|
import org.commonmark.renderer.html.HtmlRenderer
|
||||||
|
import org.matrix.android.sdk.internal.session.room.send.pills.TextPillsUtils
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,18 +28,21 @@ import javax.inject.Inject
|
|||||||
*/
|
*/
|
||||||
internal class MarkdownParser @Inject constructor(
|
internal class MarkdownParser @Inject constructor(
|
||||||
private val parser: Parser,
|
private val parser: Parser,
|
||||||
private val htmlRenderer: HtmlRenderer
|
private val htmlRenderer: HtmlRenderer,
|
||||||
|
private val textPillsUtils: TextPillsUtils
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val mdSpecialChars = "[`_\\-*>.\\[\\]#~]".toRegex()
|
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 no special char are detected, just return plain text
|
||||||
if (text.contains(mdSpecialChars).not()) {
|
if (source.contains(mdSpecialChars).not()) {
|
||||||
return TextContent(text)
|
return TextContent(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
val document = parser.parse(text)
|
val document = parser.parse(source)
|
||||||
val htmlText = htmlRenderer.render(document)
|
val htmlText = htmlRenderer.render(document)
|
||||||
|
|
||||||
// Cleanup extra paragraph
|
// Cleanup extra paragraph
|
||||||
@ -48,13 +52,14 @@ internal class MarkdownParser @Inject constructor(
|
|||||||
htmlText
|
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:
|
// 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.
|
// 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
|
// 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 {
|
} else {
|
||||||
TextContent(text)
|
TextContent(source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user