fix svg in markdown issue
This commit is contained in:
parent
92809cef3f
commit
42516c1499
1 changed files with 10 additions and 7 deletions
|
@ -26,15 +26,18 @@ module.exports = function(eleventyConfig) {
|
||||||
|
|
||||||
// override icon shortcode to make the SVGs accessible
|
// override icon shortcode to make the SVGs accessible
|
||||||
eleventyConfig.addAsyncShortcode("icon", async function(input, attrs) {
|
eleventyConfig.addAsyncShortcode("icon", async function(input, attrs) {
|
||||||
|
let out;
|
||||||
if (!attrs || !("title" in attrs)) {
|
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);
|
||||||
|
out = match[1] + "<title>" + title + "</title>" + match[2];
|
||||||
}
|
}
|
||||||
|
// line breaks cause some issues
|
||||||
const { title, ...newAttrs } = attrs;
|
return out.replaceAll("\n", "");
|
||||||
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];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// process the logo files
|
// process the logo files
|
||||||
|
|
Loading…
Reference in a new issue