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
Add support for MDX 2 comments #11563
Conversation
This adds support for MDX 2 comments (which are the same as other comments inside JSX) in addition to MDX 1 comments (HTML-like constructs). Related to GH-10706. Related to wooorm/xdm#61.
src/language-markdown/embed.js
Outdated
{ stripTrailingHardline: true } | ||
) + | ||
"}" | ||
); |
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.
I’m not sure why the MDX stuff is in embed
, but that’s why I added it here
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.
I don't think this is the right place to add it, it should be here
switch (node.type) { |
When we disable embed language, it will throw.
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.
Pushed a fix to also add it to the normal printer. It looks like embed
is for formatting embedded languages (so JS in MD), but not always available, hence it’s in two places?
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.
Given they print the same result, I think we can remove this one.
Please add a test in https://github.com/prettier/prettier/tree/main/tests/format/mdx/embedded-language-formatting
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.
Does the embedded parser perhaps break lines in comments or in other ways format them? 🤔
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.
Okay, I was going to ask you about that... I understand that's too much for you, but I failed to update remark-parse
(#9397). It will be great, if you can help us for the upgrade sometime later.
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.
My goal is to get MDX to an RC in 2 weeks (essentially porting xdm back into it and adding docs). So we do have some time (before but also probably after it).
I can help, yeah. All of unified is now ESM-only. I believe prettier is bundling dependencies so that shouldn’t be a problem for end users. Can ESM be setup internally in prettier/src/language-markdown?
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.
Unfortunately, no. We still don't know the problem, but we can't make ES Module work for the tests, even a simple esm file... #11235
I guess we'll have to wait until Jest have better support for modules.
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.
Also, our migration to Pure ESM can be tracked at #10157
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.
can the markdown language be compiled first before tests?
@@ -9,6 +9,7 @@ function startWithPragma(text) { | |||
const regex = new RegExp( | |||
[ | |||
`<!--\\s*${pragma}\\s*-->`, | |||
`{\\s*\\/\\*\\s*${pragma}\\s*\\*\\/\\s*}`, | |||
`<!--.*\r?\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`, |
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 other regex looks complex, which is why I didn’t port that to an es-comment either
@JounQin Can you please help review this? |
Will prettier support |
I see this as a workaround to at least not format MDX 2 comments. I recommend to, as soon as possible, support MDX 2 only. |
|
||
{/* Some more. */} | ||
|
||
{/* Some more. */} |
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.
Is this duplicate with the above comment? Maybe a test for multiple *
here?
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.
Remove the duplicate.
Stars are not yet supported, as old remark sees them as lists. Would be nice to have that, but it’s a lot of work, which would also be solved by updating to use latest remark and remark-mdx!
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.
A changelog should be added at https://github.com/prettier/prettier/tree/main/changelog_unreleased/mdx and mention this limitation.
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.
How should I do this? I have no experience with this
Note that there are lots of limitations currently. xdm/mdx-js@2 allow any JS expression in there, so there are many limitations anyway, but comments (like this) solve a common use case, even though it's not perfect
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.
I'm not familiar with MDX, but looks good to me
We'll merge this when we start to prepare next minor release. |
Awesome! |
I think it will be in early November. |
Thanks for merging this @sosukesuzuki, and everyone for the help! |
General MDX 2 issues: #12209 |
Does not support block comment {/*
hello
*/} |
This comment was marked as spam.
This comment was marked as spam.
* Add support for MDX 2 comments This adds support for MDX 2 comments (which are the same as other comments inside JSX) in addition to MDX 1 comments (HTML-like constructs). Related to prettierGH-10706. Related to wooorm/xdm#61. * Fix blank line before comment * Add `esComment` to `printer-markdown` * Add embedded test * Remove embedded formatter * Add support for es-comments as blocks & test prettier-ignore comments * Add a test for mdx pragma * Remove duplicate fixture * Add changelog * Add note clarifying support Co-authored-by: sosukesuzuki <aosukeke@gmail.com>
Description
This adds support for MDX 2 comments (which are the same as other
comments inside JSX) in addition to MDX 1 comments (HTML-like
constructs).
Please note that this is my first PR to prettier and I don’t know the codebase well.
Related to GH-10706.
Related to wooorm/xdm#61.
/cc @thorn0 @fisker
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨