Repository navigation
fix(muya): preserve tight mixed bullet and task lists - #5254
DePasqualeOrg wants to merge 1 commit into
Conversation
|
We require every fix to be associated with an issue first. I’ll close this PR for now. Please open a new issue to describe the problem, and then work on the fix based on that issue. Thanks for your understanding! |
|
This might be the expected behavior, because MarkText treats bullet lists and task lists as separate types of lists. A tight list only applies within a single list; when there are two separate lists, a blank line is added between them. |
|
@Jocs, the change in this PR appears to be correct, based on Muya’s parser and serializer and the GFM spec. The following analysis includes the relevant references. I used Claude Code to produce it, so I’m not claiming it as my own, but please reopen this PR if you agree with the reasoning. Muya does store these as two blocks, so the description of the internal model is accurate. What a blank line does not do is encode that boundary, for Muya's own parser or for a GFM parser. Here is
The first two rows are the problem. The parser records the authored list as tight, unchanged upstream serializes a blank line, and the same parser reads that back as loose. An unmodified round trip changes the document's spacing semantics inside Muya, independently of any question about spec conformance. The serializer already treats a real list boundary as needing no separator: when the previous list used a different marker, it suppresses the blank line because the marker change by itself starts a new list. A blank line is therefore not the mechanism upstream uses to separate lists. The third row shows the mechanism that does work, and Muya already round-trips it with both lists tight, so two genuinely separate lists stay expressible and this PR does not affect them. The fourth row shows the same-marker rule already in effect: a blank line between plain bullet items keeps one list and marks it loose. The The GFM specification (version 0.29-gfm) agrees on each point. Two items are of the same type when their markers use the same bullet character, so both belong to one list. A blank line between them makes that list loose rather than splitting it, and the same definition notes that paragraphs in a loose list are wrapped in The fix only stops a blank line that was not authored from being inserted. Authored loose spacing is preserved, with regressions covering both orderings. |
|
I double-checked this. GFM only defines task list items, which means they can be mixed with regular bullet list items. According to the specification, they should still belong to the same list. MarkText uses This is also why, during the state-to-Markdown serialization process, an empty line needs to be inserted after the list. |
|
For the record, Claude Code doesn't agree. It's not ideal for me to proxy things from Claude Code in this discussion, so if this isn't working, I'll stop trying to submit improvements to Muya (of which I already have about a dozen more that are verified against the spec and other sources).
What the blank line does change is looseness. Each split list copies The serializer already treats a blank line as something other than a list separator – the line immediately above this fix suppresses it when the marker differs, since the marker change alone starts a new list: if (lastListBullet && lastListBullet !== bulletMarkerOrDelimiter)
insertNewLine = false;The fix adds the same suppression for the tight case, in four lines. The tokens-to-state conversion is untouched, so the cost you were weighing against does not apply. |
This PR was developed with Codex using GPT-6 Astra and went through several rounds of automated review. It resolves a real issue that I encountered while using this library.
Summary
Muya stores adjacent bullet and task runs as separate blocks. This PR prevents serialization from inserting a blank line between tight runs while retaining authored loose spacing.
This input now round-trips unchanged:
Type of change
Test plan
From
packages/muya,pnpm test --maxWorkers=2passes 1,468 tests andpnpm test:spec --maxWorkers=2passes 1,347 checks.pnpm lint:types,pnpm lintandpnpm check-circularpass, with eight existing lint warnings. Four tight-list regressions fail without the fix; loose-list controls pass.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
Edit: Closes #5257.