Skip to content

Commit

Permalink
Merge pull request #231 from ouchadam/feature/blockquotes-formatting
Browse files Browse the repository at this point in the history
Adding support for blockquotes and nested tags
  • Loading branch information
ouchadam authored Oct 31, 2022
2 parents e5ae149 + 0fbef88 commit 1299d90
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ internal class PartBuilder {
private val parts = mutableListOf<RichText.Part>()

fun appendText(value: String) {
println("append text")

normalBuffer.append(value.cleanFirstTextLine())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1299d90

Please sign in to comment.