Skip to content

rehype plugin to generate a table of contents from headings in your markdown.

License

mehm8128/rehype-toc

Repository files navigation

rehype-toc

CI on main NPM Version License: MIT

rehype plugin to generate a table of contents from headings in your markdown.

You can create the table of contents as follows.

A table of contents whose each items are anchor link.

Installation

pnpm add @mehm8128/rehype-toc

Usage

astro.config.mjs

import { rehypeCollapsibleToc } from "@mehm8128/rehype-toc";

export default defineConfig({
  markdown: {
    rehypePlugins: [rehypeCollapsibleToc],
  },
});

rehype

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);

About

rehype plugin to generate a table of contents from headings in your markdown.

Resources

License

Stars

Watchers

Forks

Packages

No packages published