Skip to content
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

Merged
merged 1 commit into from
Sep 20, 2018
Merged

Fix support for comments #260

merged 1 commit into from
Sep 20, 2018

Conversation

silvenon
Copy link
Contributor

@silvenon silvenon commented Sep 15, 2018

Previous implementation of comments was simply converting all <!-- and
--> to {/* and */}. This was very naive and caused a lot of edge
cases. 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.

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
@vercel
Copy link

vercel bot commented Sep 15, 2018

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

node.type = node.mdxType || 'jsx'
if (
node.value.startsWith('<!--') &&
node.value.endsWith('-->')
Copy link
Contributor Author

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 -->
Copy link
Contributor Author

@silvenon silvenon Sep 15, 2018

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 -->
Copy link
Contributor Author

@silvenon silvenon Sep 15, 2018

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.

Copy link
Member

@johno johno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔈

@silvenon silvenon merged commit 8418885 into mdx-js:master Sep 20, 2018
@silvenon silvenon deleted the comments branch September 20, 2018 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants