Merge pull request #231 from ouchadam/feature/blockquotes-formatting
Adding support for blockquotes and nested tags
This commit is contained in:
commit
1299d900c2
|
@ -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
|
||||
|
|
|
@ -10,8 +10,6 @@ internal class PartBuilder {
|
|||
private val parts = mutableListOf<RichText.Part>()
|
||||
|
||||
fun appendText(value: String) {
|
||||
println("append text")
|
||||
|
||||
normalBuffer.append(value.cleanFirstTextLine())
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue