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
MDX: support Markdown inside JSX blocks #7041
Comments
What did the MDX spec say about this? |
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: <div>
Some `code`
</div> Error:
This does work using the |
Another mention of it in mdx-js/mdx#628 (admittedly, an RFC):
|
cc @pomber maybe worth following along here, since your Code Surfer library is relying upon this approach. |
One last link: in the Try it editor on the official MDX website, both of the examples work - both the example with the |
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. |
Hm, but the original example actually works with the It also isn't true for the If this case was handled the same as the |
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? |
I think it used to work, at least inside of VS Code. Are there playgrounds for older versions of Prettier? |
@pomber Depends on what you call "to work". It might kind of work again in the next version because of #6949. The To my knowledge, there is no playgrounds for older versions. |
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. |
It's a different error though. It happens only on the playground. |
Subscribing to this issue, since I believe I am running into this as well. I am creating a Gatsby + MDX template. ESLint and Prettier fail with I can provide a reference to the project soon. |
Ah, just ran into this again with an existing project, which I believe wasn't erroring out before. Now any files in the project using the pattern below are not formatted by the Prettier VS Code extension anymore. Here's an example (using gatsby-remark-embedded-codesandbox): <details>
<summary>Solution</summary>
[Solution on CodeSandbox](codesandbox-link://exercises/002-solution/)
</details> |
It seems have fixed by #6949 |
Hm, not sure about that. It just throws a different error ("SyntaxError: Unexpected token"):
Same problem with the code from the original reported issue too. |
It seems like there's an issue with using ---
title: Contact
---
import { Button } from '@rmwc/button';
# Contact
<Button
raised
style={{ margin: '8px' }}
>
Message Me
</Button> I'm getting this: Edit: Also, there's the potential for JSX tags within an attribute that should maybe be considered too, like: <Button
raised
icon={<Icon />}
>
Message Me
</Button> It seems to be less related to the attribute and more to do with curly brackets on an attribute. |
@karlhorky That seems to be a different regression, and we can not simply consider all contents in cc @thorn0 |
@JounQin sure, definitely. Which comment of mine are you referring to? The one about the I guess because it's a different issue, we will leave @trevordmiller's #7041 open too? |
@kachkaev Sorry, after reading the issue content again, it seems actually just as same as yours. And as @thorn0 said at #7041 (comment)
We need help from @mdx-js team. |
Where has this been fixed? In an unreleased version of Prettier? Because the original Playground link still fails: |
@karlhorky Sorry I was confused this issue with #7176, your issue is same as this one: Markdown content inside |
What is the question? If it is whether the following is valid MDX, then yes, it is. <CodeSurfer>
```js
console.log(1);
```
</CodeSurfer> |
@wooorm We're asking help for sharing ideas about maintaining |
Ah actually, thanks to @kachkaev's comment (#7176 (comment)), I just tried adding So it looks like this will be fixed as soon as Prettier Workaround for now: Change your version of Prettier in your package.json to |
Seems like this change that worked with the Prettier master branch before |
This issue has been solved for me via |
@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. |
I just encountered the same issue. Oddly enough, using That said, I updated Prettier in my repo and that seems to have worked as well in my case. |
@Kosai106 <!-- @prettier --> So it was just disabling Prettier for that file. If you try with Ref: https://prettier.io/docs/en/options.html#require-pragma |
@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. |
MDX v2 is out: The example attached to this issue may become pretty common soon 🤔 |
Let’s continue the discussion here: |
According 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
Input:
Output:
Expected behavior:
If this is valid MDX it should parse it and format it without an error.
The text was updated successfully, but these errors were encountered: