Repository navigation
Description
Description
Saving a document whose tight list holds a fenced code block inside an item rewrites the list as loose. The serializer puts a blank line between the blocks of a list item, and CommonMark makes a list loose when one of its items directly contains two block-level elements separated by a blank line. Reopening the file shows paragraph spacing on every item, and the next save adds another blank line.
The blank line is not required for this pair: a fenced code block interrupts a paragraph, so the item's blocks can stay on adjacent lines. The state tree the parser produces keeps loose: false; only the serialized text loses that.
Steps to Reproduce
- Open a document with this content (a tight list where each item places a fenced code block right below its paragraph):
- Install the dependencies:
```sh
pnpm install
```
- Start the dev server:
```sh
pnpm dev
```
- Open the app and play- Save the file.
- Close and reopen it: the list is loose and every item has paragraph spacing.
- Save again: another blank line was added.
The same happens at engine level, without the editor UI:
const states = new MarkdownToState().generate(md) // list meta.loose === false
new ExportMarkdown({ listIndentation: 1 }).generate(states)Expected Behavior
Saving does not change the document. The list stays tight, the Markdown is byte-identical to what was opened, and repeated saves are idempotent.
Actual Behavior
After one save:
- Install the dependencies:
```sh
pnpm install
```
- Start the dev server:
```sh
pnpm dev
```
- Open the app and playParsing that back gives meta.loose: true. After a second save another blank line appears before each following item.
The rendering difference after one save (left: develop, right: with the fix that is up as a PR):
Screenshots / Logs
See the image above; the left pane is the current behaviour after a single save.
Operating System
Linux (Other)
MarkText Version
0.20.0-dev (develop @ 98879ca), muya @muyajs/core 0.2.0
OS Version
Linux, engine-level reproduction inside packages/muya (Node 26 / vitest + happy-dom; no GUI involved)
Reproducibility
- I can reliably reproduce this issue
Additional context
Markdown reformatting on save is expected (#2189 covers the general case). What is not expected here is the list switching from tight to loose: that changes how the document renders, not only how it is spelled.
Related: #5297 (the editor keeps a list tight after a second paragraph is inserted into an item; two paragraphs do need the blank line, so that case is unchanged by this), #5257 (blank line between two items of one Markdown list that the parser splits into a bullet list and a task list; item-to-item spacing is untouched).
PR: #5854 (opened before this issue existed; linking it here for the discussion).

Activity
fix: marktext#5861 keep the blocks of a tight list item together when…
fix(muya): preserve tight list block boundaries on save (#5854)