html-minifier 3.5.19 → 3.5.20

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/) | 46 | **42** | 46 | 48 | 46 |
24
- | [Twitter](https://twitter.com/) | 143 | **107** | 136 | 157 | 136 |
25
- | [HTMLMinifier](https://github.com/kangax/html-minifier) | 152 | **119** | 127 | 132 | 127 |
26
- | [New York Times](https://www.nytimes.com/) | 223 | **152** | 173 | 168 | 156 |
27
- | [Stack Overflow](https://stackoverflow.com/) | 258 | **201** | 211 | 220 | 208 |
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 |
28
28
  | [Bootstrap CSS](https://getbootstrap.com/docs/3.3/css/) | 271 | **260** | 269 | 229 | 269 |
29
- | [BBC](https://www.bbc.co.uk/) | 299 | **242** | 290 | 293 | 283 |
30
- | [Amazon](https://www.amazon.co.uk/) | 398 | **342** | 385 | 397 | n/a |
31
- | [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 485 | **452** | 470 | 487 | 469 |
32
- | [NBC](https://www.nbc.com/) | 679 | **639** | 675 | 678 | n/a |
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 |
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/) | 5109 | **4353** | 4834 | n/a | n/a |
35
- | [ES6 draft](https://tc39.github.io/ecma262/) | 6063 | **5443** | 5607 | n/a | 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 |
36
36
 
37
37
  ## Options Quick Reference
38
38
 
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.19",
4
+ "version": "3.5.20",
5
5
  "keywords": [
6
6
  "cli",
7
7
  "compress",
@@ -55,8 +55,8 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "camel-case": "3.0.x",
58
- "clean-css": "4.1.x",
59
- "commander": "2.16.x",
58
+ "clean-css": "4.2.x",
59
+ "commander": "2.17.x",
60
60
  "he": "1.1.x",
61
61
  "param-case": "2.1.x",
62
62
  "relateurl": "0.2.x",
@@ -65,7 +65,7 @@
65
65
  "devDependencies": {
66
66
  "grunt": "1.0.x",
67
67
  "grunt-browserify": "5.3.x",
68
- "grunt-contrib-uglify": "3.3.x",
68
+ "grunt-contrib-uglify": "3.4.x",
69
69
  "gruntify-eslint": "4.0.x",
70
70
  "phantomjs-prebuilt": "2.1.x",
71
71
  "qunit": "2.x"
@@ -335,23 +335,33 @@ function isMetaViewport(tag, attrs) {
335
335
  }
336
336
  }
337
337
 
338
- // Wrap CSS declarations for CleanCSS > 3.x
339
- // See https://github.com/jakubpawlowicz/clean-css/issues/418
340
- function wrapInlineCSS(text) {
341
- return '*{' + text + '}';
342
- }
343
-
344
- function unwrapInlineCSS(text) {
345
- var matches = text.match(/^\*\{([\s\S]*)\}$/);
346
- return matches ? matches[1] : text;
338
+ function ignoreCSS(id) {
339
+ return '/* clean-css ignore:start */' + id + '/* clean-css ignore:end */';
347
340
  }
348
341
 
349
- function wrapMediaQuery(text) {
350
- return '@media ' + text + '{a{top:0}}';
342
+ // Wrap CSS declarations for CleanCSS > 3.x
343
+ // See https://github.com/jakubpawlowicz/clean-css/issues/418
344
+ function wrapCSS(text, type) {
345
+ switch (type) {
346
+ case 'inline':
347
+ return '*{' + text + '}';
348
+ case 'media':
349
+ return '@media ' + text + '{a{top:0}}';
350
+ default:
351
+ return text;
352
+ }
351
353
  }
352
354
 
353
- function unwrapMediaQuery(text) {
354
- var matches = text.match(/^@media ([\s\S]*?)\s*{[\s\S]*}$/);
355
+ function unwrapCSS(text, type) {
356
+ var matches;
357
+ switch (type) {
358
+ case 'inline':
359
+ matches = text.match(/^\*\{([\s\S]*)\}$/);
360
+ break;
361
+ case 'media':
362
+ matches = text.match(/^@media ([\s\S]*?)\s*{[\s\S]*}$/);
363
+ break;
364
+ }
355
365
  return matches ? matches[1] : text;
356
366
  }
357
367
 
@@ -655,20 +665,7 @@ function processOptions(values) {
655
665
  return prefix + quote + options.minifyURLs(url) + quote + suffix;
656
666
  });
657
667
  try {
658
- if (type === 'inline') {
659
- text = wrapInlineCSS(text);
660
- }
661
- else if (type === 'media') {
662
- text = wrapMediaQuery(text);
663
- }
664
- text = new CleanCSS(value).minify(text).styles;
665
- if (type === 'inline') {
666
- text = unwrapInlineCSS(text);
667
- }
668
- else if (type === 'media') {
669
- text = unwrapMediaQuery(text);
670
- }
671
- return text;
668
+ return unwrapCSS(new CleanCSS(value).minify(wrapCSS(text, type)).styles, type);
672
669
  }
673
670
  catch (err) {
674
671
  options.log(err);
@@ -859,15 +856,6 @@ function minify(value, options, partialMarkup) {
859
856
  return token;
860
857
  });
861
858
 
862
- function escapeFragments(fn) {
863
- return function(text, type) {
864
- return fn(text.replace(uidPattern, function(match, prefix, index) {
865
- var chunks = ignoredCustomMarkupChunks[+index];
866
- return chunks[1] + uidAttr + index + chunks[2];
867
- }), type);
868
- };
869
- }
870
-
871
859
  var customFragments = options.ignoreCustomFragments.map(function(re) {
872
860
  return re.source;
873
861
  });
@@ -879,10 +867,38 @@ function minify(value, options, partialMarkup) {
879
867
  uidAttr = uniqueId(value);
880
868
  uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g');
881
869
  if (options.minifyCSS) {
882
- options.minifyCSS = escapeFragments(options.minifyCSS);
870
+ options.minifyCSS = (function(fn) {
871
+ return function(text, type) {
872
+ text = text.replace(uidPattern, function(match, prefix, index) {
873
+ var chunks = ignoredCustomMarkupChunks[+index];
874
+ return chunks[1] + uidAttr + index + chunks[2];
875
+ });
876
+ var ids = [];
877
+ new CleanCSS().minify(wrapCSS(text, type)).warnings.forEach(function(warning) {
878
+ var match = uidPattern.exec(warning);
879
+ if (match) {
880
+ var id = uidAttr + match[2];
881
+ text = text.replace(id, ignoreCSS(id));
882
+ ids.push(id);
883
+ }
884
+ });
885
+ text = fn(text, type);
886
+ ids.forEach(function(id) {
887
+ text = text.replace(ignoreCSS(id), id);
888
+ });
889
+ return text;
890
+ };
891
+ })(options.minifyCSS);
883
892
  }
884
893
  if (options.minifyJS) {
885
- options.minifyJS = escapeFragments(options.minifyJS);
894
+ options.minifyJS = (function(fn) {
895
+ return function(text, type) {
896
+ return fn(text.replace(uidPattern, function(match, prefix, index) {
897
+ var chunks = ignoredCustomMarkupChunks[+index];
898
+ return chunks[1] + uidAttr + index + chunks[2];
899
+ }), type);
900
+ };
901
+ })(options.minifyJS);
886
902
  }
887
903
  }
888
904
  var token = uidAttr + ignoredCustomMarkupChunks.length;