html-minifier 3.5.4 → 3.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/package.json +6 -6
- package/src/htmlminifier.js +13 -15
- package/src/htmlparser.js +2 -2
package/README.md
CHANGED
|
@@ -22,19 +22,19 @@ How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Pe
|
|
|
22
22
|
|
|
23
23
|
| Site | Original size *(KB)* | HTMLMinifier | minimize | Will Peavy | htmlcompressor.com |
|
|
24
24
|
| ---------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:|
|
|
25
|
-
| [Google](https://www.google.com/) |
|
|
26
|
-
| [HTMLMinifier](https://github.com/kangax/html-minifier) |
|
|
27
|
-
| [
|
|
28
|
-
| [
|
|
29
|
-
| [Stack Overflow](https://stackoverflow.com/) |
|
|
25
|
+
| [Google](https://www.google.com/) | 46 | **43** | 46 | 48 | 46 |
|
|
26
|
+
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 133 | **104** | 112 | 116 | 111 |
|
|
27
|
+
| [New York Times](https://www.nytimes.com/) | 214 | **145** | 163 | 162 | 152 |
|
|
28
|
+
| [BBC](https://www.bbc.co.uk/) | 237 | **194** | 229 | 235 | 222 |
|
|
29
|
+
| [Stack Overflow](https://stackoverflow.com/) | 248 | **195** | 204 | 212 | 201 |
|
|
30
30
|
| [Bootstrap CSS](https://getbootstrap.com/docs/3.3/css/) | 272 | **260** | 269 | 229 | 269 |
|
|
31
|
-
| [Twitter](https://twitter.com/) |
|
|
32
|
-
| [
|
|
33
|
-
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) |
|
|
34
|
-
| [NBC](https://www.nbc.com/) |
|
|
31
|
+
| [Twitter](https://twitter.com/) | 348 | **260** | 313 | 345 | 313 |
|
|
32
|
+
| [Amazon](https://www.amazon.co.uk/) | 405 | **349** | 390 | 403 | n/a |
|
|
33
|
+
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 471 | **440** | 456 | 471 | 455 |
|
|
34
|
+
| [NBC](https://www.nbc.com/) | 646 | **613** | 642 | 646 | n/a |
|
|
35
35
|
| [Eloquent Javascript](https://eloquentjavascript.net/1st_edition/print.html) | 870 | **815** | 840 | 864 | n/a |
|
|
36
|
-
| [ES6 table](https://kangax.github.io/compat-table/es6/) |
|
|
37
|
-
| [ES6 draft](https://tc39.github.io/ecma262/) |
|
|
36
|
+
| [ES6 table](https://kangax.github.io/compat-table/es6/) | 4580 | **3898** | 4333 | n/a | n/a |
|
|
37
|
+
| [ES6 draft](https://tc39.github.io/ecma262/) | 5720 | **5103** | 5253 | n/a | n/a |
|
|
38
38
|
|
|
39
39
|
## Options Quick Reference
|
|
40
40
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-minifier",
|
|
3
3
|
"description": "Highly configurable, well-tested, JavaScript-based HTML minifier.",
|
|
4
|
-
"version": "3.5.
|
|
4
|
+
"version": "3.5.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
7
7
|
"compress",
|
|
@@ -56,24 +56,24 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"camel-case": "3.0.x",
|
|
58
58
|
"clean-css": "4.1.x",
|
|
59
|
-
"commander": "2.
|
|
59
|
+
"commander": "2.12.x",
|
|
60
60
|
"he": "1.1.x",
|
|
61
61
|
"ncname": "1.0.x",
|
|
62
62
|
"param-case": "2.1.x",
|
|
63
63
|
"relateurl": "0.2.x",
|
|
64
|
-
"uglify-js": "3.
|
|
64
|
+
"uglify-js": "3.3.x"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"grunt": "1.0.x",
|
|
68
68
|
"grunt-browserify": "5.2.x",
|
|
69
|
-
"grunt-contrib-uglify": "3.
|
|
69
|
+
"grunt-contrib-uglify": "3.3.x",
|
|
70
70
|
"gruntify-eslint": "4.0.x",
|
|
71
71
|
"phantomjs-prebuilt": "2.1.x",
|
|
72
|
-
"
|
|
72
|
+
"qunit": "2.x"
|
|
73
73
|
},
|
|
74
74
|
"benchmarkDependencies": {
|
|
75
75
|
"brotli": "1.3.x",
|
|
76
|
-
"chalk": "2.
|
|
76
|
+
"chalk": "2.3.x",
|
|
77
77
|
"cli-table": "0.3.x",
|
|
78
78
|
"lzma": "2.3.x",
|
|
79
79
|
"minimize": "2.1.x",
|
package/src/htmlminifier.js
CHANGED
|
@@ -8,20 +8,16 @@ var TokenChain = require('./tokenchain');
|
|
|
8
8
|
var UglifyJS = require('uglify-js');
|
|
9
9
|
var utils = require('./utils');
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
function trimWhitespace(str) {
|
|
12
12
|
if (typeof str !== 'string') {
|
|
13
13
|
return str;
|
|
14
14
|
}
|
|
15
|
-
return str.
|
|
16
|
-
}
|
|
17
|
-
if (typeof str !== 'string') {
|
|
18
|
-
return str;
|
|
19
|
-
}
|
|
20
|
-
return str.replace(/^\s+/, '').replace(/\s+$/, '');
|
|
21
|
-
};
|
|
15
|
+
return str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, '');
|
|
16
|
+
}
|
|
22
17
|
|
|
23
18
|
function collapseWhitespaceAll(str) {
|
|
24
|
-
|
|
19
|
+
// Non-breaking space is specifically handled inside the replacer function here:
|
|
20
|
+
return str && str.replace(/[ \n\r\t\f\xA0]+/g, function(spaces) {
|
|
25
21
|
return spaces === '\t' ? '\t' : spaces.replace(/(^|\xA0+)[^\xA0]+/g, '$1 ');
|
|
26
22
|
});
|
|
27
23
|
}
|
|
@@ -30,17 +26,18 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll) {
|
|
|
30
26
|
var lineBreakBefore = '', lineBreakAfter = '';
|
|
31
27
|
|
|
32
28
|
if (options.preserveLineBreaks) {
|
|
33
|
-
str = str.replace(
|
|
29
|
+
str = str.replace(/^[ \n\r\t\f]*?[\n\r][ \n\r\t\f]*/, function() {
|
|
34
30
|
lineBreakBefore = '\n';
|
|
35
31
|
return '';
|
|
36
|
-
}).replace(
|
|
32
|
+
}).replace(/[ \n\r\t\f]*?[\n\r][ \n\r\t\f]*$/, function() {
|
|
37
33
|
lineBreakAfter = '\n';
|
|
38
34
|
return '';
|
|
39
35
|
});
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
if (trimLeft) {
|
|
43
|
-
|
|
39
|
+
// Non-breaking space is specifically handled inside the replacer function here:
|
|
40
|
+
str = str.replace(/^[ \n\r\t\f\xA0]+/, function(spaces) {
|
|
44
41
|
var conservative = !lineBreakBefore && options.conservativeCollapse;
|
|
45
42
|
if (conservative && spaces === '\t') {
|
|
46
43
|
return '\t';
|
|
@@ -50,7 +47,8 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll) {
|
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
if (trimRight) {
|
|
53
|
-
|
|
50
|
+
// Non-breaking space is specifically handled inside the replacer function here:
|
|
51
|
+
str = str.replace(/[ \n\r\t\f\xA0]+$/, function(spaces) {
|
|
54
52
|
var conservative = !lineBreakAfter && options.conservativeCollapse;
|
|
55
53
|
if (conservative && spaces === '\t') {
|
|
56
54
|
return '\t';
|
|
@@ -285,7 +283,7 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs) {
|
|
|
285
283
|
attrValue = trimWhitespace(attrValue);
|
|
286
284
|
if (attrValue) {
|
|
287
285
|
if (/;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) {
|
|
288
|
-
attrValue = attrValue.replace(/\s*;$/, '');
|
|
286
|
+
attrValue = attrValue.replace(/\s*;$/, ';');
|
|
289
287
|
}
|
|
290
288
|
attrValue = unwrapInlineCSS(options.minifyCSS(wrapInlineCSS(attrValue)));
|
|
291
289
|
}
|
|
@@ -1253,7 +1251,7 @@ function minify(value, options, partialMarkup) {
|
|
|
1253
1251
|
return collapseWhitespace(chunk, {
|
|
1254
1252
|
preserveLineBreaks: options.preserveLineBreaks,
|
|
1255
1253
|
conservativeCollapse: !options.trimCustomFragments
|
|
1256
|
-
},
|
|
1254
|
+
}, /^[ \n\r\t\f]/.test(chunk), /[ \n\r\t\f]$/.test(chunk));
|
|
1257
1255
|
}
|
|
1258
1256
|
return chunk;
|
|
1259
1257
|
});
|
package/src/htmlparser.js
CHANGED
|
@@ -70,7 +70,7 @@ var inline = makeMap('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,co
|
|
|
70
70
|
|
|
71
71
|
// Elements that you can, intentionally, leave open
|
|
72
72
|
// (and which close themselves)
|
|
73
|
-
var closeSelf = makeMap('colgroup,dd,dt,li,
|
|
73
|
+
var closeSelf = makeMap('colgroup,dd,dt,li,option,p,td,tfoot,th,thead,tr,source');
|
|
74
74
|
|
|
75
75
|
// Attributes that have their values filled in disabled='disabled'
|
|
76
76
|
var fillAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected');
|
|
@@ -270,7 +270,7 @@ function HTMLParser(html, handler) {
|
|
|
270
270
|
parseEndTag('', lastTag);
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
if (!handler.html5) {
|
|
273
|
+
if (!handler.html5 && !inline(tagName)) {
|
|
274
274
|
while (lastTag && inline(lastTag)) {
|
|
275
275
|
parseEndTag('', lastTag);
|
|
276
276
|
}
|