html-minifier 1.1.1 → 1.4.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/LICENSE +1 -1
- package/README.md +43 -30
- package/cli.js +101 -98
- package/dist/htmlminifier.js +32461 -1281
- package/dist/htmlminifier.min.js +14 -2
- package/package.json +13 -7
- package/sample-cli-config-file.conf +21 -14
- package/src/.eslintrc.json +5 -0
- package/src/htmllint.js +139 -142
- package/src/htmlminifier.js +951 -681
- package/src/htmlparser.js +405 -438
- package/src/utils.js +18 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-minifier",
|
|
3
3
|
"description": "HTML minifier with lint-like capabilities.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"html",
|
|
7
7
|
"minifier",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"node": ">=0.10.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
+
"dist": "grunt dist",
|
|
36
37
|
"test": "grunt test"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
@@ -40,21 +41,26 @@
|
|
|
40
41
|
"clean-css": "3.4.x",
|
|
41
42
|
"cli": "0.11.x",
|
|
42
43
|
"concat-stream": "1.5.x",
|
|
44
|
+
"ncname": "1.0.x",
|
|
43
45
|
"relateurl": "0.2.x",
|
|
44
46
|
"uglify-js": "2.6.x"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
49
|
+
"brotli": "1.2.x",
|
|
47
50
|
"chalk": "1.1.x",
|
|
48
51
|
"cli-table": "0.3.x",
|
|
49
52
|
"grunt": "0.4.x",
|
|
50
|
-
"grunt-
|
|
51
|
-
"grunt-
|
|
52
|
-
"grunt-contrib-
|
|
53
|
-
"grunt-
|
|
53
|
+
"grunt-browserify": "5.0.x",
|
|
54
|
+
"grunt-cli": "1.1.x",
|
|
55
|
+
"grunt-contrib-uglify": "1.0.x",
|
|
56
|
+
"grunt-eslint": "18.0.x",
|
|
54
57
|
"grunt-exec": "0.4.x",
|
|
55
|
-
"grunt-
|
|
58
|
+
"grunt-lib-phantomjs": "1.0.x",
|
|
56
59
|
"load-grunt-tasks": "3.4.x",
|
|
57
|
-
"
|
|
60
|
+
"lzma": "2.3.x",
|
|
61
|
+
"minimize": "1.8.x",
|
|
62
|
+
"progress": "1.1.x",
|
|
63
|
+
"qunit": "0.9.x",
|
|
58
64
|
"time-grunt": "1.3.x"
|
|
59
65
|
},
|
|
60
66
|
"files": [
|
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
-
"removeComments":
|
|
3
|
-
"removeCommentsFromCDATA": false,
|
|
4
|
-
"removeCDATASectionsFromCDATA": false,
|
|
2
|
+
"removeComments": true,
|
|
5
3
|
"collapseWhitespace": true,
|
|
6
4
|
"conservativeCollapse": false,
|
|
7
|
-
"collapseBooleanAttributes":
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
5
|
+
"collapseBooleanAttributes": true,
|
|
6
|
+
"removeTagWhitespace": true,
|
|
7
|
+
"removeAttributeQuotes": true,
|
|
8
|
+
"removeRedundantAttributes": true,
|
|
9
|
+
"useShortDoctype": true,
|
|
10
|
+
"removeEmptyAttributes": true,
|
|
11
|
+
"removeScriptTypeAttributes": true,
|
|
12
|
+
"removeStyleLinkTypeAttributes": true,
|
|
13
|
+
"removeOptionalTags": true,
|
|
14
|
+
"removeEmptyElements": true,
|
|
14
15
|
"lint": false,
|
|
15
16
|
"keepClosingSlash": false,
|
|
16
17
|
"caseSensitive": false,
|
|
17
|
-
"minifyJS":
|
|
18
|
-
"minifyCSS":
|
|
19
|
-
"
|
|
20
|
-
"
|
|
18
|
+
"minifyJS": true,
|
|
19
|
+
"minifyCSS": true,
|
|
20
|
+
"includeAutoGeneratedTags": false,
|
|
21
|
+
"ignoreCustomFragments": [
|
|
22
|
+
"<#[\\s\\S]*?#>"
|
|
23
|
+
],
|
|
24
|
+
"processConditionalComments": true,
|
|
25
|
+
"processScripts": [
|
|
26
|
+
"text/html"
|
|
27
|
+
]
|
|
21
28
|
}
|
package/src/htmllint.js
CHANGED
|
@@ -6,163 +6,160 @@
|
|
|
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 (
|
|
61
|
+
attrName === 'href' &&
|
|
62
|
+
(/^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i).test(attrValue)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function Lint() {
|
|
67
|
+
this.log = [ ];
|
|
68
|
+
this._lastElement = null;
|
|
69
|
+
this._isElementRepeated = false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Lint.prototype.testElement = function(tag) {
|
|
73
|
+
if (isDeprecatedElement(tag)) {
|
|
74
|
+
this.log.push(
|
|
75
|
+
'Found <span class="deprecated-element">deprecated</span> <strong><code><' +
|
|
76
|
+
tag + '></code></strong> element'
|
|
58
77
|
);
|
|
59
78
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
79
|
+
else if (isPresentationalElement(tag)) {
|
|
80
|
+
this.log.push(
|
|
81
|
+
'Found <span class="presentational-element">presentational</span> <strong><code><' +
|
|
82
|
+
tag + '></code></strong> element'
|
|
64
83
|
);
|
|
65
84
|
}
|
|
85
|
+
else {
|
|
86
|
+
this.checkRepeatingElement(tag);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
66
89
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.
|
|
90
|
+
Lint.prototype.checkRepeatingElement = function(tag) {
|
|
91
|
+
if (tag === 'br' && this._lastElement === 'br') {
|
|
92
|
+
this._isElementRepeated = true;
|
|
93
|
+
}
|
|
94
|
+
else if (this._isElementRepeated) {
|
|
95
|
+
this._reportRepeatingElement();
|
|
70
96
|
this._isElementRepeated = false;
|
|
71
97
|
}
|
|
98
|
+
this._lastElement = tag;
|
|
99
|
+
};
|
|
72
100
|
|
|
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
|
+
Lint.prototype._reportRepeatingElement = function() {
|
|
102
|
+
this.log.push('Found <code><br></code> sequence. Try replacing it with styling.');
|
|
103
|
+
};
|
|
101
104
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
Lint.prototype.testAttribute = function(tag, attrName, attrValue) {
|
|
106
|
+
if (isEventAttribute(attrName)) {
|
|
107
|
+
this.log.push(
|
|
108
|
+
'Found <span class="event-attribute">event attribute</span> (<strong>' +
|
|
109
|
+
attrName + '</strong>) on <strong><code><' + tag + '></code></strong> element.'
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
else if (isDeprecatedAttribute(tag, attrName)) {
|
|
113
|
+
this.log.push(
|
|
114
|
+
'Found <span class="deprecated-attribute">deprecated</span> <strong>' +
|
|
115
|
+
attrName + '</strong> attribute on <strong><code><' + tag + '></code></strong> element.'
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
else if (isStyleAttribute(attrName)) {
|
|
119
|
+
this.log.push(
|
|
120
|
+
'Found <span class="style-attribute">style attribute</span> on <strong><code><' +
|
|
121
|
+
tag + '></code></strong> element.'
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
else if (isInaccessibleAttribute(attrName, attrValue)) {
|
|
125
|
+
this.log.push(
|
|
126
|
+
'Found <span class="inaccessible-attribute">inaccessible attribute</span> ' +
|
|
127
|
+
'(on <strong><code><' + tag + '></code></strong> element).'
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
105
131
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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><' + tag + '></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><' +
|
|
122
|
-
tag + '></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><' + tag + '></code></strong> element).'
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
+
Lint.prototype.testChars = function(chars) {
|
|
133
|
+
this._lastElement = '';
|
|
134
|
+
if (/( \s*){2,}/.test(chars)) {
|
|
135
|
+
this.log.push('Found repeating <strong><code>&nbsp;</code></strong> sequence. Try replacing it with styling.');
|
|
136
|
+
}
|
|
137
|
+
};
|
|
132
138
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
+
Lint.prototype.test = function(tag, attrName, attrValue) {
|
|
140
|
+
this.testElement(tag);
|
|
141
|
+
this.testAttribute(tag, attrName, attrValue);
|
|
142
|
+
};
|
|
139
143
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
this.
|
|
143
|
-
}
|
|
144
|
+
Lint.prototype.populate = function(writeToElement) {
|
|
145
|
+
if (this._isElementRepeated) {
|
|
146
|
+
this._reportRepeatingElement();
|
|
147
|
+
}
|
|
144
148
|
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
this.
|
|
149
|
+
if (this.log.length) {
|
|
150
|
+
if (writeToElement) {
|
|
151
|
+
writeToElement.innerHTML = '<ol><li>' + this.log.join('<li>') + '</ol>';
|
|
148
152
|
}
|
|
153
|
+
else {
|
|
154
|
+
var output = ' - ' +
|
|
155
|
+
this.log.join('\n - ')
|
|
156
|
+
.replace(/(<([^>]+)>)/ig, '')
|
|
157
|
+
.replace(/</g, '<')
|
|
158
|
+
.replace(/>/g, '>');
|
|
149
159
|
|
|
150
|
-
|
|
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(/</g, '<')
|
|
159
|
-
.replace(/>/g, '>');
|
|
160
|
-
|
|
161
|
-
console.log(output);
|
|
162
|
-
}
|
|
160
|
+
console.log(output);
|
|
163
161
|
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
global.HTMLLint = Lint;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
167
164
|
|
|
168
|
-
|
|
165
|
+
exports.HTMLLint = Lint;
|