node-html-parser 1.2.10 → 1.2.14

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/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ test/
2
+ dist/
3
+ node_modules/
package/dist/main.js CHANGED
@@ -47,7 +47,7 @@ define("nodes/node", ["require", "exports"], function (require, exports) {
47
47
  }());
48
48
  exports.default = Node;
49
49
  });
50
- define("nodes/comment", ["require", "exports", "he", "nodes/node", "nodes/type"], function (require, exports, he_1, node_1, type_1) {
50
+ define("nodes/comment", ["require", "exports", "nodes/node", "nodes/type"], function (require, exports, node_1, type_1) {
51
51
  "use strict";
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
53
  node_1 = __importDefault(node_1);
@@ -70,7 +70,7 @@ define("nodes/comment", ["require", "exports", "he", "nodes/node", "nodes/type"]
70
70
  * @return {string} text content
71
71
  */
72
72
  get: function () {
73
- return he_1.decode(this.rawText);
73
+ return this.rawText;
74
74
  },
75
75
  enumerable: true,
76
76
  configurable: true
@@ -82,7 +82,7 @@ define("nodes/comment", ["require", "exports", "he", "nodes/node", "nodes/type"]
82
82
  }(node_1.default));
83
83
  exports.default = CommentNode;
84
84
  });
85
- define("nodes/text", ["require", "exports", "he", "nodes/type", "nodes/node"], function (require, exports, he_2, type_2, node_2) {
85
+ define("nodes/text", ["require", "exports", "nodes/type", "nodes/node"], function (require, exports, type_2, node_2) {
86
86
  "use strict";
87
87
  Object.defineProperty(exports, "__esModule", { value: true });
88
88
  type_2 = __importDefault(type_2);
@@ -109,7 +109,7 @@ define("nodes/text", ["require", "exports", "he", "nodes/type", "nodes/node"], f
109
109
  * @return {string} text content
110
110
  */
111
111
  get: function () {
112
- return he_2.decode(this.rawText);
112
+ return this.rawText;
113
113
  },
114
114
  enumerable: true,
115
115
  configurable: true
@@ -188,6 +188,14 @@ define("matcher", ["require", "exports"], function (require, exports) {
188
188
  'use strict';
189
189
  return true;
190
190
  },
191
+ f55: function (el, tagName, classes, attr_key) {
192
+ 'use strict';
193
+ tagName = tagName || '';
194
+ classes = classes || [];
195
+ attr_key = attr_key || '';
196
+ var attrs = el.attributes;
197
+ return attrs.hasOwnProperty(attr_key);
198
+ },
191
199
  f245: function (el, tagName, classes, attr_key, value) {
192
200
  'use strict';
193
201
  tagName = tagName || '';
@@ -300,6 +308,10 @@ define("matcher", ["require", "exports"], function (require, exports) {
300
308
  // source += `let attrs = el.attributes;for (let key in attrs){const val = attrs[key]; if (key == "${attr_key}" && val == "${value}"){return true;}} return false;`;// 2
301
309
  function_name += '2';
302
310
  }
311
+ else if (reg = /^\[(.*?)\]/.exec(tagName)) {
312
+ attr_key = reg[1];
313
+ function_name += '5';
314
+ }
303
315
  else {
304
316
  // source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;';// 3
305
317
  function_name += '3';
@@ -370,7 +382,7 @@ define("matcher", ["require", "exports"], function (require, exports) {
370
382
  }());
371
383
  exports.default = Matcher;
372
384
  });
373
- define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "nodes/text", "matcher", "back", "nodes/comment"], function (require, exports, he_3, node_3, type_3, text_1, matcher_1, back_1, comment_1) {
385
+ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "nodes/text", "matcher", "back", "nodes/comment"], function (require, exports, he_1, node_3, type_3, text_1, matcher_1, back_1, comment_1) {
374
386
  "use strict";
375
387
  Object.defineProperty(exports, "__esModule", { value: true });
376
388
  node_3 = __importDefault(node_3);
@@ -475,7 +487,7 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
475
487
  * @return {string} text content
476
488
  */
477
489
  get: function () {
478
- return he_3.decode(this.rawText);
490
+ return he_1.decode(this.rawText);
479
491
  },
480
492
  enumerable: true,
481
493
  configurable: true
@@ -558,12 +570,13 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
558
570
  enumerable: true,
559
571
  configurable: true
560
572
  });
561
- HTMLElement.prototype.set_content = function (content) {
573
+ HTMLElement.prototype.set_content = function (content, options) {
574
+ if (options === void 0) { options = {}; }
562
575
  if (content instanceof node_3.default) {
563
576
  content = [content];
564
577
  }
565
578
  else if (typeof content == 'string') {
566
- var r = parse(content);
579
+ var r = parse(content, options);
567
580
  content = r.childNodes.length ? r.childNodes : [new text_1.default(content)];
568
581
  }
569
582
  this.childNodes = content;
@@ -681,7 +694,7 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
681
694
  return this.childNodes.reduce(function (res, cur) {
682
695
  stack.push([cur, 0, false]);
683
696
  while (stack.length) {
684
- var state = back_1.default(stack);
697
+ var state = back_1.default(stack); // get last element
685
698
  var el = state[0];
686
699
  if (state[1] === 0) {
687
700
  // Seen for first time.
@@ -689,10 +702,12 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
689
702
  stack.pop();
690
703
  continue;
691
704
  }
692
- state[2] = matcher.advance(el);
705
+ var html_el = el;
706
+ state[2] = matcher.advance(html_el);
693
707
  if (state[2]) {
694
708
  if (matcher.matched) {
695
- res.push(el);
709
+ res.push(html_el);
710
+ res.push.apply(res, (html_el.querySelectorAll(selector)));
696
711
  // no need to go further.
697
712
  matcher.rewind();
698
713
  stack.pop();
@@ -808,7 +823,7 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
808
823
  var attrs = this.rawAttributes;
809
824
  for (var key in attrs) {
810
825
  var val = attrs[key] || '';
811
- this._attrs[key] = he_3.decode(val);
826
+ this._attrs[key] = he_1.decode(val);
812
827
  }
813
828
  return this._attrs;
814
829
  },
@@ -877,7 +892,7 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
877
892
  var attrs = this.rawAttributes;
878
893
  attrs[key] = String(value);
879
894
  if (this._attrs) {
880
- this._attrs[key] = he_3.decode(attrs[key]);
895
+ this._attrs[key] = he_1.decode(attrs[key]);
881
896
  }
882
897
  // Update rawString
883
898
  this.rawAttrs = Object.keys(attrs).map(function (name) {
package/dist/matcher.js CHANGED
@@ -53,6 +53,14 @@ var functionCache = {
53
53
  'use strict';
54
54
  return true;
55
55
  },
56
+ f55: function (el, tagName, classes, attr_key) {
57
+ 'use strict';
58
+ tagName = tagName || '';
59
+ classes = classes || [];
60
+ attr_key = attr_key || '';
61
+ var attrs = el.attributes;
62
+ return attrs.hasOwnProperty(attr_key);
63
+ },
56
64
  f245: function (el, tagName, classes, attr_key, value) {
57
65
  'use strict';
58
66
  tagName = tagName || '';
@@ -165,6 +173,10 @@ var Matcher = /** @class */ (function () {
165
173
  // source += `let attrs = el.attributes;for (let key in attrs){const val = attrs[key]; if (key == "${attr_key}" && val == "${value}"){return true;}} return false;`;// 2
166
174
  function_name += '2';
167
175
  }
176
+ else if (reg = /^\[(.*?)\]/.exec(tagName)) {
177
+ attr_key = reg[1];
178
+ function_name += '5';
179
+ }
168
180
  else {
169
181
  // source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;';// 3
170
182
  function_name += '3';
@@ -16,7 +16,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  return (mod && mod.__esModule) ? mod : { "default": mod };
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- var he_1 = require("he");
20
19
  var node_1 = __importDefault(require("./node"));
21
20
  var type_1 = __importDefault(require("./type"));
22
21
  var CommentNode = /** @class */ (function (_super) {
@@ -37,7 +36,7 @@ var CommentNode = /** @class */ (function (_super) {
37
36
  * @return {string} text content
38
37
  */
39
38
  get: function () {
40
- return he_1.decode(this.rawText);
39
+ return this.rawText;
41
40
  },
42
41
  enumerable: true,
43
42
  configurable: true
@@ -70,7 +70,7 @@ export default class HTMLElement extends Node {
70
70
  get structuredText(): string;
71
71
  toString(): string;
72
72
  get innerHTML(): string;
73
- set_content(content: string | Node | Node[]): void;
73
+ set_content(content: string | Node | Node[], options?: Options): void;
74
74
  get outerHTML(): string;
75
75
  /**
76
76
  * Trim element from right (in block) after seeing pattern in a TextNode.
@@ -202,12 +202,13 @@ var HTMLElement = /** @class */ (function (_super) {
202
202
  enumerable: true,
203
203
  configurable: true
204
204
  });
205
- HTMLElement.prototype.set_content = function (content) {
205
+ HTMLElement.prototype.set_content = function (content, options) {
206
+ if (options === void 0) { options = {}; }
206
207
  if (content instanceof node_1.default) {
207
208
  content = [content];
208
209
  }
209
210
  else if (typeof content == 'string') {
210
- var r = parse(content);
211
+ var r = parse(content, options);
211
212
  content = r.childNodes.length ? r.childNodes : [new text_1.default(content)];
212
213
  }
213
214
  this.childNodes = content;
@@ -325,7 +326,7 @@ var HTMLElement = /** @class */ (function (_super) {
325
326
  return this.childNodes.reduce(function (res, cur) {
326
327
  stack.push([cur, 0, false]);
327
328
  while (stack.length) {
328
- var state = back_1.default(stack);
329
+ var state = back_1.default(stack); // get last element
329
330
  var el = state[0];
330
331
  if (state[1] === 0) {
331
332
  // Seen for first time.
@@ -333,10 +334,12 @@ var HTMLElement = /** @class */ (function (_super) {
333
334
  stack.pop();
334
335
  continue;
335
336
  }
336
- state[2] = matcher.advance(el);
337
+ var html_el = el;
338
+ state[2] = matcher.advance(html_el);
337
339
  if (state[2]) {
338
340
  if (matcher.matched) {
339
- res.push(el);
341
+ res.push(html_el);
342
+ res.push.apply(res, (html_el.querySelectorAll(selector)));
340
343
  // no need to go further.
341
344
  matcher.rewind();
342
345
  stack.pop();
@@ -16,7 +16,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  return (mod && mod.__esModule) ? mod : { "default": mod };
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- var he_1 = require("he");
20
19
  var type_1 = __importDefault(require("./type"));
21
20
  var node_1 = __importDefault(require("./node"));
22
21
  /**
@@ -41,7 +40,7 @@ var TextNode = /** @class */ (function (_super) {
41
40
  * @return {string} text content
42
41
  */
43
42
  get: function () {
44
- return he_1.decode(this.rawText);
43
+ return this.rawText;
45
44
  },
46
45
  enumerable: true,
47
46
  configurable: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-html-parser",
3
- "version": "1.2.10",
3
+ "version": "1.2.14",
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",