File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
main/kotlin/io/element/android/libraries/matrix/ui/messages
test/kotlin/io/element/android/libraries/matrix/ui/messages Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -57,10 +57,16 @@ private class PlainTextNodeVisitor : NodeVisitor {
57
57
if (node is TextNode && node.text().isNotBlank()) {
58
58
builder.append(node.text())
59
59
} else if (node is Element && node.tagName() == " li" ) {
60
- val index = node.elementSiblingIndex()
60
+ val index = node.elementSiblingIndex() + 1
61
61
val isOrdered = node.parent()?.nodeName()?.lowercase() == " ol"
62
62
if (isOrdered) {
63
- builder.append(" ${index + 1 } . " )
63
+ val startIndex = node.parent()?.attr(" start" )?.toIntOrNull()
64
+ val actualIndex = if (startIndex != null ) {
65
+ startIndex + index - 1
66
+ } else {
67
+ index
68
+ }
69
+ builder.append(" $actualIndex . " )
64
70
} else {
65
71
builder.append(" • " )
66
72
}
Original file line number Diff line number Diff line change @@ -96,6 +96,29 @@ class ToPlainTextTest {
96
96
)
97
97
}
98
98
99
+ @Test
100
+ fun `TextMessageType toPlainText - respects the ol start attr if present` () {
101
+ val messageType = TextMessageType (
102
+ body = " 1. First item\n 2. Second item\n " ,
103
+ formatted = FormattedBody (
104
+ format = MessageFormat .HTML ,
105
+ body = """
106
+ <ol start='11'>
107
+ <li>First item.</li>
108
+ <li>Second item.</li>
109
+ </ol>
110
+ <br />
111
+ """ .trimIndent()
112
+ )
113
+ )
114
+ assertThat(messageType.toPlainText(permalinkParser = FakePermalinkParser ())).isEqualTo(
115
+ """
116
+ 11. First item.
117
+ 12. Second item.
118
+ """ .trimIndent()
119
+ )
120
+ }
121
+
99
122
@Test
100
123
fun `TextMessageType toPlainText - returns the markdown body if the formatted one cannot be parsed` () {
101
124
val messageType = TextMessageType (
You can’t perform that action at this time.
0 commit comments