parse5-htmlparser2-tree-adapter 7.1.0 → 8.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/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/parse5_htmlparser2_tree_adapter.html"><b>Documentation</b></a> 📖
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/package.json CHANGED
@@ -2,9 +2,14 @@
2
2
  "name": "parse5-htmlparser2-tree-adapter",
3
3
  "type": "module",
4
4
  "description": "htmlparser2 tree adapter for parse5.",
5
- "version": "7.1.0",
5
+ "version": "8.0.1",
6
6
  "author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)",
7
- "contributors": "https://github.com/inikulin/parse5/graphs/contributors",
7
+ "contributors": [
8
+ "James Garbutt (https://github.com/43081j)",
9
+ "Felix Boehm (https://github.com/fb55)",
10
+ "Ivan Nikulin (https://github.com/inikulin)",
11
+ "Titus (https://github.com/wooorm)"
12
+ ],
8
13
  "homepage": "https://parse5.js.org",
9
14
  "funding": "https://github.com/inikulin/parse5?sponsor=1",
10
15
  "keywords": [
@@ -14,26 +19,24 @@
14
19
  "htmlparser2"
15
20
  ],
16
21
  "license": "MIT",
17
- "main": "dist/cjs/index.js",
22
+ "main": "dist/index.js",
18
23
  "module": "dist/index.js",
19
24
  "types": "dist/index.d.ts",
20
25
  "exports": {
21
- "import": "./dist/index.js",
22
- "require": "./dist/cjs/index.js"
26
+ ".": {
27
+ "default": "./dist/index.js"
28
+ }
23
29
  },
24
30
  "dependencies": {
25
- "domhandler": "^5.0.3",
26
- "parse5": "^7.0.0"
27
- },
28
- "scripts": {
29
- "build:cjs": "tsc --moduleResolution node10 --module CommonJS --target ES6 --outDir dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json"
31
+ "domhandler": "^6.0.1",
32
+ "parse5": "^8.0.0"
30
33
  },
34
+ "scripts": {},
31
35
  "repository": {
32
36
  "type": "git",
33
37
  "url": "git://github.com/inikulin/parse5.git"
34
38
  },
35
39
  "files": [
36
- "dist/cjs/package.json",
37
40
  "dist/**/*.js",
38
41
  "dist/**/*.d.ts"
39
42
  ]
@@ -1,6 +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 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>;
package/dist/cjs/index.js DELETED
@@ -1,214 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.adapter = void 0;
4
- exports.serializeDoctypeContent = serializeDoctypeContent;
5
- const parse5_1 = require("parse5");
6
- const domhandler_1 = require("domhandler");
7
- function enquoteDoctypeId(id) {
8
- const quote = id.includes('"') ? "'" : '"';
9
- return quote + id + quote;
10
- }
11
- /** @internal */
12
- function serializeDoctypeContent(name, publicId, systemId) {
13
- let str = '!DOCTYPE ';
14
- if (name) {
15
- str += name;
16
- }
17
- if (publicId) {
18
- str += ` PUBLIC ${enquoteDoctypeId(publicId)}`;
19
- }
20
- else if (systemId) {
21
- str += ' SYSTEM';
22
- }
23
- if (systemId) {
24
- str += ` ${enquoteDoctypeId(systemId)}`;
25
- }
26
- return str;
27
- }
28
- exports.adapter = {
29
- // Re-exports from domhandler
30
- isCommentNode: domhandler_1.isComment,
31
- isElementNode: domhandler_1.isTag,
32
- isTextNode: domhandler_1.isText,
33
- //Node construction
34
- createDocument() {
35
- const node = new domhandler_1.Document([]);
36
- node['x-mode'] = parse5_1.html.DOCUMENT_MODE.NO_QUIRKS;
37
- return node;
38
- },
39
- createDocumentFragment() {
40
- return new domhandler_1.Document([]);
41
- },
42
- createElement(tagName, namespaceURI, attrs) {
43
- const attribs = Object.create(null);
44
- const attribsNamespace = Object.create(null);
45
- const attribsPrefix = Object.create(null);
46
- for (let i = 0; i < attrs.length; i++) {
47
- const attrName = attrs[i].name;
48
- attribs[attrName] = attrs[i].value;
49
- attribsNamespace[attrName] = attrs[i].namespace;
50
- attribsPrefix[attrName] = attrs[i].prefix;
51
- }
52
- const node = new domhandler_1.Element(tagName, attribs, []);
53
- node.namespace = namespaceURI;
54
- node['x-attribsNamespace'] = attribsNamespace;
55
- node['x-attribsPrefix'] = attribsPrefix;
56
- return node;
57
- },
58
- createCommentNode(data) {
59
- return new domhandler_1.Comment(data);
60
- },
61
- createTextNode(value) {
62
- return new domhandler_1.Text(value);
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;
103
- doctypeNode['x-publicId'] = publicId;
104
- doctypeNode['x-systemId'] = systemId;
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, exports.adapter.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, exports.adapter.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 (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
- };
@@ -1 +0,0 @@
1
- {"type":"commonjs"}