add id attributes package

This commit is contained in:
2026-09-22 18:14:49 -07:00
parent 9f321024cf
commit 218baa9539
3 changed files with 22 additions and 3 deletions
+9 -3
View File
@@ -2,6 +2,7 @@ import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import { attrs } from "@mdit/plugin-attrs"; import { attrs } from "@mdit/plugin-attrs";
import { markdownitLinkAttributes } from 'markdown-it-link-attributes'; import { markdownitLinkAttributes } from 'markdown-it-link-attributes';
import markdownitIdAttributes from "markdown-it-anchor";
import path from "node:path"; import path from "node:path";
@@ -12,7 +13,7 @@ export default async function (eleventyConfig) {
eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(attrs)); eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(attrs));
/* Markdown apply target="_blank" to all external links */ /* Markdown apply target="_blank" to all external links */
const milaOptions = { eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(markdownitLinkAttributes, {
matcher(href) { matcher(href) {
return href.match(/^https?:\/\//); return href.match(/^https?:\/\//);
}, },
@@ -20,8 +21,13 @@ export default async function (eleventyConfig) {
target: "_blank", target: "_blank",
rel: "external", 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 */ /* Bundles */
/* CSS */ /* CSS */
+12
View File
@@ -12,6 +12,7 @@
"@11ty/eleventy-img": "^6.0.4", "@11ty/eleventy-img": "^6.0.4",
"@mdit/plugin-attrs": "^0.25.1", "@mdit/plugin-attrs": "^0.25.1",
"luxon": "^3.7.2", "luxon": "^3.7.2",
"markdown-it-anchor": "^10.0.0",
"markdown-it-link-attributes": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main" "markdown-it-link-attributes": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main"
} }
}, },
@@ -1798,6 +1799,17 @@
"markdown-it": "bin/markdown-it.mjs" "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": { "node_modules/markdown-it-link-attributes": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main", "resolved": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main",
+1
View File
@@ -14,6 +14,7 @@
"@11ty/eleventy-img": "^6.0.4", "@11ty/eleventy-img": "^6.0.4",
"@mdit/plugin-attrs": "^0.25.1", "@mdit/plugin-attrs": "^0.25.1",
"luxon": "^3.7.2", "luxon": "^3.7.2",
"markdown-it-anchor": "^10.0.0",
"markdown-it-link-attributes": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main" "markdown-it-link-attributes": "https://github.com/lee0c/markdown-it-link-attributes/tarball/main"
} }
} }