-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to remark@13 (micromark) #1367
Conversation
This updates MDX to use and support remark@13, which comes with a new internal parser (micromark), and supports CommonMark. See <https://github.com/remarkjs/remark/releases/tag/13.0.0> for more information. In short, this means MDX parses markdown closer to what folks expect. And it means all latest plugins work (again). But it also means that parsing MDX syntax (JSX, expressions, ESM) got an update. See: <https://github.com/micromark/micromark-extension-mdxjs> and <https://github.com/syntax-tree/mdast-util-mdx> for the syntax. In short, this means MDX parsing is now JavaScript-aware: import/exports are actually parsed for being valid JavaScript. Expressions previously counted braces, but now can include braces in strings or comments or whatnot. This also means we can drop Babel (in a future PR) because we already have a JavaScript AST. This also deprecates the packages `remark-mdxjs` (which is now the default in `remark-mdx`), `remark-mdx-remove-exports`, and `remark-mdx-remove-imports`. Related to GH-704. Related to GH-1041. Closes GH-720. Closes GH-1028. Closes GH-1050. Closes GH-1081. Closes GH-1193. Closes GH-1238. Closes GH-1283. Closes GH-1316. Closes GH-1318. Closes GH-1341.
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/mdx/mdx/lk7gmby28 [Deployment for e6062b1 failed] |
const importsAndExports = [] | ||
.concat(importStatements, exportStatements) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this causing an issue?
Would spread syntax be appropriate here?
const importsAndExports = [] | |
.concat(importStatements, exportStatements) | |
const importsAndExports = [...importStatements, ...exportStatements] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they used to be two strings, now they’re two arrays.
I’m fine with spread or whatnot but there doesn’t seem to be a well defined baseline on what is and isn’t allowed, so I just did what I was familiar with!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node 8-15 support spread syntax, as well as every major browser (except IE) https://kangax.github.io/compat-table/es6/
question on intended behavior. { would return
Is this the expected behavior? Similar question goes for a floating greater than in a file:
|
Another open question, how should mdx expressions interact with other MDX extensions like frontmatter? ---
property: <>{"hello world"}</>
--- Should the value of the yaml attribute |
Another curious edge case for you.
this is not:
failing with
|
This was also implemented there and further refined in the micromark rewrite. It was a common request for folks to embed expression in text (such as
I think the clearest rule is: with Markdown and JSX are very different languages. With JSX, folks are programming and expect errors, for |
Frontmatter is just a buffer for markdown, not a data structure. Similar how footnotes aren’t added inside frontmatter, JSX / expressions / ESM shouldn’t be added there IMO either. Folks coming from markdown seem to want to use frontmatter, but MDX also has its ESM for data. I believe some of the other MDX maintainers prefer using ESM instead of frontmatter with MDX. |
For: - <Icon name="hero
" /> This matches how other multiline blocks in markdown work, take this markdown: - ```js
asdasd Yields: asdasd |
The reason I thought it interesting, it (seems) to conflict a bit with:
here we're in |
I’m sure that’ll trip folks up yeah (although: it’s a bit of a weird case so it probably won’t occur much). Reason is that the list has to be dealt with before (or in fact, simultaneously as) the JSX tag. The list “knows” it’s not in a paragraph so therefore, when it sees lazy text, exits the list. |
This updates MDX to use and support remark@13, which comes with a new internal parser (micromark), and supports CommonMark. See https://github.com/remarkjs/remark/releases/tag/13.0.0 for more information. In short, this means MDX parses markdown closer to what folks expect. And it means all latest plugins work (again).
But it also means that parsing MDX syntax (JSX, expressions, ESM) got an update. See: https://github.com/micromark/micromark-extension-mdxjs and https://github.com/syntax-tree/mdast-util-mdx for the syntax. In short, this means MDX parsing is now JavaScript-aware: import/exports are actually parsed for being valid JavaScript. Expressions previously counted braces, but now can include braces in strings or comments or whatnot. This also means we can drop Babel (in a future PR) because we already have a JavaScript AST.
This also deprecates the packages
remark-mdxjs
(which is now the default inremark-mdx
),remark-mdx-remove-exports
, andremark-mdx-remove-imports
.Related to GH-704.
Related to GH-1041.
Closes GH-720.
Closes GH-1028.
Closes GH-1050.
Closes GH-1081.
Closes GH-1193.
Closes GH-1238.
Closes GH-1283.
Closes GH-1316.
Closes GH-1318.
Closes GH-1341.