diff --git a/eleventy.config.js b/eleventy.config.js index 2e53ca2..34baddb 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -2,6 +2,7 @@ import { eleventyImageTransformPlugin } from "@11ty/eleventy-img"; import { attrs } from "@mdit/plugin-attrs"; import { markdownitLinkAttributes } from 'markdown-it-link-attributes'; +import markdownitIdAttributes from "markdown-it-anchor"; import path from "node:path"; @@ -12,7 +13,7 @@ export default async function (eleventyConfig) { eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(attrs)); /* Markdown apply target="_blank" to all external links */ - const milaOptions = { + eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(markdownitLinkAttributes, { matcher(href) { return href.match(/^https?:\/\//); }, @@ -20,8 +21,13 @@ export default async function (eleventyConfig) { target: "_blank", rel: "external", }, - }; - eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(markdownitLinkAttributes, milaOptions)); + })); + + /* Markdown apply ID attributes to headers */ + eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(markdownitIdAttributes, { + level: [2, 3, 4], + tabIndex: false, + })); /* Bundles */ /* CSS */ diff --git a/package-lock.json b/package-lock.json index fa41c34..07dac14 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@11ty/eleventy-img": "^6.0.4", "@mdit/plugin-attrs": "^0.25.1", "luxon": "^3.7.2", + "markdown-it-anchor": "^10.0.0", "markdown-it-link-attributes": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main" } }, @@ -1798,6 +1799,17 @@ "markdown-it": "bin/markdown-it.mjs" } }, + "node_modules/markdown-it-anchor": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-10.0.0.tgz", + "integrity": "sha512-Q8g7Z6OBdH3eXF0lujFqukIxUvgCDZcjzCrJxmD6QiEzU1HWR9fVN+Bf6gxmM+0yrPFs+jUw8gNjLmUQqt6Eew==", + "dev": true, + "license": "Unlicense", + "peerDependencies": { + "@types/markdown-it": "*", + "markdown-it": "*" + } + }, "node_modules/markdown-it-link-attributes": { "version": "4.0.1", "resolved": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main", diff --git a/package.json b/package.json index 6ab6920..59f1f32 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@11ty/eleventy-img": "^6.0.4", "@mdit/plugin-attrs": "^0.25.1", "luxon": "^3.7.2", + "markdown-it-anchor": "^10.0.0", "markdown-it-link-attributes": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main" } }