Skip to content

Commit

Permalink
Fix ordered list start (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-Dang authored Dec 8, 2024
1 parent 9548aea commit d77bd6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 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 !== 1 ? { start } : {});
}

listItem(children: ReactNode[]) {
Expand Down
5 changes: 5 additions & 0 deletions tests/markdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ const cases = [
markdown: '1. option-1\n2. option-2',
html: '<ol><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',
markdown: '```\n<script>console.log("Hello")</script>\n```',
Expand Down

0 comments on commit d77bd6d

Please sign in to comment.