Skip to content

fix(muya): preserve tight list block boundaries on save - #5854

Merged
Jocs merged 2 commits into
marktext:developfrom
lu123bing:fix/tight-list-item-blocks
Oct 23, 2026
Merged

Jocs merged 2 commits into
marktext:developfrom
lu123bing:fix/tight-list-item-blocks

Conversation

@lu123bing

@lu123bing lu123bing commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Saving a tight list whose item contains a paragraph followed by a fenced code block inserts a blank line, reopening the list as loose. A second save then adds spacing between its items. This preserves the block boundaries so the list keeps its original meaning across saves.

Closes #5861.

The serializer now delegates separator decisions to BlockBoundaryResolver, which distinguishes adjacent blocks, required blank lines, and boundaries that require a different output spelling. Tight-item context remains local to the item's direct children. The rules cover fenced code, headings, thematic breaks, blockquote interruption, and HTML boundaries while preserving necessary separators for two paragraphs, indented code after a paragraph, Setext ambiguity, and alerts.

HTML boundaries are derived from the import lexer's grammar and cached for one export, so edited HTML is classified from its current text without introducing another HTML parser or stale document metadata. Adjacent indented-code state nodes are kept as separate blocks by fencing the next block on output; this also applies outside lists and does not mutate the document state.

Regression coverage includes CommonMark example 321 / GFM example 301, HTML termination and interruption, lazy blockquote continuation, task and ordered-task items, nested lists, loose parents, footnote containers, fence safety, and repeated round trips. Source-format preservation remains tracked in #2189; editing-state looseness updates remain tracked in #5297.

Validation:

  • Muya unit tests: 2,885 passed.
  • Muya spec tests: 1,347 passed, including existing expected-failure baseline checks.
  • Muya build, lint, type checking, and circular-dependency check passed.
  • Root pnpm run lint and pnpm run typecheck passed. Existing lint warnings remain.
  • Additional block-pair, source-fixture, and serialized-spec differential checks found no new regressions against the previous serializer.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@lu123bing

Copy link
Copy Markdown
Contributor Author

Friendly bump: the first-time-contributor workflows are parked for approval (Muya Lint, Muya Test, Muya Spec, Muya Build, Muya E2E, Muya Circular Dep Check), so the PR currently shows no checks. Could someone approve the runs? Lint, types, the unit suite and the spec suite are green locally.

@lu123bing
lu123bing force-pushed the fix/tight-list-item-blocks branch from 3ac9975 to e36b698 Compare October 22, 2026 18:43
@lu123bing lu123bing changed the title fix(muya): stop turning a tight list loose when saving a multi-block item fix(muya): keep the blocks of a tight list item together when saving Oct 22, 2026
@lu123bing
lu123bing force-pushed the fix/tight-list-item-blocks branch 2 times, most recently from e458851 to 40e7b0e Compare October 22, 2026 19:00
@Jocs

Jocs commented Oct 22, 2026

Copy link
Copy Markdown
Member

Related: #5297, #5257 — same tight/loose area, different case (see Notes for reviewers).

Open a related issue before submit a PR.

… saving

A tight list item whose content is more than one block was serialized with a blank line between the blocks. CommonMark makes a list loose when one of its items directly contains two block-level elements separated by a blank line, so saving such a file changed how it renders: every item picks up paragraph spacing, and the next save changed the file again.

The blank line is now written only for pairs that would otherwise end up as one block - a second paragraph, a setext underline, a dash-only thematic break, an indented code block, a footnote definition - and for the block kinds the serializer stays conservative about (an HTML block, whose block type the state does not record, and a GitHub alert, whose marker needs a blank-line delimited block). The new tests cover each shape that stays tight and each pair that keeps the separator.
@lu123bing
lu123bing force-pushed the fix/tight-list-item-blocks branch from 40e7b0e to ad944b8 Compare October 23, 2026 03:29
@lu123bing lu123bing changed the title fix(muya): keep the blocks of a tight list item together when saving fix: #5861 keep the blocks of a tight list item together when saving Oct 23, 2026
@lu123bing

Copy link
Copy Markdown
Contributor Author

Filed #5861 and linked it; thanks for the pointer, should have opened it first. The workflow runs on the latest push are still waiting for approval if you have a sec.

@Jocs Jocs changed the title fix: #5861 keep the blocks of a tight list item together when saving fix(muya): preserve tight list block boundaries on save Oct 23, 2026
@Jocs

Jocs commented Oct 23, 2026

Copy link
Copy Markdown
Member

Since I've been dealing with this type of issues recently, to keep things consistent going forward, I went ahead and made the changes directly in the PR base on your design. Thanks for your contribution.

@lu123bing

Copy link
Copy Markdown
Contributor Author

Thanks, splitting the rules into a resolver is cleaner than what I had. Ping me if anything falls out of the e2e run or if you want a follow-up on the indented-code rewrite.

@Jocs
Jocs merged commit b7988bd into marktext:develop Oct 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants