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.
- package/README.md +66 -52
- package/cli.js +220 -290
- package/package.json +12 -14
- package/sample-cli-config-file.conf +29 -16
- package/src/.eslintrc.json +5 -0
- package/src/htmllint.js +153 -144
- package/src/htmlminifier.js +1029 -925
- package/src/htmlparser.js +405 -409
- package/src/tokenchain.js +58 -0
- package/src/utils.js +18 -0
- package/CHANGELOG.md +0 -120
- package/dist/htmlminifier.js +0 -1821
- package/dist/htmlminifier.min.js +0 -6
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
2
|
+
"caseSensitive": false,
|
|
3
|
+
"collapseBooleanAttributes": true,
|
|
4
|
+
"collapseInlineTagWhitespace": false,
|
|
5
5
|
"collapseWhitespace": true,
|
|
6
6
|
"conservativeCollapse": false,
|
|
7
|
-
"
|
|
8
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
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
|
}
|
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-
|
|
4
|
+
* Copyright (c) 2010-2016 Juriy "kangax" Zaytsev
|
|
5
5
|
* Licensed under the MIT license.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
9
|
+
'use strict';
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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><' +
|
|
74
|
+
tag + '></code></strong> element'
|
|
58
75
|
);
|
|
59
76
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
else if (isPresentationalElement(tag)) {
|
|
78
|
+
this.log.push(
|
|
79
|
+
'Found <span class="presentational-element">presentational</span> <strong><code><' +
|
|
80
|
+
tag + '></code></strong> element'
|
|
64
81
|
);
|
|
65
82
|
}
|
|
83
|
+
else {
|
|
84
|
+
this.checkRepeatingElement(tag);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
66
87
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'Found <span class="deprecated-element">deprecated</span> <strong><code><' +
|
|
77
|
-
tag + '></code></strong> element'
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
else if (isPresentationalElement(tag)) {
|
|
81
|
-
this.log.push(
|
|
82
|
-
'Found <span class="presentational-element">presentational</span> <strong><code><' +
|
|
83
|
-
tag + '></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><br></code> sequence. Try replacing it with styling.');
|
|
104
|
-
};
|
|
99
|
+
Lint.prototype._reportRepeatingElement = function() {
|
|
100
|
+
this.log.push('Found <code><br></code> sequence. Try replacing it with styling.');
|
|
101
|
+
};
|
|
105
102
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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><' + tag + '></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><' + tag + '></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><' + tag + '></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><' +
|
|
128
|
+
tag + '></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><' + tag + '></code></strong> element).'
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
132
138
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
Lint.prototype.testChars = function(chars) {
|
|
140
|
+
this._lastElement = '';
|
|
141
|
+
if (/( \s*){2,}/.test(chars)) {
|
|
142
|
+
this.log.push('Found repeating <strong><code>&nbsp;</code></strong> sequence. Try replacing it with styling.');
|
|
143
|
+
}
|
|
144
|
+
};
|
|
139
145
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
Lint.prototype.test = function(tag, attrName, attrValue) {
|
|
147
|
+
this.testElement(tag);
|
|
148
|
+
this.testAttribute(tag, attrName, attrValue);
|
|
149
|
+
};
|
|
144
150
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
151
|
+
Lint.prototype.testDoctype = function(doctype) {
|
|
152
|
+
this._doctype = doctype;
|
|
153
|
+
};
|
|
149
154
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
else {
|
|
155
|
-
var output = ' - ' +
|
|
156
|
-
this.log.join('\n - ')
|
|
157
|
-
.replace(/(<([^>]+)>)/ig, '')
|
|
158
|
-
.replace(/</g, '<')
|
|
159
|
-
.replace(/>/g, '>');
|
|
155
|
+
Lint.prototype.populate = function(writeToElement) {
|
|
156
|
+
if (!this._doctype) {
|
|
157
|
+
this.log.push('No DOCTYPE found.');
|
|
158
|
+
}
|
|
160
159
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
160
|
+
if (this._isElementRepeated) {
|
|
161
|
+
this._reportRepeatingElement();
|
|
162
|
+
}
|
|
165
163
|
|
|
166
|
-
|
|
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(/</g, '<').replace(/>/g, '>'));
|
|
174
|
+
}
|
|
175
|
+
};
|
|
167
176
|
|
|
168
|
-
|
|
177
|
+
exports.HTMLLint = Lint;
|