Compare commits

...

1 Commits

Author SHA1 Message Date
codecalm
e098fdfaa6 fix: ensure generated IDs do not start with a number in headings
Some checks failed
Bundlewatch / bundlewatch (push) Has been cancelled
2025-10-06 20:18:50 +02:00

View File

@@ -216,13 +216,20 @@ export default function (eleventyConfig) {
});
const generateUniqueId = (text) => {
return text
let id = text
.replace(/<[^>]+>/g, "")
.replace(/\s/g, "-")
.replace(/[^\w-]+/g, "")
.replace(/--+/g, "-")
.replace(/^-+|-+$/g, "")
.toLowerCase();
// Ensure ID doesn't start with a number (invalid HTML)
if (/^[0-9]/.test(id)) {
id = "h" + id;
}
return id;
}
eleventyConfig.addFilter("headings-id", function (content) {