parse5-htmlparser2-tree-adapter 7.0.0 → 8.0.0
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 +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +9 -10
- package/package.json +11 -12
- package/dist/cjs/index.d.ts +0 -7
- package/dist/cjs/index.js +0 -215
- package/dist/cjs/package.json +0 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<br>
|
|
17
17
|
|
|
18
18
|
<p align="center">
|
|
19
|
-
📖 <a href="https://parse5.js.org/modules/
|
|
19
|
+
📖 <a href="https://parse5.js.org/modules/parse5-htmlparser2-tree-adapter.html"><b>Documentation</b></a> 📖
|
|
20
20
|
</p>
|
|
21
21
|
|
|
22
22
|
---
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type TreeAdapterTypeMap, type TreeAdapter } from 'parse5';
|
|
2
2
|
import { type AnyNode, type ParentNode, type ChildNode, Element, Document, ProcessingInstruction, Comment, Text } from 'domhandler';
|
|
3
|
-
export
|
|
3
|
+
export type Htmlparser2TreeAdapterMap = TreeAdapterTypeMap<AnyNode, ParentNode, ChildNode, Document, Document, Element, Comment, Text, Element, ProcessingInstruction>;
|
|
4
4
|
/** @internal */
|
|
5
5
|
export declare function serializeDoctypeContent(name: string, publicId: string, systemId: string): string;
|
|
6
6
|
export declare const adapter: TreeAdapter<Htmlparser2TreeAdapterMap>;
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { html } from 'parse5';
|
|
2
2
|
import { Element, Document, ProcessingInstruction, Comment, Text, isDirective, isText, isComment, isTag, } from 'domhandler';
|
|
3
|
-
function createTextNode(value) {
|
|
4
|
-
return new Text(value);
|
|
5
|
-
}
|
|
6
3
|
function enquoteDoctypeId(id) {
|
|
7
4
|
const quote = id.includes('"') ? "'" : '"';
|
|
8
5
|
return quote + id + quote;
|
|
@@ -57,6 +54,9 @@ export const adapter = {
|
|
|
57
54
|
createCommentNode(data) {
|
|
58
55
|
return new Comment(data);
|
|
59
56
|
},
|
|
57
|
+
createTextNode(value) {
|
|
58
|
+
return new Text(value);
|
|
59
|
+
},
|
|
60
60
|
//Tree mutation
|
|
61
61
|
appendChild(parentNode, newNode) {
|
|
62
62
|
const prev = parentNode.children[parentNode.children.length - 1];
|
|
@@ -95,9 +95,9 @@ export const adapter = {
|
|
|
95
95
|
doctypeNode = new ProcessingInstruction('!doctype', data);
|
|
96
96
|
adapter.appendChild(document, doctypeNode);
|
|
97
97
|
}
|
|
98
|
-
doctypeNode['x-name'] = name
|
|
99
|
-
doctypeNode['x-publicId'] = publicId
|
|
100
|
-
doctypeNode['x-systemId'] = systemId
|
|
98
|
+
doctypeNode['x-name'] = name;
|
|
99
|
+
doctypeNode['x-publicId'] = publicId;
|
|
100
|
+
doctypeNode['x-systemId'] = systemId;
|
|
101
101
|
},
|
|
102
102
|
setDocumentMode(document, mode) {
|
|
103
103
|
document['x-mode'] = mode;
|
|
@@ -127,7 +127,7 @@ export const adapter = {
|
|
|
127
127
|
lastChild.data += text;
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
|
-
adapter.appendChild(parentNode, createTextNode(text));
|
|
130
|
+
adapter.appendChild(parentNode, adapter.createTextNode(text));
|
|
131
131
|
}
|
|
132
132
|
},
|
|
133
133
|
insertTextBefore(parentNode, text, referenceNode) {
|
|
@@ -136,13 +136,13 @@ export const adapter = {
|
|
|
136
136
|
prevNode.data += text;
|
|
137
137
|
}
|
|
138
138
|
else {
|
|
139
|
-
adapter.insertBefore(parentNode, createTextNode(text), referenceNode);
|
|
139
|
+
adapter.insertBefore(parentNode, adapter.createTextNode(text), referenceNode);
|
|
140
140
|
}
|
|
141
141
|
},
|
|
142
142
|
adoptAttributes(recipient, attrs) {
|
|
143
143
|
for (let i = 0; i < attrs.length; i++) {
|
|
144
144
|
const attrName = attrs[i].name;
|
|
145
|
-
if (
|
|
145
|
+
if (recipient.attribs[attrName] === undefined) {
|
|
146
146
|
recipient.attribs[attrName] = attrs[i].value;
|
|
147
147
|
recipient['x-attribsNamespace'][attrName] = attrs[i].namespace;
|
|
148
148
|
recipient['x-attribsPrefix'][attrName] = attrs[i].prefix;
|
|
@@ -211,4 +211,3 @@ export const adapter = {
|
|
|
211
211
|
};
|
|
212
212
|
},
|
|
213
213
|
};
|
|
214
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"name": "parse5-htmlparser2-tree-adapter",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "htmlparser2 tree adapter for parse5.",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "8.0.0",
|
|
6
6
|
"author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)",
|
|
7
7
|
"contributors": "https://github.com/inikulin/parse5/graphs/contributors",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://parse5.js.org",
|
|
9
9
|
"funding": "https://github.com/inikulin/parse5?sponsor=1",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"parse5",
|
|
@@ -14,26 +14,25 @@
|
|
|
14
14
|
"htmlparser2"
|
|
15
15
|
],
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"main": "dist/
|
|
17
|
+
"main": "dist/index.js",
|
|
18
18
|
"module": "dist/index.js",
|
|
19
19
|
"types": "dist/index.d.ts",
|
|
20
20
|
"exports": {
|
|
21
|
-
"
|
|
22
|
-
|
|
21
|
+
".": {
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"domhandler": "^5.0.
|
|
26
|
-
"parse5": "^
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build:cjs": "tsc --module CommonJS --target ES6 --outDir dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json"
|
|
26
|
+
"domhandler": "^5.0.3",
|
|
27
|
+
"parse5": "^8.0.0"
|
|
30
28
|
},
|
|
29
|
+
"scripts": {},
|
|
31
30
|
"repository": {
|
|
32
31
|
"type": "git",
|
|
33
32
|
"url": "git://github.com/inikulin/parse5.git"
|
|
34
33
|
},
|
|
35
34
|
"files": [
|
|
36
|
-
"dist",
|
|
37
|
-
"
|
|
35
|
+
"dist/**/*.js",
|
|
36
|
+
"dist/**/*.d.ts"
|
|
38
37
|
]
|
|
39
38
|
}
|
package/dist/cjs/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type TreeAdapterTypeMap, type TreeAdapter } from 'parse5';
|
|
2
|
-
import { type AnyNode, type ParentNode, type ChildNode, Element, Document, ProcessingInstruction, Comment, Text } from 'domhandler';
|
|
3
|
-
export declare type Htmlparser2TreeAdapterMap = TreeAdapterTypeMap<AnyNode, ParentNode, ChildNode, Document, Document, Element, Comment, Text, Element, ProcessingInstruction>;
|
|
4
|
-
/** @internal */
|
|
5
|
-
export declare function serializeDoctypeContent(name: string, publicId: string, systemId: string): string;
|
|
6
|
-
export declare const adapter: TreeAdapter<Htmlparser2TreeAdapterMap>;
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.adapter = exports.serializeDoctypeContent = void 0;
|
|
4
|
-
const parse5_1 = require("parse5");
|
|
5
|
-
const domhandler_1 = require("domhandler");
|
|
6
|
-
function createTextNode(value) {
|
|
7
|
-
return new domhandler_1.Text(value);
|
|
8
|
-
}
|
|
9
|
-
function enquoteDoctypeId(id) {
|
|
10
|
-
const quote = id.includes('"') ? "'" : '"';
|
|
11
|
-
return quote + id + quote;
|
|
12
|
-
}
|
|
13
|
-
/** @internal */
|
|
14
|
-
function serializeDoctypeContent(name, publicId, systemId) {
|
|
15
|
-
let str = '!DOCTYPE ';
|
|
16
|
-
if (name) {
|
|
17
|
-
str += name;
|
|
18
|
-
}
|
|
19
|
-
if (publicId) {
|
|
20
|
-
str += ` PUBLIC ${enquoteDoctypeId(publicId)}`;
|
|
21
|
-
}
|
|
22
|
-
else if (systemId) {
|
|
23
|
-
str += ' SYSTEM';
|
|
24
|
-
}
|
|
25
|
-
if (systemId) {
|
|
26
|
-
str += ` ${enquoteDoctypeId(systemId)}`;
|
|
27
|
-
}
|
|
28
|
-
return str;
|
|
29
|
-
}
|
|
30
|
-
exports.serializeDoctypeContent = serializeDoctypeContent;
|
|
31
|
-
exports.adapter = {
|
|
32
|
-
// Re-exports from domhandler
|
|
33
|
-
isCommentNode: domhandler_1.isComment,
|
|
34
|
-
isElementNode: domhandler_1.isTag,
|
|
35
|
-
isTextNode: domhandler_1.isText,
|
|
36
|
-
//Node construction
|
|
37
|
-
createDocument() {
|
|
38
|
-
const node = new domhandler_1.Document([]);
|
|
39
|
-
node['x-mode'] = parse5_1.html.DOCUMENT_MODE.NO_QUIRKS;
|
|
40
|
-
return node;
|
|
41
|
-
},
|
|
42
|
-
createDocumentFragment() {
|
|
43
|
-
return new domhandler_1.Document([]);
|
|
44
|
-
},
|
|
45
|
-
createElement(tagName, namespaceURI, attrs) {
|
|
46
|
-
const attribs = Object.create(null);
|
|
47
|
-
const attribsNamespace = Object.create(null);
|
|
48
|
-
const attribsPrefix = Object.create(null);
|
|
49
|
-
for (let i = 0; i < attrs.length; i++) {
|
|
50
|
-
const attrName = attrs[i].name;
|
|
51
|
-
attribs[attrName] = attrs[i].value;
|
|
52
|
-
attribsNamespace[attrName] = attrs[i].namespace;
|
|
53
|
-
attribsPrefix[attrName] = attrs[i].prefix;
|
|
54
|
-
}
|
|
55
|
-
const node = new domhandler_1.Element(tagName, attribs, []);
|
|
56
|
-
node.namespace = namespaceURI;
|
|
57
|
-
node['x-attribsNamespace'] = attribsNamespace;
|
|
58
|
-
node['x-attribsPrefix'] = attribsPrefix;
|
|
59
|
-
return node;
|
|
60
|
-
},
|
|
61
|
-
createCommentNode(data) {
|
|
62
|
-
return new domhandler_1.Comment(data);
|
|
63
|
-
},
|
|
64
|
-
//Tree mutation
|
|
65
|
-
appendChild(parentNode, newNode) {
|
|
66
|
-
const prev = parentNode.children[parentNode.children.length - 1];
|
|
67
|
-
if (prev) {
|
|
68
|
-
prev.next = newNode;
|
|
69
|
-
newNode.prev = prev;
|
|
70
|
-
}
|
|
71
|
-
parentNode.children.push(newNode);
|
|
72
|
-
newNode.parent = parentNode;
|
|
73
|
-
},
|
|
74
|
-
insertBefore(parentNode, newNode, referenceNode) {
|
|
75
|
-
const insertionIdx = parentNode.children.indexOf(referenceNode);
|
|
76
|
-
const { prev } = referenceNode;
|
|
77
|
-
if (prev) {
|
|
78
|
-
prev.next = newNode;
|
|
79
|
-
newNode.prev = prev;
|
|
80
|
-
}
|
|
81
|
-
referenceNode.prev = newNode;
|
|
82
|
-
newNode.next = referenceNode;
|
|
83
|
-
parentNode.children.splice(insertionIdx, 0, newNode);
|
|
84
|
-
newNode.parent = parentNode;
|
|
85
|
-
},
|
|
86
|
-
setTemplateContent(templateElement, contentElement) {
|
|
87
|
-
exports.adapter.appendChild(templateElement, contentElement);
|
|
88
|
-
},
|
|
89
|
-
getTemplateContent(templateElement) {
|
|
90
|
-
return templateElement.children[0];
|
|
91
|
-
},
|
|
92
|
-
setDocumentType(document, name, publicId, systemId) {
|
|
93
|
-
const data = serializeDoctypeContent(name, publicId, systemId);
|
|
94
|
-
let doctypeNode = document.children.find((node) => (0, domhandler_1.isDirective)(node) && node.name === '!doctype');
|
|
95
|
-
if (doctypeNode) {
|
|
96
|
-
doctypeNode.data = data !== null && data !== void 0 ? data : null;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
doctypeNode = new domhandler_1.ProcessingInstruction('!doctype', data);
|
|
100
|
-
exports.adapter.appendChild(document, doctypeNode);
|
|
101
|
-
}
|
|
102
|
-
doctypeNode['x-name'] = name !== null && name !== void 0 ? name : undefined;
|
|
103
|
-
doctypeNode['x-publicId'] = publicId !== null && publicId !== void 0 ? publicId : undefined;
|
|
104
|
-
doctypeNode['x-systemId'] = systemId !== null && systemId !== void 0 ? systemId : undefined;
|
|
105
|
-
},
|
|
106
|
-
setDocumentMode(document, mode) {
|
|
107
|
-
document['x-mode'] = mode;
|
|
108
|
-
},
|
|
109
|
-
getDocumentMode(document) {
|
|
110
|
-
return document['x-mode'];
|
|
111
|
-
},
|
|
112
|
-
detachNode(node) {
|
|
113
|
-
if (node.parent) {
|
|
114
|
-
const idx = node.parent.children.indexOf(node);
|
|
115
|
-
const { prev, next } = node;
|
|
116
|
-
node.prev = null;
|
|
117
|
-
node.next = null;
|
|
118
|
-
if (prev) {
|
|
119
|
-
prev.next = next;
|
|
120
|
-
}
|
|
121
|
-
if (next) {
|
|
122
|
-
next.prev = prev;
|
|
123
|
-
}
|
|
124
|
-
node.parent.children.splice(idx, 1);
|
|
125
|
-
node.parent = null;
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
insertText(parentNode, text) {
|
|
129
|
-
const lastChild = parentNode.children[parentNode.children.length - 1];
|
|
130
|
-
if (lastChild && (0, domhandler_1.isText)(lastChild)) {
|
|
131
|
-
lastChild.data += text;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
exports.adapter.appendChild(parentNode, createTextNode(text));
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
insertTextBefore(parentNode, text, referenceNode) {
|
|
138
|
-
const prevNode = parentNode.children[parentNode.children.indexOf(referenceNode) - 1];
|
|
139
|
-
if (prevNode && (0, domhandler_1.isText)(prevNode)) {
|
|
140
|
-
prevNode.data += text;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
exports.adapter.insertBefore(parentNode, createTextNode(text), referenceNode);
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
adoptAttributes(recipient, attrs) {
|
|
147
|
-
for (let i = 0; i < attrs.length; i++) {
|
|
148
|
-
const attrName = attrs[i].name;
|
|
149
|
-
if (typeof recipient.attribs[attrName] === 'undefined') {
|
|
150
|
-
recipient.attribs[attrName] = attrs[i].value;
|
|
151
|
-
recipient['x-attribsNamespace'][attrName] = attrs[i].namespace;
|
|
152
|
-
recipient['x-attribsPrefix'][attrName] = attrs[i].prefix;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
//Tree traversing
|
|
157
|
-
getFirstChild(node) {
|
|
158
|
-
return node.children[0];
|
|
159
|
-
},
|
|
160
|
-
getChildNodes(node) {
|
|
161
|
-
return node.children;
|
|
162
|
-
},
|
|
163
|
-
getParentNode(node) {
|
|
164
|
-
return node.parent;
|
|
165
|
-
},
|
|
166
|
-
getAttrList(element) {
|
|
167
|
-
return element.attributes;
|
|
168
|
-
},
|
|
169
|
-
//Node data
|
|
170
|
-
getTagName(element) {
|
|
171
|
-
return element.name;
|
|
172
|
-
},
|
|
173
|
-
getNamespaceURI(element) {
|
|
174
|
-
return element.namespace;
|
|
175
|
-
},
|
|
176
|
-
getTextNodeContent(textNode) {
|
|
177
|
-
return textNode.data;
|
|
178
|
-
},
|
|
179
|
-
getCommentNodeContent(commentNode) {
|
|
180
|
-
return commentNode.data;
|
|
181
|
-
},
|
|
182
|
-
getDocumentTypeNodeName(doctypeNode) {
|
|
183
|
-
var _a;
|
|
184
|
-
return (_a = doctypeNode['x-name']) !== null && _a !== void 0 ? _a : '';
|
|
185
|
-
},
|
|
186
|
-
getDocumentTypeNodePublicId(doctypeNode) {
|
|
187
|
-
var _a;
|
|
188
|
-
return (_a = doctypeNode['x-publicId']) !== null && _a !== void 0 ? _a : '';
|
|
189
|
-
},
|
|
190
|
-
getDocumentTypeNodeSystemId(doctypeNode) {
|
|
191
|
-
var _a;
|
|
192
|
-
return (_a = doctypeNode['x-systemId']) !== null && _a !== void 0 ? _a : '';
|
|
193
|
-
},
|
|
194
|
-
//Node types
|
|
195
|
-
isDocumentTypeNode(node) {
|
|
196
|
-
return (0, domhandler_1.isDirective)(node) && node.name === '!doctype';
|
|
197
|
-
},
|
|
198
|
-
// Source code location
|
|
199
|
-
setNodeSourceCodeLocation(node, location) {
|
|
200
|
-
if (location) {
|
|
201
|
-
node.startIndex = location.startOffset;
|
|
202
|
-
node.endIndex = location.endOffset;
|
|
203
|
-
}
|
|
204
|
-
node.sourceCodeLocation = location;
|
|
205
|
-
},
|
|
206
|
-
getNodeSourceCodeLocation(node) {
|
|
207
|
-
return node.sourceCodeLocation;
|
|
208
|
-
},
|
|
209
|
-
updateNodeSourceCodeLocation(node, endLocation) {
|
|
210
|
-
if (endLocation.endOffset != null)
|
|
211
|
-
node.endIndex = endLocation.endOffset;
|
|
212
|
-
node.sourceCodeLocation = Object.assign(Object.assign({}, node.sourceCodeLocation), endLocation);
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|