html-minifier 1.2.0 → 1.5.0

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.
@@ -1,24 +1,37 @@
1
1
  {
2
- "removeComments": true,
3
- "removeCommentsFromCDATA": true,
4
- "removeCDATASectionsFromCDATA": true,
2
+ "caseSensitive": false,
3
+ "collapseBooleanAttributes": true,
4
+ "collapseInlineTagWhitespace": false,
5
5
  "collapseWhitespace": true,
6
6
  "conservativeCollapse": false,
7
- "collapseBooleanAttributes": true,
8
- "removeTagWhitespace": true,
7
+ "customAttrCollapse": ".*",
8
+ "decodeEntities": true,
9
+ "html5": true,
10
+ "ignoreCustomFragments": [
11
+ "<#[\\s\\S]*?#>"
12
+ ],
13
+ "includeAutoGeneratedTags": false,
14
+ "keepClosingSlash": false,
15
+ "lint": false,
16
+ "maxLineLength": 0,
17
+ "minifyCSS": true,
18
+ "minifyJS": true,
19
+ "preserveLineBreaks": false,
20
+ "preventAttributesEscaping": false,
21
+ "processConditionalComments": true,
22
+ "processScripts": [
23
+ "text/html"
24
+ ],
9
25
  "removeAttributeQuotes": true,
10
- "removeRedundantAttributes": true,
11
- "useShortDoctype": true,
26
+ "removeComments": true,
12
27
  "removeEmptyAttributes": true,
28
+ "removeEmptyElements": true,
29
+ "removeOptionalTags": true,
30
+ "removeRedundantAttributes": true,
13
31
  "removeScriptTypeAttributes": true,
14
32
  "removeStyleLinkTypeAttributes": true,
15
- "removeOptionalTags": true,
16
- "removeEmptyElements": true,
17
- "lint": false,
18
- "keepClosingSlash": false,
19
- "caseSensitive": false,
20
- "minifyJS": true,
21
- "minifyCSS": true,
22
- "ignoreCustomComments": [],
23
- "processScripts": []
33
+ "removeTagWhitespace": true,
34
+ "sortAttributes": true,
35
+ "sortClassName": true,
36
+ "useShortDoctype": true
24
37
  }
@@ -0,0 +1,5 @@
1
+ {
2
+ "env": {
3
+ "browser": true
4
+ }
5
+ }
package/src/htmllint.js CHANGED
@@ -1,168 +1,177 @@
1
1
  /*!
2
2
  * HTMLLint (to be used in conjunction with HTMLMinifier)
3
3
  *
4
- * Copyright (c) 2010-2013 Juriy "kangax" Zaytsev
4
+ * Copyright (c) 2010-2016 Juriy "kangax" Zaytsev
5
5
  * Licensed under the MIT license.
6
6
  *
7
7
  */
8
8
 
9
- (function(global) {
10
- 'use strict';
9
+ 'use strict';
11
10
 
12
- function isPresentationalElement(tag) {
13
- return (/^(?:big|small|hr|blink|marquee)$/).test(tag);
14
- }
15
- function isDeprecatedElement(tag) {
16
- return (/^(?:applet|basefont|center|dir|font|isindex|strike)$/).test(tag);
17
- }
18
- function isEventAttribute(attrName) {
19
- return (/^on[a-z]+/).test(attrName);
20
- }
21
- function isStyleAttribute(attrName) {
22
- return (attrName.toLowerCase() === 'style');
23
- }
24
- function isDeprecatedAttribute(tag, attrName) {
25
- return (
26
- (attrName === 'align' &&
27
- (/^(?:caption|applet|iframe|img|imput|object|legend|table|hr|div|h[1-6]|p)$/).test(tag)) ||
28
- (attrName === 'alink' && tag === 'body') ||
29
- (attrName === 'alt' && tag === 'applet') ||
30
- (attrName === 'archive' && tag === 'applet') ||
31
- (attrName === 'background' && tag === 'body') ||
32
- (attrName === 'bgcolor' && (/^(?:table|t[rdh]|body)$/).test(tag)) ||
33
- (attrName === 'border' && (/^(?:img|object)$/).test(tag)) ||
34
- (attrName === 'clear' && tag === 'br') ||
35
- (attrName === 'code' && tag === 'applet') ||
36
- (attrName === 'codebase' && tag === 'applet') ||
37
- (attrName === 'color' && (/^(?:base(?:font)?)$/).test(tag)) ||
38
- (attrName === 'compact' && (/^(?:dir|[dou]l|menu)$/).test(tag)) ||
39
- (attrName === 'face' && (/^base(?:font)?$/).test(tag)) ||
40
- (attrName === 'height' && (/^(?:t[dh]|applet)$/).test(tag)) ||
41
- (attrName === 'hspace' && (/^(?:applet|img|object)$/).test(tag)) ||
42
- (attrName === 'language' && tag === 'script') ||
43
- (attrName === 'link' && tag === 'body') ||
44
- (attrName === 'name' && tag === 'applet') ||
45
- (attrName === 'noshade' && tag === 'hr') ||
46
- (attrName === 'nowrap' && (/^t[dh]$/).test(tag)) ||
47
- (attrName === 'object' && tag === 'applet') ||
48
- (attrName === 'prompt' && tag === 'isindex') ||
49
- (attrName === 'size' && (/^(?:hr|font|basefont)$/).test(tag)) ||
50
- (attrName === 'start' && tag === 'ol') ||
51
- (attrName === 'text' && tag === 'body') ||
52
- (attrName === 'type' && (/^(?:li|ol|ul)$/).test(tag)) ||
53
- (attrName === 'value' && tag === 'li') ||
54
- (attrName === 'version' && tag === 'html') ||
55
- (attrName === 'vlink' && tag === 'body') ||
56
- (attrName === 'vspace' && (/^(?:applet|img|object)$/).test(tag)) ||
57
- (attrName === 'width' && (/^(?:hr|td|th|applet|pre)$/).test(tag))
11
+ function isPresentationalElement(tag) {
12
+ return /^(?:big|small|hr|blink|marquee)$/.test(tag);
13
+ }
14
+ function isDeprecatedElement(tag) {
15
+ return /^(?:applet|basefont|center|dir|font|isindex|strike)$/.test(tag);
16
+ }
17
+ function isEventAttribute(attrName) {
18
+ return /^on[a-z]+/.test(attrName);
19
+ }
20
+ function isStyleAttribute(attrName) {
21
+ return attrName.toLowerCase() === 'style';
22
+ }
23
+ function isDeprecatedAttribute(tag, attrName) {
24
+ return (
25
+ attrName === 'align' &&
26
+ /^(?:caption|applet|iframe|img|imput|object|legend|table|hr|div|h[1-6]|p)$/.test(tag) ||
27
+ attrName === 'alink' && tag === 'body' ||
28
+ attrName === 'alt' && tag === 'applet' ||
29
+ attrName === 'archive' && tag === 'applet' ||
30
+ attrName === 'background' && tag === 'body' ||
31
+ attrName === 'bgcolor' && /^(?:table|t[rdh]|body)$/.test(tag) ||
32
+ attrName === 'border' && /^(?:img|object)$/.test(tag) ||
33
+ attrName === 'clear' && tag === 'br' ||
34
+ attrName === 'code' && tag === 'applet' ||
35
+ attrName === 'codebase' && tag === 'applet' ||
36
+ attrName === 'color' && /^(?:base(?:font)?)$/.test(tag) ||
37
+ attrName === 'compact' && /^(?:dir|[dou]l|menu)$/.test(tag) ||
38
+ attrName === 'face' && /^base(?:font)?$/.test(tag) ||
39
+ attrName === 'height' && /^(?:t[dh]|applet)$/.test(tag) ||
40
+ attrName === 'hspace' && /^(?:applet|img|object)$/.test(tag) ||
41
+ attrName === 'language' && tag === 'script' ||
42
+ attrName === 'link' && tag === 'body' ||
43
+ attrName === 'name' && tag === 'applet' ||
44
+ attrName === 'noshade' && tag === 'hr' ||
45
+ attrName === 'nowrap' && /^t[dh]$/.test(tag) ||
46
+ attrName === 'object' && tag === 'applet' ||
47
+ attrName === 'prompt' && tag === 'isindex' ||
48
+ attrName === 'size' && /^(?:hr|font|basefont)$/.test(tag) ||
49
+ attrName === 'start' && tag === 'ol' ||
50
+ attrName === 'text' && tag === 'body' ||
51
+ attrName === 'type' && /^(?:li|ol|ul)$/.test(tag) ||
52
+ attrName === 'value' && tag === 'li' ||
53
+ attrName === 'version' && tag === 'html' ||
54
+ attrName === 'vlink' && tag === 'body' ||
55
+ attrName === 'vspace' && /^(?:applet|img|object)$/.test(tag) ||
56
+ attrName === 'width' && /^(?:hr|td|th|applet|pre)$/.test(tag)
57
+ );
58
+ }
59
+ function isInaccessibleAttribute(attrName, attrValue) {
60
+ return attrName === 'href' && /^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i.test(attrValue);
61
+ }
62
+
63
+ function Lint() {
64
+ this.log = [];
65
+ this._lastElement = null;
66
+ this._isElementRepeated = false;
67
+ }
68
+
69
+ Lint.prototype.testElement = function(tag) {
70
+ this._attributes = Object.create(null);
71
+ if (isDeprecatedElement(tag)) {
72
+ this.log.push(
73
+ 'Found <span class="deprecated-element">deprecated</span> <strong><code>&lt;' +
74
+ tag + '&gt;</code></strong> element'
58
75
  );
59
76
  }
60
- function isInaccessibleAttribute(attrName, attrValue) {
61
- return (
62
- attrName === 'href' &&
63
- (/^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i).test(attrValue)
77
+ else if (isPresentationalElement(tag)) {
78
+ this.log.push(
79
+ 'Found <span class="presentational-element">presentational</span> <strong><code>&lt;' +
80
+ tag + '&gt;</code></strong> element'
64
81
  );
65
82
  }
83
+ else {
84
+ this.checkRepeatingElement(tag);
85
+ }
86
+ };
66
87
 
67
- function Lint() {
68
- this.log = [ ];
69
- this._lastElement = null;
88
+ Lint.prototype.checkRepeatingElement = function(tag) {
89
+ if (tag === 'br' && this._lastElement === 'br') {
90
+ this._isElementRepeated = true;
91
+ }
92
+ else if (this._isElementRepeated) {
93
+ this._reportRepeatingElement();
70
94
  this._isElementRepeated = false;
71
95
  }
96
+ this._lastElement = tag;
97
+ };
72
98
 
73
- Lint.prototype.testElement = function(tag) {
74
- if (isDeprecatedElement(tag)) {
75
- this.log.push(
76
- 'Found <span class="deprecated-element">deprecated</span> <strong><code>&lt;' +
77
- tag + '&gt;</code></strong> element'
78
- );
79
- }
80
- else if (isPresentationalElement(tag)) {
81
- this.log.push(
82
- 'Found <span class="presentational-element">presentational</span> <strong><code>&lt;' +
83
- tag + '&gt;</code></strong> element'
84
- );
85
- }
86
- else {
87
- this.checkRepeatingElement(tag);
88
- }
89
- };
90
-
91
- Lint.prototype.checkRepeatingElement = function(tag) {
92
- if (tag === 'br' && this._lastElement === 'br') {
93
- this._isElementRepeated = true;
94
- }
95
- else if (this._isElementRepeated) {
96
- this._reportRepeatingElement();
97
- this._isElementRepeated = false;
98
- }
99
- this._lastElement = tag;
100
- };
101
-
102
- Lint.prototype._reportRepeatingElement = function() {
103
- this.log.push('Found <code>&lt;br></code> sequence. Try replacing it with styling.');
104
- };
99
+ Lint.prototype._reportRepeatingElement = function() {
100
+ this.log.push('Found <code>&lt;br></code> sequence. Try replacing it with styling.');
101
+ };
105
102
 
106
- Lint.prototype.testAttribute = function(tag, attrName, attrValue) {
107
- if (isEventAttribute(attrName)) {
108
- this.log.push(
109
- 'Found <span class="event-attribute">event attribute</span> (<strong>' +
110
- attrName + '</strong>) on <strong><code>&lt;' + tag + '&gt;</code></strong> element.'
111
- );
112
- }
113
- else if (isDeprecatedAttribute(tag, attrName)) {
114
- this.log.push(
115
- 'Found <span class="deprecated-attribute">deprecated</span> <strong>' +
116
- attrName + '</strong> attribute on <strong><code>&lt;' + tag + '&gt;</code></strong> element.'
117
- );
118
- }
119
- else if (isStyleAttribute(attrName)) {
120
- this.log.push(
121
- 'Found <span class="style-attribute">style attribute</span> on <strong><code>&lt;' +
122
- tag + '&gt;</code></strong> element.'
123
- );
124
- }
125
- else if (isInaccessibleAttribute(attrName, attrValue)) {
126
- this.log.push(
127
- 'Found <span class="inaccessible-attribute">inaccessible attribute</span> ' +
128
- '(on <strong><code>&lt;' + tag + '&gt;</code></strong> element).'
129
- );
130
- }
131
- };
103
+ Lint.prototype.testAttribute = function(tag, attrName, attrValue) {
104
+ if (this._attributes[attrName]) {
105
+ this.log.push(
106
+ 'Found <span class="repeating-attribute">repeating attribute</span> (<strong>' +
107
+ attrName + '</strong>) on <strong><code>&lt;' + tag + '&gt;</code></strong> element.'
108
+ );
109
+ }
110
+ else {
111
+ this._attributes[attrName] = true;
112
+ }
113
+ if (isEventAttribute(attrName)) {
114
+ this.log.push(
115
+ 'Found <span class="event-attribute">event attribute</span> (<strong>' +
116
+ attrName + '</strong>) on <strong><code>&lt;' + tag + '&gt;</code></strong> element.'
117
+ );
118
+ }
119
+ else if (isDeprecatedAttribute(tag, attrName)) {
120
+ this.log.push(
121
+ 'Found <span class="deprecated-attribute">deprecated</span> <strong>' +
122
+ attrName + '</strong> attribute on <strong><code>&lt;' + tag + '&gt;</code></strong> element.'
123
+ );
124
+ }
125
+ else if (isStyleAttribute(attrName)) {
126
+ this.log.push(
127
+ 'Found <span class="style-attribute">style attribute</span> on <strong><code>&lt;' +
128
+ tag + '&gt;</code></strong> element.'
129
+ );
130
+ }
131
+ else if (isInaccessibleAttribute(attrName, attrValue)) {
132
+ this.log.push(
133
+ 'Found <span class="inaccessible-attribute">inaccessible attribute</span> ' +
134
+ '(on <strong><code>&lt;' + tag + '&gt;</code></strong> element).'
135
+ );
136
+ }
137
+ };
132
138
 
133
- Lint.prototype.testChars = function(chars) {
134
- this._lastElement = '';
135
- if (/(&nbsp;\s*){2,}/.test(chars)) {
136
- this.log.push('Found repeating <strong><code>&amp;nbsp;</code></strong> sequence. Try replacing it with styling.');
137
- }
138
- };
139
+ Lint.prototype.testChars = function(chars) {
140
+ this._lastElement = '';
141
+ if (/(&nbsp;\s*){2,}/.test(chars)) {
142
+ this.log.push('Found repeating <strong><code>&amp;nbsp;</code></strong> sequence. Try replacing it with styling.');
143
+ }
144
+ };
139
145
 
140
- Lint.prototype.test = function(tag, attrName, attrValue) {
141
- this.testElement(tag);
142
- this.testAttribute(tag, attrName, attrValue);
143
- };
146
+ Lint.prototype.test = function(tag, attrName, attrValue) {
147
+ this.testElement(tag);
148
+ this.testAttribute(tag, attrName, attrValue);
149
+ };
144
150
 
145
- Lint.prototype.populate = function(writeToElement) {
146
- if (this._isElementRepeated) {
147
- this._reportRepeatingElement();
148
- }
151
+ Lint.prototype.testDoctype = function(doctype) {
152
+ this._doctype = doctype;
153
+ };
149
154
 
150
- if (this.log.length) {
151
- if (writeToElement) {
152
- writeToElement.innerHTML = '<ol><li>' + this.log.join('<li>') + '</ol>';
153
- }
154
- else {
155
- var output = ' - ' +
156
- this.log.join('\n - ')
157
- .replace(/(<([^>]+)>)/ig, '')
158
- .replace(/&lt;/g, '<')
159
- .replace(/&gt;/g, '>');
155
+ Lint.prototype.populate = function(writeToElement) {
156
+ if (!this._doctype) {
157
+ this.log.push('No DOCTYPE found.');
158
+ }
160
159
 
161
- console.log(output);
162
- }
163
- }
164
- };
160
+ if (this._isElementRepeated) {
161
+ this._reportRepeatingElement();
162
+ }
165
163
 
166
- global.HTMLLint = Lint;
164
+ var output;
165
+ if (writeToElement) {
166
+ output = this.log.map(function(line) {
167
+ return '<li>' + line + '</li>';
168
+ }).join('');
169
+ writeToElement.innerHTML = '<ol>' + output + '</ol>';
170
+ }
171
+ else if (this.log.length) {
172
+ output = this.log.join('\n - ').replace(/<[^>]+>/g, '');
173
+ console.log(' - ' + output.replace(/&lt;/g, '<').replace(/&gt;/g, '>'));
174
+ }
175
+ };
167
176
 
168
- })(typeof exports === 'undefined' ? this : exports);
177
+ exports.HTMLLint = Lint;