Skip to content

Commit

Permalink
plugins/removeNonInheritableGroupAttrs: new plugin to fix #101
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsweet committed Feb 22, 2013
1 parent f50b4f8 commit f47220c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .svgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ plugins:
unknownAttrs: true
defaultAttrs: true

- name: removeNonInheritableGroupAttrs
active: true
type: perItem

- name: removeUselessStrokeAndFill
active: true
type: perItem
Expand Down
5 changes: 0 additions & 5 deletions plugins/_collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
31 changes: 31 additions & 0 deletions plugins/removeNonInheritableGroupAttrs.js
Original file line number Diff line number Diff line change
@@ -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);
}
});

}

};
5 changes: 5 additions & 0 deletions test/plugins/removeNonInheritableGroupAttrs.01.orig.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions test/plugins/removeNonInheritableGroupAttrs.01.should.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f47220c

Please sign in to comment.