Skip to content

[Bug] Empty list items are serialized onto one line after editing, corrupting the document on reload #4679

Closed

Description

@Renakoni

Description

Empty list items can be corrupted when a document is edited and saved.

If a Markdown document contains empty bullet list items such as - , MarkText initially renders them correctly. However, after making any edit in the document and saving, the Markdown serializer writes adjacent empty list items without line breaks. On the next reload, the saved Markdown is parsed as a different structure.

The most severe case is three empty bullet items. After an edit and save, they are written as - - -, which CommonMark interprets as a thematic break / horizontal rule. The original list items disappear after reopening the file.

Steps to Reproduce

Case 1: three empty bullet items become a horizontal rule

Create a file with this content:

- 
- 
- 

z

Note: each empty list item line is a hyphen followed by one space. Escaped form:

"- \n- \n- \n\nz\n"

Then:

  1. Open the file in MarkText.
  2. Click after the z paragraph.
  3. Type any character, for example y.
  4. Save the file.
  5. Close and reopen the file.

Case 2: an empty item between filled items causes the following item to become nested

Create a file with this content:

- a
- 
- c

Escaped form:

"- a\n- \n- c\n"

Then:

  1. Open the file in MarkText.
  2. Click after c.
  3. Type any character, for example x.
  4. Save the file.
  5. Close and reopen the file.

Expected Behavior

Empty list items should remain separate list items after editing, saving, and reopening the document.

For Case 1, the saved Markdown should still contain three separate empty bullet items, followed by the edited paragraph:

- 
- 
- 

zy

For Case 2, the saved Markdown should preserve three sibling list items:

- a
- 
- cx

Actual Behavior

For Case 1, after editing and saving, the file is saved like this:

- - - 
zy

After reopening, - - - is rendered as a horizontal rule. The three empty list items are gone.

For Case 2, after editing and saving, the file is saved like this:

- a
- - cx

After reopening, cx is parsed as a nested bullet list inside the second list item instead of remaining the third sibling item.

Screenshots / Logs

No crash log is produced. This is a silent serialization / round-trip data corruption issue

Image

The issue appears to come from the Markdown serializer in packages/muya/src/state/stateToMarkdown.ts.

In _serializeListItem(), the serializer writes the list marker first, for example - , and then appends the serialized children:

result.push(`${indent}${itemMarker}`);
result.push(
  this._convertStatesToMarkdown(children, newIndent, listIndent).substring(
    newIndent.length,
  ),
);

For an empty list item, children is an empty array. _convertStatesToMarkdown([]) returns an empty string, so the serialized result for that list item is only - with no trailing newline.

For tight lists, _serializeListItemBlock() does not insert a separator between items. As a result, adjacent empty list items are concatenated into one physical Markdown line:

-  + -  + -  => - - -

This is valid Markdown syntax for a thematic break, so the document structure changes after reload.

In the desktop app, opening a clean file and immediately saving may not trigger the bug because the original Markdown string is still cached. The issue becomes visible after any edit causes MarkText to refresh the current document Markdown from the Muya serializer before saving.

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

  1. Jocs commented on Jun 26, 2026

    @Jocs
    Member

    fixed by #4680

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