Skip to content

[Bug] Saving a tight list whose item holds a code block reopens it as a loose list #5861

Closed

Description

@lu123bing

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

  1. 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
  1. Save the file.
  2. Close and reopen it: the list is loose and every item has paragraph spacing.
  3. 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 play

Parsing 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):

before and after one save

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

  1. added a commit that references this issue on Oct 23, 2026
    ad944b8
  2. added a commit that references this issue on Oct 23, 2026
    b7988bd
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