Skip to content

A list's bullet marker is rewritten and its numbers renumbered on save #317

Description

@Azganoth

Summary

Saving rewrites a list's bullet character and renumbers an ordered list. The serializer picks a marker per list rather than writing the one the author used, and it alternates that pick between adjacent lists, so a document written with - comes back as a mixture of * and - that follows the order the lists appear in rather than anything in the source.

The alternation is not arbitrary and constrains the fix: two adjacent lists must not share a marker, or they merge into one list on the next read. Preserving the authored marker satisfies that constraint wherever the author already chose different markers, but it cannot be assumed to.

Steps to reproduce

  1. Open a document containing a - list, then a + list, then a * list, each separated by a blank line.
  2. Save it without editing.
  3. Read the file.

Expected behavior

Each list keeps the marker it was authored with, and an ordered list keeps the numbers it was authored with.

Actual behavior

Measured against 83e12b19 by driving the editor mount used by the plugin tests.

Document Saved
- Hyphen item * Hyphen item
+ Plus item starts another list - Plus item starts another list
* Asterisk item starts another list * Asterisk item starts another list
3. / 8. Subsequent source numbers do not set new starts 3. / 4. Subsequent source numbers do not set new starts
- two spaces * two spaces
- three spaces * three spaces
- four spaces * four spaces
- / content on the line after the marker * content on the line after the marker

The third row is the alternation rather than a preserved marker: that list keeps * only because it follows a list the serializer had already written as -.

A nested list follows its ancestor's rewritten marker for the same reason, so - nested one under a - parent saves as * nested one.

4) and 5) come back unchanged, but only because that list's numbers already run consecutively from its start. The renumbering applies to it too.

Related context

Done when

  • A bullet list writes the marker it was authored with, for -, +, and *.
  • Two adjacent lists never share a marker, including where the authored markers would collide, and coverage asserts they do not merge on the next read.
  • An ordered list writes the numbers it was authored with rather than renumbering from its start.
  • A list made in the editor, with no authored marker, still writes a defined default.
  • Marker padding and an item that begins on the line after its marker are preserved, or the reason they cannot be is recorded.
  • corpus/commonmark/lists-and-blockquotes.md loses these differences, or the reason it cannot is recorded.

Notes, logs, screenshots

Implementation direction

bulletListSchema is already overridden in src/features/editor/utils/createMilkdownEditor.ts, so the seam for a bullet list exists. Note the trap documented beside it: extendSchema registers a new slice, so an override on listItemSchema never reaches the schema the editor holds, which is why the task-list override goes through extendListItemSchemaForTask.

The authored marker is stamped at parse from node.position against the source, the way src/features/editor/plugins/characterReference.ts stamps an authored destination and title marker and src/features/editor/utils/markdownTitle.ts reads one back with a defined fallback.

Out of scope

  • List tightness, settled by Tight bullet lists are saved as loose lists #250.
  • The task marker inside a list item, which belongs to the task-marker class.
  • The - five spaces item, whose content is indented code and belongs to the indented-code class.

Activity

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

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions