html-minifier 3.5.20 → 3.5.21

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,19 +20,19 @@ How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Pe
20
20
 
21
21
  | Site | Original size *(KB)* | HTMLMinifier | minimize | Will Peavy | htmlcompressor.com |
22
22
  | ---------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:|
23
- | [Google](https://www.google.com/) | 47 | **43** | 47 | 49 | 47 |
24
- | [Twitter](https://twitter.com/) | 146 | **115** | 138 | 155 | 138 |
25
- | [HTMLMinifier](https://github.com/kangax/html-minifier) | 171 | **128** | 143 | 148 | 142 |
26
- | [New York Times](https://www.nytimes.com/) | 207 | **139** | 158 | 155 | 144 |
27
- | [Stack Overflow](https://stackoverflow.com/) | 256 | **199** | 209 | 217 | 206 |
23
+ | [Google](https://www.google.com/) | 48 | **44** | 48 | 49 | 48 |
24
+ | [HTMLMinifier](https://github.com/kangax/html-minifier) | 154 | **117** | 128 | 133 | 128 |
25
+ | [Twitter](https://twitter.com/) | 203 | **162** | 195 | 219 | 195 |
26
+ | [Stack Overflow](https://stackoverflow.com/) | 254 | **196** | 208 | 216 | 205 |
28
27
  | [Bootstrap CSS](https://getbootstrap.com/docs/3.3/css/) | 271 | **260** | 269 | 229 | 269 |
29
- | [BBC](https://www.bbc.co.uk/) | 294 | **238** | 285 | 289 | 278 |
30
- | [Amazon](https://www.amazon.co.uk/) | 377 | **328** | 368 | 379 | n/a |
31
- | [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 520 | **484** | 504 | 523 | 503 |
32
- | [NBC](https://www.nbc.com/) | 669 | **633** | 668 | 669 | n/a |
28
+ | [BBC](https://www.bbc.co.uk/) | 288 | **230** | 280 | 281 | 272 |
29
+ | [Amazon](https://www.amazon.co.uk/) | 508 | **439** | 495 | 501 | n/a |
30
+ | [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 533 | **434** | 517 | 536 | 517 |
31
+ | [New York Times](https://mathiasbynens.be/_tmp/nyt.html) | 699 | **619** | 693 | 683 | n/a |
32
+ | [NBC](https://www.nbc.com/) | 700 | **657** | 698 | 699 | n/a |
33
33
  | [Eloquent Javascript](https://eloquentjavascript.net/1st_edition/print.html) | 870 | **815** | 840 | 864 | n/a |
34
- | [ES6 table](https://kangax.github.io/compat-table/es6/) | 5243 | **4472** | 4963 | n/a | n/a |
35
- | [ES6 draft](https://tc39.github.io/ecma262/) | 6072 | **5449** | 5615 | n/a | n/a |
34
+ | [ES6 table](https://kangax.github.io/compat-table/es6/) | 5308 | **4529** | 5025 | n/a | n/a |
35
+ | [ES draft](https://tc39.github.io/ecma262/) | 6082 | **5456** | 5624 | n/a | n/a |
36
36
 
37
37
  ## Options Quick Reference
38
38
 
@@ -136,7 +136,9 @@ npm link .
136
136
 
137
137
  ## Usage
138
138
 
139
- For command line usage please see `html-minifier --help`
139
+ Note that almost all options are disabled by default. For command line usage please see `html-minifier --help` for a list of available options. Experiment and find what works best for you and your project.
140
+
141
+ * **Sample command line:** ``html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true``
140
142
 
141
143
  ### Node.js
142
144
 
package/cli.js CHANGED
@@ -197,7 +197,7 @@ program.arguments('[files...]').action(function(files) {
197
197
  function createOptions() {
198
198
  var options = {};
199
199
  mainOptionKeys.forEach(function(key) {
200
- var param = program[camelCase(key)];
200
+ var param = program[key === 'minifyURLs' ? 'minifyUrls' : camelCase(key)];
201
201
  if (typeof param !== 'undefined') {
202
202
  options[key] = param;
203
203
  }
@@ -297,7 +297,7 @@ if (inputDir || outputDir) {
297
297
  processDirectory(inputDir, outputDir, fileExt);
298
298
  }
299
299
  // Minifying one or more files specified on the CMD line
300
- else if (typeof content === 'string') {
300
+ else if (content) {
301
301
  writeMinify();
302
302
  }
303
303
  // Minifying input coming from STDIN
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.20",
4
+ "version": "3.5.21",
5
5
  "keywords": [
6
6
  "cli",
7
7
  "compress",
@@ -57,7 +57,7 @@
57
57
  "camel-case": "3.0.x",
58
58
  "clean-css": "4.2.x",
59
59
  "commander": "2.17.x",
60
- "he": "1.1.x",
60
+ "he": "1.2.x",
61
61
  "param-case": "2.1.x",
62
62
  "relateurl": "0.2.x",
63
63
  "uglify-js": "3.4.x"
@@ -664,13 +664,12 @@ function processOptions(values) {
664
664
  text = text.replace(/(url\s*\(\s*)("|'|)(.*?)\2(\s*\))/ig, function(match, prefix, quote, url, suffix) {
665
665
  return prefix + quote + options.minifyURLs(url) + quote + suffix;
666
666
  });
667
- try {
668
- return unwrapCSS(new CleanCSS(value).minify(wrapCSS(text, type)).styles, type);
669
- }
670
- catch (err) {
671
- options.log(err);
667
+ var cleanCssOutput = new CleanCSS(value).minify(wrapCSS(text, type));
668
+ if (cleanCssOutput.errors.length > 0) {
669
+ cleanCssOutput.errors.forEach(options.log);
672
670
  return text;
673
671
  }
672
+ return unwrapCSS(cleanCssOutput.styles, type);
674
673
  };
675
674
  }
676
675
  else if (key === 'minifyJS' && typeof value !== 'function') {
@@ -1196,9 +1195,12 @@ function minify(value, options, partialMarkup) {
1196
1195
  }
1197
1196
  charsPrevTag = /^\s*$/.test(text) ? prevTag : 'comment';
1198
1197
  if (options.decodeEntities && text && !specialContentTags(currentTag)) {
1199
- // semi-colon can be omitted
1198
+ // Escape any `&` symbols that start either:
1199
+ // 1) a legacy named character reference (i.e. one that doesn't end with `;`)
1200
+ // 2) or any other character reference (i.e. one that does end with `;`)
1201
+ // Note that `&` can be escaped as `&amp`, without the semi-colon.
1200
1202
  // https://mathiasbynens.be/notes/ambiguous-ampersands
1201
- text = text.replace(/&(#?[0-9a-zA-Z]+;)/g, '&amp$1').replace(/</g, '&lt;');
1203
+ text = text.replace(/&((?:Iacute|aacute|uacute|plusmn|Otilde|otilde|agrave|Agrave|Yacute|yacute|Oslash|oslash|atilde|Atilde|brvbar|ccedil|Ccedil|Ograve|curren|divide|eacute|Eacute|ograve|Oacute|egrave|Egrave|Ugrave|frac12|frac14|frac34|ugrave|oacute|iacute|Ntilde|ntilde|Uacute|middot|igrave|Igrave|iquest|Aacute|cedil|laquo|micro|iexcl|Icirc|icirc|acirc|Ucirc|Ecirc|ocirc|Ocirc|ecirc|ucirc|Aring|aring|AElig|aelig|acute|pound|raquo|Acirc|times|THORN|szlig|thorn|COPY|auml|ordf|ordm|Uuml|macr|uuml|Auml|ouml|Ouml|para|nbsp|euml|quot|QUOT|Euml|yuml|cent|sect|copy|sup1|sup2|sup3|iuml|Iuml|ETH|shy|reg|not|yen|amp|AMP|REG|uml|eth|deg|gt|GT|LT|lt)(?!;)|(?:#?[0-9a-zA-Z]+;))/g, '&amp$1').replace(/</g, '&lt;');
1202
1204
  }
1203
1205
  if (uidPattern && options.collapseWhitespace && stackNoTrimWhitespace.length) {
1204
1206
  text = text.replace(uidPattern, function(match, prefix, index) {
@@ -1236,7 +1238,9 @@ function minify(value, options, partialMarkup) {
1236
1238
  buffer.push(text);
1237
1239
  },
1238
1240
  doctype: function(doctype) {
1239
- buffer.push(options.useShortDoctype ? '<!doctype html>' : collapseWhitespaceAll(doctype));
1241
+ buffer.push(options.useShortDoctype ? '<!doctype' +
1242
+ (options.removeTagWhitespace ? '' : ' ') + 'html>' :
1243
+ collapseWhitespaceAll(doctype));
1240
1244
  },
1241
1245
  customAttrAssign: options.customAttrAssign,
1242
1246
  customAttrSurround: options.customAttrSurround
package/src/htmlparser.js CHANGED
@@ -60,7 +60,7 @@ var singleAttrIdentifier = /([^\s"'<>/=]+)/,
60
60
  startTagOpen = new RegExp('^<' + qnameCapture),
61
61
  startTagClose = /^\s*(\/?)>/,
62
62
  endTag = new RegExp('^<\\/' + qnameCapture + '[^>]*>'),
63
- doctype = /^<!DOCTYPE\s[^>]+>/i;
63
+ doctype = /^<!DOCTYPE\s?[^>]+>/i;
64
64
 
65
65
  var IS_REGEX_CAPTURING_BROKEN = false;
66
66
  'x'.replace(/x(.)?/g, function(m, g) {