Skip to content

Commit 8ffa2d3

Browse files
authored
🐛 mdast lists need to be in paragraphs (#2241)
1 parent 8ea7245 commit 8ffa2d3

File tree

16 files changed

+835
-121
lines changed

16 files changed

+835
-121
lines changed

.changeset/smart-feet-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"myst-parser": patch
3+
---
4+
5+
Transform lists that have non-block content (text, italic, inlineCode, etc.) to ensure they are in paragraphs.

packages/myst-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"clean": "rimraf dist",
3232
"test": "vitest run",
3333
"test:watch": "vitest watch",
34-
"lint": "eslint \"src/**/*.ts\" -c .eslintrc.cjs",
34+
"lint": "eslint \"src/**/!(*.spec).ts\" -c ./.eslintrc.cjs",
3535
"lint:format": "prettier --check src/*.ts src/**/*.ts",
3636
"build:bundle:browser": "esbuild bundle/myst.ts --bundle --outfile=dist/myst.min.js --platform=browser --minify",
3737
"build:esm": "tsc --project ./src/tsconfig.json",

packages/myst-parser/src/fromMarkdown.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const UNHIDDEN_TOKENS = new Set([
2424
export type MdastOptions = {
2525
handlers?: Record<string, TokenHandlerSpec>;
2626
hoistSingleImagesOutofParagraphs?: boolean;
27+
listItemParagraphs?: boolean;
2728
nestBlocks?: boolean;
2829
};
2930

packages/myst-parser/src/tokensToMyst.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { selectAll } from 'unist-util-select';
88
import { u } from 'unist-builder';
99
import { MarkdownParseState, withoutTrailingNewline } from './fromMarkdown.js';
1010
import type { MdastOptions, TokenHandlerSpec } from './fromMarkdown.js';
11+
import { listItemParagraphsTransform } from './transforms/index.js';
1112

1213
export function computeAmsmathTightness(
1314
src: string,
@@ -519,6 +520,7 @@ function nestSingleImagesIntoParagraphs(tree: GenericParent) {
519520
const defaultOptions: MdastOptions = {
520521
handlers: defaultMdast,
521522
hoistSingleImagesOutofParagraphs: true,
523+
listItemParagraphs: true,
522524
nestBlocks: true,
523525
};
524526

@@ -571,6 +573,11 @@ export function tokensToMyst(
571573
}
572574
});
573575

576+
if (opts.listItemParagraphs) {
577+
// Ensure that listItems that are not paragraphs are wrapped in paragraphs
578+
listItemParagraphsTransform(tree);
579+
}
580+
574581
// Move crossReference text value to children
575582
visit(tree, 'crossReference', (node: GenericNode) => {
576583
delete node.children;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { listItemParagraphsTransform } from './listItemParagraphs.js';

0 commit comments

Comments
 (0)