html-minifier-next 2.1.3 → 2.1.5
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 +26 -24
- package/cli.js +0 -1
- package/dist/htmlminifier.cjs +46 -11
- package/dist/htmlminifier.esm.bundle.js +46 -11
- package/dist/htmlminifier.umd.bundle.js +46 -11
- package/dist/htmlminifier.umd.bundle.min.js +2 -2
- package/package.json +5 -6
- package/src/htmlminifier.js +0 -1
- package/src/htmlparser.js +46 -11
package/package.json
CHANGED
|
@@ -7,22 +7,21 @@
|
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"change-case": "^4.1.2",
|
|
9
9
|
"clean-css": "~5.3.3",
|
|
10
|
-
"commander": "^14.0.
|
|
10
|
+
"commander": "^14.0.1",
|
|
11
11
|
"entities": "^7.0.0",
|
|
12
12
|
"relateurl": "^0.2.7",
|
|
13
13
|
"terser": "^5.44.0"
|
|
14
14
|
},
|
|
15
|
-
"description": "Highly configurable, well-tested, JavaScript-based HTML minifier
|
|
15
|
+
"description": "Highly configurable, well-tested, JavaScript-based HTML minifier",
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@commitlint/cli": "^19.8.1",
|
|
18
|
-
"@eslint/js": "^9.
|
|
18
|
+
"@eslint/js": "^9.35.0",
|
|
19
19
|
"@jest/globals": "^30.1.2",
|
|
20
20
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
21
21
|
"@rollup/plugin-json": "^6.1.0",
|
|
22
22
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
23
23
|
"@rollup/plugin-terser": "^0.4.4",
|
|
24
|
-
"
|
|
25
|
-
"eslint": "^9.33.0",
|
|
24
|
+
"eslint": "^9.35.0",
|
|
26
25
|
"jest": "^30.1.3",
|
|
27
26
|
"rollup": "^4.50.0",
|
|
28
27
|
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
@@ -86,5 +85,5 @@
|
|
|
86
85
|
"test:watch": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --watch"
|
|
87
86
|
},
|
|
88
87
|
"type": "module",
|
|
89
|
-
"version": "2.1.
|
|
88
|
+
"version": "2.1.5"
|
|
90
89
|
}
|
package/src/htmlminifier.js
CHANGED
|
@@ -2,7 +2,6 @@ import CleanCSS from 'clean-css';
|
|
|
2
2
|
import { decodeHTMLStrict, decodeHTML } from 'entities';
|
|
3
3
|
import RelateURL from 'relateurl';
|
|
4
4
|
import { minify as terser } from 'terser';
|
|
5
|
-
|
|
6
5
|
import { HTMLParser, endTag } from './htmlparser.js';
|
|
7
6
|
import TokenChain from './tokenchain.js';
|
|
8
7
|
import { replaceAsync } from './utils.js';
|
package/src/htmlparser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* HTML Parser By John Resig (ejohn.org)
|
|
3
|
-
* Modified by Juriy
|
|
3
|
+
* Modified by Juriy “kangax” Zaytsev
|
|
4
4
|
* Original code by Erik Arvidsson, Mozilla Public License
|
|
5
5
|
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
|
|
6
6
|
*/
|
|
@@ -122,7 +122,7 @@ export class HTMLParser {
|
|
|
122
122
|
if (!lastTag || !special.has(lastTag)) {
|
|
123
123
|
let textEnd = html.indexOf('<');
|
|
124
124
|
if (textEnd === 0) {
|
|
125
|
-
// Comment
|
|
125
|
+
// Comment
|
|
126
126
|
if (/^<!--/.test(html)) {
|
|
127
127
|
const commentEnd = html.indexOf('-->');
|
|
128
128
|
|
|
@@ -150,7 +150,7 @@ export class HTMLParser {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
// Doctype
|
|
153
|
+
// Doctype
|
|
154
154
|
const doctypeMatch = html.match(doctype);
|
|
155
155
|
if (doctypeMatch) {
|
|
156
156
|
if (handler.doctype) {
|
|
@@ -161,7 +161,7 @@ export class HTMLParser {
|
|
|
161
161
|
continue;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
// End tag
|
|
164
|
+
// End tag
|
|
165
165
|
const endTagMatch = html.match(endTag);
|
|
166
166
|
if (endTagMatch) {
|
|
167
167
|
html = html.substring(endTagMatch[0].length);
|
|
@@ -170,7 +170,7 @@ export class HTMLParser {
|
|
|
170
170
|
continue;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
// Start tag
|
|
173
|
+
// Start tag
|
|
174
174
|
const startTagMatch = parseStartTag(html);
|
|
175
175
|
if (startTagMatch) {
|
|
176
176
|
html = startTagMatch.rest;
|
|
@@ -263,11 +263,41 @@ export class HTMLParser {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
function findTagInCurrentTable(tagName) {
|
|
267
|
+
let pos;
|
|
268
|
+
const needle = tagName.toLowerCase();
|
|
269
|
+
for (pos = stack.length - 1; pos >= 0; pos--) {
|
|
270
|
+
const currentTag = stack[pos].tag.toLowerCase();
|
|
271
|
+
if (currentTag === needle) {
|
|
272
|
+
return pos;
|
|
273
|
+
}
|
|
274
|
+
// Stop searching if we hit a table boundary
|
|
275
|
+
if (currentTag === 'table') {
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return -1;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async function parseEndTagAt(pos) {
|
|
283
|
+
// Close all open elements up to pos (mirrors parseEndTag’s core branch)
|
|
284
|
+
for (let i = stack.length - 1; i >= pos; i--) {
|
|
285
|
+
if (handler.end) {
|
|
286
|
+
await handler.end(stack[i].tag, stack[i].attrs, true);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
stack.length = pos;
|
|
290
|
+
lastTag = pos && stack[pos - 1].tag;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async function closeIfFoundInCurrentTable(tagName) {
|
|
294
|
+
const pos = findTagInCurrentTable(tagName);
|
|
295
|
+
if (pos >= 0) {
|
|
296
|
+
// Close at the specific index to avoid re-searching
|
|
297
|
+
await parseEndTagAt(pos);
|
|
269
298
|
return true;
|
|
270
299
|
}
|
|
300
|
+
return false;
|
|
271
301
|
}
|
|
272
302
|
|
|
273
303
|
async function handleStartTag(match) {
|
|
@@ -278,10 +308,15 @@ export class HTMLParser {
|
|
|
278
308
|
if (lastTag === 'p' && nonPhrasing.has(tagName)) {
|
|
279
309
|
await parseEndTag('', lastTag);
|
|
280
310
|
} else if (tagName === 'tbody') {
|
|
281
|
-
await
|
|
311
|
+
await closeIfFoundInCurrentTable('thead');
|
|
282
312
|
} else if (tagName === 'tfoot') {
|
|
283
|
-
if (!await
|
|
284
|
-
await
|
|
313
|
+
if (!await closeIfFoundInCurrentTable('tbody')) {
|
|
314
|
+
await closeIfFoundInCurrentTable('thead');
|
|
315
|
+
}
|
|
316
|
+
} else if (tagName === 'thead') {
|
|
317
|
+
// If a `tbody` or `tfoot` is open in the current table, close it
|
|
318
|
+
if (!await closeIfFoundInCurrentTable('tbody')) {
|
|
319
|
+
await closeIfFoundInCurrentTable('tfoot');
|
|
285
320
|
}
|
|
286
321
|
}
|
|
287
322
|
if (tagName === 'col' && findTag('colgroup') < 0) {
|