From 389bad367e594359c79a3d40564da2ef037bddb3 Mon Sep 17 00:00:00 2001 From: John Kenny Date: Tue, 2 Jan 2024 19:56:55 -0800 Subject: [PATCH 1/2] Fixed bug in removeUselessDefs - treat nonrendering elements the same as defs (preserve useful nodes). --- plugins/removeUselessDefs.js | 11 +++++------ test/plugins/removeUselessDefs.04.svg | 23 +++++++++++++++++++++++ test/plugins/removeUselessDefs.05.svg | 23 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 test/plugins/removeUselessDefs.04.svg create mode 100644 test/plugins/removeUselessDefs.05.svg diff --git a/plugins/removeUselessDefs.js b/plugins/removeUselessDefs.js index 5d19810e3..9091eeb89 100644 --- a/plugins/removeUselessDefs.js +++ b/plugins/removeUselessDefs.js @@ -21,7 +21,11 @@ exports.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[]} */ @@ -38,11 +42,6 @@ exports.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..fb29f9b8b --- /dev/null +++ b/test/plugins/removeUselessDefs.04.svg @@ -0,0 +1,23 @@ +Don't remove used symbols. + +=== + + + + + + + + + + +@@@ + + + + + + + + + \ 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 From a6628c94c2d82a8417f54f4ba52e63515826b645 Mon Sep 17 00:00:00 2001 From: johnkenny54 <45182853+johnkenny54@users.noreply.github.com> Date: Wed, 3 Jan 2024 08:53:08 -0800 Subject: [PATCH 2/2] Make suggested change to description. Co-authored-by: Seth Falco --- test/plugins/removeUselessDefs.04.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plugins/removeUselessDefs.04.svg b/test/plugins/removeUselessDefs.04.svg index fb29f9b8b..84e729072 100644 --- a/test/plugins/removeUselessDefs.04.svg +++ b/test/plugins/removeUselessDefs.04.svg @@ -1,4 +1,4 @@ -Don't remove used symbols. +Don't remove non-rendering elements if children have IDs. ===