Repository navigation
Description
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:
-
-
-
zNote: each empty list item line is a hyphen followed by one space. Escaped form:
"- \n- \n- \n\nz\n"
Then:
- Open the file in MarkText.
- Click after the
zparagraph. - Type any character, for example
y. - Save the file.
- 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
-
- cEscaped form:
"- a\n- \n- c\n"
Then:
- Open the file in MarkText.
- Click after
c. - Type any character, for example
x. - Save the file.
- 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:
-
-
-
zyFor Case 2, the saved Markdown should preserve three sibling list items:
- a
-
- cxActual Behavior
For Case 1, after editing and saving, the file is saved like this:
- - -
zyAfter 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
- - cxAfter 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
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
Jocs commentedon Jun 26, 2026
fixed by #4680