Skip to content

fix(lists): keep the start number of ordered lists - #1001

Merged
petyosi merged 2 commits into
mdx-editor:mainfrom
mohsensc:fix/ordered-list-start-number
Nov 2, 2026
Merged

petyosi merged 2 commits into
mdx-editor:mainfrom
mohsensc:fix/ordered-list-start-number

Conversation

@mohsensc

Copy link
Copy Markdown
Contributor

Typing 3. or loading 3. a\n4. b exports as 1. a\n2. b. Any ordered list that doesn't start at 1 gets renumbered on save.

Root cause: the list start never makes it through. The mdast import calls $createListNode(listType) without start, and the export builds the mdast list without start either, so the serializer falls back to 1. That's also why incrementListMarker: false didn't help the person who asked on #471 in April. There was no start in the mdast tree to keep.

Changes: pass mdastNode.start into $createListNode on import, and add start: getStart() on export for number lists only.

Heads up: lists that Lexical splits or restarts (setStart) now export their real start instead of 1. 3) still exports as 3. and 3. [ ] a still exports as * [ ] a, same as main. The nested test drops the blank line because 5. can't interrupt a paragraph in CommonMark.

Fixes #471

Ran:

  • npm run test:once: 180 --> 188 passed. New lists.test.tsx is 5 failing / 3 passing on main, 8/8 with the fix
  • npm run lint, npm run typecheck, npm run build: clean

@petyosi petyosi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down. Carrying start through import and export is the right fix. One round-trip problem before it can go in.

Nested ordered lists that don't start at 1 lose their structure on reload. The nested test expects 1. a\n 5. b\n 6. c. CommonMark only lets an ordered list that starts at 1 interrupt a paragraph, so that output parses back as one paragraph, a\n5. b\n6. c (checked with mdast-util-from-markdown). Main renumbers the nested list to 1., which is wrong but keeps the structure. With this PR the nested list is gone after one save and load.

Please emit a blank line before a nested ordered list whose start isn't 1, for example by marking the containing list item as spread in that case. Please also make the nested test assert that a second round-trip produces the same tree, instead of asserting a specific string.

@petyosi

petyosi commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

One addition: 0. has the same restriction as 5., since only 1. can interrupt a paragraph. So the blank line is needed whenever start !== 1, not only when start > 1.

Only a list starting at 1 can interrupt a paragraph, so mark the parent
item as spread to emit a blank line before a nested ordered list whose
start isn't 1. Nested tests now check that a second round-trip parses
to the same tree.
@mohsensc
mohsensc requested a review from petyosi October 27, 2026 15:32
@petyosi
petyosi merged commit f1baa87 into mdx-editor:main Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 4.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG/INQUIRY] Ordered Lists always start with 1

2 participants