A simple version of rehype-autolink-headings.
Less dependencies and less useless code. Using typescript to develop.
npm install rehype-autolink-headings-simpleimport { rehypeAutolinkHeadings } from "rehype-autolink-headings-simple";
import { unified } from "unified";
import { parse } from "rehype-parse";
import { stringify } from "rehype-stringify";
const processor = unified()
.use(parse)
.use(rehypeAutolinkHeadings, {
behavior: "append",
properties: {
behavior: "append",
properties: { className: ["anchor"] },
content: { type: "text", value: "#" },
},
})
.use(stringify);
const result = processor.processSync("<h1>Heading</h1>").toString();Astro should change render order manually. See Astro: Heading IDs and plugins
The MIT License (MIT).