node-html-parser 6.1.6 → 6.1.8
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/CHANGELOG.md +16 -0
- package/README.md +2 -3
- package/dist/main.js +6 -34
- package/dist/nodes/html.js +4 -32
- package/dist/void-tag.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [6.1.8](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.7...v6.1.8) (2023-09-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* [#248](https://github.com/taoqf/node-fast-html-parser/issues/248) void tag ([01ff9f4](https://github.com/taoqf/node-fast-html-parser/commit/01ff9f41e416d0ef0c47bc40c282d6aeb405e100))
|
|
11
|
+
|
|
12
|
+
### [6.1.7](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.6...v6.1.7) (2023-09-08)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* block text elements [#242](https://github.com/taoqf/node-fast-html-parser/issues/242) ([97e593c](https://github.com/taoqf/node-fast-html-parser/commit/97e593c2bdefbfefd35c2c9ccaef914517d60fe7))
|
|
18
|
+
* docs [#245](https://github.com/taoqf/node-fast-html-parser/issues/245) ([f656c7b](https://github.com/taoqf/node-fast-html-parser/commit/f656c7b2de2a62a9a363f797c6f03a2477e7312e))
|
|
19
|
+
* remove test code ([d3980c5](https://github.com/taoqf/node-fast-html-parser/commit/d3980c5fb7744d6fda4b270619bb581a19a4cb18))
|
|
20
|
+
|
|
5
21
|
### [6.1.6](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.5...v6.1.6) (2023-08-17)
|
|
6
22
|
|
|
7
23
|
|
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@ no closing `<li>`, `<td>` etc).
|
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
```shell
|
|
15
14
|
npm install --save node-html-parser
|
|
16
15
|
```
|
|
@@ -86,7 +85,7 @@ Parse the data provided, and return the root of the generated DOM.
|
|
|
86
85
|
comment: false, // retrieve comments (hurts performance slightly)
|
|
87
86
|
voidTag:{
|
|
88
87
|
tags: ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'], // optional and case insensitive, default value is ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']
|
|
89
|
-
|
|
88
|
+
closingSlash: true // optional, default false. void tag serialisation, add a final slash <br/>
|
|
90
89
|
},
|
|
91
90
|
blockTextElements: {
|
|
92
91
|
script: true, // keep text content when parsing
|
|
@@ -293,7 +292,7 @@ Get class names.
|
|
|
293
292
|
|
|
294
293
|
Clone a node.
|
|
295
294
|
|
|
296
|
-
#### getElementById(id: string): HTMLElement
|
|
295
|
+
#### getElementById(id: string): HTMLElement
|
|
297
296
|
|
|
298
297
|
Get element by it's ID.
|
|
299
298
|
|
package/dist/main.js
CHANGED
|
@@ -222,12 +222,12 @@ define("void-tag", ["require", "exports"], function (require, exports) {
|
|
|
222
222
|
this.addClosingSlash = addClosingSlash;
|
|
223
223
|
if (Array.isArray(tags)) {
|
|
224
224
|
this.voidTags = tags.reduce(function (set, tag) {
|
|
225
|
-
return set.add(tag.toLowerCase());
|
|
225
|
+
return set.add(tag.toLowerCase()).add(tag.toUpperCase()).add(tag);
|
|
226
226
|
}, new Set());
|
|
227
227
|
}
|
|
228
228
|
else {
|
|
229
229
|
this.voidTags = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'].reduce(function (set, tag) {
|
|
230
|
-
return set.add(tag);
|
|
230
|
+
return set.add(tag.toLowerCase()).add(tag.toUpperCase()).add(tag);
|
|
231
231
|
}, new Set());
|
|
232
232
|
}
|
|
233
233
|
}
|
|
@@ -1294,36 +1294,6 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1294
1294
|
// https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
1295
1295
|
var kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
|
|
1296
1296
|
var kAttributePattern = /(?:^|\s)(id|class)\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+)/gi;
|
|
1297
|
-
var kSelfClosingElements = {
|
|
1298
|
-
area: true,
|
|
1299
|
-
AREA: true,
|
|
1300
|
-
base: true,
|
|
1301
|
-
BASE: true,
|
|
1302
|
-
br: true,
|
|
1303
|
-
BR: true,
|
|
1304
|
-
col: true,
|
|
1305
|
-
COL: true,
|
|
1306
|
-
hr: true,
|
|
1307
|
-
HR: true,
|
|
1308
|
-
img: true,
|
|
1309
|
-
IMG: true,
|
|
1310
|
-
input: true,
|
|
1311
|
-
INPUT: true,
|
|
1312
|
-
link: true,
|
|
1313
|
-
LINK: true,
|
|
1314
|
-
meta: true,
|
|
1315
|
-
META: true,
|
|
1316
|
-
source: true,
|
|
1317
|
-
SOURCE: true,
|
|
1318
|
-
embed: true,
|
|
1319
|
-
EMBED: true,
|
|
1320
|
-
param: true,
|
|
1321
|
-
PARAM: true,
|
|
1322
|
-
track: true,
|
|
1323
|
-
TRACK: true,
|
|
1324
|
-
wbr: true,
|
|
1325
|
-
WBR: true,
|
|
1326
|
-
};
|
|
1327
1297
|
var kElementsClosedByOpening = {
|
|
1328
1298
|
li: { li: true, LI: true },
|
|
1329
1299
|
LI: { li: true, LI: true },
|
|
@@ -1381,7 +1351,9 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1381
1351
|
style: true,
|
|
1382
1352
|
pre: true,
|
|
1383
1353
|
};
|
|
1384
|
-
var element_names = Object.keys(elements)
|
|
1354
|
+
var element_names = Object.keys(elements).filter(function (name) {
|
|
1355
|
+
return Boolean(elements[name]);
|
|
1356
|
+
});
|
|
1385
1357
|
var kBlockTextElements = element_names.map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1386
1358
|
var kIgnoreElements = element_names.filter(function (it) { return elements[it]; }).map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1387
1359
|
function element_should_be_ignore(tag) {
|
|
@@ -1488,7 +1460,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1488
1460
|
}
|
|
1489
1461
|
}
|
|
1490
1462
|
// Handle closing tags or self-closed elements (ie </tag> or <br>)
|
|
1491
|
-
if (leadingSlash || closingSlash ||
|
|
1463
|
+
if (leadingSlash || closingSlash || voidTag.isVoidElement(tagName)) {
|
|
1492
1464
|
while (true) {
|
|
1493
1465
|
if (noNestedTagIndex != null && (tagName === 'a' || tagName === 'A'))
|
|
1494
1466
|
noNestedTagIndex = undefined;
|
package/dist/nodes/html.js
CHANGED
|
@@ -960,36 +960,6 @@ exports.default = HTMLElement;
|
|
|
960
960
|
// https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
961
961
|
var kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
|
|
962
962
|
var kAttributePattern = /(?:^|\s)(id|class)\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+)/gi;
|
|
963
|
-
var kSelfClosingElements = {
|
|
964
|
-
area: true,
|
|
965
|
-
AREA: true,
|
|
966
|
-
base: true,
|
|
967
|
-
BASE: true,
|
|
968
|
-
br: true,
|
|
969
|
-
BR: true,
|
|
970
|
-
col: true,
|
|
971
|
-
COL: true,
|
|
972
|
-
hr: true,
|
|
973
|
-
HR: true,
|
|
974
|
-
img: true,
|
|
975
|
-
IMG: true,
|
|
976
|
-
input: true,
|
|
977
|
-
INPUT: true,
|
|
978
|
-
link: true,
|
|
979
|
-
LINK: true,
|
|
980
|
-
meta: true,
|
|
981
|
-
META: true,
|
|
982
|
-
source: true,
|
|
983
|
-
SOURCE: true,
|
|
984
|
-
embed: true,
|
|
985
|
-
EMBED: true,
|
|
986
|
-
param: true,
|
|
987
|
-
PARAM: true,
|
|
988
|
-
track: true,
|
|
989
|
-
TRACK: true,
|
|
990
|
-
wbr: true,
|
|
991
|
-
WBR: true,
|
|
992
|
-
};
|
|
993
963
|
var kElementsClosedByOpening = {
|
|
994
964
|
li: { li: true, LI: true },
|
|
995
965
|
LI: { li: true, LI: true },
|
|
@@ -1047,7 +1017,9 @@ function base_parse(data, options) {
|
|
|
1047
1017
|
style: true,
|
|
1048
1018
|
pre: true,
|
|
1049
1019
|
};
|
|
1050
|
-
var element_names = Object.keys(elements)
|
|
1020
|
+
var element_names = Object.keys(elements).filter(function (name) {
|
|
1021
|
+
return Boolean(elements[name]);
|
|
1022
|
+
});
|
|
1051
1023
|
var kBlockTextElements = element_names.map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1052
1024
|
var kIgnoreElements = element_names.filter(function (it) { return elements[it]; }).map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1053
1025
|
function element_should_be_ignore(tag) {
|
|
@@ -1154,7 +1126,7 @@ function base_parse(data, options) {
|
|
|
1154
1126
|
}
|
|
1155
1127
|
}
|
|
1156
1128
|
// Handle closing tags or self-closed elements (ie </tag> or <br>)
|
|
1157
|
-
if (leadingSlash || closingSlash ||
|
|
1129
|
+
if (leadingSlash || closingSlash || voidTag.isVoidElement(tagName)) {
|
|
1158
1130
|
while (true) {
|
|
1159
1131
|
if (noNestedTagIndex != null && (tagName === 'a' || tagName === 'A'))
|
|
1160
1132
|
noNestedTagIndex = undefined;
|
package/dist/void-tag.js
CHANGED
|
@@ -6,12 +6,12 @@ var VoidTag = /** @class */ (function () {
|
|
|
6
6
|
this.addClosingSlash = addClosingSlash;
|
|
7
7
|
if (Array.isArray(tags)) {
|
|
8
8
|
this.voidTags = tags.reduce(function (set, tag) {
|
|
9
|
-
return set.add(tag.toLowerCase());
|
|
9
|
+
return set.add(tag.toLowerCase()).add(tag.toUpperCase()).add(tag);
|
|
10
10
|
}, new Set());
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
13
|
this.voidTags = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'].reduce(function (set, tag) {
|
|
14
|
-
return set.add(tag);
|
|
14
|
+
return set.add(tag.toLowerCase()).add(tag.toUpperCase()).add(tag);
|
|
15
15
|
}, new Set());
|
|
16
16
|
}
|
|
17
17
|
}
|
package/package.json
CHANGED