removeAttrs
Remove attributes from elements matching a custom syntax.
The format accepted is [ element* : attribute* : value* ]
, where:
element
: A regular expression matching element names. An asterisk or omission matches all elements.attribute
: A regular expression matching attribute names.value
: A regular expression matching attribute values. An asterisk or omission matches all values.
For example, path:fill
matches all fill
attributes in <path>
elements.
Usage
- Basic
- Parameters
svgo.config.js
module.exports = {
plugins: [
"removeAttrs"
]
}
svgo.config.js
module.exports = {
plugins: [
{
name: "removeAttrs",
params: {
attrs: null,
elemSeparator: ":",
preserveCurrentColor: false
}
}
]
}
Parameters
attrs
A selector that matches attributes.
elemSeparator
The pattern syntax used by this plugin is
element:attribute:value
, this changes the delimiter from:
to another string.preserveCurrentColor
If to ignore the attribute when it's set to
currentcolor
.
Demo
Live Editor
const svg = ` <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox=" 0 0 150 100 " width="150"> <!-- Created with love! --> <defs> <ellipse cx="50" cy="50.0" rx="50.00" ry="auto" fill="black" id="circle"/> </defs> <g> <use href="#circle" transform="skewX(16)"/> <rect id="useless" width="0" height="0" fill="#ff0000"/> </g> </svg> `; const svgoConfig = { js2svg: { indent: 2, pretty: true }, plugins: [ "removeAttrs" ] } render(<SvgoPreview svg={svg} svgoConfig={svgoConfig}/>);
Result
Loading...