rehype plugin to generate a table of contents from headings in your markdown.
You can create the table of contents as follows.
pnpm add @mehm8128/rehype-tocimport { rehypeCollapsibleToc } from "@mehm8128/rehype-toc";
export default defineConfig({
markdown: {
rehypePlugins: [rehypeCollapsibleToc],
},
});import { rehype } from "rehype"
import { rehypeCollapsibleToc } from "@mehm8128/rehype-toc";
const input = "<h2 id="heading-id"><a href="#heading-id">Heading</a></h2>";
const { value } = await rehype().use(rehypeCollapsibleToc).process(input);