-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
addClassesToSVGElement doesn't clear out existing classes #2209
Copy link
Copy link
Description
Describe the bug
The docs say:
If there is no
classattribute to begin with, it will be added. However, if the[sic] there were already classes assigned, these are removed and replaced with the classes configured in this plugin.
However, this does not appear to be the case because the logic inside the addClassesToSVGElement builds its classList from the existing classes that may be present here.
To Reproduce
Steps to reproduce the behavior:
- Take an existing
.svgfile and ensure it has aclassfield on thesvgelement and has an existing classname, such asclass="first". - Add config for the
addClassesToSVGElement, such as:
{
name: 'addClassesToSVGElement',
params: {
className: 'second',
},
}
- Run
svgoon the.svgfile. - See that the class field now says
class="first second", instead ofclass="second".
Expected behavior
The plugin should clear out existing classes and/or not say in the docs it should clear out the existing classes and add the option to clear them out.
- SVGO Version 4.0.1
- Node.js Version v25.6.1
- OS: macOS 15.7.4
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels