You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:mdxIssues affecting the MDX extension to Markdown (not general Markdown issues)
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.
Reacted by Gersom van Ginkel, Jonah Snider, Nikolaus Kühn, Václav Jančařík, Alexander Kachkaev, Varun, skube, Maxime Richard, Danh Le, Kirill K and 2 more
This will work if you add newlines between the JSX and Markdown tags
<Referencetitle='JS Reference'>
My explanation of `this`
</Reference>
It seems that in Prettier, this example does not work.
Furthermore, it seems as if nesting other Markdown after newlines generally does not work:
<div>
Some `code`
</div>
Error:
SyntaxError: Unexpected closing tag "div". 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 | <div>
| ^
2 |
3 | Some `code`
4 |
One last link: in the Try it editor on the official MDX website, both of the examples work - both the example with the div and the original example with the CodeSurfer component.
The MDX support in Prettier is really basic. Prettier parses MDX like plain Markdown with the only (I guess) difference that if a JSX block is found, it's passed to Babel. That's it. Things like inline JSX and Markdown inside JSX blocks aren't supported as of now.
@pomber Depends on what you call "to work". It might kind of work again in the next version because of #6949. The SyntaxError should get fixed, but Prettier won't really format JSX blocks with Markdown inside. It'll just leave them as is like it currently does with inline JSX. So if someone here is blocked by this issue, consider installing Prettier directly from GitHub (npm install prettier/prettier) until this fix is released.
To my knowledge, there is no playgrounds for older versions.
Where has this been fixed? In an unreleased version of Prettier?
Ah actually, thanks to @kachkaev's comment (#7176 (comment)), I just tried adding "prettier": "prettier/prettier" to my devDependencies 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 or 1.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 by prettier-vscode.
Reacted by Titus, Trevor Miller, Georgii Dolzhykov, Christopher Boyd, skube, Maxime Richard, South Drifter, Kirill K, Vojta Holik, Ellis Min and 2 more
help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:mdxIssues affecting the MDX extension to Markdown (not general Markdown issues)
Activity
thorn0 commentedon Nov 24, 2019
What did the MDX spec say about this?
karlhorky commentedon Nov 24, 2019
Hm, there is no mention of it from my quick glance at https://github.com/mdx-js/specification, but in the issues there is mdx-js/specification#11, which mentions:
Question:
Answer:
It seems that in Prettier, this example does not work.
Furthermore, it seems as if nesting other Markdown after newlines generally does not work:
Error:
This does work using the
markdownparser.karlhorky commentedon Nov 24, 2019
Another mention of it in mdx-js/mdx#628 (admittedly, an RFC):
karlhorky commentedon Nov 24, 2019
cc @pomber maybe worth following along here, since your Code Surfer library is relying upon this approach.
karlhorky commentedon Nov 24, 2019
One last link: in the Try it editor on the official MDX website, both of the examples work - both the example with the
divand the original example with theCodeSurfercomponent.thorn0 commentedon Nov 24, 2019
The MDX support in Prettier is really basic. Prettier parses MDX like plain Markdown with the only (I guess) difference that if a JSX block is found, it's passed to Babel. That's it. Things like inline JSX and Markdown inside JSX blocks aren't supported as of now.
karlhorky commentedon Nov 25, 2019
Hm, but the original example actually works with the
markdownparser:Markdown (no errors)
It also isn't true for the
divMDX <> Markdown comparison that I posted:MDX (fails)
Markdown (no errors)
If this case was handled the same as the
markdownparser (newlines inside tags), maybe this issue would be fixed.karlhorky commentedon Nov 25, 2019
Ah, in my comment above I missed your point about "if a JSX block is found, it's passed to Babel"... maybe that's the reason for this inconsistency?
pomber commentedon Nov 25, 2019
I think it used to work, at least inside of VS Code. Are there playgrounds for older versions of Prettier?
thorn0 commentedon Nov 25, 2019
@pomber Depends on what you call "to work". It might kind of work again in the next version because of #6949. The
SyntaxErrorshould get fixed, but Prettier won't really format JSX blocks with Markdown inside. It'll just leave them as is like it currently does with inline JSX. So if someone here is blocked by this issue, consider installing Prettier directly from GitHub (npm install prettier/prettier) until this fix is released.To my knowledge, there is no playgrounds for older versions.
pomber commentedon Nov 25, 2019
Yes, maybe it was just ignoring the JSX's children. That was good enough for me.
BTW, I tried 6949 playground and it's still throwing a similar error.
thorn0 commentedon Nov 25, 2019
It's a different error though. It happens only on the playground.
14 remaining items
JounQin commentedon Jan 27, 2020
@wooorm We're asking help for sharing ideas about maintaining
mdxsupport inprettier.karlhorky commentedon Jan 27, 2020
Ah actually, thanks to @kachkaev's comment (#7176 (comment)), I just tried adding
"prettier": "prettier/prettier"to mydevDependenciesand it seems to format with all examples here! 🚀Show gif
So it looks like this will be fixed as soon as Prettier
1.20.0or1.19.2is 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.[-]MDX parsing error: Unexpected closing tag[/-][+]MDX: support Markdown inside JSX blocks[/+]karlhorky commentedon Apr 9, 2020
Seems like this change that worked with the Prettier master branch before
[email protected]is not a part of the v2 release 😞Playground
Playground
bsgreenb commentedon May 13, 2020
This issue has been solved for me via
npm i -D prettier@latestthorn0 commentedon May 13, 2020
@bsgreenb It might seem that it works sometimes, but this never was implemented.
In this code
the tags aren't parsed as JSX at all. Prettier just leaves them as is, without formatting.
Whereas in this code
Prettier parses the tags as JSX, but it doesn't parse the text inside as Markdown.
Kosai106 commentedon Sep 12, 2020
I just encountered the same issue. Oddly enough, using
--require-pragmaseems to make the error go away, at least on the Prettier Playground.That said, I updated Prettier in my repo and that seems to have worked as well in my case.
karlhorky commentedon Sep 12, 2020
@Kosai106
--require-pragmawill ignore all files without a pragma at the top of the file. MDX pragma:<!-- @prettier -->So it was just disabling Prettier for that file. If you try with
--require-pragmaand the pragma above, you'll have the same errors again.Ref: https://prettier.io/docs/en/options.html#require-pragma
Kosai106 commentedon Sep 13, 2020
@karlhorky Ah, yeah that would explain it, lol. It was pretty late, I didn't think too much about it.
Like I said however, upgrading the Prettier version seems to have solved the issue on my end.
kachkaev commentedon Feb 1, 2022
MDX v2 is out:
The example attached to this issue may become pretty common soon 🤔
kachkaev commentedon Feb 1, 2022
Let’s continue the discussion here: