Skip to content

Commit

Permalink
fix(removeUselessDefs): dont remove node if children has id (#1923)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkenny54 committed Jan 3, 2024
1 parent 2442f74 commit 51c59f5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
11 changes: 5 additions & 6 deletions plugins/removeUselessDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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[]}
*/
Expand All @@ -36,11 +40,6 @@ export const fn = () => {
});
}
node.children = usefulNodes;
} else if (
elemsGroups.nonRendering.has(node.name) &&
node.attributes.id == null
) {
detachNodeFromParent(node, parentNode);
}
},
},
Expand Down
23 changes: 23 additions & 0 deletions test/plugins/removeUselessDefs.04.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions test/plugins/removeUselessDefs.05.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 51c59f5

Please sign in to comment.