From d77bd6dabf80a71eab509fb81d1ee8f413ba1e44 Mon Sep 17 00:00:00 2001 From: Harry Dang <36112469+Harry-Dang@users.noreply.github.com> Date: Sat, 7 Dec 2024 19:40:11 -0800 Subject: [PATCH] Fix ordered list start (#34) --- src/ReactParser.ts | 2 +- src/ReactRenderer.ts | 4 ++-- tests/markdown.spec.ts | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ReactParser.ts b/src/ReactParser.ts index e7c6761..a67e2f4 100644 --- a/src/ReactParser.ts +++ b/src/ReactParser.ts @@ -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': { diff --git a/src/ReactRenderer.ts b/src/ReactRenderer.ts index bc148d8..cd22340 100644 --- a/src/ReactRenderer.ts +++ b/src/ReactRenderer.ts @@ -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[]) { diff --git a/tests/markdown.spec.ts b/tests/markdown.spec.ts index 1af0309..b7da56f 100644 --- a/tests/markdown.spec.ts +++ b/tests/markdown.spec.ts @@ -88,6 +88,11 @@ const cases = [ markdown: '1. option-1\n2. option-2', html: '
  1. option-1
  2. option-2
', }, + { + title: 'render ordered lists with different start value', + markdown: '2. option-2\n3. option-3', + html: '
  1. option-2
  2. option-3
', + }, { title: 'render codeblocks', markdown: '```\n\n```',