fix svg in markdown issue

This commit is contained in:
Lyn Fugmann 2024-09-28 12:35:37 +02:00
parent 92809cef3f
commit 42516c1499

View file

@ -26,15 +26,18 @@ module.exports = function(eleventyConfig) {
// override icon shortcode to make the SVGs accessible
eleventyConfig.addAsyncShortcode("icon", async function(input, attrs) {
let out;
if (!attrs || !("title" in attrs)) {
return eleventyConfig.nunjucksAsyncShortcodes.rawIcon(input, attrs);
}
out = await eleventyConfig.nunjucksAsyncShortcodes.rawIcon(input, attrs);
} else {
const { title, ...newAttrs } = attrs;
newAttrs.role = "img";
const svgStr = await eleventyConfig.nunjucksAsyncShortcodes.rawIcon(input, newAttrs);
const match = svgStr.match(/(<svg.*?>)(.*$)/s);
return match[1] + "<title>" + title + "</title>" + match[2];
out = match[1] + "<title>" + title + "</title>" + match[2];
}
// line breaks cause some issues
return out.replaceAll("\n", "");
});
// process the logo files