Skip to content

[Bug] Nested empty list items saved from the editor reopen as a setext heading #4683

Closed

Description

@Renakoni

Description

Nested empty bullet list items can corrupt the surrounding list structure after saving and reopening a document.

Starting from a normal nested list, if the text of the nested child items is deleted so that the child items become empty, MarkText saves Markdown that is ambiguous on reload. The first empty nested item marker is then interpreted as a setext heading underline for the parent item text.

As a result, normal list item text such as a becomes an H2 heading after reopening the file, and one of the empty nested child items disappears.

Steps to Reproduce

Create a Markdown file with this content:

- a
  - b
  - c

Then:

  1. Open the file in MarkText.
  2. Delete only the text c, leaving the third nested bullet item empty.
  3. Delete only the text b, leaving the second nested bullet item empty.
  4. Save the file.
  5. Close and reopen the file.

The important part is that the file starts as a non-empty nested list, and the empty nested items are produced through normal editing in MarkText.

Expected Behavior

After deleting b and c, saving, and reopening, the document should still be a nested list:

- a
  - 
  - 

Expected structure:

- parent list item: paragraph text "a"
  - empty nested bullet item
  - empty nested bullet item

The text a should remain normal paragraph text inside the parent list item.

Actual Behavior

Before saving, while still in the same editing session, MarkText shows the expected structure:

setext headings: 0
bullet lists: 2
list items: 3
paragraphs: 3

After saving, the file is written as:

- a
  - 
  - 

After closing and reopening that saved file, the structure changes:

setext headings: 1
bullet lists: 2
list items: 2
paragraphs: 0

The parent item text a becomes an H2 setext heading. One of the two empty nested child items is no longer represented as a child item.

The reopened DOM contains a setext heading similar to:

<h2 class="mu-setext-heading">a</h2>

Screenshots / Logs

No crash log is produced. This is a silent Markdown round-trip / structure corruption issue.

Image

This appears to be a serializer/parser interaction around empty nested list items and setext heading syntax.

After normal editing, MarkText can hold this structure in memory:

bullet-list
  list-item
    paragraph: "a"
    bullet-list
      list-item
        paragraph: ""
      list-item
        paragraph: ""

When serialized by packages/muya/src/state/stateToMarkdown.ts, it is written as:

- a
  - 
  - 

On reload, the line containing the first nested empty marker:

  -

is immediately below the parent text line:

- a

Inside the parent list item, this can be parsed as a setext heading underline for a rather than as the first nested empty bullet item. The next - line then becomes the remaining nested list item.

So the saved Markdown is not round-trip safe for the state MarkText just produced through normal editing.

This is related to empty list item handling in the Markdown serializer. The serializer should avoid producing an ambiguous form where a nested empty bullet marker immediately follows paragraph text in a position where it can be consumed as a setext heading underline.

Opening the final saved Markdown directly may already show the corrupted structure because the saved form is ambiguous. The stronger reproduction is starting from a normal non-empty nested list, deleting the child item text in the editor, saving, and then reopening. That proves MarkText can produce the problematic Markdown through ordinary editing.

Operating System

Windows

MarkText Version

0.20.0-beta.2

OS Version

Windows 11 Pro 10.0.26200

Reproducibility

  • I can reliably reproduce this issue

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions