Skip to content

Commit

Permalink
Merge pull request #128 from atulgpt/fixes/112/fix-ordered-list-start
Browse files Browse the repository at this point in the history
Pass `astNodeType.startNumber` as `startIndex`
  • Loading branch information
halilozercan authored Feb 7, 2024
2 parents edff0f6 + 05c1839 commit 8920e78
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ private val sampleMarkdown = """
* Unordered list can use asterisks
- Or minuses
+ Or pluses
<!-- -->
2. Ordered list starting with `2.`
3. Another item
<!-- -->
0. Ordered list starting with `0.`
<!-- -->
003. Ordered list starting with `003.`
<!-- -->
-1. Starting with `-1.` should not be list
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ internal fun RichTextScope.RecursiveRenderMarkdownAst(astNode: AstNode?) {
is AstOrderedList -> {
FormattedList(
listType = Ordered,
items = astNode.childrenSequence().toList()
items = astNode.childrenSequence().toList(),
startIndex = astNodeType.startNumber - 1,
) { astListItem ->
visitChildren(astListItem)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private val LocalListLevel = compositionLocalOf { 0 }
@Composable public inline fun RichTextScope.FormattedList(
listType: ListType,
vararg children: @Composable RichTextScope.() -> Unit
): Unit = FormattedList(listType, children.asList()) { it() }
): Unit = FormattedList(listType, children.asList(), 0) { it() }

/**
* Creates a formatted list such as a bullet list or numbered list.
Expand All @@ -195,6 +195,7 @@ private val LocalListLevel = compositionLocalOf { 0 }
@Composable public fun <T> RichTextScope.FormattedList(
listType: ListType,
items: List<T>,
startIndex: Int = 0,
drawItem: @Composable RichTextScope.(T) -> Unit
) {
val listStyle = currentRichTextStyle.resolveDefaults().listStyle!!
Expand All @@ -210,7 +211,7 @@ private val LocalListLevel = compositionLocalOf { 0 }
prefixPadding = PaddingValues(start = markerIndent, end = contentsIndent),
prefixForIndex = { index ->
when (listType) {
Ordered -> listStyle.orderedMarkers!!().drawMarker(currentLevel, index)
Ordered -> listStyle.orderedMarkers!!().drawMarker(currentLevel, startIndex + index)
Unordered -> listStyle.unorderedMarkers!!().drawMarker(currentLevel)
}
},
Expand Down

0 comments on commit 8920e78

Please sign in to comment.