help readers find their way @mdsvex/plugin-anchors
Anchors
Heading anchors, a link on every heading that has an id
Install
pnpm add -D @mdsvex/plugin-anchors Turn it on
import { anchors } from '@mdsvex/plugin-anchors';
mdsvex({ heading_ids: true, plugins: [anchors()] }); What it reads
heading
## Headingacts on headings
An example
You write
## Getting started Every heading with an id links to itself.
You get
Getting started
Every heading with an id links to itself.
Puts a link to itself on every heading that has an id:
<h2 id="getting-started"><a href="#getting-started">Getting started</a></h2>It needs heading_ids. The plugin makes no ids of its own. It links the id each heading has once heading_ids has run, so with the option off no heading has one and nothing is linked. A heading left without an id, such as ## {title}, gets no link either. An id a parse plugin set is linked like any other.
anchors({
position: 'wrap' | 'prepend' | 'append' = 'wrap',
attrs: Record<string, string>
});'wrap'puts the content of the heading inside the link. A heading that already holds a link is left as it is, since a link can't hold another.'prepend'and'append'add an empty link before or after the content, witharia-hidden="true"andtabindex="-1", for a stylesheet to draw:
anchors({ position: 'prepend', attrs: { class: 'anchor' } });<h2 id="getting-started">
<a href="#getting-started" aria-hidden="true" tabindex="-1" class="anchor"></a>Getting started
</h2>.anchor::before {
content: '#';
}attrsare more attributes for the link. One named as a default replaces it.