From 6dfded9441387233b204380f014883ec3af8bd80 Mon Sep 17 00:00:00 2001 From: John Kenny Date: Wed, 21 Aug 2024 12:45:28 -0700 Subject: [PATCH 1/3] inlineStyles plugin should not remove id attribute from elements. --- plugins/inlineStyles.js | 19 +------------------ test/plugins/inlineStyles.16.svg.txt | 2 +- test/plugins/inlineStyles.29.svg.txt | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 test/plugins/inlineStyles.29.svg.txt diff --git a/plugins/inlineStyles.js b/plugins/inlineStyles.js index 26b4314b8..0928a2bbe 100644 --- a/plugins/inlineStyles.js +++ b/plugins/inlineStyles.js @@ -293,7 +293,7 @@ export const fn = (root, params) => { return; } - // clean up matched class + ID attribute values + // clean up matched class values for (const selector of sortedSelectors) { if (selector.matchedElements == null) { continue; @@ -333,23 +333,6 @@ export const fn = (root, params) => { } else { selectedEl.attributes.class = Array.from(classList).join(' '); } - - // ID - const firstSubSelector = selector.node.children.first; - if ( - firstSubSelector?.type === 'IdSelector' && - selectedEl.attributes.id === firstSubSelector.name && - !selectors.some((selector) => - includesAttrSelector( - selector.item, - 'id', - firstSubSelector.name, - true, - ), - ) - ) { - delete selectedEl.attributes.id; - } } } diff --git a/test/plugins/inlineStyles.16.svg.txt b/test/plugins/inlineStyles.16.svg.txt index 31f548af2..822700015 100644 --- a/test/plugins/inlineStyles.16.svg.txt +++ b/test/plugins/inlineStyles.16.svg.txt @@ -27,7 +27,7 @@ button - + diff --git a/test/plugins/inlineStyles.29.svg.txt b/test/plugins/inlineStyles.29.svg.txt new file mode 100644 index 000000000..be69bb657 --- /dev/null +++ b/test/plugins/inlineStyles.29.svg.txt @@ -0,0 +1,20 @@ +inlineStyles plugin should not remove id attribute from target element. + +See: https://github.com/svg/svgo/issues/1486 + +=== + + + + + + + +@@@ + + + + + From 78026c8595f11fed6e0ef5a03bf21e312cd0585b Mon Sep 17 00:00:00 2001 From: John Kenny Date: Wed, 21 Aug 2024 17:08:53 -0700 Subject: [PATCH 2/3] Changed related issue number. --- test/plugins/inlineStyles.29.svg.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plugins/inlineStyles.29.svg.txt b/test/plugins/inlineStyles.29.svg.txt index be69bb657..ae503ea66 100644 --- a/test/plugins/inlineStyles.29.svg.txt +++ b/test/plugins/inlineStyles.29.svg.txt @@ -1,6 +1,6 @@ inlineStyles plugin should not remove id attribute from target element. -See: https://github.com/svg/svgo/issues/1486 +See: https://github.com/svg/svgo/issues/2065 === From fc49fc1ebfe63deb8490fbf8ff117b285e710641 Mon Sep 17 00:00:00 2001 From: John Kenny Date: Wed, 21 Aug 2024 18:24:36 -0700 Subject: [PATCH 3/3] Rename file to avoid conflict with PR 2056. --- test/plugins/{inlineStyles.29.svg.txt => inlineStyles.30.svg.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/plugins/{inlineStyles.29.svg.txt => inlineStyles.30.svg.txt} (100%) diff --git a/test/plugins/inlineStyles.29.svg.txt b/test/plugins/inlineStyles.30.svg.txt similarity index 100% rename from test/plugins/inlineStyles.29.svg.txt rename to test/plugins/inlineStyles.30.svg.txt