diff --git a/.svgo.yml b/.svgo.yml index 9a138406..45bd4764 100644 --- a/.svgo.yml +++ b/.svgo.yml @@ -61,6 +61,10 @@ plugins: unknownAttrs: true defaultAttrs: true + - name: removeNonInheritableGroupAttrs + active: true + type: perItem + - name: removeUselessStrokeAndFill active: true type: perItem diff --git a/plugins/_collections.js b/plugins/_collections.js index 60afc2c7..77c32850 100644 --- a/plugins/_collections.js +++ b/plugins/_collections.js @@ -15,11 +15,6 @@ exports.elemsGroups = { exports.pathElems = ['path', 'glyph', 'missing-glyph']; -// var defaults = exports.defaults = { -// 'externalResourcesRequired': 'false', -// 'xlink:type': 'simple' -// }; - // http://www.w3.org/TR/SVG/intro.html#Definitions exports.attrsGroups = { animationAddition: ['additive', 'accumulate'], diff --git a/plugins/removeNonInheritableGroupAttrs.js b/plugins/removeNonInheritableGroupAttrs.js new file mode 100644 index 00000000..24a244c0 --- /dev/null +++ b/plugins/removeNonInheritableGroupAttrs.js @@ -0,0 +1,31 @@ +'use strict'; + +var inheritableAttrs = require('./_collections').inheritableAttrs, + presentationAttrs = require('./_collections').attrsGroups.presentation, + excludedAttrs = ['display', 'opacity']; + +/** + * Remove non-inheritable group's "presentation" attributes. + * + * @param {Object} item current iteration item + * @return {Boolean} if false, item will be filtered out + * + * @author Kir Belevich + */ +exports.removeNonInheritableGroupAttrs = function(item) { + + if (item.isElem('g')) { + + item.eachAttr(function(attr) { + if ( + presentationAttrs.indexOf(attr.name) !== -1 && + excludedAttrs.indexOf(attr.name) === -1 && + inheritableAttrs.indexOf(attr.name) === -1 + ) { + item.removeAttr(attr.name); + } + }); + + } + +}; diff --git a/test/plugins/removeNonInheritableGroupAttrs.01.orig.svg b/test/plugins/removeNonInheritableGroupAttrs.01.orig.svg new file mode 100644 index 00000000..0438050e --- /dev/null +++ b/test/plugins/removeNonInheritableGroupAttrs.01.orig.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/test/plugins/removeNonInheritableGroupAttrs.01.should.svg b/test/plugins/removeNonInheritableGroupAttrs.01.should.svg new file mode 100644 index 00000000..59a98b8f --- /dev/null +++ b/test/plugins/removeNonInheritableGroupAttrs.01.should.svg @@ -0,0 +1,5 @@ + + + + +