Updated the markdown parser with slightly better style for lists

master
Wynd 2025-11-09 23:13:10 +02:00
parent 3badc4889b
commit 7a3c9730a2
1 changed files with 13 additions and 2 deletions

View File

@ -56,6 +56,7 @@ private fun AnnotatedString.Builder.visitMarkdownNode(
style.toParagraphStyle().merge(ParagraphStyle(textAlign = TextAlign.Center)) style.toParagraphStyle().merge(ParagraphStyle(textAlign = TextAlign.Center))
) { ) {
withStyle(style.toSpanStyle().copy(color = headingColor)) { withStyle(style.toSpanStyle().copy(color = headingColor)) {
appendLine()
visitChildren(node, typography) visitChildren(node, typography)
appendLine() appendLine()
} }
@ -133,8 +134,15 @@ private fun AnnotatedString.Builder.visitMarkdownNode(
} }
is ListItem -> { is ListItem -> {
withStyle(ParagraphStyle(lineHeight = 18.sp)) { var newLine = false
var indent = node.contentIndent * 4
if ( node.parents.any { it is BulletList } && node.parents.any {it is OrderedList} ) {
indent += 20
}
withStyle(ParagraphStyle(lineHeight = 18.sp, textIndent = TextIndent(firstLine = indent.sp, restLine = (indent - 10).sp))) {
if (node.parents.any { it is BulletList }) { if (node.parents.any { it is BulletList }) {
appendLine()
append("") append("")
} else if (node.parents.any { it is OrderedList }) { } else if (node.parents.any { it is OrderedList }) {
val startNumber = val startNumber =
@ -142,9 +150,12 @@ private fun AnnotatedString.Builder.visitMarkdownNode(
val index = val index =
startNumber + node.previousSiblings.filterIsInstance<ListItem>().size startNumber + node.previousSiblings.filterIsInstance<ListItem>().size
append("$index. ") append("$index. ")
newLine = true
} }
visitChildren(node, typography) visitChildren(node, typography)
appendLine() if (newLine) {
appendLine()
}
} }
} }