node-html-parser 6.1.13 → 7.0.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/CHANGELOG.md +30 -0
- package/README.md +50 -11
- package/dist/index.js +8 -9
- package/dist/main.js +147 -53
- package/dist/matcher.js +26 -26
- package/dist/nodes/comment.js +22 -46
- package/dist/nodes/html.d.ts +33 -13
- package/dist/nodes/html.js +561 -653
- package/dist/nodes/node.js +18 -29
- package/dist/nodes/text.js +61 -100
- package/dist/valid.js +3 -4
- package/dist/void-tag.js +13 -15
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
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
|
+
### [7.0.1](https://github.com/taoqf/node-fast-html-parser/compare/v7.0.0...v7.0.1) (2024-12-26)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* upgrade node version ([efd77ff](https://github.com/taoqf/node-fast-html-parser/commit/efd77ff93593922512b12216984ba778b2f46593))
|
|
11
|
+
|
|
12
|
+
## [7.0.0](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.14...v7.0.0) (2024-12-26)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### ⚠ BREAKING CHANGES
|
|
16
|
+
|
|
17
|
+
* fix #277, for that change estarget to es6
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* fix [#277](https://github.com/taoqf/node-fast-html-parser/issues/277), for that change estarget to es6 ([432a3e7](https://github.com/taoqf/node-fast-html-parser/commit/432a3e71ba219e76188bcc2e89e525e40911d164))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* add tests for [#227](https://github.com/taoqf/node-fast-html-parser/issues/227) ([5856ee2](https://github.com/taoqf/node-fast-html-parser/commit/5856ee2ef2a0dfef43d75f6d4d13c37c213f25cf))
|
|
27
|
+
|
|
28
|
+
### [6.1.14](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.13...v6.1.14) (2024-05-14)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* [#274](https://github.com/taoqf/node-fast-html-parser/issues/274) ([fef574d](https://github.com/taoqf/node-fast-html-parser/commit/fef574da98ce224980ce6fb9f9ea033d3331a161))
|
|
34
|
+
|
|
5
35
|
### [6.1.13](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.12...v6.1.13) (2024-03-29)
|
|
6
36
|
|
|
7
37
|
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ DOM tree, with element query support.
|
|
|
6
6
|
Per the design, it intends to parse massive HTML files in lowest price, thus the
|
|
7
7
|
performance is the top priority. For this reason, some malformatted HTML may not
|
|
8
8
|
be able to parse correctly, but most usual errors are covered (eg. HTML4 style
|
|
9
|
-
no closing `<
|
|
9
|
+
no closing `<td>` etc).
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -81,15 +81,17 @@ Parse the data provided, and return the root of the generated DOM.
|
|
|
81
81
|
|
|
82
82
|
```js
|
|
83
83
|
{
|
|
84
|
-
lowerCaseTagName: false,
|
|
85
|
-
comment: false,
|
|
86
|
-
|
|
84
|
+
lowerCaseTagName: false, // convert tag name to lower case (hurts performance heavily)
|
|
85
|
+
comment: false, // retrieve comments (hurts performance slightly)
|
|
86
|
+
fixNestedATags: false, // fix invalid nested <a> HTML tags
|
|
87
|
+
parseNoneClosedTags: false, // close none closed HTML tags instead of removing them
|
|
88
|
+
voidTag: {
|
|
87
89
|
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']
|
|
88
|
-
closingSlash: true
|
|
90
|
+
closingSlash: true // optional, default false. void tag serialisation, add a final slash <br/>
|
|
89
91
|
},
|
|
90
92
|
blockTextElements: {
|
|
91
|
-
script: true,
|
|
92
|
-
noscript: true,
|
|
93
|
+
script: true, // keep text content when parsing
|
|
94
|
+
noscript: true, // keep text content when parsing
|
|
93
95
|
style: true, // keep text content when parsing
|
|
94
96
|
pre: true // keep text content when parsing
|
|
95
97
|
}
|
|
@@ -214,9 +216,26 @@ Note: Use * for all elements.
|
|
|
214
216
|
|
|
215
217
|
Query closest element by css selector. `null` if not found.
|
|
216
218
|
|
|
219
|
+
### before(...nodesOrStrings)
|
|
220
|
+
|
|
221
|
+
Insert one or multiple nodes or text before the current element. Does not work on root.
|
|
222
|
+
|
|
223
|
+
### after(...nodesOrStrings)
|
|
224
|
+
|
|
225
|
+
Insert one or multiple nodes or text after the current element. Does not work on root.
|
|
226
|
+
|
|
227
|
+
### prepend(...nodesOrStrings)
|
|
228
|
+
|
|
229
|
+
Insert one or multiple nodes or text to the first position of an element's child nodes.
|
|
230
|
+
|
|
231
|
+
### append(...nodesOrStrings)
|
|
232
|
+
|
|
233
|
+
Insert one or multiple nodes or text to the last position of an element's child nodes.
|
|
234
|
+
This is similar to appendChild, but accepts arbitrarily many nodes and converts strings to text nodes.
|
|
235
|
+
|
|
217
236
|
### appendChild(node)
|
|
218
237
|
|
|
219
|
-
Append a
|
|
238
|
+
Append a node to an element's child nodes.
|
|
220
239
|
|
|
221
240
|
### insertAdjacentHTML(where, html)
|
|
222
241
|
|
|
@@ -310,7 +329,7 @@ Get escaped (as-is) text value of current node and its children. May have
|
|
|
310
329
|
|
|
311
330
|
### tagName
|
|
312
331
|
|
|
313
|
-
Get or Set tag name of HTMLElement.
|
|
332
|
+
Get or Set tag name of HTMLElement. Note that the returned value is an uppercase string.
|
|
314
333
|
|
|
315
334
|
### structuredText
|
|
316
335
|
|
|
@@ -320,13 +339,33 @@ Get structured Text.
|
|
|
320
339
|
|
|
321
340
|
Get DOM structure.
|
|
322
341
|
|
|
342
|
+
### childNodes
|
|
343
|
+
|
|
344
|
+
Get all child nodes. A child node can be a TextNode, a CommentNode and a HTMLElement.
|
|
345
|
+
|
|
346
|
+
### children
|
|
347
|
+
|
|
348
|
+
Get all child elements, so all child nodes of type HTMLELement.
|
|
349
|
+
|
|
323
350
|
### firstChild
|
|
324
351
|
|
|
325
|
-
Get first child node. `undefined` if no
|
|
352
|
+
Get first child node. `undefined` if the node has no children.
|
|
326
353
|
|
|
327
354
|
### lastChild
|
|
328
355
|
|
|
329
|
-
Get last child node. `undefined` if no
|
|
356
|
+
Get last child node. `undefined` if the node has no children.
|
|
357
|
+
|
|
358
|
+
### firstElementChild
|
|
359
|
+
|
|
360
|
+
Get the first child of type HTMLElement. `undefined` if none exists.
|
|
361
|
+
|
|
362
|
+
### lastElementChild
|
|
363
|
+
|
|
364
|
+
Get the first child of type HTMLElement. `undefined` if none exists.
|
|
365
|
+
|
|
366
|
+
### childElementCount
|
|
367
|
+
|
|
368
|
+
Get the number of children that are of type HTMLElement.
|
|
330
369
|
|
|
331
370
|
### innerHTML
|
|
332
371
|
|
package/dist/index.js
CHANGED
|
@@ -4,21 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.NodeType = exports.TextNode = exports.Node = exports.valid = exports.CommentNode = exports.HTMLElement = exports.parse = void 0;
|
|
7
|
-
|
|
7
|
+
const comment_1 = __importDefault(require("./nodes/comment"));
|
|
8
8
|
exports.CommentNode = comment_1.default;
|
|
9
|
-
|
|
9
|
+
const html_1 = __importDefault(require("./nodes/html"));
|
|
10
10
|
exports.HTMLElement = html_1.default;
|
|
11
|
-
|
|
11
|
+
const node_1 = __importDefault(require("./nodes/node"));
|
|
12
12
|
exports.Node = node_1.default;
|
|
13
|
-
|
|
13
|
+
const text_1 = __importDefault(require("./nodes/text"));
|
|
14
14
|
exports.TextNode = text_1.default;
|
|
15
|
-
|
|
15
|
+
const type_1 = __importDefault(require("./nodes/type"));
|
|
16
16
|
exports.NodeType = type_1.default;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const parse_1 = __importDefault(require("./parse"));
|
|
18
|
+
const valid_1 = __importDefault(require("./valid"));
|
|
19
19
|
exports.valid = valid_1.default;
|
|
20
|
-
function parse(data, options) {
|
|
21
|
-
if (options === void 0) { options = {}; }
|
|
20
|
+
function parse(data, options = {}) {
|
|
22
21
|
return (0, parse_1.default)(data, options);
|
|
23
22
|
}
|
|
24
23
|
exports.default = parse;
|
package/dist/main.js
CHANGED
|
@@ -535,7 +535,11 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
535
535
|
if (attr == null) {
|
|
536
536
|
return 'null';
|
|
537
537
|
}
|
|
538
|
-
return JSON.stringify(attr.replace(/"/g, '"'))
|
|
538
|
+
return JSON.stringify(attr.replace(/"/g, '"'))
|
|
539
|
+
.replace(/\\t/g, '\t')
|
|
540
|
+
.replace(/\\n/g, '\n')
|
|
541
|
+
.replace(/\\r/g, '\r')
|
|
542
|
+
.replace(/\\/g, '');
|
|
539
543
|
};
|
|
540
544
|
/**
|
|
541
545
|
* Remove Child element from childNodes array
|
|
@@ -824,6 +828,15 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
824
828
|
_this.childNodes[o++] = node;
|
|
825
829
|
});
|
|
826
830
|
this.childNodes.length = o;
|
|
831
|
+
// remove whitespace between attributes
|
|
832
|
+
var attrs = Object.keys(this.rawAttributes)
|
|
833
|
+
.map(function (key) {
|
|
834
|
+
var val = _this.rawAttributes[key];
|
|
835
|
+
return "".concat(key, "=").concat(JSON.stringify(val));
|
|
836
|
+
})
|
|
837
|
+
.join(' ');
|
|
838
|
+
this.rawAttrs = attrs;
|
|
839
|
+
delete this._rawAttrs;
|
|
827
840
|
return this;
|
|
828
841
|
};
|
|
829
842
|
/**
|
|
@@ -913,7 +926,6 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
913
926
|
if (child.id === id) {
|
|
914
927
|
return child;
|
|
915
928
|
}
|
|
916
|
-
;
|
|
917
929
|
// if children are existing push the current status to the stack and keep searching for elements in the level below
|
|
918
930
|
if (child.childNodes.length > 0) {
|
|
919
931
|
stack.push(index);
|
|
@@ -980,34 +992,9 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
980
992
|
* @return {Node} node appended
|
|
981
993
|
*/
|
|
982
994
|
HTMLElement.prototype.appendChild = function (node) {
|
|
983
|
-
|
|
984
|
-
node.remove();
|
|
985
|
-
this.childNodes.push(node);
|
|
986
|
-
node.parentNode = this;
|
|
995
|
+
this.append(node);
|
|
987
996
|
return node;
|
|
988
997
|
};
|
|
989
|
-
Object.defineProperty(HTMLElement.prototype, "firstChild", {
|
|
990
|
-
/**
|
|
991
|
-
* Get first child node
|
|
992
|
-
* @return {Node | undefined} first child node; or undefined if none
|
|
993
|
-
*/
|
|
994
|
-
get: function () {
|
|
995
|
-
return this.childNodes[0];
|
|
996
|
-
},
|
|
997
|
-
enumerable: false,
|
|
998
|
-
configurable: true
|
|
999
|
-
});
|
|
1000
|
-
Object.defineProperty(HTMLElement.prototype, "lastChild", {
|
|
1001
|
-
/**
|
|
1002
|
-
* Get last child node
|
|
1003
|
-
* @return {Node | undefined} last child node; or undefined if none
|
|
1004
|
-
*/
|
|
1005
|
-
get: function () {
|
|
1006
|
-
return (0, back_1.default)(this.childNodes);
|
|
1007
|
-
},
|
|
1008
|
-
enumerable: false,
|
|
1009
|
-
configurable: true
|
|
1010
|
-
});
|
|
1011
998
|
Object.defineProperty(HTMLElement.prototype, "attrs", {
|
|
1012
999
|
/**
|
|
1013
1000
|
* Get attributes
|
|
@@ -1053,7 +1040,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1053
1040
|
}
|
|
1054
1041
|
var attrs = {};
|
|
1055
1042
|
if (this.rawAttrs) {
|
|
1056
|
-
var re = /([a-zA-Z()[\]#@$.?:][a-zA-Z0-9
|
|
1043
|
+
var re = /([a-zA-Z()[\]#@$.?:][a-zA-Z0-9-._:()[\]#]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
|
|
1057
1044
|
var match = void 0;
|
|
1058
1045
|
while ((match = re.exec(this.rawAttrs))) {
|
|
1059
1046
|
var key = match[1];
|
|
@@ -1166,42 +1153,70 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1166
1153
|
return this;
|
|
1167
1154
|
};
|
|
1168
1155
|
HTMLElement.prototype.insertAdjacentHTML = function (where, html) {
|
|
1169
|
-
var _a, _b, _c;
|
|
1170
|
-
var _this = this;
|
|
1171
1156
|
if (arguments.length < 2) {
|
|
1172
1157
|
throw new Error('2 arguments required');
|
|
1173
1158
|
}
|
|
1174
1159
|
var p = parse(html, this._parseOptions);
|
|
1175
1160
|
if (where === 'afterend') {
|
|
1176
|
-
|
|
1177
|
-
return child === _this;
|
|
1178
|
-
});
|
|
1179
|
-
resetParent(p.childNodes, this.parentNode);
|
|
1180
|
-
(_a = this.parentNode.childNodes).splice.apply(_a, __spreadArray([idx + 1, 0], p.childNodes, false));
|
|
1161
|
+
this.after.apply(this, p.childNodes);
|
|
1181
1162
|
}
|
|
1182
1163
|
else if (where === 'afterbegin') {
|
|
1183
|
-
|
|
1184
|
-
(_b = this.childNodes).unshift.apply(_b, p.childNodes);
|
|
1164
|
+
this.prepend.apply(this, p.childNodes);
|
|
1185
1165
|
}
|
|
1186
1166
|
else if (where === 'beforeend') {
|
|
1187
|
-
|
|
1188
|
-
_this.appendChild(n);
|
|
1189
|
-
});
|
|
1167
|
+
this.append.apply(this, p.childNodes);
|
|
1190
1168
|
}
|
|
1191
1169
|
else if (where === 'beforebegin') {
|
|
1192
|
-
|
|
1193
|
-
return child === _this;
|
|
1194
|
-
});
|
|
1195
|
-
resetParent(p.childNodes, this.parentNode);
|
|
1196
|
-
(_c = this.parentNode.childNodes).splice.apply(_c, __spreadArray([idx, 0], p.childNodes, false));
|
|
1170
|
+
this.before.apply(this, p.childNodes);
|
|
1197
1171
|
}
|
|
1198
1172
|
else {
|
|
1199
1173
|
throw new Error("The value provided ('".concat(where, "') is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'"));
|
|
1200
1174
|
}
|
|
1201
1175
|
return this;
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1176
|
+
};
|
|
1177
|
+
/** Prepend nodes or strings to this node's children. */
|
|
1178
|
+
HTMLElement.prototype.prepend = function () {
|
|
1179
|
+
var _a;
|
|
1180
|
+
var insertable = [];
|
|
1181
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1182
|
+
insertable[_i] = arguments[_i];
|
|
1183
|
+
}
|
|
1184
|
+
var nodes = resolveInsertable(insertable);
|
|
1185
|
+
resetParent(nodes, this);
|
|
1186
|
+
(_a = this.childNodes).unshift.apply(_a, nodes);
|
|
1187
|
+
};
|
|
1188
|
+
/** Append nodes or strings to this node's children. */
|
|
1189
|
+
HTMLElement.prototype.append = function () {
|
|
1190
|
+
var _a;
|
|
1191
|
+
var insertable = [];
|
|
1192
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1193
|
+
insertable[_i] = arguments[_i];
|
|
1194
|
+
}
|
|
1195
|
+
var nodes = resolveInsertable(insertable);
|
|
1196
|
+
resetParent(nodes, this);
|
|
1197
|
+
(_a = this.childNodes).push.apply(_a, nodes);
|
|
1198
|
+
};
|
|
1199
|
+
/** Insert nodes or strings before this node. */
|
|
1200
|
+
HTMLElement.prototype.before = function () {
|
|
1201
|
+
var insertable = [];
|
|
1202
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1203
|
+
insertable[_i] = arguments[_i];
|
|
1204
|
+
}
|
|
1205
|
+
var nodes = resolveInsertable(insertable);
|
|
1206
|
+
var siblings = this.parentNode.childNodes;
|
|
1207
|
+
resetParent(nodes, this.parentNode);
|
|
1208
|
+
siblings.splice.apply(siblings, __spreadArray([siblings.indexOf(this), 0], nodes, false));
|
|
1209
|
+
};
|
|
1210
|
+
/** Insert nodes or strings after this node. */
|
|
1211
|
+
HTMLElement.prototype.after = function () {
|
|
1212
|
+
var insertable = [];
|
|
1213
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1214
|
+
insertable[_i] = arguments[_i];
|
|
1215
|
+
}
|
|
1216
|
+
var nodes = resolveInsertable(insertable);
|
|
1217
|
+
var siblings = this.parentNode.childNodes;
|
|
1218
|
+
resetParent(nodes, this.parentNode);
|
|
1219
|
+
siblings.splice.apply(siblings, __spreadArray([siblings.indexOf(this) + 1, 0], nodes, false));
|
|
1205
1220
|
};
|
|
1206
1221
|
Object.defineProperty(HTMLElement.prototype, "nextSibling", {
|
|
1207
1222
|
get: function () {
|
|
@@ -1281,6 +1296,72 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1281
1296
|
enumerable: false,
|
|
1282
1297
|
configurable: true
|
|
1283
1298
|
});
|
|
1299
|
+
Object.defineProperty(HTMLElement.prototype, "children", {
|
|
1300
|
+
/** Get all childNodes of type {@link HTMLElement}. */
|
|
1301
|
+
get: function () {
|
|
1302
|
+
var children = [];
|
|
1303
|
+
for (var _i = 0, _a = this.childNodes; _i < _a.length; _i++) {
|
|
1304
|
+
var childNode = _a[_i];
|
|
1305
|
+
if (childNode instanceof HTMLElement) {
|
|
1306
|
+
children.push(childNode);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
return children;
|
|
1310
|
+
},
|
|
1311
|
+
enumerable: false,
|
|
1312
|
+
configurable: true
|
|
1313
|
+
});
|
|
1314
|
+
Object.defineProperty(HTMLElement.prototype, "firstChild", {
|
|
1315
|
+
/**
|
|
1316
|
+
* Get the first child node.
|
|
1317
|
+
* @return The first child or undefined if none exists.
|
|
1318
|
+
*/
|
|
1319
|
+
get: function () {
|
|
1320
|
+
return this.childNodes[0];
|
|
1321
|
+
},
|
|
1322
|
+
enumerable: false,
|
|
1323
|
+
configurable: true
|
|
1324
|
+
});
|
|
1325
|
+
Object.defineProperty(HTMLElement.prototype, "firstElementChild", {
|
|
1326
|
+
/**
|
|
1327
|
+
* Get the first child node of type {@link HTMLElement}.
|
|
1328
|
+
* @return The first child element or undefined if none exists.
|
|
1329
|
+
*/
|
|
1330
|
+
get: function () {
|
|
1331
|
+
return this.children[0];
|
|
1332
|
+
},
|
|
1333
|
+
enumerable: false,
|
|
1334
|
+
configurable: true
|
|
1335
|
+
});
|
|
1336
|
+
Object.defineProperty(HTMLElement.prototype, "lastChild", {
|
|
1337
|
+
/**
|
|
1338
|
+
* Get the last child node.
|
|
1339
|
+
* @return The last child or undefined if none exists.
|
|
1340
|
+
*/
|
|
1341
|
+
get: function () {
|
|
1342
|
+
return (0, back_1.default)(this.childNodes);
|
|
1343
|
+
},
|
|
1344
|
+
enumerable: false,
|
|
1345
|
+
configurable: true
|
|
1346
|
+
});
|
|
1347
|
+
Object.defineProperty(HTMLElement.prototype, "lastElementChild", {
|
|
1348
|
+
/**
|
|
1349
|
+
* Get the last child node of type {@link HTMLElement}.
|
|
1350
|
+
* @return The last child element or undefined if none exists.
|
|
1351
|
+
*/
|
|
1352
|
+
get: function () {
|
|
1353
|
+
return this.children[this.children.length - 1];
|
|
1354
|
+
},
|
|
1355
|
+
enumerable: false,
|
|
1356
|
+
configurable: true
|
|
1357
|
+
});
|
|
1358
|
+
Object.defineProperty(HTMLElement.prototype, "childElementCount", {
|
|
1359
|
+
get: function () {
|
|
1360
|
+
return this.children.length;
|
|
1361
|
+
},
|
|
1362
|
+
enumerable: false,
|
|
1363
|
+
configurable: true
|
|
1364
|
+
});
|
|
1284
1365
|
Object.defineProperty(HTMLElement.prototype, "classNames", {
|
|
1285
1366
|
get: function () {
|
|
1286
1367
|
return this.classList.toString();
|
|
@@ -1288,17 +1369,17 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1288
1369
|
enumerable: false,
|
|
1289
1370
|
configurable: true
|
|
1290
1371
|
});
|
|
1291
|
-
/**
|
|
1292
|
-
* Clone this Node
|
|
1293
|
-
*/
|
|
1372
|
+
/** Clone this Node */
|
|
1294
1373
|
HTMLElement.prototype.clone = function () {
|
|
1295
1374
|
return parse(this.toString(), this._parseOptions).firstChild;
|
|
1296
1375
|
};
|
|
1297
1376
|
return HTMLElement;
|
|
1298
1377
|
}(node_2.default));
|
|
1299
1378
|
exports.default = HTMLElement;
|
|
1379
|
+
// #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
1300
1380
|
// https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
1301
|
-
var kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/
|
|
1381
|
+
var kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z@\xB7\xC0-\xD6\xD8-\xF6\u00F8-\u03A1\u03A3-\u03D9\u03DB-\u03EF\u03F7-\u03FF\u0400-\u04FF\u0500-\u052F\u1D00-\u1D2B\u1D6B-\u1D77\u1D79-\u1D9A\u1E00-\u1E9B\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u2132\u214E\u2160-\u2188\u2C60-\u2C7F\uA722-\uA787\uA78B-\uA78E\uA790-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA7FF\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64-\uAB65\uFB00-\uFB06\uFB13-\uFB17\uFF21-\uFF3A\uFF41-\uFF5A\x37F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/gu;
|
|
1382
|
+
// const kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
|
|
1302
1383
|
var kAttributePattern = /(?:^|\s)(id|class)\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+)/gi;
|
|
1303
1384
|
var kElementsClosedByOpening = {
|
|
1304
1385
|
li: { li: true, LI: true },
|
|
@@ -1545,6 +1626,19 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1545
1626
|
return root;
|
|
1546
1627
|
}
|
|
1547
1628
|
exports.parse = parse;
|
|
1629
|
+
/**
|
|
1630
|
+
* Resolves a list of {@link NodeInsertable} to a list of nodes,
|
|
1631
|
+
* and removes nodes from any potential parent.
|
|
1632
|
+
*/
|
|
1633
|
+
function resolveInsertable(insertable) {
|
|
1634
|
+
return insertable.map(function (val) {
|
|
1635
|
+
if (typeof val === 'string') {
|
|
1636
|
+
return new text_1.default(val);
|
|
1637
|
+
}
|
|
1638
|
+
val.remove();
|
|
1639
|
+
return val;
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1548
1642
|
function resetParent(nodes, parent) {
|
|
1549
1643
|
return nodes.map(function (node) {
|
|
1550
1644
|
node.parentNode = parent;
|
package/dist/matcher.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const type_1 = __importDefault(require("./nodes/type"));
|
|
7
7
|
function isTag(node) {
|
|
8
8
|
return node && node.nodeType === type_1.default.ELEMENT_NODE;
|
|
9
9
|
}
|
|
@@ -23,10 +23,10 @@ function getText(node) {
|
|
|
23
23
|
return node.text;
|
|
24
24
|
}
|
|
25
25
|
function removeSubsets(nodes) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
let idx = nodes.length;
|
|
27
|
+
let node;
|
|
28
|
+
let ancestor;
|
|
29
|
+
let replace;
|
|
30
30
|
// Check if each node (or one of its ancestors) is already contained in the
|
|
31
31
|
// array.
|
|
32
32
|
while (--idx > -1) {
|
|
@@ -50,26 +50,26 @@ function removeSubsets(nodes) {
|
|
|
50
50
|
return nodes;
|
|
51
51
|
}
|
|
52
52
|
function existsOne(test, elems) {
|
|
53
|
-
return elems.some(
|
|
53
|
+
return elems.some((elem) => {
|
|
54
54
|
return isTag(elem) ? test(elem) || existsOne(test, getChildren(elem)) : false;
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
function getSiblings(node) {
|
|
58
|
-
|
|
58
|
+
const parent = getParent(node);
|
|
59
59
|
return parent ? getChildren(parent) : [];
|
|
60
60
|
}
|
|
61
61
|
function hasAttrib(elem, name) {
|
|
62
62
|
return getAttributeValue(elem, name) !== undefined;
|
|
63
63
|
}
|
|
64
64
|
function findOne(test, elems) {
|
|
65
|
-
|
|
66
|
-
for (
|
|
67
|
-
|
|
65
|
+
let elem = null;
|
|
66
|
+
for (let i = 0, l = elems === null || elems === void 0 ? void 0 : elems.length; i < l && !elem; i++) {
|
|
67
|
+
const el = elems[i];
|
|
68
68
|
if (test(el)) {
|
|
69
69
|
elem = el;
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
|
|
72
|
+
const childs = getChildren(el);
|
|
73
73
|
if (childs && childs.length > 0) {
|
|
74
74
|
elem = findOne(test, childs);
|
|
75
75
|
}
|
|
@@ -78,29 +78,29 @@ function findOne(test, elems) {
|
|
|
78
78
|
return elem;
|
|
79
79
|
}
|
|
80
80
|
function findAll(test, nodes) {
|
|
81
|
-
|
|
82
|
-
for (
|
|
81
|
+
let result = [];
|
|
82
|
+
for (let i = 0, j = nodes.length; i < j; i++) {
|
|
83
83
|
if (!isTag(nodes[i]))
|
|
84
84
|
continue;
|
|
85
85
|
if (test(nodes[i]))
|
|
86
86
|
result.push(nodes[i]);
|
|
87
|
-
|
|
87
|
+
const childs = getChildren(nodes[i]);
|
|
88
88
|
if (childs)
|
|
89
89
|
result = result.concat(findAll(test, childs));
|
|
90
90
|
}
|
|
91
91
|
return result;
|
|
92
92
|
}
|
|
93
93
|
exports.default = {
|
|
94
|
-
isTag
|
|
95
|
-
getAttributeValue
|
|
96
|
-
getName
|
|
97
|
-
getChildren
|
|
98
|
-
getParent
|
|
99
|
-
getText
|
|
100
|
-
removeSubsets
|
|
101
|
-
existsOne
|
|
102
|
-
getSiblings
|
|
103
|
-
hasAttrib
|
|
104
|
-
findOne
|
|
105
|
-
findAll
|
|
94
|
+
isTag,
|
|
95
|
+
getAttributeValue,
|
|
96
|
+
getName,
|
|
97
|
+
getChildren,
|
|
98
|
+
getParent,
|
|
99
|
+
getText,
|
|
100
|
+
removeSubsets,
|
|
101
|
+
existsOne,
|
|
102
|
+
getSiblings,
|
|
103
|
+
hasAttrib,
|
|
104
|
+
findOne,
|
|
105
|
+
findAll
|
|
106
106
|
};
|
package/dist/nodes/comment.js
CHANGED
|
@@ -1,57 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
4
|
};
|
|
20
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
6
|
+
const node_1 = __importDefault(require("./node"));
|
|
7
|
+
const type_1 = __importDefault(require("./type"));
|
|
8
|
+
class CommentNode extends node_1.default {
|
|
9
|
+
clone() {
|
|
10
|
+
return new CommentNode(this.rawText, null, undefined, this.rawTagName);
|
|
11
|
+
}
|
|
12
|
+
constructor(rawText, parentNode = null, range, rawTagName = '!--') {
|
|
13
|
+
super(parentNode, range);
|
|
14
|
+
this.rawText = rawText;
|
|
15
|
+
this.rawTagName = rawTagName;
|
|
31
16
|
/**
|
|
32
17
|
* Node Type declaration.
|
|
33
18
|
* @type {Number}
|
|
34
19
|
*/
|
|
35
|
-
|
|
36
|
-
return _this;
|
|
20
|
+
this.nodeType = type_1.default.COMMENT_NODE;
|
|
37
21
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
enumerable: false,
|
|
50
|
-
configurable: true
|
|
51
|
-
});
|
|
52
|
-
CommentNode.prototype.toString = function () {
|
|
53
|
-
return "<!--".concat(this.rawText, "-->");
|
|
54
|
-
};
|
|
55
|
-
return CommentNode;
|
|
56
|
-
}(node_1.default));
|
|
22
|
+
/**
|
|
23
|
+
* Get unescaped text value of current node and its children.
|
|
24
|
+
* @return {string} text content
|
|
25
|
+
*/
|
|
26
|
+
get text() {
|
|
27
|
+
return this.rawText;
|
|
28
|
+
}
|
|
29
|
+
toString() {
|
|
30
|
+
return `<!--${this.rawText}-->`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
57
33
|
exports.default = CommentNode;
|