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.
Additionally, AnchorHeading
is useful when rendering partial files into one location where there are duplicate headings (for example, when there are multiple H3 corresponding to /#create
in one page). AnchorHeading
allows you to explicitly define fragments, ensuring that each heading can be referred correctly with unique anchors.