node-html-parser 5.3.0 → 5.3.1
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/dist/main.js +27 -13
- package/dist/nodes/html.d.ts +7 -7
- package/dist/nodes/html.js +27 -13
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -495,7 +495,9 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
495
495
|
this.parentNode.childNodes = children.filter(function (child) {
|
|
496
496
|
return _this !== child;
|
|
497
497
|
});
|
|
498
|
+
this.parentNode = null;
|
|
498
499
|
}
|
|
500
|
+
return this;
|
|
499
501
|
};
|
|
500
502
|
/**
|
|
501
503
|
* Remove Child element from childNodes array
|
|
@@ -505,6 +507,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
505
507
|
this.childNodes = this.childNodes.filter(function (child) {
|
|
506
508
|
return child !== node;
|
|
507
509
|
});
|
|
510
|
+
return this;
|
|
508
511
|
};
|
|
509
512
|
/**
|
|
510
513
|
* Exchanges given child with new child
|
|
@@ -519,6 +522,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
519
522
|
}
|
|
520
523
|
return child;
|
|
521
524
|
});
|
|
525
|
+
return this;
|
|
522
526
|
};
|
|
523
527
|
Object.defineProperty(HTMLElement.prototype, "tagName", {
|
|
524
528
|
get: function () {
|
|
@@ -647,7 +651,10 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
647
651
|
set: function (content) {
|
|
648
652
|
//const r = parse(content, global.options); // TODO global.options ?
|
|
649
653
|
var r = parse(content);
|
|
650
|
-
|
|
654
|
+
var nodes = r.childNodes.length ? r.childNodes : [new text_1.default(content, this)];
|
|
655
|
+
resetParent(nodes, this);
|
|
656
|
+
resetParent(this.childNodes, null);
|
|
657
|
+
this.childNodes = nodes;
|
|
651
658
|
},
|
|
652
659
|
enumerable: false,
|
|
653
660
|
configurable: true
|
|
@@ -661,7 +668,10 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
661
668
|
var r = parse(content, options);
|
|
662
669
|
content = r.childNodes.length ? r.childNodes : [new text_1.default(content, this)];
|
|
663
670
|
}
|
|
671
|
+
resetParent(this.childNodes, null);
|
|
672
|
+
resetParent(content, this);
|
|
664
673
|
this.childNodes = content;
|
|
674
|
+
return this;
|
|
665
675
|
};
|
|
666
676
|
HTMLElement.prototype.replaceWith = function () {
|
|
667
677
|
var _this = this;
|
|
@@ -669,6 +679,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
669
679
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
670
680
|
nodes[_i] = arguments[_i];
|
|
671
681
|
}
|
|
682
|
+
var parent = this.parentNode;
|
|
672
683
|
var content = nodes
|
|
673
684
|
.map(function (node) {
|
|
674
685
|
if (node instanceof node_2.default) {
|
|
@@ -682,10 +693,11 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
682
693
|
return [];
|
|
683
694
|
})
|
|
684
695
|
.flat();
|
|
685
|
-
var idx =
|
|
696
|
+
var idx = parent.childNodes.findIndex(function (child) {
|
|
686
697
|
return child === _this;
|
|
687
698
|
});
|
|
688
|
-
|
|
699
|
+
resetParent([this], null);
|
|
700
|
+
parent.childNodes = __spreadArray(__spreadArray(__spreadArray([], parent.childNodes.slice(0, idx), true), resetParent(content, parent), true), parent.childNodes.slice(idx + 1), true);
|
|
689
701
|
};
|
|
690
702
|
Object.defineProperty(HTMLElement.prototype, "outerHTML", {
|
|
691
703
|
get: function () {
|
|
@@ -1033,6 +1045,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1033
1045
|
if (key === 'id') {
|
|
1034
1046
|
this.id = '';
|
|
1035
1047
|
}
|
|
1048
|
+
return this;
|
|
1036
1049
|
};
|
|
1037
1050
|
HTMLElement.prototype.hasAttribute = function (key) {
|
|
1038
1051
|
return key.toLowerCase() in this.attrs;
|
|
@@ -1104,6 +1117,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1104
1117
|
return "".concat(name, "=").concat(_this.quoteAttribute(String(val)));
|
|
1105
1118
|
})
|
|
1106
1119
|
.join(' ');
|
|
1120
|
+
return this;
|
|
1107
1121
|
};
|
|
1108
1122
|
HTMLElement.prototype.insertAdjacentHTML = function (where, html) {
|
|
1109
1123
|
var _a, _b, _c;
|
|
@@ -1116,14 +1130,11 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1116
1130
|
var idx = this.parentNode.childNodes.findIndex(function (child) {
|
|
1117
1131
|
return child === _this;
|
|
1118
1132
|
});
|
|
1133
|
+
resetParent(p.childNodes, this.parentNode);
|
|
1119
1134
|
(_a = this.parentNode.childNodes).splice.apply(_a, __spreadArray([idx + 1, 0], p.childNodes, false));
|
|
1120
|
-
p.childNodes.forEach(function (n) {
|
|
1121
|
-
if (n instanceof HTMLElement) {
|
|
1122
|
-
n.parentNode = _this.parentNode;
|
|
1123
|
-
}
|
|
1124
|
-
});
|
|
1125
1135
|
}
|
|
1126
1136
|
else if (where === 'afterbegin') {
|
|
1137
|
+
resetParent(p.childNodes, this);
|
|
1127
1138
|
(_b = this.childNodes).unshift.apply(_b, p.childNodes);
|
|
1128
1139
|
}
|
|
1129
1140
|
else if (where === 'beforeend') {
|
|
@@ -1135,16 +1146,13 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1135
1146
|
var idx = this.parentNode.childNodes.findIndex(function (child) {
|
|
1136
1147
|
return child === _this;
|
|
1137
1148
|
});
|
|
1149
|
+
resetParent(p.childNodes, this.parentNode);
|
|
1138
1150
|
(_c = this.parentNode.childNodes).splice.apply(_c, __spreadArray([idx, 0], p.childNodes, false));
|
|
1139
|
-
p.childNodes.forEach(function (n) {
|
|
1140
|
-
if (n instanceof HTMLElement) {
|
|
1141
|
-
n.parentNode = _this.parentNode;
|
|
1142
|
-
}
|
|
1143
|
-
});
|
|
1144
1151
|
}
|
|
1145
1152
|
else {
|
|
1146
1153
|
throw new Error("The value provided ('".concat(where, "') is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'"));
|
|
1147
1154
|
}
|
|
1155
|
+
return this;
|
|
1148
1156
|
// if (!where || html === undefined || html === null) {
|
|
1149
1157
|
// return;
|
|
1150
1158
|
// }
|
|
@@ -1519,6 +1527,12 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1519
1527
|
return root;
|
|
1520
1528
|
}
|
|
1521
1529
|
exports.parse = parse;
|
|
1530
|
+
function resetParent(nodes, parent) {
|
|
1531
|
+
return nodes.map(function (node) {
|
|
1532
|
+
node.parentNode = parent;
|
|
1533
|
+
return node;
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1522
1536
|
});
|
|
1523
1537
|
define("nodes/comment", ["require", "exports", "nodes/node", "nodes/type"], function (require, exports, node_3, type_4) {
|
|
1524
1538
|
"use strict";
|
package/dist/nodes/html.d.ts
CHANGED
|
@@ -63,18 +63,18 @@ export default class HTMLElement extends Node {
|
|
|
63
63
|
/**
|
|
64
64
|
* Remove current element
|
|
65
65
|
*/
|
|
66
|
-
remove():
|
|
66
|
+
remove(): this;
|
|
67
67
|
/**
|
|
68
68
|
* Remove Child element from childNodes array
|
|
69
69
|
* @param {HTMLElement} node node to remove
|
|
70
70
|
*/
|
|
71
|
-
removeChild(node: Node):
|
|
71
|
+
removeChild(node: Node): this;
|
|
72
72
|
/**
|
|
73
73
|
* Exchanges given child with new child
|
|
74
74
|
* @param {HTMLElement} oldNode node to exchange
|
|
75
75
|
* @param {HTMLElement} newNode new node
|
|
76
76
|
*/
|
|
77
|
-
exchangeChild(oldNode: Node, newNode: Node):
|
|
77
|
+
exchangeChild(oldNode: Node, newNode: Node): this;
|
|
78
78
|
get tagName(): string;
|
|
79
79
|
set tagName(newname: string);
|
|
80
80
|
get localName(): string;
|
|
@@ -99,7 +99,7 @@ export default class HTMLElement extends Node {
|
|
|
99
99
|
toString(): string;
|
|
100
100
|
get innerHTML(): string;
|
|
101
101
|
set innerHTML(content: string);
|
|
102
|
-
set_content(content: string | Node | Node[], options?: Options):
|
|
102
|
+
set_content(content: string | Node | Node[], options?: Options): this;
|
|
103
103
|
replaceWith(...nodes: (string | Node)[]): void;
|
|
104
104
|
get outerHTML(): string;
|
|
105
105
|
/**
|
|
@@ -173,7 +173,7 @@ export default class HTMLElement extends Node {
|
|
|
173
173
|
* @return {Object} parsed attributes
|
|
174
174
|
*/
|
|
175
175
|
get rawAttributes(): RawAttributes;
|
|
176
|
-
removeAttribute(key: string):
|
|
176
|
+
removeAttribute(key: string): this;
|
|
177
177
|
hasAttribute(key: string): boolean;
|
|
178
178
|
/**
|
|
179
179
|
* Get an attribute
|
|
@@ -190,8 +190,8 @@ export default class HTMLElement extends Node {
|
|
|
190
190
|
* Replace all the attributes of the HTMLElement by the provided attributes
|
|
191
191
|
* @param {Attributes} attributes the new attribute set
|
|
192
192
|
*/
|
|
193
|
-
setAttributes(attributes: Attributes):
|
|
194
|
-
insertAdjacentHTML(where: InsertPosition, html: string):
|
|
193
|
+
setAttributes(attributes: Attributes): this;
|
|
194
|
+
insertAdjacentHTML(where: InsertPosition, html: string): this;
|
|
195
195
|
get nextSibling(): Node;
|
|
196
196
|
get nextElementSibling(): HTMLElement;
|
|
197
197
|
get previousSibling(): Node;
|
package/dist/nodes/html.js
CHANGED
|
@@ -207,7 +207,9 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
207
207
|
this.parentNode.childNodes = children.filter(function (child) {
|
|
208
208
|
return _this !== child;
|
|
209
209
|
});
|
|
210
|
+
this.parentNode = null;
|
|
210
211
|
}
|
|
212
|
+
return this;
|
|
211
213
|
};
|
|
212
214
|
/**
|
|
213
215
|
* Remove Child element from childNodes array
|
|
@@ -217,6 +219,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
217
219
|
this.childNodes = this.childNodes.filter(function (child) {
|
|
218
220
|
return child !== node;
|
|
219
221
|
});
|
|
222
|
+
return this;
|
|
220
223
|
};
|
|
221
224
|
/**
|
|
222
225
|
* Exchanges given child with new child
|
|
@@ -231,6 +234,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
231
234
|
}
|
|
232
235
|
return child;
|
|
233
236
|
});
|
|
237
|
+
return this;
|
|
234
238
|
};
|
|
235
239
|
Object.defineProperty(HTMLElement.prototype, "tagName", {
|
|
236
240
|
get: function () {
|
|
@@ -359,7 +363,10 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
359
363
|
set: function (content) {
|
|
360
364
|
//const r = parse(content, global.options); // TODO global.options ?
|
|
361
365
|
var r = parse(content);
|
|
362
|
-
|
|
366
|
+
var nodes = r.childNodes.length ? r.childNodes : [new text_1.default(content, this)];
|
|
367
|
+
resetParent(nodes, this);
|
|
368
|
+
resetParent(this.childNodes, null);
|
|
369
|
+
this.childNodes = nodes;
|
|
363
370
|
},
|
|
364
371
|
enumerable: false,
|
|
365
372
|
configurable: true
|
|
@@ -373,7 +380,10 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
373
380
|
var r = parse(content, options);
|
|
374
381
|
content = r.childNodes.length ? r.childNodes : [new text_1.default(content, this)];
|
|
375
382
|
}
|
|
383
|
+
resetParent(this.childNodes, null);
|
|
384
|
+
resetParent(content, this);
|
|
376
385
|
this.childNodes = content;
|
|
386
|
+
return this;
|
|
377
387
|
};
|
|
378
388
|
HTMLElement.prototype.replaceWith = function () {
|
|
379
389
|
var _this = this;
|
|
@@ -381,6 +391,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
381
391
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
382
392
|
nodes[_i] = arguments[_i];
|
|
383
393
|
}
|
|
394
|
+
var parent = this.parentNode;
|
|
384
395
|
var content = nodes
|
|
385
396
|
.map(function (node) {
|
|
386
397
|
if (node instanceof node_1.default) {
|
|
@@ -394,10 +405,11 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
394
405
|
return [];
|
|
395
406
|
})
|
|
396
407
|
.flat();
|
|
397
|
-
var idx =
|
|
408
|
+
var idx = parent.childNodes.findIndex(function (child) {
|
|
398
409
|
return child === _this;
|
|
399
410
|
});
|
|
400
|
-
|
|
411
|
+
resetParent([this], null);
|
|
412
|
+
parent.childNodes = __spreadArray(__spreadArray(__spreadArray([], parent.childNodes.slice(0, idx), true), resetParent(content, parent), true), parent.childNodes.slice(idx + 1), true);
|
|
401
413
|
};
|
|
402
414
|
Object.defineProperty(HTMLElement.prototype, "outerHTML", {
|
|
403
415
|
get: function () {
|
|
@@ -745,6 +757,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
745
757
|
if (key === 'id') {
|
|
746
758
|
this.id = '';
|
|
747
759
|
}
|
|
760
|
+
return this;
|
|
748
761
|
};
|
|
749
762
|
HTMLElement.prototype.hasAttribute = function (key) {
|
|
750
763
|
return key.toLowerCase() in this.attrs;
|
|
@@ -816,6 +829,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
816
829
|
return "".concat(name, "=").concat(_this.quoteAttribute(String(val)));
|
|
817
830
|
})
|
|
818
831
|
.join(' ');
|
|
832
|
+
return this;
|
|
819
833
|
};
|
|
820
834
|
HTMLElement.prototype.insertAdjacentHTML = function (where, html) {
|
|
821
835
|
var _a, _b, _c;
|
|
@@ -828,14 +842,11 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
828
842
|
var idx = this.parentNode.childNodes.findIndex(function (child) {
|
|
829
843
|
return child === _this;
|
|
830
844
|
});
|
|
845
|
+
resetParent(p.childNodes, this.parentNode);
|
|
831
846
|
(_a = this.parentNode.childNodes).splice.apply(_a, __spreadArray([idx + 1, 0], p.childNodes, false));
|
|
832
|
-
p.childNodes.forEach(function (n) {
|
|
833
|
-
if (n instanceof HTMLElement) {
|
|
834
|
-
n.parentNode = _this.parentNode;
|
|
835
|
-
}
|
|
836
|
-
});
|
|
837
847
|
}
|
|
838
848
|
else if (where === 'afterbegin') {
|
|
849
|
+
resetParent(p.childNodes, this);
|
|
839
850
|
(_b = this.childNodes).unshift.apply(_b, p.childNodes);
|
|
840
851
|
}
|
|
841
852
|
else if (where === 'beforeend') {
|
|
@@ -847,16 +858,13 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
847
858
|
var idx = this.parentNode.childNodes.findIndex(function (child) {
|
|
848
859
|
return child === _this;
|
|
849
860
|
});
|
|
861
|
+
resetParent(p.childNodes, this.parentNode);
|
|
850
862
|
(_c = this.parentNode.childNodes).splice.apply(_c, __spreadArray([idx, 0], p.childNodes, false));
|
|
851
|
-
p.childNodes.forEach(function (n) {
|
|
852
|
-
if (n instanceof HTMLElement) {
|
|
853
|
-
n.parentNode = _this.parentNode;
|
|
854
|
-
}
|
|
855
|
-
});
|
|
856
863
|
}
|
|
857
864
|
else {
|
|
858
865
|
throw new Error("The value provided ('".concat(where, "') is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'"));
|
|
859
866
|
}
|
|
867
|
+
return this;
|
|
860
868
|
// if (!where || html === undefined || html === null) {
|
|
861
869
|
// return;
|
|
862
870
|
// }
|
|
@@ -1231,3 +1239,9 @@ function parse(data, options) {
|
|
|
1231
1239
|
return root;
|
|
1232
1240
|
}
|
|
1233
1241
|
exports.parse = parse;
|
|
1242
|
+
function resetParent(nodes, parent) {
|
|
1243
|
+
return nodes.map(function (node) {
|
|
1244
|
+
node.parentNode = parent;
|
|
1245
|
+
return node;
|
|
1246
|
+
});
|
|
1247
|
+
}
|
package/package.json
CHANGED