Add new test for complex checkbox list parsing, update parser to reset checkboxList correctly, and bump version to 1.0.11

This commit is contained in:
2026-01-16 09:46:58 +01:00
parent a10532d762
commit deb96c665e
3 changed files with 31 additions and 3 deletions

View File

@@ -8,7 +8,7 @@ plugins {
} }
group = "nl.astraeus" group = "nl.astraeus"
version = "1.0.10" version = "1.0.11"
repositories { repositories {
mavenCentral() mavenCentral()

View File

@@ -20,7 +20,7 @@ fun markdown(text: String): List<MarkdownPart> {
var index = 0 var index = 0
val buffer = StringBuilder() val buffer = StringBuilder()
val checkboxList = mutableListOf<CheckboxItem>() var checkboxList = mutableListOf<CheckboxItem>()
fun parseBuffer() { fun parseBuffer() {
if (buffer.isNotBlank()) { if (buffer.isNotBlank()) {
@@ -59,7 +59,7 @@ fun markdown(text: String): List<MarkdownPart> {
addCheckbox(checkboxList, checkboxLine, buffer) addCheckbox(checkboxList, checkboxLine, buffer)
} }
parts.add(MarkdownPart.CheckboxList(checkboxList)) parts.add(MarkdownPart.CheckboxList(checkboxList))
checkboxList.clear() checkboxList = mutableListOf()
parseBuffer() parseBuffer()
continue continue
} else if (line.startsWith("- [ ]") || line.startsWith("- [x]")) { } else if (line.startsWith("- [ ]") || line.startsWith("- [x]")) {

View File

@@ -156,6 +156,34 @@ class ParseTest {
printMarkdownParts(md) printMarkdownParts(md)
} }
@Test
fun testCheckboxList3() {
val input = """
Dit is een text
- [ ] Not checked,
with some more text here
- [x] Checked!
- [x] Checked,
text it!
Nog 1:
- [ ] Not checked,
with some more text here
- [x] Checked!
- [x] Checked,
text it!
Meer text
""".trimIndent()
val md = markdown(input)
printMarkdownParts(md)
}
@Test @Test
fun testCheckboxListError() { fun testCheckboxListError() {