node-html-parser 6.1.7 → 6.1.9

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 CHANGED
@@ -2,6 +2,21 @@
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.9](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.8...v6.1.9) (2023-09-11)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * [#249](https://github.com/taoqf/node-fast-html-parser/issues/249) ([5a0a795](https://github.com/taoqf/node-fast-html-parser/commit/5a0a79573d51da9eccf6d13647413447eba413b1))
11
+ * test code for issue 249 ([799ee31](https://github.com/taoqf/node-fast-html-parser/commit/799ee31155a0635955b0a85e3d21ec4967223a25))
12
+
13
+ ### [6.1.8](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.7...v6.1.8) (2023-09-08)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * [#248](https://github.com/taoqf/node-fast-html-parser/issues/248) void tag ([01ff9f4](https://github.com/taoqf/node-fast-html-parser/commit/01ff9f41e416d0ef0c47bc40c282d6aeb405e100))
19
+
5
20
  ### [6.1.7](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.6...v6.1.7) (2023-09-08)
6
21
 
7
22
 
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
  }
@@ -591,6 +591,10 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
591
591
  * @return {string} text content
592
592
  */
593
593
  get: function () {
594
+ // https://github.com/taoqf/node-html-parser/issues/249
595
+ if (/br/i.test(this.rawTagName)) {
596
+ return '\n';
597
+ }
594
598
  return this.childNodes.reduce(function (pre, cur) {
595
599
  return (pre += cur.rawText);
596
600
  }, '');
@@ -1294,36 +1298,6 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
1294
1298
  // https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
1295
1299
  var kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
1296
1300
  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
1301
  var kElementsClosedByOpening = {
1328
1302
  li: { li: true, LI: true },
1329
1303
  LI: { li: true, LI: true },
@@ -1490,7 +1464,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
1490
1464
  }
1491
1465
  }
1492
1466
  // Handle closing tags or self-closed elements (ie </tag> or <br>)
1493
- if (leadingSlash || closingSlash || kSelfClosingElements[tagName]) {
1467
+ if (leadingSlash || closingSlash || voidTag.isVoidElement(tagName)) {
1494
1468
  while (true) {
1495
1469
  if (noNestedTagIndex != null && (tagName === 'a' || tagName === 'A'))
1496
1470
  noNestedTagIndex = undefined;
@@ -257,6 +257,10 @@ var HTMLElement = /** @class */ (function (_super) {
257
257
  * @return {string} text content
258
258
  */
259
259
  get: function () {
260
+ // https://github.com/taoqf/node-html-parser/issues/249
261
+ if (/br/i.test(this.rawTagName)) {
262
+ return '\n';
263
+ }
260
264
  return this.childNodes.reduce(function (pre, cur) {
261
265
  return (pre += cur.rawText);
262
266
  }, '');
@@ -960,36 +964,6 @@ exports.default = HTMLElement;
960
964
  // https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
961
965
  var kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
962
966
  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
967
  var kElementsClosedByOpening = {
994
968
  li: { li: true, LI: true },
995
969
  LI: { li: true, LI: true },
@@ -1156,7 +1130,7 @@ function base_parse(data, options) {
1156
1130
  }
1157
1131
  }
1158
1132
  // Handle closing tags or self-closed elements (ie </tag> or <br>)
1159
- if (leadingSlash || closingSlash || kSelfClosingElements[tagName]) {
1133
+ if (leadingSlash || closingSlash || voidTag.isVoidElement(tagName)) {
1160
1134
  while (true) {
1161
1135
  if (noNestedTagIndex != null && (tagName === 'a' || tagName === 'A'))
1162
1136
  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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-html-parser",
3
- "version": "6.1.7",
3
+ "version": "6.1.9",
4
4
  "description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",