mdx-js / mdx

Markdown for the component era
https://mdxjs.com
MIT License
17.71k stars 1.14k forks source link

Cannot parse `<!-- HTML comment -->` #1737

Closed ferdinandant closed 3 years ago

ferdinandant commented 3 years ago

Subject of the issue

I updated my blog to use @mdx-js/loader v2.0.0-next.9, and it suddenly unable to parse HTML comments. (I used comments to put <!-- prettier-ignore -->)

Unexpected character `!` (U+0021) before name, expected a character that can start a name, such as a letter, `$`, or `_` (note: to create a comment in MDX, use `{/* text */}`)

Removing all <!-- --> in the file will fix the issue.

Your environment

Steps to reproduce

You can recreate the error in mdx-js playground: https://mdxjs.com/playground/

# Hello, world!

<!-- Hello! -->
<button>Here is a button</button>
example.mdx
  3:2  error  Unexpected character `!` (U+0021) before name, expected a character that can start a name, such as a letter, `$`, or `_` (note: to create a comment in MDX, use `{/* text */}`)  unexpected-character  micromark-extension-mdx-jsx

✖ 1 error

Expected behaviour

Parsing should succeed

Actual behaviour

Throws syntax error

ferdinandant commented 3 years ago

whoops, sorry the error log made it clear: Closing this now :bow:

note: to create a comment in MDX, use {/* text */}

Side note

if anyone stumbles with prettier keeps formatting your code, try {/** **/}\ (but it won't work for prettier-ignore since it will add a new newline):