Conversation
🦋 Changeset detectedLatest commit: f527c7e The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
6da0b3b to
19cd532
Compare
| import type { GenericNode, GenericParent } from 'myst-common'; | ||
| import { selectAll } from 'unist-util-select'; | ||
|
|
||
| export function listItemParagraphsTransform(tree: GenericParent) { |
There was a problem hiding this comment.
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.
fwkoch
left a comment
There was a problem hiding this comment.
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.
|
@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. |
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