All files / plugins / anchors.ts

100.00% Branches 0/0
100.00% Lines 10/10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
x1
 
x1
x1
 
x1
 
 
 
 
 
 
 
 
 
x1
x1
x1
x6
x2
x1


















// Imports
import type { Plugin } from "../renderer.ts"
import rehypeSlug from "rehype-slug"
import rehypeAutolinkHeadings from "rehype-autolink-headings"

/**
 * Add anchors to headings and autolink them.
 *
 * @example
 * ```md
 * # foo
 * ```
 * ```html
 * <h1 id="foo"><a href="#foo">foo</a></h1>
 * ```
 */
export default {
  rehype(processor) {
    return processor.use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: "wrap" })
  },
} as Plugin