Skip to content

Commit 3fa08b0

Browse files
committed
Adds useXlinkHref: true option to opt-out of xlink:href attributes on generator SVG
1 parent e2c0eb7 commit 3fa08b0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

plugin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export default function(eleventyConfig, pluginOptions = {}) {
1818
},
1919
ignoredClasses: [],
2020
generateId: () => `fa11-text-${nanoid()}`,
21+
22+
// https://docs.fontawesome.com/web/add-icons/svg-symbols#what-about-xlinkhref-what-happened-to-that
23+
// https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/xlink:href versus https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/href#svg.elements.use.href
24+
useXlinkHref: true, // use xlink:href for further backwards compat
2125
}, pluginOptions);
2226

2327
if(!options.bundle || typeof options.bundle !== "string") {

src/transform.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,15 @@ function Transform(eleventyConfig, options = {}) {
160160
});
161161
}
162162

163-
content.push({
164-
tag: "use",
165-
attrs: {
166-
href: `#${ref}`,
167-
"xlink:href": `#${ref}`,
168-
}
169-
});
163+
if(options.useXlinkHref) {
164+
content.push({
165+
tag: "use",
166+
attrs: {
167+
href: `#${ref}`,
168+
"xlink:href": `#${ref}`,
169+
}
170+
});
171+
}
170172

171173
return {
172174
tag: "svg",

0 commit comments

Comments
 (0)