Skip to main content
Metaist

Adding a table of contents

Contents

Goal #

To easily add a table of contents for longer posts especially traces.

Which library should I pick? #

pnpm install --save-dev markdown-it-toc-done-right markdown-it-attrs
// eleventy.config.js
const markdownItAttrs = require("markdown-it-attrs");
const markdownItTOC = require("markdown-it-toc-done-right");
// ...
eleventyConfig.amendLibrary("md", (mdLib) => {
    mdLib.use(markdownItAttrs);
    mdLib.use(markdownItTOC, { listType: "ul" });
    // ...
};

Then just slap a [[toc]] tag in the markdown and we're good to go.