diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/HtmlParser.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/HtmlParser.kt index f9e2e0f..c7b1ece 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/HtmlParser.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/HtmlParser.kt @@ -73,7 +73,7 @@ internal class HtmlParser { } } - "b" -> { + "b", "strong" -> { builder.appendBold(tagContent) exitTagCloseIndex } @@ -81,21 +81,16 @@ internal class HtmlParser { "p" -> { builder.appendText(tagContent) builder.appendNewline() + exitTagCloseIndex + } + + "h1", "h2", "h3", "h4", "h5" -> { + builder.appendBold(tagContent) builder.appendNewline() exitTagCloseIndex } - "strong" -> { - builder.appendBold(tagContent) - exitTagCloseIndex - } - - "i" -> { - builder.appendItalic(tagContent) - exitTagCloseIndex - } - - "em" -> { + "i", "em" -> { builder.appendItalic(tagContent) exitTagCloseIndex } diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/PartBuilder.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/PartBuilder.kt index ab34699..3fd60bb 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/PartBuilder.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/PartBuilder.kt @@ -37,6 +37,14 @@ internal class PartBuilder { fun build(): Set { flushNormalBuffer() + val last = parts.last() + if (last is RichText.Part.Normal) { + parts.remove(last) + val newContent = last.content.trimEnd() + if (newContent.isNotEmpty()) { + parts.add(last.copy(content = newContent)) + } + } return parts } diff --git a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RichMessageParserTest.kt b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RichMessageParserTest.kt index 7f8f01e..13e8649 100644 --- a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RichMessageParserTest.kt +++ b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RichMessageParserTest.kt @@ -21,7 +21,7 @@ class RichMessageParserTest { @Test fun `parses p tags`() = runParserTest( input = "

Hello world!

foo bar

after paragraph", - expected = RichText(setOf(Normal("Hello world!\n\nfoo bar\n\nafter paragraph"))) + expected = RichText(setOf(Normal("Hello world!\nfoo bar\nafter paragraph"))) ) @Test @@ -49,18 +49,22 @@ class RichMessageParserTest { ) @Test - fun `skips header tags`() = runParserTest( + fun `parses header tags`() = runParserTest( Case( input = "

hello

", - expected = RichText(setOf(Normal("hello"))) + expected = RichText(setOf(Bold("hello"))) + ), + Case( + input = "

hello

text after title", + expected = RichText(setOf(Bold("hello"), Normal("\ntext after title"))) ), Case( input = "

hello

", - expected = RichText(setOf(Normal("hello"))) + expected = RichText(setOf(Bold("hello"))) ), Case( input = "

hello

", - expected = RichText(setOf(Normal("hello"))) + expected = RichText(setOf(Bold("hello"))) ), )