Anchor heading
The AnchorHeading
component defines headings. Specifically, AnchorHeading
performs the following:
- Generates URL fragments corresponding to headings.
- Formats URL fragments into compatible syntax. For example, a
&
is replaced with a-
. - Creates a button to copy the URL at each fragment.
- Allows heading fragments to be defined separately from the text of the heading itself.
Markdown files (including partials) have this behavior by default, applied via rehype plugins. Therefore, the AnchorHeading
component is usually only required when writing headings yourself inside components, or when working on non-markdown files.
To override the ID given to a heading within Markdown, add an MDX comment at the end of the line:
It will result in the following HTML: