Repository navigation
fix(lists): keep the start number of ordered lists - #1001
Conversation
petyosi
left a comment
There was a problem hiding this comment.
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.
|
One addition: |
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.
|
🎉 This PR is included in version 4.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Typing
3.or loading3. a\n4. bexports as1. 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)withoutstart, and the export builds the mdast list withoutstarteither, so the serializer falls back to 1. That's also whyincrementListMarker: falsedidn't help the person who asked on #471 in April. There was no start in the mdast tree to keep.Changes: pass
mdastNode.startinto$createListNodeon import, and addstart: 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 as3.and3. [ ] astill exports as* [ ] a, same as main. The nested test drops the blank line because5.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 fixnpm run lint,npm run typecheck,npm run build: clean