Skip to content

Commit

Permalink
removeXMLNS plugin: remove xmlns attribute for inline svg usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobeat committed Apr 5, 2016
1 parent b35d828 commit 768107b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions .svgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ plugins:
- removeXMLProcInst
- removeComments
- removeMetadata
- removeXMLNS
- removeEditorsNSData
- cleanupAttrs
- minifyStyles
Expand Down
28 changes: 28 additions & 0 deletions plugins/removeXMLNS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

exports.type = 'perItem';

exports.active = false;

exports.description = 'removes xmlns attribute (for inline svg, disabled by default)';

/**
* Remove the xmlns attribute when present.
*
* @example
* <svg viewBox="0 0 100 50" xmlns="http://www.w3.org/2000/svg">
* ↓
* <svg viewBox="0 0 100 50">
*
* @param {Object} item current iteration item
* @return {Boolean} if true, xmlns will be filtered out
*
* @author Ricardo Tomasi
*/
exports.fn = function(item) {

if (item.isElem('svg') && item.hasAttr('xmlns')) {
item.removeAttr('xmlns');
}

};

0 comments on commit 768107b

Please sign in to comment.