MDX: support Markdown inside JSX blocks
See original GitHub issueAccording to the commonmark spec, it seems that the example below is valid MDX. However, Prettier is throwing an error.
Prettier 1.19.1 Playground link
--parser mdx
Input:
<CodeSurfer>
```js
console.log(1);
```
</CodeSurfer>
Output:
SyntaxError: Unexpected closing tag "CodeSurfer". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (1:1)
> 1 | <CodeSurfer>
| ^
2 |
3 | ```js
4 | console.log(1);
Expected behavior:
If this is valid MDX it should parse it and format it without an error.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:35 (29 by maintainers)
Top Results From Across the Web
MDX: Markdown for the component era
MDX allows you to use JSX in your markdown content. You can import components, such as interactive charts or alerts, and embed them...
Read more >Guide to Writing MDX and Markdown | Chicago Docs
MDX is a combination of Markdown and JSX, and regular Markdown syntax can be used for most formatting. What follows is a guide...
Read more >MDX and React - Docusaurus
Docusaurus has built-in support for MDX v1, which allows you to write JSX within your Markdown files and render them as React components....
Read more >MDX Format - Storybook - JS.ORG
MDX is a standard file format that combines Markdown with JSX. It means you can use Markdown's terse syntax (such as # heading...
Read more >MDX - JSX in Markdown - DEV Community
There is a new markup-language on the block, called MDX, which is essentially Markdown sprinkeled with JSX elements and JavaScript import s.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah actually, thanks to @kachkaev’s comment (https://github.com/prettier/prettier/issues/7176#issuecomment-571218217), I just tried adding
"prettier": "prettier/prettier"
to mydevDependencies
and it seems to format with all examples here! 🚀Show gif
So it looks like this will be fixed as soon as Prettier
1.20.0
or1.19.2
is released. 🙌Workaround for now:
Change your version of Prettier in your package.json to
"prettier": "prettier/prettier"
. If you’re using VS Code, this new local version will be picked up automatically byprettier-vscode
.This issue has been solved for me via
npm i -D prettier@latest