Heading ID plugin recommendation results in incorrect header IDs
Nobody has claimed this yet.
- Dominant language
- MDX
- Stars
- 1.7k
- Forks
- 1.9k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 97
Description
📚 Subject area/topic
Markdown
📋 Page(s) affected (or suggested, for new content)
https://docs.astro.build/en/guides/markdown-content/#heading-ids-and-plugins
📋 Description of content that is out-of-date or incorrect
The section titled "Heading IDs and plugins" recommends applying the satteriHeadingIdsPlugin() before custom plugins when the custom plugins need to access the IDs injected by Astro. However, the code suggestion reads as follows:
hastPlugins: [
satteriHeadingIdsPlugin(),
otherPluginThatReliesOnHeadingIDs,
],
This approach creates only one plugin instance (and thus one github-slugger instance) for the whole site, causing header ID disambiguation (e.g., "some-header-1" instead of "some-header") to occur when it's not necessary. For example, if page one has # Heading and page two also has # Heading, one of the pages will get a header ID of "heading" and the other will get a header ID of "heading-1". This behavior is unpredictable and unnecessary, since disambiguation is necessary only within a single page.
Instead, the code snippet should read:
hastPlugins: [
() => satteriHeadingIdsPlugin(),
otherPluginThatReliesOnHeadingIDs,
],
(perhaps with an explanation of why that structure is needed) so that a plugin instance is created per-page, preventing disambiguation from occurring unnecessarily and making generated header IDs more predictable.
🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the “Heading IDs and plugins” section at docs.astro.build/en/guides/markdown-content/#heading-ids-and-plugins and review the hastPlugins example. Update the snippet to create satteriHeadingIdsPlugin() per page, add the explanation about avoiding cross-page ID disambiguation, and verify the example matches the reported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 92/100