generated from rnentjes/kotlin-server-web-empty
Add test for unordered list indentation, enhance parser to handle nested lists with indentation, and bump version to 1.1.0
This commit is contained in:
@@ -8,7 +8,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "nl.astraeus"
|
group = "nl.astraeus"
|
||||||
version = "1.0.11"
|
version = "1.1.0"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ sealed class MarkdownPart {
|
|||||||
) : MarkdownPart()
|
) : MarkdownPart()
|
||||||
|
|
||||||
data class UnorderedList(
|
data class UnorderedList(
|
||||||
val lines: List<String>,
|
val lines: List<Pair<Int, String>>,
|
||||||
) : MarkdownPart()
|
) : MarkdownPart()
|
||||||
|
|
||||||
data class CheckboxList(
|
data class CheckboxList(
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ fun markdown(text: String): List<MarkdownPart> {
|
|||||||
continue
|
continue
|
||||||
} else if (line.startsWith("- ") || line.startsWith("* ")) {
|
} else if (line.startsWith("- ") || line.startsWith("* ")) {
|
||||||
buffer.append("\n")
|
buffer.append("\n")
|
||||||
buffer.append(line.substring(2))
|
buffer.append(rawLine)
|
||||||
} else {
|
} else {
|
||||||
buffer.append(" ")
|
buffer.append(" ")
|
||||||
buffer.append(line)
|
buffer.append(line)
|
||||||
@@ -146,7 +146,7 @@ fun markdown(text: String): List<MarkdownPart> {
|
|||||||
line.startsWith("- ") || line.startsWith("* ") -> {
|
line.startsWith("- ") || line.startsWith("* ") -> {
|
||||||
parseBuffer()
|
parseBuffer()
|
||||||
type = MarkdownType.UNORDERED_LIST
|
type = MarkdownType.UNORDERED_LIST
|
||||||
buffer.append(line.substring(2))
|
buffer.append(rawLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
line.startsWith("|") -> {
|
line.startsWith("|") -> {
|
||||||
@@ -220,6 +220,16 @@ private fun addCheckbox(
|
|||||||
buffer.clear()
|
buffer.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.countSpaces(): Int {
|
||||||
|
var count = 0
|
||||||
|
|
||||||
|
while (count < this.length && this[count] == ' ') {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleBuffer(
|
private fun handleBuffer(
|
||||||
type: MarkdownType,
|
type: MarkdownType,
|
||||||
text: String,
|
text: String,
|
||||||
@@ -242,7 +252,14 @@ private fun handleBuffer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
MarkdownType.UNORDERED_LIST -> {
|
MarkdownType.UNORDERED_LIST -> {
|
||||||
listOf(MarkdownPart.UnorderedList(text.lines()))
|
val lines = text.lines()
|
||||||
|
val list = mutableListOf<Pair<Int, String>>()
|
||||||
|
|
||||||
|
for (line in lines) {
|
||||||
|
val indent: Int = line.countSpaces()
|
||||||
|
list.add((indent / 2) to line.substring(indent + 2))
|
||||||
|
}
|
||||||
|
listOf(MarkdownPart.UnorderedList(list))
|
||||||
}
|
}
|
||||||
|
|
||||||
MarkdownType.CHECKBOX_LIST -> {
|
MarkdownType.CHECKBOX_LIST -> {
|
||||||
|
|||||||
@@ -86,6 +86,26 @@ class ParseTest {
|
|||||||
printMarkdownParts(md)
|
printMarkdownParts(md)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testUnorderedListIndentation() {
|
||||||
|
val input = """
|
||||||
|
Dit is een text
|
||||||
|
|
||||||
|
* First
|
||||||
|
More text
|
||||||
|
* Second
|
||||||
|
More text
|
||||||
|
* Sub 1
|
||||||
|
* Sub 2
|
||||||
|
|
||||||
|
Another paragraph
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
val md = markdown(input)
|
||||||
|
|
||||||
|
printMarkdownParts(md)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOrderedList() {
|
fun testOrderedList() {
|
||||||
val input = """
|
val input = """
|
||||||
|
|||||||
Reference in New Issue
Block a user