html-minifier
Advanced tools
Comparing version 3.5.15 to 3.5.16
{ | ||
"name": "html-minifier", | ||
"description": "Highly configurable, well-tested, JavaScript-based HTML minifier.", | ||
"version": "3.5.15", | ||
"version": "3.5.16", | ||
"keywords": [ | ||
@@ -75,3 +75,3 @@ "cli", | ||
"brotli": "1.3.x", | ||
"chalk": "2.3.x", | ||
"chalk": "2.4.x", | ||
"cli-table": "0.3.x", | ||
@@ -78,0 +78,0 @@ "lzma": "2.3.x", |
@@ -25,15 +25,15 @@ # HTMLMinifier | ||
| ---------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:| | ||
| [Google](https://www.google.com/) | 45 | **42** | 45 | 47 | 45 | | ||
| [Twitter](https://twitter.com/) | 122 | **89** | 115 | 134 | 115 | | ||
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 142 | **110** | 119 | 123 | 118 | | ||
| [New York Times](https://www.nytimes.com/) | 221 | **152** | 172 | 168 | 156 | | ||
| [Stack Overflow](https://stackoverflow.com/) | 247 | **193** | 202 | 210 | 200 | | ||
| [Google](https://www.google.com/) | 50 | **45** | 49 | 51 | 49 | | ||
| [Twitter](https://twitter.com/) | 128 | **94** | 121 | 140 | 121 | | ||
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 144 | **112** | 120 | 125 | 120 | | ||
| [New York Times](https://www.nytimes.com/) | 212 | **145** | 164 | 159 | 148 | | ||
| [Stack Overflow](https://stackoverflow.com/) | 249 | **194** | 203 | 212 | 201 | | ||
| [Bootstrap CSS](https://getbootstrap.com/docs/3.3/css/) | 272 | **260** | 269 | 229 | 269 | | ||
| [BBC](https://www.bbc.co.uk/) | 283 | **228** | 275 | 278 | 262 | | ||
| [Amazon](https://www.amazon.co.uk/) | 370 | **315** | 356 | 367 | n/a | | ||
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 474 | **442** | 458 | 473 | 457 | | ||
| [NBC](https://www.nbc.com/) | 666 | **627** | 663 | 665 | n/a | | ||
| [BBC](https://www.bbc.co.uk/) | 295 | **237** | 287 | 290 | 272 | | ||
| [Amazon](https://www.amazon.co.uk/) | 391 | **336** | 377 | 389 | n/a | | ||
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 474 | **442** | 458 | 474 | 458 | | ||
| [NBC](https://www.nbc.com/) | 689 | **647** | 685 | 687 | n/a | | ||
| [Eloquent Javascript](https://eloquentjavascript.net/1st_edition/print.html) | 870 | **815** | 840 | 864 | n/a | | ||
| [ES6 table](https://kangax.github.io/compat-table/es6/) | 4916 | **4189** | 4652 | n/a | n/a | | ||
| [ES6 draft](https://tc39.github.io/ecma262/) | 6099 | **5435** | 5597 | n/a | n/a | | ||
| [ES6 table](https://kangax.github.io/compat-table/es6/) | 5014 | **4273** | 4745 | n/a | n/a | | ||
| [ES6 draft](https://tc39.github.io/ecma262/) | 6101 | **5437** | 5599 | n/a | n/a | | ||
@@ -40,0 +40,0 @@ ## Options Quick Reference |
@@ -12,6 +12,3 @@ 'use strict'; | ||
function trimWhitespace(str) { | ||
if (typeof str !== 'string') { | ||
return str; | ||
} | ||
return str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, ''); | ||
return str && str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, ''); | ||
} | ||
@@ -262,3 +259,3 @@ | ||
function cleanAttributeValue(tag, attrName, attrValue, options, attrs) { | ||
if (attrValue && isEventAttribute(attrName, options)) { | ||
if (isEventAttribute(attrName, options)) { | ||
attrValue = trimWhitespace(attrValue).replace(/^javascript:\s*/i, ''); | ||
@@ -319,3 +316,3 @@ return options.minifyJS(attrValue, true); | ||
} | ||
else if (attrValue && options.customAttrCollapse && options.customAttrCollapse.test(attrName)) { | ||
else if (options.customAttrCollapse && options.customAttrCollapse.test(attrName)) { | ||
attrValue = attrValue.replace(/\n+|\r+|\s{2,}/g, ''); | ||
@@ -528,3 +525,3 @@ } | ||
function normalizeAttr(attr, attrs, tag, options) { | ||
var attrName = options.caseSensitive ? attr.name : attr.name.toLowerCase(), | ||
var attrName = options.name(attr.name), | ||
attrValue = attr.value; | ||
@@ -545,3 +542,5 @@ | ||
attrValue = cleanAttributeValue(tag, attrName, attrValue, options, attrs); | ||
if (attrValue) { | ||
attrValue = cleanAttributeValue(tag, attrName, attrValue, options, attrs); | ||
} | ||
@@ -623,2 +622,5 @@ if (options.removeEmptyAttributes && | ||
var options = { | ||
name: function(name) { | ||
return name.toLowerCase(); | ||
}, | ||
canCollapseWhitespace: canCollapseWhitespace, | ||
@@ -640,3 +642,8 @@ canTrimWhitespace: canTrimWhitespace, | ||
var value = values[key]; | ||
if (key === 'log') { | ||
if (key === 'caseSensitive') { | ||
if (value) { | ||
options.name = identity; | ||
} | ||
} | ||
else if (key === 'log') { | ||
if (typeof value === 'function') { | ||
@@ -742,3 +749,3 @@ options.log = value; | ||
return attrs.map(function(attr) { | ||
return options.caseSensitive ? attr.name : attr.name.toLowerCase(); | ||
return options.name(attr.name); | ||
}); | ||
@@ -767,3 +774,3 @@ } | ||
var attr = attrs[i]; | ||
if (classChain && (options.caseSensitive ? attr.name : attr.name.toLowerCase()) === 'class') { | ||
if (classChain && attr.value && options.name(attr.name) === 'class') { | ||
classChain.add(trimWhitespace(attr.value).split(/[ \t\n\f\r]+/).filter(shouldSkipUIDs)); | ||
@@ -958,12 +965,9 @@ } | ||
start: function(tag, attrs, unary, unarySlash, autoGenerated) { | ||
var lowerTag = tag.toLowerCase(); | ||
if (lowerTag === 'svg') { | ||
if (tag.toLowerCase() === 'svg') { | ||
options = Object.create(options); | ||
options.caseSensitive = true; | ||
options.keepClosingSlash = true; | ||
options.caseSensitive = true; | ||
options.name = identity; | ||
} | ||
tag = options.caseSensitive ? tag : lowerTag; | ||
tag = options.name(tag); | ||
currentTag = tag; | ||
@@ -1048,7 +1052,6 @@ charsPrevTag = tag; | ||
end: function(tag, attrs, autoGenerated) { | ||
var lowerTag = tag.toLowerCase(); | ||
if (lowerTag === 'svg') { | ||
if (tag.toLowerCase() === 'svg') { | ||
options = Object.getPrototypeOf(options); | ||
} | ||
tag = options.caseSensitive ? tag : lowerTag; | ||
tag = options.name(tag); | ||
@@ -1285,16 +1288,25 @@ // check if current tag is in a whitespace stack | ||
if (maxLineLength) { | ||
var token; | ||
var lines = []; | ||
var line = ''; | ||
for (var i = 0, len = results.length; i < len; i++) { | ||
token = results[i]; | ||
if (line.length + token.length < maxLineLength) { | ||
line += token; | ||
var line = '', lines = []; | ||
while (results.length) { | ||
var len = line.length; | ||
var end = results[0].indexOf('\n'); | ||
if (end < 0) { | ||
line += results.shift(); | ||
} | ||
else { | ||
lines.push(line.replace(/^\n/, '')); | ||
line = token; | ||
line += results[0].slice(0, end); | ||
results[0] = results[0].slice(end + 1); | ||
} | ||
if (len > 0 && line.length >= maxLineLength) { | ||
lines.push(line.slice(0, len)); | ||
line = line.slice(len); | ||
} | ||
else if (end >= 0) { | ||
lines.push(line); | ||
line = ''; | ||
} | ||
} | ||
lines.push(line); | ||
if (line) { | ||
lines.push(line); | ||
} | ||
@@ -1301,0 +1313,0 @@ str = lines.join('\n'); |
@@ -270,2 +270,9 @@ /*! | ||
function closeIfFound(tagName) { | ||
if (findTag(tagName) >= 0) { | ||
parseEndTag('', tagName); | ||
return true; | ||
} | ||
} | ||
function handleStartTag(match) { | ||
@@ -275,4 +282,21 @@ var tagName = match.tagName; | ||
if (handler.html5 && lastTag === 'p' && nonPhrasing(tagName)) { | ||
parseEndTag('', lastTag); | ||
if (handler.html5) { | ||
if (lastTag === 'p' && nonPhrasing(tagName)) { | ||
parseEndTag('', lastTag); | ||
} | ||
else if (tagName === 'tbody') { | ||
closeIfFound('thead'); | ||
} | ||
else if (tagName === 'tfoot') { | ||
if (!closeIfFound('tbody')) { | ||
closeIfFound('thead'); | ||
} | ||
} | ||
if (tagName === 'col' && findTag('colgroup') < 0) { | ||
lastTag = 'colgroup'; | ||
stack.push({ tag: lastTag, attrs: [] }); | ||
if (handler.start) { | ||
handler.start(lastTag, [], false, ''); | ||
} | ||
} | ||
} | ||
@@ -358,2 +382,13 @@ | ||
function findTag(tagName) { | ||
var pos; | ||
var needle = tagName.toLowerCase(); | ||
for (pos = stack.length - 1; pos >= 0; pos--) { | ||
if (stack[pos].tag.toLowerCase() === needle) { | ||
break; | ||
} | ||
} | ||
return pos; | ||
} | ||
function parseEndTag(tag, tagName) { | ||
@@ -364,8 +399,3 @@ var pos; | ||
if (tagName) { | ||
var needle = tagName.toLowerCase(); | ||
for (pos = stack.length - 1; pos >= 0; pos--) { | ||
if (stack[pos].tag.toLowerCase() === needle) { | ||
break; | ||
} | ||
} | ||
pos = findTag(tagName); | ||
} | ||
@@ -372,0 +402,0 @@ // If no tag name is provided, clean shop |
93771
2091