-
-
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
Fix support for comments #260
Conversation
Previous implementation of comments was simply converting all "<!--" and "-->" to "{/*" and "*/}". This was very naive and caused a lot of edge cases. This also supported nesting Markdown comments in JSX, which isn't how regular Markdown works; nesting comments inside regular HTML doesn't work, so it doesn't make sense that it works here. This fix simply takes advantage of remark's support for comments, which takes care of all of the edge cases and doesn't reinvent the wheel. Fixes #256 Fixes #244
This pull request is automatically deployed with Now. |
node.type = node.mdxType || 'jsx' | ||
if ( | ||
node.value.startsWith('<!--') && | ||
node.value.endsWith('-->') |
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.
Remark contains all comments as separate html
nodes.
@@ -20,7 +20,6 @@ I'm an awesome paragraph. | |||
<Bar>hi</Bar> | |||
{hello} | |||
{/* another commment */} | |||
<!-- one more comment --> |
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 removed this line because, now that this is no longer treated as a comment, it causes an error when Babel tries to parse it.
<div> | ||
{/* a nested JSX comment */} | ||
<!-- a nested Markdown comment --> | ||
<!-- div content --> |
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 would technically cause a Babel error (as mentioned above), but I included it in the test to ensure that it doesn't turn into a comment.
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.
🔈
Previous implementation of comments was simply converting all
<!--
and-->
to{/*
and*/}
. This was very naive and caused a lot of edgecases. It also supported nesting Markdown comments in JSX, which isn't
how regular Markdown works; nesting comments inside regular HTML doesn't
work, so it doesn't make sense that it works here. So that part is a breaking change.
This fix simply takes advantage of remark's support for comments, which
takes care of all of the edge cases and doesn't reinvent the wheel.