Merge pull request #231 from ouchadam/feature/blockquotes-formatting

Adding support for blockquotes and nested tags
This commit is contained in:
Adam Brown 2022-10-31 18:31:25 +00:00 committed by GitHub
commit 1299d900c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -99,6 +99,25 @@ internal class HtmlParser {
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" -> {
if (tagContent.isNotEmpty() && nestingLevel < 2) {
var lastIndex = 0

View File

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

View File

@ -84,6 +84,11 @@ class RichMessageParserTest {
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
fun `parses lists`() = runParserTest(