Fix toPlainText where <ol start='n'> tags appear (#5044)
This commit is contained in:
parent
7f65075bbd
commit
760ff51061
2 changed files with 31 additions and 2 deletions
|
|
@ -57,10 +57,16 @@ private class PlainTextNodeVisitor : NodeVisitor {
|
|||
if (node is TextNode && node.text().isNotBlank()) {
|
||||
builder.append(node.text())
|
||||
} else if (node is Element && node.tagName() == "li") {
|
||||
val index = node.elementSiblingIndex()
|
||||
val index = node.elementSiblingIndex() + 1
|
||||
val isOrdered = node.parent()?.nodeName()?.lowercase() == "ol"
|
||||
if (isOrdered) {
|
||||
builder.append("${index + 1}. ")
|
||||
val startIndex = node.parent()?.attr("start")?.toIntOrNull()
|
||||
val actualIndex = if (startIndex != null) {
|
||||
startIndex + index - 1
|
||||
} else {
|
||||
index
|
||||
}
|
||||
builder.append("$actualIndex. ")
|
||||
} else {
|
||||
builder.append("• ")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,6 +96,29 @@ class ToPlainTextTest {
|
|||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `TextMessageType toPlainText - respects the ol start attr if present`() {
|
||||
val messageType = TextMessageType(
|
||||
body = "1. First item\n2. Second item\n",
|
||||
formatted = FormattedBody(
|
||||
format = MessageFormat.HTML,
|
||||
body = """
|
||||
<ol start='11'>
|
||||
<li>First item.</li>
|
||||
<li>Second item.</li>
|
||||
</ol>
|
||||
<br />
|
||||
""".trimIndent()
|
||||
)
|
||||
)
|
||||
assertThat(messageType.toPlainText(permalinkParser = FakePermalinkParser())).isEqualTo(
|
||||
"""
|
||||
11. First item.
|
||||
12. Second item.
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `TextMessageType toPlainText - returns the markdown body if the formatted one cannot be parsed`() {
|
||||
val messageType = TextMessageType(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue