-
-
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
Rewrite how MDX is parsed #1039
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/mdx/mdx/e0mp24bx8 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
(Although it should be fatal, so an error. https://github.com/vfile/vfile-to-eslint covers how to do that) |
There is only a single |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Noticed the { or < in text won't work anymore. Is that still the case if they're in backticks? I suspect |
Thanks for trying it out! I indeed decided to throw parse errors on those, but there is an exception for code (so in backticks), and also in JavaScript (so in braces). On other cases, character references can be used (see “You can’t have random < or { in text anymore” above for examples!). And for your example: that is correct! Do you think this makes sense, or should it be different? |
That seems reasonable. I think this comes down to docs to make it clear that in-line "text" inside of backticks is treated/parsed as code. So if you want an errant { you can do so by including it in backticks, but beyond that there isn't a way to escape a character. |
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.
💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟💟
This completely rewrites the parser, which was previously regex based and error prone, and now follows a well-defined state machine.
TL;DR:
I <3 Markdown and JSX
->I <3 Markdown and JSX
<!--I'm a comment-->
->{/*I'm a comment*/}
<h2>`code`</h2>
->## `code`
Too long
Where MDXjs is different than Markdown
HTML
(mostly didn’t work, doesn’t work now)
Incorrect
Correct:
Indented code
(worked sometimes but mixed weirdly with indented elements; doesn’t work now)
Incorrect:
console.log(1)
Correct:
Autolinks
(worked; doesn’t work now)
Incorrect:
Correct:
Where MDXjs is different than JSX
Comments
(didn’t work, won’t work)
Incorrect:
Correct:
Elements / fragments as attribute values
(didn’t work, doesn’t work)
Incorrect:
Correct:
>
and}
in text(worked, still works)
Correct:
Brace counting in expressions
(worked, doesn’t work anymore)
Incorrect:
Correct:
Most likely breaking changes from MDXjs 1
You can’t have random
<
or{
in text anymoreIncorrect:
Correct:
I <3 Markdown and JSX
You can’t have HTML comments anymore
Previously HTML comments were allowed. We aren’t lax anymore and going w/ JSX all the way.
Incorrect:
<!--I'm a comment-->
Correct:
Blocks will be blocks
We wanted to make MDX easier to reason about. We’re now more chill about mixing Markdown with JSX, for example: this is perfectly fine:
<Wrapper>## Heading</Wrapper>
. BecauseWrapper
is a block, its contents is also block. Meaning, the heading works. By extension, this means that<Wrapper>Paragraph</Wrapper>
is a paragraph in a wrapper. Which then results in<h2>Paragraph</h2>
being a paragraph in a heading!Incorrect:
Correct:
## `code`
Or:
New features
Indent
You can indent your tags and expressions the way you want (within reason):
Interleaving
These are all fine now:
Blocks
Blocks can have blank lines now:
Expressions everywhere
All works:
# Hello, <>{props.name}</>
# Hello, {props.name}
Related-to: GH-195. (fixes everything except for imports/exports)
Closes GH-556.
Closes GH-611.
Closes GH-628.
Closes GH-716.
Closes GH-755.
Closes GH-757.
Closes GH-767.
Closes GH-784.