adding support for blockquotes

This commit is contained in:
Adam Brown 2022-10-31 18:25:38 +00:00
parent e5ae1495bc
commit 0fbef88c2d
3 changed files with 24 additions and 2 deletions

View File

@ -99,6 +99,25 @@ internal class HtmlParser {
exitTagCloseIndex exitTagCloseIndex
} }
"blockquote" -> {
if (tagContent.isNotEmpty() && nestingLevel < 3) {
var lastIndex = 0
val trimmedTagContent = tagContent.trim()
builder.appendText("> ")
iterateSearchIndex { searchIndex ->
lastIndex = searchIndex
parseHtmlTags(trimmedTagContent, searchIndex, builder, nestingLevel = nestingLevel + 1)
}
if (lastIndex < trimmedTagContent.length) {
builder.appendText(trimmedTagContent.substring(lastIndex))
}
}
builder.appendNewline()
exitTagCloseIndex
}
"p" -> { "p" -> {
if (tagContent.isNotEmpty() && nestingLevel < 2) { if (tagContent.isNotEmpty() && nestingLevel < 2) {
var lastIndex = 0 var lastIndex = 0

View File

@ -10,8 +10,6 @@ internal class PartBuilder {
private val parts = mutableListOf<RichText.Part>() private val parts = mutableListOf<RichText.Part>()
fun appendText(value: String) { fun appendText(value: String) {
println("append text")
normalBuffer.append(value.cleanFirstTextLine()) normalBuffer.append(value.cleanFirstTextLine())
} }

View File

@ -84,6 +84,11 @@ class RichMessageParserTest {
expected = RichText(listOf(Normal("Hello world!\nnext line\nanother line"))) expected = RichText(listOf(Normal("Hello world!\nnext line\nanother line")))
) )
@Test
fun `parses blockquote tags`() = runParserTest(
input = "<blockquote>\n<p><strong>hello</strong> <em>world</em></p>\n</blockquote>\n",
expected = RichText(listOf(Normal("> "), Bold("hello"), Normal(" "), Italic("world")))
)
@Test @Test
fun `parses lists`() = runParserTest( fun `parses lists`() = runParserTest(