node-html-parser 5.2.2 → 5.2.5
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 +19 -19
- package/dist/nodes/comment.js +1 -1
- package/dist/nodes/html.js +18 -18
- package/package.json +1 -2
package/dist/main.js
CHANGED
|
@@ -374,7 +374,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
374
374
|
}
|
|
375
375
|
DOMTokenList.prototype._validate = function (c) {
|
|
376
376
|
if (/\s/.test(c)) {
|
|
377
|
-
throw new Error("DOMException in DOMTokenList.add: The token '"
|
|
377
|
+
throw new Error("DOMException in DOMTokenList.add: The token '".concat(c, "' contains HTML space characters, which are not valid in tokens."));
|
|
378
378
|
}
|
|
379
379
|
};
|
|
380
380
|
DOMTokenList.prototype.add = function (c) {
|
|
@@ -458,14 +458,14 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
458
458
|
);
|
|
459
459
|
if (keyAttrs.id) {
|
|
460
460
|
if (!rawAttrs) {
|
|
461
|
-
_this.rawAttrs = "id=\""
|
|
461
|
+
_this.rawAttrs = "id=\"".concat(keyAttrs.id, "\"");
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
if (keyAttrs.class) {
|
|
465
465
|
if (!rawAttrs) {
|
|
466
|
-
var cls = "class=\""
|
|
466
|
+
var cls = "class=\"".concat(_this.classList.toString(), "\"");
|
|
467
467
|
if (_this.rawAttrs) {
|
|
468
|
-
_this.rawAttrs += " "
|
|
468
|
+
_this.rawAttrs += " ".concat(cls);
|
|
469
469
|
}
|
|
470
470
|
else {
|
|
471
471
|
_this.rawAttrs = cls;
|
|
@@ -610,7 +610,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
610
610
|
else {
|
|
611
611
|
var text = node.trimmedText;
|
|
612
612
|
if (currentBlock.prependWhitespace) {
|
|
613
|
-
text = " "
|
|
613
|
+
text = " ".concat(text);
|
|
614
614
|
currentBlock.prependWhitespace = false;
|
|
615
615
|
}
|
|
616
616
|
currentBlock.push(text);
|
|
@@ -631,8 +631,8 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
631
631
|
HTMLElement.prototype.toString = function () {
|
|
632
632
|
var tag = this.rawTagName;
|
|
633
633
|
if (tag) {
|
|
634
|
-
var attrs = this.rawAttrs ? " "
|
|
635
|
-
return this.isVoidElement ? "<"
|
|
634
|
+
var attrs = this.rawAttrs ? " ".concat(this.rawAttrs) : '';
|
|
635
|
+
return this.isVoidElement ? "<".concat(tag).concat(attrs, ">") : "<".concat(tag).concat(attrs, ">").concat(this.innerHTML, "</").concat(tag, ">");
|
|
636
636
|
}
|
|
637
637
|
return this.innerHTML;
|
|
638
638
|
};
|
|
@@ -728,9 +728,9 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
728
728
|
res.push(' '.repeat(indention) + str);
|
|
729
729
|
}
|
|
730
730
|
function dfs(node) {
|
|
731
|
-
var idStr = node.id ? "#"
|
|
732
|
-
var classStr = node.classList.length ? "."
|
|
733
|
-
write(""
|
|
731
|
+
var idStr = node.id ? "#".concat(node.id) : '';
|
|
732
|
+
var classStr = node.classList.length ? ".".concat(node.classList.value.join('.')) : ''; // eslint-disable-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-call
|
|
733
|
+
write("".concat(node.rawTagName).concat(idStr).concat(classStr));
|
|
734
734
|
indention++;
|
|
735
735
|
node.childNodes.forEach(function (childNode) {
|
|
736
736
|
if (childNode.nodeType === type_3.default.ELEMENT_NODE) {
|
|
@@ -989,7 +989,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
989
989
|
if (val === undefined || val === 'null') {
|
|
990
990
|
return name;
|
|
991
991
|
}
|
|
992
|
-
return name
|
|
992
|
+
return "".concat(name, "=").concat(val);
|
|
993
993
|
})
|
|
994
994
|
.join(' ');
|
|
995
995
|
// Update this.id
|
|
@@ -1036,7 +1036,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1036
1036
|
var val = _this.quoteAttribute(attrs[name]);
|
|
1037
1037
|
if (val === 'null' || val === '""')
|
|
1038
1038
|
return name;
|
|
1039
|
-
return name
|
|
1039
|
+
return "".concat(name, "=").concat(val);
|
|
1040
1040
|
})
|
|
1041
1041
|
.join(' ');
|
|
1042
1042
|
// Update this.id
|
|
@@ -1064,7 +1064,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1064
1064
|
var val = attributes[name];
|
|
1065
1065
|
if (val === 'null' || val === '""')
|
|
1066
1066
|
return name;
|
|
1067
|
-
return name
|
|
1067
|
+
return "".concat(name, "=").concat(_this.quoteAttribute(String(val)));
|
|
1068
1068
|
})
|
|
1069
1069
|
.join(' ');
|
|
1070
1070
|
};
|
|
@@ -1106,7 +1106,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1106
1106
|
});
|
|
1107
1107
|
}
|
|
1108
1108
|
else {
|
|
1109
|
-
throw new Error("The value provided ('"
|
|
1109
|
+
throw new Error("The value provided ('".concat(where, "') is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'"));
|
|
1110
1110
|
}
|
|
1111
1111
|
// if (!where || html === undefined || html === null) {
|
|
1112
1112
|
// return;
|
|
@@ -1295,8 +1295,8 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1295
1295
|
pre: true,
|
|
1296
1296
|
};
|
|
1297
1297
|
var element_names = Object.keys(elements);
|
|
1298
|
-
var kBlockTextElements = element_names.map(function (it) { return new RegExp("^"
|
|
1299
|
-
var kIgnoreElements = element_names.filter(function (it) { return elements[it]; }).map(function (it) { return new RegExp("^"
|
|
1298
|
+
var kBlockTextElements = element_names.map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1299
|
+
var kIgnoreElements = element_names.filter(function (it) { return elements[it]; }).map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1300
1300
|
function element_should_be_ignore(tag) {
|
|
1301
1301
|
return kIgnoreElements.some(function (it) { return it.test(tag); });
|
|
1302
1302
|
}
|
|
@@ -1311,7 +1311,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1311
1311
|
var noNestedTagIndex = undefined;
|
|
1312
1312
|
var match;
|
|
1313
1313
|
// https://github.com/taoqf/node-html-parser/issues/38
|
|
1314
|
-
data = "<"
|
|
1314
|
+
data = "<".concat(frameflag, ">").concat(data, "</").concat(frameflag, ">");
|
|
1315
1315
|
var lowerCaseTagName = options.lowerCaseTagName;
|
|
1316
1316
|
var dataEndPos = data.length - (frameflag.length + 2);
|
|
1317
1317
|
var frameFlagOffset = frameflag.length + 2;
|
|
@@ -1379,7 +1379,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1379
1379
|
stack.push(currentParent);
|
|
1380
1380
|
if (is_block_text_element(tagName)) {
|
|
1381
1381
|
// Find closing tag
|
|
1382
|
-
var closeMarkup = "</"
|
|
1382
|
+
var closeMarkup = "</".concat(tagName, ">");
|
|
1383
1383
|
var closeIndex = lowerCaseTagName
|
|
1384
1384
|
? data.toLocaleLowerCase().indexOf(closeMarkup, kMarkupPattern.lastIndex)
|
|
1385
1385
|
: data.indexOf(closeMarkup, kMarkupPattern.lastIndex);
|
|
@@ -1515,7 +1515,7 @@ define("nodes/comment", ["require", "exports", "nodes/node", "nodes/type"], func
|
|
|
1515
1515
|
configurable: true
|
|
1516
1516
|
});
|
|
1517
1517
|
CommentNode.prototype.toString = function () {
|
|
1518
|
-
return "<!--"
|
|
1518
|
+
return "<!--".concat(this.rawText, "-->");
|
|
1519
1519
|
};
|
|
1520
1520
|
return CommentNode;
|
|
1521
1521
|
}(node_3.default));
|
package/dist/nodes/comment.js
CHANGED
|
@@ -47,7 +47,7 @@ var CommentNode = /** @class */ (function (_super) {
|
|
|
47
47
|
configurable: true
|
|
48
48
|
});
|
|
49
49
|
CommentNode.prototype.toString = function () {
|
|
50
|
-
return "<!--"
|
|
50
|
+
return "<!--".concat(this.rawText, "-->");
|
|
51
51
|
};
|
|
52
52
|
return CommentNode;
|
|
53
53
|
}(node_1.default));
|
package/dist/nodes/html.js
CHANGED
|
@@ -86,7 +86,7 @@ var DOMTokenList = /** @class */ (function () {
|
|
|
86
86
|
}
|
|
87
87
|
DOMTokenList.prototype._validate = function (c) {
|
|
88
88
|
if (/\s/.test(c)) {
|
|
89
|
-
throw new Error("DOMException in DOMTokenList.add: The token '"
|
|
89
|
+
throw new Error("DOMException in DOMTokenList.add: The token '".concat(c, "' contains HTML space characters, which are not valid in tokens."));
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
92
|
DOMTokenList.prototype.add = function (c) {
|
|
@@ -170,14 +170,14 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
170
170
|
);
|
|
171
171
|
if (keyAttrs.id) {
|
|
172
172
|
if (!rawAttrs) {
|
|
173
|
-
_this.rawAttrs = "id=\""
|
|
173
|
+
_this.rawAttrs = "id=\"".concat(keyAttrs.id, "\"");
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
if (keyAttrs.class) {
|
|
177
177
|
if (!rawAttrs) {
|
|
178
|
-
var cls = "class=\""
|
|
178
|
+
var cls = "class=\"".concat(_this.classList.toString(), "\"");
|
|
179
179
|
if (_this.rawAttrs) {
|
|
180
|
-
_this.rawAttrs += " "
|
|
180
|
+
_this.rawAttrs += " ".concat(cls);
|
|
181
181
|
}
|
|
182
182
|
else {
|
|
183
183
|
_this.rawAttrs = cls;
|
|
@@ -322,7 +322,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
322
322
|
else {
|
|
323
323
|
var text = node.trimmedText;
|
|
324
324
|
if (currentBlock.prependWhitespace) {
|
|
325
|
-
text = " "
|
|
325
|
+
text = " ".concat(text);
|
|
326
326
|
currentBlock.prependWhitespace = false;
|
|
327
327
|
}
|
|
328
328
|
currentBlock.push(text);
|
|
@@ -343,8 +343,8 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
343
343
|
HTMLElement.prototype.toString = function () {
|
|
344
344
|
var tag = this.rawTagName;
|
|
345
345
|
if (tag) {
|
|
346
|
-
var attrs = this.rawAttrs ? " "
|
|
347
|
-
return this.isVoidElement ? "<"
|
|
346
|
+
var attrs = this.rawAttrs ? " ".concat(this.rawAttrs) : '';
|
|
347
|
+
return this.isVoidElement ? "<".concat(tag).concat(attrs, ">") : "<".concat(tag).concat(attrs, ">").concat(this.innerHTML, "</").concat(tag, ">");
|
|
348
348
|
}
|
|
349
349
|
return this.innerHTML;
|
|
350
350
|
};
|
|
@@ -440,9 +440,9 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
440
440
|
res.push(' '.repeat(indention) + str);
|
|
441
441
|
}
|
|
442
442
|
function dfs(node) {
|
|
443
|
-
var idStr = node.id ? "#"
|
|
444
|
-
var classStr = node.classList.length ? "."
|
|
445
|
-
write(""
|
|
443
|
+
var idStr = node.id ? "#".concat(node.id) : '';
|
|
444
|
+
var classStr = node.classList.length ? ".".concat(node.classList.value.join('.')) : ''; // eslint-disable-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-call
|
|
445
|
+
write("".concat(node.rawTagName).concat(idStr).concat(classStr));
|
|
446
446
|
indention++;
|
|
447
447
|
node.childNodes.forEach(function (childNode) {
|
|
448
448
|
if (childNode.nodeType === type_1.default.ELEMENT_NODE) {
|
|
@@ -701,7 +701,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
701
701
|
if (val === undefined || val === 'null') {
|
|
702
702
|
return name;
|
|
703
703
|
}
|
|
704
|
-
return name
|
|
704
|
+
return "".concat(name, "=").concat(val);
|
|
705
705
|
})
|
|
706
706
|
.join(' ');
|
|
707
707
|
// Update this.id
|
|
@@ -748,7 +748,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
748
748
|
var val = _this.quoteAttribute(attrs[name]);
|
|
749
749
|
if (val === 'null' || val === '""')
|
|
750
750
|
return name;
|
|
751
|
-
return name
|
|
751
|
+
return "".concat(name, "=").concat(val);
|
|
752
752
|
})
|
|
753
753
|
.join(' ');
|
|
754
754
|
// Update this.id
|
|
@@ -776,7 +776,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
776
776
|
var val = attributes[name];
|
|
777
777
|
if (val === 'null' || val === '""')
|
|
778
778
|
return name;
|
|
779
|
-
return name
|
|
779
|
+
return "".concat(name, "=").concat(_this.quoteAttribute(String(val)));
|
|
780
780
|
})
|
|
781
781
|
.join(' ');
|
|
782
782
|
};
|
|
@@ -818,7 +818,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
818
818
|
});
|
|
819
819
|
}
|
|
820
820
|
else {
|
|
821
|
-
throw new Error("The value provided ('"
|
|
821
|
+
throw new Error("The value provided ('".concat(where, "') is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'"));
|
|
822
822
|
}
|
|
823
823
|
// if (!where || html === undefined || html === null) {
|
|
824
824
|
// return;
|
|
@@ -1007,8 +1007,8 @@ function base_parse(data, options) {
|
|
|
1007
1007
|
pre: true,
|
|
1008
1008
|
};
|
|
1009
1009
|
var element_names = Object.keys(elements);
|
|
1010
|
-
var kBlockTextElements = element_names.map(function (it) { return new RegExp("^"
|
|
1011
|
-
var kIgnoreElements = element_names.filter(function (it) { return elements[it]; }).map(function (it) { return new RegExp("^"
|
|
1010
|
+
var kBlockTextElements = element_names.map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1011
|
+
var kIgnoreElements = element_names.filter(function (it) { return elements[it]; }).map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1012
1012
|
function element_should_be_ignore(tag) {
|
|
1013
1013
|
return kIgnoreElements.some(function (it) { return it.test(tag); });
|
|
1014
1014
|
}
|
|
@@ -1023,7 +1023,7 @@ function base_parse(data, options) {
|
|
|
1023
1023
|
var noNestedTagIndex = undefined;
|
|
1024
1024
|
var match;
|
|
1025
1025
|
// https://github.com/taoqf/node-html-parser/issues/38
|
|
1026
|
-
data = "<"
|
|
1026
|
+
data = "<".concat(frameflag, ">").concat(data, "</").concat(frameflag, ">");
|
|
1027
1027
|
var lowerCaseTagName = options.lowerCaseTagName;
|
|
1028
1028
|
var dataEndPos = data.length - (frameflag.length + 2);
|
|
1029
1029
|
var frameFlagOffset = frameflag.length + 2;
|
|
@@ -1091,7 +1091,7 @@ function base_parse(data, options) {
|
|
|
1091
1091
|
stack.push(currentParent);
|
|
1092
1092
|
if (is_block_text_element(tagName)) {
|
|
1093
1093
|
// Find closing tag
|
|
1094
|
-
var closeMarkup = "</"
|
|
1094
|
+
var closeMarkup = "</".concat(tagName, ">");
|
|
1095
1095
|
var closeIndex = lowerCaseTagName
|
|
1096
1096
|
? data.toLocaleLowerCase().indexOf(closeMarkup, kMarkupPattern.lastIndex)
|
|
1097
1097
|
: data.indexOf(closeMarkup, kMarkupPattern.lastIndex);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-html-parser",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.5",
|
|
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",
|
|
@@ -72,7 +72,6 @@
|
|
|
72
72
|
"high5": "^1.0.0",
|
|
73
73
|
"html-dom-parser": "^1.0.4",
|
|
74
74
|
"html-parser": "^0.11.0",
|
|
75
|
-
"html5": "^1.0.5",
|
|
76
75
|
"html5parser": "^2.0.2",
|
|
77
76
|
"htmljs-parser": "^2.11.1",
|
|
78
77
|
"htmlparser": "^1.7.7",
|