node-html-parser 1.2.16 → 1.2.20
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/README.md +6 -8
- package/dist/main.js +14 -8
- package/dist/nodes/html.d.ts +12 -5
- package/dist/nodes/html.js +14 -8
- package/package.json +8 -2
- package/yarn-error.log +753 -29
package/README.md
CHANGED
|
@@ -19,14 +19,12 @@ npm install --save node-html-parser
|
|
|
19
19
|
Faster than htmlparser2!
|
|
20
20
|
|
|
21
21
|
```shell
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
htmlparser :
|
|
25
|
-
htmlparser2
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
libxmljs : 7.19406 ms/file ± 7.04495
|
|
29
|
-
parse5 : 10.7590 ms/file ± 8.09687
|
|
22
|
+
node-html-parser:1.94548 ms/file ± 2.15709
|
|
23
|
+
libxmljs :5.28893 ms/file ± 3.69863
|
|
24
|
+
htmlparser :24.9625 ms/file ± 168.380
|
|
25
|
+
htmlparser2 :3.34011 ms/file ± 4.76959
|
|
26
|
+
parse5 :13.9589 ms/file ± 9.84068
|
|
27
|
+
high5 :6.98078 ms/file ± 4.47575
|
|
30
28
|
```
|
|
31
29
|
|
|
32
30
|
Tested with [htmlparser-benchmark](https://github.com/AndreasMadsen/htmlparser-benchmark).
|
package/dist/main.js
CHANGED
|
@@ -438,9 +438,21 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
|
|
|
438
438
|
_this.childNodes = [];
|
|
439
439
|
if (keyAttrs.id) {
|
|
440
440
|
_this.id = keyAttrs.id;
|
|
441
|
+
if (!rawAttrs) {
|
|
442
|
+
_this.rawAttrs = "id=\"" + keyAttrs.id + "\"";
|
|
443
|
+
}
|
|
441
444
|
}
|
|
442
445
|
if (keyAttrs.class) {
|
|
443
446
|
_this.classNames = keyAttrs.class.split(/\s+/);
|
|
447
|
+
if (!rawAttrs) {
|
|
448
|
+
var cls = "class=\"" + _this.classNames.join(' ') + "\"";
|
|
449
|
+
if (_this.rawAttrs) {
|
|
450
|
+
_this.rawAttrs += " " + cls;
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
_this.rawAttrs = cls;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
444
456
|
}
|
|
445
457
|
return _this;
|
|
446
458
|
}
|
|
@@ -893,7 +905,7 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
|
|
|
893
905
|
// Update rawString
|
|
894
906
|
this.rawAttrs = Object.keys(attrs).map(function (name) {
|
|
895
907
|
var val = JSON.stringify(attrs[name]);
|
|
896
|
-
if (val ===
|
|
908
|
+
if (val === 'null' || val === '""') {
|
|
897
909
|
return name;
|
|
898
910
|
}
|
|
899
911
|
else {
|
|
@@ -917,7 +929,7 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
|
|
|
917
929
|
// Update rawString
|
|
918
930
|
this.rawAttrs = Object.keys(attributes).map(function (name) {
|
|
919
931
|
var val = attributes[name];
|
|
920
|
-
if (val ===
|
|
932
|
+
if (val === 'null' || val === '""') {
|
|
921
933
|
return name;
|
|
922
934
|
}
|
|
923
935
|
else {
|
|
@@ -1002,12 +1014,6 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
|
|
|
1002
1014
|
pre: true
|
|
1003
1015
|
};
|
|
1004
1016
|
var frameflag = 'documentfragmentcontainer';
|
|
1005
|
-
/**
|
|
1006
|
-
* Parses HTML and returns a root element
|
|
1007
|
-
* Parse a chuck of HTML source.
|
|
1008
|
-
* @param {string} data html
|
|
1009
|
-
* @return {HTMLElement} root element
|
|
1010
|
-
*/
|
|
1011
1017
|
function parse(data, options) {
|
|
1012
1018
|
if (options === void 0) { options = {}; }
|
|
1013
1019
|
var root = new HTMLElement(null, {});
|
package/dist/nodes/html.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ export default class HTMLElement extends Node {
|
|
|
134
134
|
* Get an attribute
|
|
135
135
|
* @return {string} value of the attribute
|
|
136
136
|
*/
|
|
137
|
-
getAttribute(key: string): string;
|
|
137
|
+
getAttribute(key: string): string | undefined;
|
|
138
138
|
/**
|
|
139
139
|
* Set an attribute value to the HTMLElement
|
|
140
140
|
* @param {string} key The attribute name
|
|
@@ -150,7 +150,6 @@ export default class HTMLElement extends Node {
|
|
|
150
150
|
}
|
|
151
151
|
export interface Options {
|
|
152
152
|
lowerCaseTagName?: boolean;
|
|
153
|
-
noFix?: boolean;
|
|
154
153
|
script?: boolean;
|
|
155
154
|
style?: boolean;
|
|
156
155
|
pre?: boolean;
|
|
@@ -162,8 +161,16 @@ export interface Options {
|
|
|
162
161
|
* @param {string} data html
|
|
163
162
|
* @return {HTMLElement} root element
|
|
164
163
|
*/
|
|
165
|
-
export declare function parse(data: string, options?: Options):
|
|
164
|
+
export declare function parse(data: string, options?: Options): HTMLElement & {
|
|
166
165
|
valid: boolean;
|
|
167
|
-
}
|
|
166
|
+
};
|
|
167
|
+
export declare function parse(data: string, options?: Options & {
|
|
168
|
+
noFix: false;
|
|
169
|
+
}): HTMLElement & {
|
|
168
170
|
valid: boolean;
|
|
169
|
-
}
|
|
171
|
+
};
|
|
172
|
+
export declare function parse(data: string, options?: Options & {
|
|
173
|
+
noFix: true;
|
|
174
|
+
}): (HTMLElement | TextNode) & {
|
|
175
|
+
valid: boolean;
|
|
176
|
+
};
|
package/dist/nodes/html.js
CHANGED
|
@@ -70,9 +70,21 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
70
70
|
_this.childNodes = [];
|
|
71
71
|
if (keyAttrs.id) {
|
|
72
72
|
_this.id = keyAttrs.id;
|
|
73
|
+
if (!rawAttrs) {
|
|
74
|
+
_this.rawAttrs = "id=\"" + keyAttrs.id + "\"";
|
|
75
|
+
}
|
|
73
76
|
}
|
|
74
77
|
if (keyAttrs.class) {
|
|
75
78
|
_this.classNames = keyAttrs.class.split(/\s+/);
|
|
79
|
+
if (!rawAttrs) {
|
|
80
|
+
var cls = "class=\"" + _this.classNames.join(' ') + "\"";
|
|
81
|
+
if (_this.rawAttrs) {
|
|
82
|
+
_this.rawAttrs += " " + cls;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
_this.rawAttrs = cls;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
76
88
|
}
|
|
77
89
|
return _this;
|
|
78
90
|
}
|
|
@@ -525,7 +537,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
525
537
|
// Update rawString
|
|
526
538
|
this.rawAttrs = Object.keys(attrs).map(function (name) {
|
|
527
539
|
var val = JSON.stringify(attrs[name]);
|
|
528
|
-
if (val ===
|
|
540
|
+
if (val === 'null' || val === '""') {
|
|
529
541
|
return name;
|
|
530
542
|
}
|
|
531
543
|
else {
|
|
@@ -549,7 +561,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
549
561
|
// Update rawString
|
|
550
562
|
this.rawAttrs = Object.keys(attributes).map(function (name) {
|
|
551
563
|
var val = attributes[name];
|
|
552
|
-
if (val ===
|
|
564
|
+
if (val === 'null' || val === '""') {
|
|
553
565
|
return name;
|
|
554
566
|
}
|
|
555
567
|
else {
|
|
@@ -634,12 +646,6 @@ var kBlockTextElements = {
|
|
|
634
646
|
pre: true
|
|
635
647
|
};
|
|
636
648
|
var frameflag = 'documentfragmentcontainer';
|
|
637
|
-
/**
|
|
638
|
-
* Parses HTML and returns a root element
|
|
639
|
-
* Parse a chuck of HTML source.
|
|
640
|
-
* @param {string} data html
|
|
641
|
-
* @return {HTMLElement} root element
|
|
642
|
-
*/
|
|
643
649
|
function parse(data, options) {
|
|
644
650
|
if (options === void 0) { options = {}; }
|
|
645
651
|
var root = new HTMLElement(null, {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-html-parser",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.20",
|
|
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",
|
|
@@ -35,11 +35,17 @@
|
|
|
35
35
|
"blanket": "latest",
|
|
36
36
|
"del-cli": "latest",
|
|
37
37
|
"eslint": "latest",
|
|
38
|
+
"high5": "^1.0.0",
|
|
39
|
+
"htmlparser": "^1.7.7",
|
|
40
|
+
"htmlparser-benchmark": "^1.1.3",
|
|
41
|
+
"htmlparser2": "^4.1.0",
|
|
42
|
+
"libxmljs": "^0.19.7",
|
|
38
43
|
"mocha": "latest",
|
|
44
|
+
"parse5": "^6.0.0",
|
|
39
45
|
"should": "latest",
|
|
40
46
|
"spec": "latest",
|
|
41
47
|
"travis-cov": "latest",
|
|
42
|
-
"tslint": "
|
|
48
|
+
"tslint": "^5.0.0",
|
|
43
49
|
"typescript": "next"
|
|
44
50
|
},
|
|
45
51
|
"config": {
|