diff --git a/plugins/removeUselessDefs.js b/plugins/removeUselessDefs.js index bde64c39b..f61fcb3b5 100644 --- a/plugins/removeUselessDefs.js +++ b/plugins/removeUselessDefs.js @@ -19,7 +19,11 @@ export const fn = () => { return { element: { enter: (node, parentNode) => { - if (node.name === 'defs') { + if ( + node.name === 'defs' || + (elemsGroups.nonRendering.has(node.name) && + node.attributes.id == null) + ) { /** * @type {XastElement[]} */ @@ -36,11 +40,6 @@ export const fn = () => { }); } node.children = usefulNodes; - } else if ( - elemsGroups.nonRendering.has(node.name) && - node.attributes.id == null - ) { - detachNodeFromParent(node, parentNode); } }, }, diff --git a/test/plugins/removeUselessDefs.04.svg b/test/plugins/removeUselessDefs.04.svg new file mode 100644 index 000000000..84e729072 --- /dev/null +++ b/test/plugins/removeUselessDefs.04.svg @@ -0,0 +1,23 @@ +Don't remove non-rendering elements if children have IDs. + +=== + + + + + + + + + + +@@@ + + + + + + + + + \ No newline at end of file diff --git a/test/plugins/removeUselessDefs.05.svg b/test/plugins/removeUselessDefs.05.svg new file mode 100644 index 000000000..ef3557e0a --- /dev/null +++ b/test/plugins/removeUselessDefs.05.svg @@ -0,0 +1,23 @@ +Don't remove used symbols. + +=== + + + + + + + + + + +@@@ + + + + + + + + + \ No newline at end of file