caseSensitive: [[false, 'Treat attributes in case sensitive manner (useful for SVG; e.g. viewBox)']],
minifyJS: [[false, 'Minify Javascript in script elements and on* attributes (uses UglifyJS)']],
minifyCSS: [[false, 'Minify CSS in style elements and style attributes (uses clean-css)']],
+ minifySVG:[[false, 'Minify SVG (uses SVGO)']],
minifyURLs: [[false, 'Minify URLs in various attributes (uses relateurl)']],
ignoreCustomComments: [[false, 'Array of regex\'es that allow to ignore certain comments, when matched', 'string'], 'json-regex'],
processScripts: [[false, 'Array of strings corresponding to types of script elements to process through minifier (e.g. "text/ng-template", "text/x-handlebars-template", etc.)', 'string'], 'json-regex'],
'a', 'abbr', 'acronym', 'b', 'bdi', 'bdo', 'big', 'button', 'cite',
'code', 'del', 'dfn', 'em', 'font', 'i', 'ins', 'kbd', 'mark', 'q',
'rt', 'rp', 's', 'samp', 'small', 'span', 'strike', 'strong',
- 'sub', 'sup', 'svg', 'time', 'tt', 'u', 'var'
+ 'sub', 'sup', 'time', 'tt', 'u', 'var'
],
lineBreakBefore = /^[\t ]*[\n\r]+[\t\n\r ]*/,
lineBreakAfter = /[\t\n\r ]*[\n\r]+[\t ]*$/,
return text;
}
+ function minifySVG(text, options) {
+ if (!text.trim().length) {
+ return text;
+ }
+
+ if (typeof options !== 'object') {
+ options = { };
+ }
+
+ try {
+ if (typeof require === 'function'){
+ var SVGO = require( 'svgo' );
+
+ if (text){
+ var svgo1 = new SVGO(options);
+ svgo1.optimize(text, function (rr) {
+ text = rr.data;
+ });
+ }
+ }
+ }
+ catch (err) {
+ log(err);
+ }
+
+ return text;
+ }
+
function minify(value, options) {
options = options || {};
if (currentTag === 'style' && options.minifyCSS) {
text = minifyCSS(text, options.minifyCSS);
}
+ if (currentTag === 'svg' && options.minifySVG) {
+ text = minifySVG(text, options.minifySVG);
+ }
if (options.collapseWhitespace) {
if (!stackNoTrimWhitespace.length) {
text = ((prevTag && prevTag !== 'comment') || (nextTag && nextTag !== 'comment')) ?
// var block = makeMap('address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul');
// Inline Elements - HTML 4.01
- var inline = makeMap('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,noscript,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,svg,textarea,tt,u,var');
+ var inline = makeMap('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,noscript,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var');
// Elements that you can, intentionally, leave open
// (and which close themselves)
var fillAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected');
// Special Elements (can contain anything)
- var special = makeMap('script,style');
+ var special = makeMap('script,style,svg');
var reCache = {}, stackedTag, reStackedTag, tagMatch;