node-html-parser 6.1.5 → 6.1.7
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 +22 -0
- package/README.md +2 -3
- package/dist/main.js +9 -3
- package/dist/nodes/comment.d.ts +1 -1
- package/dist/nodes/comment.js +1 -0
- package/dist/nodes/html.d.ts +1 -1
- package/dist/nodes/html.js +7 -3
- package/dist/nodes/text.d.ts +1 -1
- package/dist/nodes/text.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
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.7](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.6...v6.1.7) (2023-09-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* block text elements [#242](https://github.com/taoqf/node-fast-html-parser/issues/242) ([97e593c](https://github.com/taoqf/node-fast-html-parser/commit/97e593c2bdefbfefd35c2c9ccaef914517d60fe7))
|
|
11
|
+
* docs [#245](https://github.com/taoqf/node-fast-html-parser/issues/245) ([f656c7b](https://github.com/taoqf/node-fast-html-parser/commit/f656c7b2de2a62a9a363f797c6f03a2477e7312e))
|
|
12
|
+
* remove test code ([d3980c5](https://github.com/taoqf/node-fast-html-parser/commit/d3980c5fb7744d6fda4b270619bb581a19a4cb18))
|
|
13
|
+
|
|
14
|
+
### [6.1.6](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.5...v6.1.6) (2023-08-17)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* [#203](https://github.com/taoqf/node-fast-html-parser/issues/203) ([6006c52](https://github.com/taoqf/node-fast-html-parser/commit/6006c52c20e6c3c07405c808c8d81fa78425e794))
|
|
20
|
+
* [#218](https://github.com/taoqf/node-fast-html-parser/issues/218) ([6f6c824](https://github.com/taoqf/node-fast-html-parser/commit/6f6c824df54fa53af47956048b42ea47cd3b53bf))
|
|
21
|
+
* 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))
|
|
22
|
+
* 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))
|
|
23
|
+
* 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))
|
|
24
|
+
* 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))
|
|
25
|
+
* remove test code ([f0b176e](https://github.com/taoqf/node-fast-html-parser/commit/f0b176eb1ba5b5bc162744a37adcd18d3d64a515))
|
|
26
|
+
|
|
5
27
|
### [6.1.5](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.4...v6.1.5) (2023-02-21)
|
|
6
28
|
|
|
7
29
|
### [6.1.4](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.3...v6.1.4) (2022-11-15)
|
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@ no closing `<li>`, `<td>` etc).
|
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
```shell
|
|
15
14
|
npm install --save node-html-parser
|
|
16
15
|
```
|
|
@@ -86,7 +85,7 @@ Parse the data provided, and return the root of the generated DOM.
|
|
|
86
85
|
comment: false, // retrieve comments (hurts performance slightly)
|
|
87
86
|
voidTag:{
|
|
88
87
|
tags: ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'], // optional and case insensitive, default value is ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']
|
|
89
|
-
|
|
88
|
+
closingSlash: true // optional, default false. void tag serialisation, add a final slash <br/>
|
|
90
89
|
},
|
|
91
90
|
blockTextElements: {
|
|
92
91
|
script: true, // keep text content when parsing
|
|
@@ -293,7 +292,7 @@ Get class names.
|
|
|
293
292
|
|
|
294
293
|
Clone a node.
|
|
295
294
|
|
|
296
|
-
#### getElementById(id: string): HTMLElement
|
|
295
|
+
#### getElementById(id: string): HTMLElement
|
|
297
296
|
|
|
298
297
|
Get element by it's ID.
|
|
299
298
|
|
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
|
|
@@ -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 =
|
|
1076
|
+
var val = _this.quoteAttribute(attrs[name]);
|
|
1074
1077
|
if (val === undefined || val === 'null') {
|
|
1075
1078
|
return name;
|
|
1076
1079
|
}
|
|
@@ -1378,7 +1381,9 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1378
1381
|
style: true,
|
|
1379
1382
|
pre: true,
|
|
1380
1383
|
};
|
|
1381
|
-
var element_names = Object.keys(elements)
|
|
1384
|
+
var element_names = Object.keys(elements).filter(function (name) {
|
|
1385
|
+
return Boolean(elements[name]);
|
|
1386
|
+
});
|
|
1382
1387
|
var kBlockTextElements = element_names.map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1383
1388
|
var kIgnoreElements = element_names.filter(function (it) { return elements[it]; }).map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1384
1389
|
function element_should_be_ignore(tag) {
|
|
@@ -1581,6 +1586,7 @@ define("nodes/comment", ["require", "exports", "nodes/node", "nodes/type"], func
|
|
|
1581
1586
|
var CommentNode = /** @class */ (function (_super) {
|
|
1582
1587
|
__extends(CommentNode, _super);
|
|
1583
1588
|
function CommentNode(rawText, parentNode, range) {
|
|
1589
|
+
if (parentNode === void 0) { parentNode = null; }
|
|
1584
1590
|
var _this = _super.call(this, parentNode, range) || this;
|
|
1585
1591
|
_this.rawText = rawText;
|
|
1586
1592
|
/**
|
package/dist/nodes/comment.d.ts
CHANGED
|
@@ -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
|
|
7
|
+
constructor(rawText: string, parentNode?: HTMLElement, range?: [number, number]);
|
|
8
8
|
/**
|
|
9
9
|
* Node Type declaration.
|
|
10
10
|
* @type {Number}
|
package/dist/nodes/comment.js
CHANGED
|
@@ -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
|
/**
|
package/dist/nodes/html.d.ts
CHANGED
|
@@ -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
|
|
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
|
package/dist/nodes/html.js
CHANGED
|
@@ -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, '"'));
|
|
203
|
+
return JSON.stringify(attr.replace(/"/g, '"')).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
|
|
@@ -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 =
|
|
742
|
+
var val = _this.quoteAttribute(attrs[name]);
|
|
741
743
|
if (val === undefined || val === 'null') {
|
|
742
744
|
return name;
|
|
743
745
|
}
|
|
@@ -1045,7 +1047,9 @@ function base_parse(data, options) {
|
|
|
1045
1047
|
style: true,
|
|
1046
1048
|
pre: true,
|
|
1047
1049
|
};
|
|
1048
|
-
var element_names = Object.keys(elements)
|
|
1050
|
+
var element_names = Object.keys(elements).filter(function (name) {
|
|
1051
|
+
return Boolean(elements[name]);
|
|
1052
|
+
});
|
|
1049
1053
|
var kBlockTextElements = element_names.map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1050
1054
|
var kIgnoreElements = element_names.filter(function (it) { return elements[it]; }).map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
|
|
1051
1055
|
function element_should_be_ignore(tag) {
|
package/dist/nodes/text.d.ts
CHANGED
|
@@ -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
|
|
10
|
+
constructor(rawText: string, parentNode?: HTMLElement, range?: [number, number]);
|
|
11
11
|
/**
|
|
12
12
|
* Node Type declaration.
|
|
13
13
|
* @type {Number}
|
package/dist/nodes/text.js
CHANGED
|
@@ -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