Skip to content

Commit

Permalink
Add ordered list start value
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-Dang committed Dec 3, 2024
1 parent 9548aea commit 113b38e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ReactParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ReactParser {
return this.renderer.listItem(listItemChildren);
});

return this.renderer.list(children, token.ordered);
return this.renderer.list(children, token.ordered, token.ordered ? token.start : undefined);
}

case 'code': {
Expand Down
4 changes: 2 additions & 2 deletions src/ReactRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class ReactRenderer {
return this.#h('blockquote', children);
}

list(children: ReactNode, ordered: boolean) {
return this.#h(ordered ? 'ol' : 'ul', children);
list(children: ReactNode, ordered: boolean, start: number | undefined) {
return this.#h(ordered ? 'ol' : 'ul', children, ordered ? { start } : {});
}

listItem(children: ReactNode[]) {
Expand Down
7 changes: 6 additions & 1 deletion tests/markdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ const cases = [
{
title: 'render ordered lists',
markdown: '1. option-1\n2. option-2',
html: '<ol><li>option-1</li><li>option-2</li></ol>',
html: '<ol start="1"><li>option-1</li><li>option-2</li></ol>',
},
{
title: 'render ordered lists with different start value',
markdown: '2. option-2\n3. option-3',
html: '<ol start="2"><li>option-2</li><li>option-3</li></ol>',
},
{
title: 'render codeblocks',
Expand Down

0 comments on commit 113b38e

Please sign in to comment.