Skip to content

Instantly share code, notes, and snippets.

@fyrebase
Created October 1, 2016 10:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fyrebase/4604f540bc4a329ff3bfde225775d39e to your computer and use it in GitHub Desktop.
Save fyrebase/4604f540bc4a329ff3bfde225775d39e to your computer and use it in GitHub Desktop.
Convert dimensions to viewBox - SVGO Plugin
plugins:
...
- convertDimensions
...
'use strict';
exports.type = 'full';
exports.active = false;
exports.description = 'removes width and height in presence of viewBox';
/**
* Convert width/height to viewBox. Remove width/height attributes when a viewBox attribute converted.
*
* @author Kirk Bentley / Fyrebase
*/
exports.fn = function(data) {
var svg = data.content[0];
if (svg.isElem('svg')) {
svg.addAttr({
name: 'viewBox',
value: '0 0 ' + svg.attr('width').value + ' ' + svg.attr('height').value,
prefix: '',
local: 'class'
});
svg.removeAttr('width');
svg.removeAttr('height');
}
return data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment