node-html-parser 6.1.4 → 6.1.6

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.6](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.5...v6.1.6) (2023-08-17)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * [#203](https://github.com/taoqf/node-fast-html-parser/issues/203) ([6006c52](https://github.com/taoqf/node-fast-html-parser/commit/6006c52c20e6c3c07405c808c8d81fa78425e794))
11
+ * [#218](https://github.com/taoqf/node-fast-html-parser/issues/218) ([6f6c824](https://github.com/taoqf/node-fast-html-parser/commit/6f6c824df54fa53af47956048b42ea47cd3b53bf))
12
+ * add tests for issue [#242](https://github.com/taoqf/node-fast-html-parser/issues/242) ([7615e27](https://github.com/taoqf/node-fast-html-parser/commit/7615e27e3eea47142beff11101d293c4f93cb6ce))
13
+ * do not decode special chractors [#240](https://github.com/taoqf/node-fast-html-parser/issues/240) ([cdadb13](https://github.com/taoqf/node-fast-html-parser/commit/cdadb132f681ca587d17df991d09ff8d22997f4e))
14
+ * improve constructor types [#230](https://github.com/taoqf/node-fast-html-parser/issues/230) ([24fd055](https://github.com/taoqf/node-fast-html-parser/commit/24fd055913125a964cb5aa61330376274c938035))
15
+ * more change about types [#230](https://github.com/taoqf/node-fast-html-parser/issues/230) ([2852d20](https://github.com/taoqf/node-fast-html-parser/commit/2852d20f865dc18a8dc6727d5b5e586282e7d50d))
16
+ * remove test code ([f0b176e](https://github.com/taoqf/node-fast-html-parser/commit/f0b176eb1ba5b5bc162744a37adcd18d3d64a515))
17
+
18
+ ### [6.1.5](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.4...v6.1.5) (2023-02-21)
19
+
5
20
  ### [6.1.4](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.3...v6.1.4) (2022-11-15)
6
21
 
7
22
 
package/dist/main.js CHANGED
@@ -256,6 +256,7 @@ define("nodes/text", ["require", "exports", "he", "nodes/node", "nodes/type"], f
256
256
  var TextNode = /** @class */ (function (_super) {
257
257
  __extends(TextNode, _super);
258
258
  function TextNode(rawText, parentNode, range) {
259
+ if (parentNode === void 0) { parentNode = null; }
259
260
  var _this = _super.call(this, parentNode, range) || this;
260
261
  /**
261
262
  * Node Type declaration.
@@ -489,6 +490,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
489
490
  */
490
491
  function HTMLElement(tagName, keyAttrs, rawAttrs, parentNode, range, voidTag, _parseOptions) {
491
492
  if (rawAttrs === void 0) { rawAttrs = ''; }
493
+ if (parentNode === void 0) { parentNode = null; }
492
494
  if (voidTag === void 0) { voidTag = new void_tag_1.default(); }
493
495
  if (_parseOptions === void 0) { _parseOptions = {}; }
494
496
  var _this = _super.call(this, parentNode, range) || this;
@@ -532,7 +534,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
532
534
  if (attr == null) {
533
535
  return 'null';
534
536
  }
535
- return JSON.stringify(attr.replace(/"/g, '"'));
537
+ return JSON.stringify(attr.replace(/"/g, '"')).replace(/\\t/g, '\t').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\/g, '');
536
538
  };
537
539
  /**
538
540
  * Remove Child element from childNodes array
@@ -1044,14 +1046,14 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
1044
1046
  }
1045
1047
  var attrs = {};
1046
1048
  if (this.rawAttrs) {
1047
- var re = /([a-zA-Z()[\]#@$.?][a-zA-Z0-9-_:()[\]#]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
1049
+ var re = /([a-zA-Z()[\]#@$.?:][a-zA-Z0-9-_:()[\]#]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
1048
1050
  var match = void 0;
1049
1051
  while ((match = re.exec(this.rawAttrs))) {
1050
1052
  var key = match[1];
1051
1053
  var val = match[2] || null;
1052
1054
  if (val && (val[0] === "'" || val[0] === "\""))
1053
1055
  val = val.slice(1, val.length - 1);
1054
- attrs[key] = val;
1056
+ attrs[key] = attrs[key] || val;
1055
1057
  }
1056
1058
  }
1057
1059
  this._rawAttrs = attrs;
@@ -1061,6 +1063,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
1061
1063
  configurable: true
1062
1064
  });
1063
1065
  HTMLElement.prototype.removeAttribute = function (key) {
1066
+ var _this = this;
1064
1067
  var attrs = this.rawAttributes;
1065
1068
  delete attrs[key];
1066
1069
  // Update this.attribute
@@ -1070,7 +1073,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
1070
1073
  // Update rawString
1071
1074
  this.rawAttrs = Object.keys(attrs)
1072
1075
  .map(function (name) {
1073
- var val = JSON.stringify(attrs[name]);
1076
+ var val = _this.quoteAttribute(attrs[name]);
1074
1077
  if (val === undefined || val === 'null') {
1075
1078
  return name;
1076
1079
  }
@@ -1581,6 +1584,7 @@ define("nodes/comment", ["require", "exports", "nodes/node", "nodes/type"], func
1581
1584
  var CommentNode = /** @class */ (function (_super) {
1582
1585
  __extends(CommentNode, _super);
1583
1586
  function CommentNode(rawText, parentNode, range) {
1587
+ if (parentNode === void 0) { parentNode = null; }
1584
1588
  var _this = _super.call(this, parentNode, range) || this;
1585
1589
  _this.rawText = rawText;
1586
1590
  /**
@@ -4,7 +4,7 @@ import NodeType from './type';
4
4
  export default class CommentNode extends Node {
5
5
  rawText: string;
6
6
  clone(): CommentNode;
7
- constructor(rawText: string, parentNode: HTMLElement, range?: [number, number]);
7
+ constructor(rawText: string, parentNode?: HTMLElement, range?: [number, number]);
8
8
  /**
9
9
  * Node Type declaration.
10
10
  * @type {Number}
@@ -23,6 +23,7 @@ var type_1 = __importDefault(require("./type"));
23
23
  var CommentNode = /** @class */ (function (_super) {
24
24
  __extends(CommentNode, _super);
25
25
  function CommentNode(rawText, parentNode, range) {
26
+ if (parentNode === void 0) { parentNode = null; }
26
27
  var _this = _super.call(this, parentNode, range) || this;
27
28
  _this.rawText = rawText;
28
29
  /**
@@ -62,7 +62,7 @@ export default class HTMLElement extends Node {
62
62
  *
63
63
  * @memberof HTMLElement
64
64
  */
65
- constructor(tagName: string, keyAttrs: KeyAttributes, rawAttrs: string, parentNode: HTMLElement | null, range: [number, number], voidTag?: VoidTag, _parseOptions?: Partial<Options>);
65
+ constructor(tagName: string, keyAttrs: KeyAttributes, rawAttrs?: string, parentNode?: HTMLElement, range?: [number, number], voidTag?: VoidTag, _parseOptions?: Partial<Options>);
66
66
  /**
67
67
  * Remove Child element from childNodes array
68
68
  * @param {HTMLElement} node node to remove
@@ -156,6 +156,7 @@ var HTMLElement = /** @class */ (function (_super) {
156
156
  */
157
157
  function HTMLElement(tagName, keyAttrs, rawAttrs, parentNode, range, voidTag, _parseOptions) {
158
158
  if (rawAttrs === void 0) { rawAttrs = ''; }
159
+ if (parentNode === void 0) { parentNode = null; }
159
160
  if (voidTag === void 0) { voidTag = new void_tag_1.default(); }
160
161
  if (_parseOptions === void 0) { _parseOptions = {}; }
161
162
  var _this = _super.call(this, parentNode, range) || this;
@@ -199,7 +200,7 @@ var HTMLElement = /** @class */ (function (_super) {
199
200
  if (attr == null) {
200
201
  return 'null';
201
202
  }
202
- return JSON.stringify(attr.replace(/"/g, '&quot;'));
203
+ return JSON.stringify(attr.replace(/"/g, '&quot;')).replace(/\\t/g, '\t').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\/g, '');
203
204
  };
204
205
  /**
205
206
  * Remove Child element from childNodes array
@@ -711,14 +712,14 @@ var HTMLElement = /** @class */ (function (_super) {
711
712
  }
712
713
  var attrs = {};
713
714
  if (this.rawAttrs) {
714
- var re = /([a-zA-Z()[\]#@$.?][a-zA-Z0-9-_:()[\]#]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
715
+ var re = /([a-zA-Z()[\]#@$.?:][a-zA-Z0-9-_:()[\]#]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
715
716
  var match = void 0;
716
717
  while ((match = re.exec(this.rawAttrs))) {
717
718
  var key = match[1];
718
719
  var val = match[2] || null;
719
720
  if (val && (val[0] === "'" || val[0] === "\""))
720
721
  val = val.slice(1, val.length - 1);
721
- attrs[key] = val;
722
+ attrs[key] = attrs[key] || val;
722
723
  }
723
724
  }
724
725
  this._rawAttrs = attrs;
@@ -728,6 +729,7 @@ var HTMLElement = /** @class */ (function (_super) {
728
729
  configurable: true
729
730
  });
730
731
  HTMLElement.prototype.removeAttribute = function (key) {
732
+ var _this = this;
731
733
  var attrs = this.rawAttributes;
732
734
  delete attrs[key];
733
735
  // Update this.attribute
@@ -737,7 +739,7 @@ var HTMLElement = /** @class */ (function (_super) {
737
739
  // Update rawString
738
740
  this.rawAttrs = Object.keys(attrs)
739
741
  .map(function (name) {
740
- var val = JSON.stringify(attrs[name]);
742
+ var val = _this.quoteAttribute(attrs[name]);
741
743
  if (val === undefined || val === 'null') {
742
744
  return name;
743
745
  }
@@ -7,7 +7,7 @@ import NodeType from './type';
7
7
  */
8
8
  export default class TextNode extends Node {
9
9
  clone(): TextNode;
10
- constructor(rawText: string, parentNode: HTMLElement, range?: [number, number]);
10
+ constructor(rawText: string, parentNode?: HTMLElement, range?: [number, number]);
11
11
  /**
12
12
  * Node Type declaration.
13
13
  * @type {Number}
@@ -28,6 +28,7 @@ var type_1 = __importDefault(require("./type"));
28
28
  var TextNode = /** @class */ (function (_super) {
29
29
  __extends(TextNode, _super);
30
30
  function TextNode(rawText, parentNode, range) {
31
+ if (parentNode === void 0) { parentNode = null; }
31
32
  var _this = _super.call(this, parentNode, range) || this;
32
33
  /**
33
34
  * Node Type declaration.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-html-parser",
3
- "version": "6.1.4",
3
+ "version": "6.1.6",
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",