-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Is your feature request related to a problem? Please describe.
When a heading comes from a Vue component, it gets an id
and shows up in the "On this page" outline, but the invisible <a class="header-anchor">
, which appears on mouse hover, is missing.
Minimal repro:
docs/index.md
<script setup lang="ts">
import AComponent from './AComponent.vue'
</script>
## foo {#foo}
<AComponent />
docs/AComponent.vue
<template>
<h2 id="bar">bar</h2>
<h2 id="baz">baz</h2>
</template>
Result: ## bar
and ## baz
appear in the outline and are linkable, but they have no header‑anchor element, so users cannot easily copy a permalink, and the UI feels a bit inconsistent when hovering the mouse over headings added by the component and the ones written in Markdown.
Describe the solution you'd like
During the same client‑side pass that builds the outline, scan for any <h1‑h6>
with an id
but lacking .header-anchor
, and inject an anchor with the same markup VitePress generates for Markdown headings.
Describe alternatives you've considered
Manually adding the anchor works...
<h2 id="qux">
qux
<a class="header-anchor" href="#qux" aria-label='Permalink to "qux {#qux}"'>​</a>
</h2>
...but is somewhat boilerplate and is brittle. It must be manually added to each place where <h1‑h6>
is used and will break if the theme changes.
Additional context
Screencast of how the repro example looks:
chrome_2025-07-30--19-07-12--488.mp4
Validations
- Follow our Code of Conduct
- Read the docs.
- Read the Contributing Guidelines.
- Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate.