Describe the bug
The docs say:
If there is no class attribute 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
.svg file and ensure it has a class field on the svg element and has an existing classname, such as class="first".
- Add config for the
addClassesToSVGElement, such as:
{
name: 'addClassesToSVGElement',
params: {
className: 'second',
},
}
- Run
svgo on the .svg file.
- See that the class field now says
class="first second", instead of class="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
Describe the bug
The docs say:
However, this does not appear to be the case because the logic inside the
addClassesToSVGElementbuilds itsclassListfrom the existing classes that may be present here.To Reproduce
Steps to reproduce the behavior:
.svgfile and ensure it has aclassfield on thesvgelement and has an existing classname, such asclass="first".addClassesToSVGElement, such as:svgoon the.svgfile.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.