-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Unable to parse custom heading ids #2485
Comments
In MDX, what’s between
Personally I recommend going with option 1 or 2. |
You can also use JSX: # Some heading {<a name="custom-id" />} MDX intentionally has a strictly defined syntax mixing CommonMark with ESM/JSX/expressions, and will not deviate out of the box. |
Thanks folks! Both suggestions make sense. Creating a special case for I still haven’t wrapped my head about generating toc for your examples, will probably pause my investigation for now. If anyone has ides, please share! This is what I am using to extract toc: This code ignores |
Ah, yes, that code there looks a) not tooo smart, b) focussed on plain static markdown. As MDX/JSX are JavaScript, which is evaluated somewhere, to properly support MDX you’d need to handle that. E.g., what if there was an |
Initial checklist
Affected packages and versions
@mdx-js/[email protected]
Link to runnable example
No response
Steps to reproduce
{#custom-id}
to the header:Expected behavior
The document parses. Ideally,
{#custom-id}
is understood as custom heading id, according to Extended markdown syntax. If this kind of parsing is out of scope, at least{#custom-id}
remains a part of the headline and does not break the parsing of the whole document.Actual behavior
Error at 1:18:
Could not parse expression with acorn
Runtime
Other (please specify in steps to reproduce)
Package manager
Other (please specify in steps to reproduce)
OS
Other (please specify in steps to reproduce)
Build and bundle tools
Other (please specify in steps to reproduce)
Additional context
I am here after trying to upgrade from contentlayer to contentlayer2 (the fork upgraded mdx dependencies). I was able to use remark-custom-heading-id previously, but it did not work after the upgrade. An alternative plugin (remark-heading-id) seems to suffer from the same issue. Custom ids are quite important for documents in non-latin alphabets, so it’d be great to figure out how to make them work in the latest mdx ecosystem.
The text was updated successfully, but these errors were encountered: