Skip to content

🐛 mdast lists need to be in paragraphs#2241

Merged
rowanc1 merged 2 commits intomainfrom
mdast/lists
Aug 13, 2025
Merged

🐛 mdast lists need to be in paragraphs#2241
rowanc1 merged 2 commits intomainfrom
mdast/lists

Conversation

@rowanc1
Copy link
Member

@rowanc1 rowanc1 commented Aug 12, 2025

This transforms listItems after parsing with markdown-it, to ensure that they are mdast compliant. This is important in formatting (e.g. #1948). Without this each inline element of the list item will be on a different line.

Fixes #1957

@changeset-bot
Copy link

changeset-bot bot commented Aug 12, 2025

🦋 Changeset detected

Latest commit: f527c7e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
myst-parser Patch
myst-roles Patch
myst-directives Patch
myst-to-html Patch
myst-transforms Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rowanc1 rowanc1 added the bug Something isn't working label Aug 12, 2025
@rowanc1 rowanc1 force-pushed the mdast/lists branch 2 times, most recently from 6da0b3b to 19cd532 Compare August 12, 2025 03:01
import type { GenericNode, GenericParent } from 'myst-common';
import { selectAll } from 'unist-util-select';

export function listItemParagraphsTransform(tree: GenericParent) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the transform that is added at the end of a markdown parse. It is optional, but turned on by default to be compatible with mdast.

Copy link
Member

@fwkoch fwkoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense! Some background on this - the inconsistency around listItems including inline elements as direct children comes from markdown-it compliance with the commonmark spec. This spec defines markdown input and html output, and there are tests where list items sometimes have paragraphs and sometimes do not. The html structure in these tests corresponds directly to the tokens created by markdown-it (and therefore the mdast from myst-parser).

However, the mdast spec requires listItem children to always be "flow content" (e.g. paragraphs, block quotes, code, etc). This is much more consistent; when dealing with listItem children, there is a narrower suite of node types to expect.

This PR provides consistency by adhering to the mdast spec and nesting non-flow-content listItem children in paragraphs.

@rowanc1 rowanc1 merged commit 8ffa2d3 into main Aug 13, 2025
7 checks passed
@rowanc1 rowanc1 deleted the mdast/lists branch August 13, 2025 14:01
@agoose77
Copy link
Contributor

agoose77 commented Aug 13, 2025

@fwkoch to add even more context, I opened #1957 after noticing that the commonmark spec apparently differs from the mdast spec.

Upon digging down, it looks like this is not actually the case — rather, the CommonMark spec page is misleading: there's something funky going on with the HTML rendering. As such, this PR feels like the proper "commonmark compliant" solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AST for lists is not mdast compliant

3 participants