Updated the markdown parser with slightly better style for lists
parent
3badc4889b
commit
7a3c9730a2
|
|
@ -56,6 +56,7 @@ private fun AnnotatedString.Builder.visitMarkdownNode(
|
|||
style.toParagraphStyle().merge(ParagraphStyle(textAlign = TextAlign.Center))
|
||||
) {
|
||||
withStyle(style.toSpanStyle().copy(color = headingColor)) {
|
||||
appendLine()
|
||||
visitChildren(node, typography)
|
||||
appendLine()
|
||||
}
|
||||
|
|
@ -133,8 +134,15 @@ private fun AnnotatedString.Builder.visitMarkdownNode(
|
|||
}
|
||||
|
||||
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 }) {
|
||||
appendLine()
|
||||
append("• ")
|
||||
} else if (node.parents.any { it is OrderedList }) {
|
||||
val startNumber =
|
||||
|
|
@ -142,9 +150,12 @@ private fun AnnotatedString.Builder.visitMarkdownNode(
|
|||
val index =
|
||||
startNumber + node.previousSiblings.filterIsInstance<ListItem>().size
|
||||
append("$index. ")
|
||||
newLine = true
|
||||
}
|
||||
visitChildren(node, typography)
|
||||
appendLine()
|
||||
if (newLine) {
|
||||
appendLine()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue