MDX doesn't seem to support comments. I tried both JS and Markdown comments:
const mdx = require('@mdx-js/mdx');
console.log(mdx.sync(`
import { Foo } from 'bar'
// this is a JS comment
# Hello, world!
<!-- this is a Markdown comment -->
<Foo />
`));
↓
import { Foo } from 'bar'
export default ({components}) => <MDXTag name="wrapper" components={components}>
<MDXTag name="p" components={components}>{`// this is a JS comment`}</MDXTag>
<MDXTag name="h1" components={components}>{`Hello, world!`}</MDXTag>
<!-- this is a Markdown comment -->
<Foo /></MDXTag>
Found them:
# Title
{/* this is a comment */}
Lorem ipsum
This makes sense, so I'll close this.
No, that also produces a component:
<MDXTag name="p" components={components}>
{` {/`}
<MDXTag name="em" components={components} parentName="p">
{` this is a comment `}
</MDXTag>
{`/}`}
</MDXTag>
It looks like this is working for most comments but I just ran into an error with comments in MD
The markdown looks like this:
# login
<!-- AUTO-GENERATED-CONTENT:START (TOC) -->
- [login](#login-1)
<!-- AUTO-GENERATED-CONTENT:END -->
It replaces the top <!-- AUTO-GENERATED-CONTENT:START (TOC) --> correctly but passes over the second comment <!-- AUTO-GENERATED-CONTENT:END --> because there is no newline
This results in a babel error:
Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (15:1)
13 | <MDXTag name="li" components={components} parentName="ul">
14 | <MDXTag name="p" components={components} parentName="li"><MDXTag name="a" components={components} parentName="p" props={{"href":"#login-1"}}>{`login`}</MDXTag></MDXTag>
> 15 | <!-- AUTO-GENERATED-CONTENT:END -->
| ^
16 | </MDXTag>
17 | </MDXTag>
18 | {/* AUTO-GENERATED-CONTENT:START (GENERATE_COMMANDS_DOCS) */}
I was able to work around it by adding a newline after the list. This markdown works because there is a newline after the list
# login
<!-- AUTO-GENERATED-CONTENT:START (TOC) -->
- [login](#login-1)
<!-- AUTO-GENERATED-CONTENT:END -->
Is there a way to support this without the newline? Thanks!
Loving MDX btw it's freaking sweet
Thanks for the bug report! Could you please open a new issue? That way it's easier to track it.
Most helpful comment
Found them:
This makes sense, so I'll close this.