html-minifier 3.5.1 → 3.5.5

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 CHANGED
@@ -20,21 +20,21 @@ For lint-like capabilities take a look at [HTMLLint](https://github.com/kangax/h
20
20
 
21
21
  How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Peavy](http://www.willpeavy.com/minifier/) (1st result in [Google search for "html minifier"](https://www.google.com/#q=html+minifier)) as well as [htmlcompressor.com](http://htmlcompressor.com) and [minimize](https://github.com/Swaagie/minimize)?
22
22
 
23
- | Site | Original size *(KB)* | HTMLMinifier | minimize | Will Peavy | htmlcompressor.com |
24
- | --------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:|
25
- | [Google](https://www.google.com/) | 44 | **42** | 45 | 46 | 45 |
26
- | [HTMLMinifier](https://github.com/kangax/html-minifier) | 127 | **100** | 108 | 112 | 107 |
27
- | [CNN](http://www.cnn.com/) | 136 | **125** | 133 | 134 | 129 |
28
- | [Amazon](http://www.amazon.co.uk/) | 196 | **165** | 188 | 192 | n/a |
29
- | [Stack Overflow](http://stackoverflow.com/) | 223 | **172** | 181 | 188 | 178 |
30
- | [New York Times](http://www.nytimes.com/) | 224 | **153** | 172 | 170 | 159 |
31
- | [BBC](http://www.bbc.co.uk/) | 236 | **194** | 229 | 236 | 223 |
32
- | [Bootstrap CSS](http://getbootstrap.com/css/) | 272 | **260** | 269 | 229 | 269 |
33
- | [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 550 | **503** | 530 | 548 | 529 |
34
- | [NBC](http://www.nbc.com/) | 643 | **612** | 641 | 643 | n/a |
35
- | [Eloquent Javascript](http://eloquentjavascript.net/1st_edition/print.html) | 870 | **815** | 840 | 864 | n/a |
36
- | [ES6 table](http://kangax.github.io/compat-table/es6/) | 4105 | **3467** | 3871 | n/a | n/a |
37
- | [ES6 draft](https://tc39.github.io/ecma262/) | 5512 | **4919** | 5066 | n/a | n/a |
23
+ | Site | Original size *(KB)* | HTMLMinifier | minimize | Will Peavy | htmlcompressor.com |
24
+ | ---------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:|
25
+ | [Google](https://www.google.com/) | 45 | **42** | 45 | 47 | 45 |
26
+ | [HTMLMinifier](https://github.com/kangax/html-minifier) | 133 | **104** | 112 | 116 | 111 |
27
+ | [Amazon](https://www.amazon.co.uk/) | 203 | **171** | 195 | 199 | n/a |
28
+ | [New York Times](https://www.nytimes.com/) | 233 | **158** | 182 | 178 | 166 |
29
+ | [Stack Overflow](https://stackoverflow.com/) | 239 | **186** | 195 | 203 | 192 |
30
+ | [Bootstrap CSS](https://getbootstrap.com/docs/3.3/css/) | 272 | **260** | 269 | 229 | 269 |
31
+ | [BBC](https://www.bbc.co.uk/) | 279 | **229** | 271 | 278 | 262 |
32
+ | [Twitter](https://twitter.com/) | 298 | **223** | 263 | 287 | 263 |
33
+ | [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 469 | **437** | 453 | 468 | 453 |
34
+ | [NBC](https://www.nbc.com/) | 665 | **627** | 661 | 664 | n/a |
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/) | 4228 | **3586** | 3999 | n/a | n/a |
37
+ | [ES6 draft](https://tc39.github.io/ecma262/) | 5701 | **5087** | 5236 | n/a | n/a |
38
38
 
39
39
  ## Options Quick Reference
40
40
 
package/cli.js CHANGED
@@ -148,11 +148,7 @@ mainOptionKeys.forEach(function(key) {
148
148
  program.option(key, option);
149
149
  }
150
150
  });
151
- program.option('-o --output <file>', 'Specify output file (if not specified STDOUT will be used for output)', function(outputPath) {
152
- return fs.createWriteStream(outputPath).on('error', function(e) {
153
- fatal('Cannot write ' + outputPath + '\n' + e.message);
154
- });
155
- }, process.stdout);
151
+ program.option('-o --output <file>', 'Specify output file (if not specified STDOUT will be used for output)');
156
152
 
157
153
  function readFile(file) {
158
154
  try {
@@ -280,7 +276,9 @@ function writeMinify() {
280
276
  catch (e) {
281
277
  fatal('Minification error:\n' + e.message);
282
278
  }
283
- program.output.write(minified);
279
+ (program.output ? fs.createWriteStream(program.output).on('error', function(e) {
280
+ fatal('Cannot write ' + program.output + '\n' + e.message);
281
+ }) : process.stdout).write(minified);
284
282
  }
285
283
 
286
284
  var inputDir = program.inputDir;
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.1",
4
+ "version": "3.5.5",
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.9.x",
59
+ "commander": "2.11.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.0.x"
64
+ "uglify-js": "3.1.x"
65
65
  },
66
66
  "devDependencies": {
67
67
  "grunt": "1.0.x",
68
- "grunt-browserify": "5.0.x",
69
- "grunt-contrib-uglify": "3.0.x",
70
- "gruntify-eslint": "3.1.x",
68
+ "grunt-browserify": "5.2.x",
69
+ "grunt-contrib-uglify": "3.1.x",
70
+ "gruntify-eslint": "4.0.x",
71
71
  "phantomjs-prebuilt": "2.1.x",
72
72
  "qunitjs": "2.x"
73
73
  },
74
74
  "benchmarkDependencies": {
75
75
  "brotli": "1.3.x",
76
- "chalk": "1.1.x",
76
+ "chalk": "2.1.x",
77
77
  "cli-table": "0.3.x",
78
78
  "lzma": "2.3.x",
79
79
  "minimize": "2.1.x",
@@ -8,20 +8,16 @@ var TokenChain = require('./tokenchain');
8
8
  var UglifyJS = require('uglify-js');
9
9
  var utils = require('./utils');
10
10
 
11
- var trimWhitespace = String.prototype.trim ? function(str) {
11
+ function trimWhitespace(str) {
12
12
  if (typeof str !== 'string') {
13
13
  return str;
14
14
  }
15
- return str.trim();
16
- } : function(str) {
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
- return str && str.replace(/\s+/g, function(spaces) {
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(/^\s*?[\n\r]\s*/, function() {
29
+ str = str.replace(/^[ \n\r\t\f]*?[\n\r][ \n\r\t\f]*/, function() {
34
30
  lineBreakBefore = '\n';
35
31
  return '';
36
- }).replace(/\s*?[\n\r]\s*$/, function() {
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
- str = str.replace(/^\s+/, function(spaces) {
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
- str = str.replace(/\s+$/, function(spaces) {
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';
@@ -131,29 +129,29 @@ function isAttributeRedundant(tag, attrName, attrValue, attrs) {
131
129
  attrValue = attrValue ? trimWhitespace(attrValue.toLowerCase()) : '';
132
130
 
133
131
  return (
134
- tag === 'script' &&
135
- attrName === 'language' &&
136
- attrValue === 'javascript' ||
132
+ tag === 'script' &&
133
+ attrName === 'language' &&
134
+ attrValue === 'javascript' ||
137
135
 
138
- tag === 'form' &&
139
- attrName === 'method' &&
140
- attrValue === 'get' ||
136
+ tag === 'form' &&
137
+ attrName === 'method' &&
138
+ attrValue === 'get' ||
141
139
 
142
- tag === 'input' &&
143
- attrName === 'type' &&
144
- attrValue === 'text' ||
140
+ tag === 'input' &&
141
+ attrName === 'type' &&
142
+ attrValue === 'text' ||
145
143
 
146
- tag === 'script' &&
147
- attrName === 'charset' &&
148
- !attributesInclude(attrs, 'src') ||
144
+ tag === 'script' &&
145
+ attrName === 'charset' &&
146
+ !attributesInclude(attrs, 'src') ||
149
147
 
150
- tag === 'a' &&
151
- attrName === 'name' &&
152
- attributesInclude(attrs, 'id') ||
148
+ tag === 'a' &&
149
+ attrName === 'name' &&
150
+ attributesInclude(attrs, 'id') ||
153
151
 
154
- tag === 'area' &&
155
- attrName === 'shape' &&
156
- attrValue === 'rect'
152
+ tag === 'area' &&
153
+ attrName === 'shape' &&
154
+ attrValue === 'rect'
157
155
  );
158
156
  }
159
157
 
@@ -998,10 +996,10 @@ function minify(value, options, partialMarkup) {
998
996
  if (!stackNoTrimWhitespace.length) {
999
997
  squashTrailingWhitespace(tag);
1000
998
  }
1001
- if (!_canTrimWhitespace(tag, attrs)) {
999
+ if (!_canTrimWhitespace(tag, attrs) || stackNoTrimWhitespace.length) {
1002
1000
  stackNoTrimWhitespace.push(tag);
1003
1001
  }
1004
- if (!_canCollapseWhitespace(tag, attrs)) {
1002
+ if (!_canCollapseWhitespace(tag, attrs) || stackNoCollapseWhitespace.length) {
1005
1003
  stackNoCollapseWhitespace.push(tag);
1006
1004
  }
1007
1005
  }
@@ -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
- }, /^\s/.test(chunk), /\s$/.test(chunk));
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
@@ -26,7 +26,7 @@
26
26
  *
27
27
  */
28
28
 
29
- /* global ActiveXObject, DOMDocument */
29
+ /* global ActiveXObject, DOMDocument */
30
30
 
31
31
  'use strict';
32
32