htmlminifier.js (html-minifier-3.6.0) | : | htmlminifier.js (html-minifier-4.0.0) | ||
---|---|---|---|---|
skipping to change at line 314 | skipping to change at line 314 | |||
}).join(', '); | }).join(', '); | |||
} | } | |||
else if (isMetaViewport(tag, attrs) && attrName === 'content') { | else if (isMetaViewport(tag, attrs) && attrName === 'content') { | |||
attrValue = attrValue.replace(/\s+/g, '').replace(/[0-9]+\.[0-9]+/g, functio n(numString) { | attrValue = attrValue.replace(/\s+/g, '').replace(/[0-9]+\.[0-9]+/g, functio n(numString) { | |||
// "0.90000" -> "0.9" | // "0.90000" -> "0.9" | |||
// "1.0" -> "1" | // "1.0" -> "1" | |||
// "1.0001" -> "1.0001" (unchanged) | // "1.0001" -> "1.0001" (unchanged) | |||
return (+numString).toString(); | return (+numString).toString(); | |||
}); | }); | |||
} | } | |||
else if (isContentSecurityPolicy(tag, attrs) && attrName.toLowerCase() === 'co | ||||
ntent') { | ||||
return collapseWhitespaceAll(attrValue); | ||||
} | ||||
else if (options.customAttrCollapse && options.customAttrCollapse.test(attrNam e)) { | else if (options.customAttrCollapse && options.customAttrCollapse.test(attrNam e)) { | |||
attrValue = attrValue.replace(/\n+|\r+|\s{2,}/g, ''); | attrValue = attrValue.replace(/\n+|\r+|\s{2,}/g, ''); | |||
} | } | |||
else if (tag === 'script' && attrName === 'type') { | else if (tag === 'script' && attrName === 'type') { | |||
attrValue = trimWhitespace(attrValue.replace(/\s*;\s*/g, ';')); | attrValue = trimWhitespace(attrValue.replace(/\s*;\s*/g, ';')); | |||
} | } | |||
else if (isMediaQuery(tag, attrs, attrName)) { | else if (isMediaQuery(tag, attrs, attrName)) { | |||
attrValue = trimWhitespace(attrValue); | attrValue = trimWhitespace(attrValue); | |||
return options.minifyCSS(attrValue, 'media'); | return options.minifyCSS(attrValue, 'media'); | |||
} | } | |||
skipping to change at line 338 | skipping to change at line 341 | |||
if (tag !== 'meta') { | if (tag !== 'meta') { | |||
return false; | return false; | |||
} | } | |||
for (var i = 0, len = attrs.length; i < len; i++) { | for (var i = 0, len = attrs.length; i < len; i++) { | |||
if (attrs[i].name === 'name' && attrs[i].value === 'viewport') { | if (attrs[i].name === 'name' && attrs[i].value === 'viewport') { | |||
return true; | return true; | |||
} | } | |||
} | } | |||
} | } | |||
function isContentSecurityPolicy(tag, attrs) { | ||||
if (tag !== 'meta') { | ||||
return false; | ||||
} | ||||
for (var i = 0, len = attrs.length; i < len; i++) { | ||||
if (attrs[i].name.toLowerCase() === 'http-equiv' && attrs[i].value.toLowerCa | ||||
se() === 'content-security-policy') { | ||||
return true; | ||||
} | ||||
} | ||||
} | ||||
function ignoreCSS(id) { | function ignoreCSS(id) { | |||
return '/* clean-css ignore:start */' + id + '/* clean-css ignore:end */'; | return '/* clean-css ignore:start */' + id + '/* clean-css ignore:end */'; | |||
} | } | |||
// Wrap CSS declarations for CleanCSS > 3.x | // Wrap CSS declarations for CleanCSS > 3.x | |||
// See https://github.com/jakubpawlowicz/clean-css/issues/418 | // See https://github.com/jakubpawlowicz/clean-css/issues/418 | |||
function wrapCSS(text, type) { | function wrapCSS(text, type) { | |||
switch (type) { | switch (type) { | |||
case 'inline': | case 'inline': | |||
return '*{' + text + '}'; | return '*{' + text + '}'; | |||
skipping to change at line 867 | skipping to change at line 881 | |||
var customFragments = options.ignoreCustomFragments.map(function(re) { | var customFragments = options.ignoreCustomFragments.map(function(re) { | |||
return re.source; | return re.source; | |||
}); | }); | |||
if (customFragments.length) { | if (customFragments.length) { | |||
var reCustomIgnore = new RegExp('\\s*(?:' + customFragments.join('|') + ')+\ \s*', 'g'); | var reCustomIgnore = new RegExp('\\s*(?:' + customFragments.join('|') + ')+\ \s*', 'g'); | |||
// temporarily replace custom ignored fragments with unique attributes | // temporarily replace custom ignored fragments with unique attributes | |||
value = value.replace(reCustomIgnore, function(match) { | value = value.replace(reCustomIgnore, function(match) { | |||
if (!uidAttr) { | if (!uidAttr) { | |||
uidAttr = uniqueId(value); | uidAttr = uniqueId(value); | |||
uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g'); | uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)' + uidAttr + '(\\ s*)', 'g'); | |||
if (options.minifyCSS) { | if (options.minifyCSS) { | |||
options.minifyCSS = (function(fn) { | options.minifyCSS = (function(fn) { | |||
return function(text, type) { | return function(text, type) { | |||
text = text.replace(uidPattern, function(match, prefix, index) { | text = text.replace(uidPattern, function(match, prefix, index) { | |||
var chunks = ignoredCustomMarkupChunks[+index]; | var chunks = ignoredCustomMarkupChunks[+index]; | |||
return chunks[1] + uidAttr + index + chunks[2]; | return chunks[1] + uidAttr + index + uidAttr + chunks[2]; | |||
}); | }); | |||
var ids = []; | var ids = []; | |||
new CleanCSS().minify(wrapCSS(text, type)).warnings.forEach(functi on(warning) { | new CleanCSS().minify(wrapCSS(text, type)).warnings.forEach(functi on(warning) { | |||
var match = uidPattern.exec(warning); | var match = uidPattern.exec(warning); | |||
if (match) { | if (match) { | |||
var id = uidAttr + match[2]; | var id = uidAttr + match[2] + uidAttr; | |||
text = text.replace(id, ignoreCSS(id)); | text = text.replace(id, ignoreCSS(id)); | |||
ids.push(id); | ids.push(id); | |||
} | } | |||
}); | }); | |||
text = fn(text, type); | text = fn(text, type); | |||
ids.forEach(function(id) { | ids.forEach(function(id) { | |||
text = text.replace(ignoreCSS(id), id); | text = text.replace(ignoreCSS(id), id); | |||
}); | }); | |||
return text; | return text; | |||
}; | }; | |||
})(options.minifyCSS); | })(options.minifyCSS); | |||
} | } | |||
if (options.minifyJS) { | if (options.minifyJS) { | |||
options.minifyJS = (function(fn) { | options.minifyJS = (function(fn) { | |||
return function(text, type) { | return function(text, type) { | |||
return fn(text.replace(uidPattern, function(match, prefix, index) { | return fn(text.replace(uidPattern, function(match, prefix, index) { | |||
var chunks = ignoredCustomMarkupChunks[+index]; | var chunks = ignoredCustomMarkupChunks[+index]; | |||
return chunks[1] + uidAttr + index + chunks[2]; | return chunks[1] + uidAttr + index + uidAttr + chunks[2]; | |||
}), type); | }), type); | |||
}; | }; | |||
})(options.minifyJS); | })(options.minifyJS); | |||
} | } | |||
} | } | |||
var token = uidAttr + ignoredCustomMarkupChunks.length; | var token = uidAttr + ignoredCustomMarkupChunks.length + uidAttr; | |||
ignoredCustomMarkupChunks.push(/^(\s*)[\s\S]*?(\s*)$/.exec(match)); | ignoredCustomMarkupChunks.push(/^(\s*)[\s\S]*?(\s*)$/.exec(match)); | |||
return '\t' + token + '\t'; | return '\t' + token + '\t'; | |||
}); | }); | |||
} | } | |||
if (options.sortAttributes && typeof options.sortAttributes !== 'function' || | if (options.sortAttributes && typeof options.sortAttributes !== 'function' || | |||
options.sortClassName && typeof options.sortClassName !== 'function') { | options.sortClassName && typeof options.sortClassName !== 'function') { | |||
createSortFns(value, options, uidIgnore, uidAttr); | createSortFns(value, options, uidIgnore, uidAttr); | |||
} | } | |||
skipping to change at line 968 | skipping to change at line 982 | |||
var item = buffer[buffer.length - 1]; | var item = buffer[buffer.length - 1]; | |||
if (/^(?:<!|$)/.test(item) && item.indexOf(uidIgnore) === -1) { | if (/^(?:<!|$)/.test(item) && item.indexOf(uidIgnore) === -1) { | |||
charsIndex--; | charsIndex--; | |||
} | } | |||
} | } | |||
trimTrailingWhitespace(charsIndex, nextTag); | trimTrailingWhitespace(charsIndex, nextTag); | |||
} | } | |||
new HTMLParser(value, { | new HTMLParser(value, { | |||
partialMarkup: partialMarkup, | partialMarkup: partialMarkup, | |||
continueOnParseError: options.continueOnParseError, | ||||
customAttrAssign: options.customAttrAssign, | ||||
customAttrSurround: options.customAttrSurround, | ||||
html5: options.html5, | html5: options.html5, | |||
start: function(tag, attrs, unary, unarySlash, autoGenerated) { | start: function(tag, attrs, unary, unarySlash, autoGenerated) { | |||
if (tag.toLowerCase() === 'svg') { | if (tag.toLowerCase() === 'svg') { | |||
options = Object.create(options); | options = Object.create(options); | |||
options.caseSensitive = true; | options.caseSensitive = true; | |||
options.keepClosingSlash = true; | options.keepClosingSlash = true; | |||
options.name = identity; | options.name = identity; | |||
} | } | |||
tag = options.name(tag); | tag = options.name(tag); | |||
skipping to change at line 1244 | skipping to change at line 1261 | |||
// preceding comments suppress tag omissions | // preceding comments suppress tag omissions | |||
optionalStartTag = ''; | optionalStartTag = ''; | |||
optionalEndTag = ''; | optionalEndTag = ''; | |||
} | } | |||
buffer.push(text); | buffer.push(text); | |||
}, | }, | |||
doctype: function(doctype) { | doctype: function(doctype) { | |||
buffer.push(options.useShortDoctype ? '<!doctype' + | buffer.push(options.useShortDoctype ? '<!doctype' + | |||
(options.removeTagWhitespace ? '' : ' ') + 'html>' : | (options.removeTagWhitespace ? '' : ' ') + 'html>' : | |||
collapseWhitespaceAll(doctype)); | collapseWhitespaceAll(doctype)); | |||
}, | } | |||
customAttrAssign: options.customAttrAssign, | ||||
customAttrSurround: options.customAttrSurround | ||||
}); | }); | |||
if (options.removeOptionalTags) { | if (options.removeOptionalTags) { | |||
// <html> may be omitted if first thing inside is not comment | // <html> may be omitted if first thing inside is not comment | |||
// <head> or <body> may be omitted if empty | // <head> or <body> may be omitted if empty | |||
if (topLevelTags(optionalStartTag)) { | if (topLevelTags(optionalStartTag)) { | |||
removeStartTag(); | removeStartTag(); | |||
} | } | |||
// except for </dt> or </thead>, end tags may be omitted if no more content in parent element | // except for </dt> or </thead>, end tags may be omitted if no more content in parent element | |||
if (optionalEndTag && !trailingTags(optionalEndTag)) { | if (optionalEndTag && !trailingTags(optionalEndTag)) { | |||
End of changes. 9 change blocks. | ||||
8 lines changed or deleted | 25 lines changed or added |