Trim whitespace at the end of messages (#2169)

Trim whitespace at the end of messages
This commit is contained in:
Jorge Martin Espinosa 2024-01-05 12:40:10 +01:00 committed by GitHub
parent 936127c682
commit 0e3f0ac6b5
3 changed files with 42 additions and 29 deletions

View file

@ -32,7 +32,11 @@ import org.jsoup.nodes.Document
* @param prefix if not null, the prefix will be inserted at the beginning of the message.
*/
fun FormattedBody.toHtmlDocument(prefix: String? = null): Document? {
return takeIf { it.format == MessageFormat.HTML }?.body?.let { formattedBody ->
return takeIf { it.format == MessageFormat.HTML }?.body
// Trim whitespace at the end to avoid having wrong rendering of the message.
// We don't trim the start in case it's used as indentation.
?.trimEnd()
?.let { formattedBody ->
val dom = if (prefix != null) {
Jsoup.parse("$prefix $formattedBody")
} else {