@dvaji/cheerox 0.0.0-stage → 0.1.2
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/CONTRIBUTING.md +74 -0
- package/Cargo.lock +1091 -0
- package/Cargo.toml +47 -0
- package/LICENSE +21 -0
- package/README.md +121 -2
- package/RELEASING.md +114 -0
- package/THIRD_PARTY_NOTICES.md +7581 -0
- package/build.rs +3 -0
- package/cheerox.darwin-arm64.node +0 -0
- package/cheerox.darwin-x64.node +0 -0
- package/cheerox.linux-arm64-gnu.node +0 -0
- package/cheerox.linux-arm64-musl.node +0 -0
- package/cheerox.linux-x64-gnu.node +0 -0
- package/cheerox.linux-x64-musl.node +0 -0
- package/cheerox.win32-arm64-msvc.node +0 -0
- package/cheerox.win32-x64-msvc.node +0 -0
- package/dist/cheerio-compat-BKkfJEAr.mjs +1648 -0
- package/dist/cheerio-compat-BKkfJEAr.mjs.map +1 -0
- package/dist/cheerio-compat-DRLPzBdX.d.mts +88 -0
- package/dist/cheerio-compat-DRsINTwV.d.cts +88 -0
- package/dist/cheerio-compat-DRsINTwV.d.ts +88 -0
- package/dist/cheerio-compat-DcnYK9OB.cjs +1719 -0
- package/dist/cheerio-compat-DcnYK9OB.cjs.map +1 -0
- package/dist/cheerio-compat.cjs +18 -0
- package/dist/cheerio-compat.d.cts +2 -0
- package/dist/cheerio-compat.d.mts +2 -0
- package/dist/cheerio-compat.d.ts +2 -0
- package/dist/cheerio-compat.mjs +1 -0
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.mjs +53 -0
- package/dist/index.mjs.map +1 -0
- package/dist/legacy-parse.cjs +5 -0
- package/dist/legacy-parse.d.mts +8 -0
- package/dist/legacy-parse.d.ts +7 -0
- package/dist/legacy-parse.mjs +1 -0
- package/dist/modern-B7hyW4cI.d.cts +102 -0
- package/dist/modern-B7hyW4cI.d.ts +102 -0
- package/dist/modern-CHQGP0Yt.cjs +2858 -0
- package/dist/modern-CHQGP0Yt.cjs.map +1 -0
- package/dist/modern-CJvSD_y5.d.mts +102 -0
- package/dist/modern-CvXcTn82.mjs +2769 -0
- package/dist/modern-CvXcTn82.mjs.map +1 -0
- package/dist/modern.cjs +19 -0
- package/dist/modern.d.cts +3 -0
- package/dist/modern.d.mts +3 -0
- package/dist/modern.d.ts +3 -0
- package/dist/modern.mjs +3 -0
- package/dist/nodes-jbWWhssj.cjs +4210 -0
- package/dist/nodes-jbWWhssj.cjs.map +1 -0
- package/dist/nodes-sYxb5qyZ.mjs +3803 -0
- package/dist/nodes-sYxb5qyZ.mjs.map +1 -0
- package/dist/slim.cjs +16 -0
- package/dist/slim.cjs.map +1 -0
- package/dist/slim.d.cts +6 -0
- package/dist/slim.d.mts +6 -0
- package/dist/slim.d.ts +6 -0
- package/dist/slim.mjs +12 -0
- package/dist/slim.mjs.map +1 -0
- package/dist/types-CA01Zg3r.d.cts +526 -0
- package/dist/types-CA01Zg3r.d.mts +526 -0
- package/dist/types-CA01Zg3r.d.ts +526 -0
- package/dist/utils.cjs +31 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +8 -0
- package/dist/utils.d.mts +8 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.mjs +25 -0
- package/dist/utils.mjs.map +1 -0
- package/native/src/arena.rs +2109 -0
- package/native/src/attributes.rs +946 -0
- package/native/src/codec.rs +298 -0
- package/native/src/diagnostics.rs +1249 -0
- package/native/src/document_order.rs +711 -0
- package/native/src/extraction.rs +321 -0
- package/native/src/gc.rs +175 -0
- package/native/src/hook_sink.rs +801 -0
- package/native/src/hook_stream.rs +513 -0
- package/native/src/id_hash.rs +42 -0
- package/native/src/immutable.rs +333 -0
- package/native/src/lib.rs +4120 -0
- package/native/src/location.rs +392 -0
- package/native/src/markup_tokenizer.rs +668 -0
- package/native/src/runtime.rs +368 -0
- package/native/src/selector.rs +1596 -0
- package/native/src/sink.rs +274 -0
- package/native/src/snapshot.rs +672 -0
- package/native/src/stream.rs +334 -0
- package/native/src/tokenizer.rs +581 -0
- package/native/src/tracker.rs +232 -0
- package/native/vendor/README.md +35 -0
- package/native/vendor/html5ever-0.35.0/.cargo_vcs_info.json +6 -0
- package/native/vendor/html5ever-0.35.0/Cargo.lock +828 -0
- package/native/vendor/html5ever-0.35.0/Cargo.toml +85 -0
- package/native/vendor/html5ever-0.35.0/LICENSE-APACHE +201 -0
- package/native/vendor/html5ever-0.35.0/LICENSE-MIT +25 -0
- package/native/vendor/html5ever-0.35.0/README.md +60 -0
- package/native/vendor/html5ever-0.35.0/benches/html5ever.rs +86 -0
- package/native/vendor/html5ever-0.35.0/data/bench/lipsum-zh.html +19 -0
- package/native/vendor/html5ever-0.35.0/data/bench/lipsum.html +40 -0
- package/native/vendor/html5ever-0.35.0/data/bench/medium-fragment.html +24 -0
- package/native/vendor/html5ever-0.35.0/data/bench/small-fragment.html +7 -0
- package/native/vendor/html5ever-0.35.0/data/bench/strong.html +1 -0
- package/native/vendor/html5ever-0.35.0/data/bench/tiny-fragment.html +1 -0
- package/native/vendor/html5ever-0.35.0/examples/arena.rs +356 -0
- package/native/vendor/html5ever-0.35.0/examples/capi/tokenize.c +74 -0
- package/native/vendor/html5ever-0.35.0/examples/noop-tokenize.rs +47 -0
- package/native/vendor/html5ever-0.35.0/examples/noop-tree-builder.rs +132 -0
- package/native/vendor/html5ever-0.35.0/examples/print-tree-actions.rs +185 -0
- package/native/vendor/html5ever-0.35.0/examples/tokenize.rs +111 -0
- package/native/vendor/html5ever-0.35.0/src/driver.rs +148 -0
- package/native/vendor/html5ever-0.35.0/src/lib.rs +30 -0
- package/native/vendor/html5ever-0.35.0/src/macros.rs +34 -0
- package/native/vendor/html5ever-0.35.0/src/serialize/mod.rs +255 -0
- package/native/vendor/html5ever-0.35.0/src/tokenizer/char_ref/mod.rs +530 -0
- package/native/vendor/html5ever-0.35.0/src/tokenizer/interface.rs +99 -0
- package/native/vendor/html5ever-0.35.0/src/tokenizer/mod.rs +2628 -0
- package/native/vendor/html5ever-0.35.0/src/tokenizer/states.rs +97 -0
- package/native/vendor/html5ever-0.35.0/src/tree_builder/data.rs +170 -0
- package/native/vendor/html5ever-0.35.0/src/tree_builder/mod.rs +1848 -0
- package/native/vendor/html5ever-0.35.0/src/tree_builder/rules.rs +1494 -0
- package/native/vendor/html5ever-0.35.0/src/tree_builder/tag_sets.rs +114 -0
- package/native/vendor/html5ever-0.35.0/src/tree_builder/types.rs +91 -0
- package/native/vendor/html5ever-0.35.0/src/util/str.rs +52 -0
- package/native/vendor/html5gum-0.8.4/Cargo.lock +1006 -0
- package/native/vendor/html5gum-0.8.4/Cargo.toml +109 -0
- package/native/vendor/html5gum-0.8.4/LICENSE +19 -0
- package/native/vendor/html5gum-0.8.4/README.md +110 -0
- package/native/vendor/html5gum-0.8.4/benches/files/0050.html +2131 -0
- package/native/vendor/html5gum-0.8.4/benches/files/6D30.html +1004 -0
- package/native/vendor/html5gum-0.8.4/benches/files.rs +32 -0
- package/native/vendor/html5gum-0.8.4/benches/patterns.rs +31 -0
- package/native/vendor/html5gum-0.8.4/src/arrayvec.rs +29 -0
- package/native/vendor/html5gum-0.8.4/src/char_validator.rs +134 -0
- package/native/vendor/html5gum-0.8.4/src/emitters/callback.rs +676 -0
- package/native/vendor/html5gum-0.8.4/src/emitters/default.rs +207 -0
- package/native/vendor/html5gum-0.8.4/src/emitters/emitter.rs +344 -0
- package/native/vendor/html5gum-0.8.4/src/emitters/html5ever.rs +306 -0
- package/native/vendor/html5gum-0.8.4/src/emitters/mod.rs +25 -0
- package/native/vendor/html5gum-0.8.4/src/entities.rs +3342 -0
- package/native/vendor/html5gum-0.8.4/src/error.rs +96 -0
- package/native/vendor/html5gum-0.8.4/src/htmlstring.rs +130 -0
- package/native/vendor/html5gum-0.8.4/src/lib.rs +66 -0
- package/native/vendor/html5gum-0.8.4/src/machine.rs +2136 -0
- package/native/vendor/html5gum-0.8.4/src/machine_helper.rs +277 -0
- package/native/vendor/html5gum-0.8.4/src/read_helper.rs +244 -0
- package/native/vendor/html5gum-0.8.4/src/reader.rs +440 -0
- package/native/vendor/html5gum-0.8.4/src/span.rs +98 -0
- package/native/vendor/html5gum-0.8.4/src/state.rs +16 -0
- package/native/vendor/html5gum-0.8.4/src/testutils.rs +71 -0
- package/native/vendor/html5gum-0.8.4/src/tokenizer.rs +189 -0
- package/native/vendor/html5gum-0.8.4/src/utils.rs +88 -0
- package/native/vendor/markup5ever-0.35.0/.cargo_vcs_info.json +6 -0
- package/native/vendor/markup5ever-0.35.0/Cargo.toml +45 -0
- package/native/vendor/markup5ever-0.35.0/LICENSE-APACHE +201 -0
- package/native/vendor/markup5ever-0.35.0/LICENSE-MIT +25 -0
- package/native/vendor/markup5ever-0.35.0/interface/mod.rs +422 -0
- package/native/vendor/markup5ever-0.35.0/interface/tree_builder.rs +280 -0
- package/native/vendor/markup5ever-0.35.0/lib.rs +59 -0
- package/native/vendor/markup5ever-0.35.0/serialize.rs +77 -0
- package/native/vendor/markup5ever-0.35.0/util/buffer_queue.rs +333 -0
- package/native/vendor/markup5ever-0.35.0/util/smallcharset.rs +88 -0
- package/native/vendor/scraper-0.24.0/Cargo.toml +52 -0
- package/native/vendor/scraper-0.24.0/LICENSE +15 -0
- package/native/vendor/scraper-0.24.0/src/element_ref/element.rs +212 -0
- package/native/vendor/scraper-0.24.0/src/element_ref/mod.rs +236 -0
- package/native/vendor/scraper-0.24.0/src/element_ref/serializable.rs +15 -0
- package/native/vendor/scraper-0.24.0/src/error/utils.rs +91 -0
- package/native/vendor/scraper-0.24.0/src/error.rs +118 -0
- package/native/vendor/scraper-0.24.0/src/html/mod.rs +270 -0
- package/native/vendor/scraper-0.24.0/src/html/serializable.rs +27 -0
- package/native/vendor/scraper-0.24.0/src/html/tree_sink.rs +285 -0
- package/native/vendor/scraper-0.24.0/src/lib.rs +180 -0
- package/native/vendor/scraper-0.24.0/src/node/serializable.rs +52 -0
- package/native/vendor/scraper-0.24.0/src/node.rs +465 -0
- package/native/vendor/scraper-0.24.0/src/selectable.rs +70 -0
- package/native/vendor/scraper-0.24.0/src/selector.rs +290 -0
- package/package.json +167 -4
- package/scripts/check-native.mjs +15 -0
- package/scripts/check-release.mjs +234 -0
- package/scripts/fix-declarations.mjs +39 -0
- package/scripts/generate-notices.mjs +194 -0
- package/scripts/notices/README.md +13 -0
- package/scripts/notices/cheerio-MIT.txt +21 -0
- package/scripts/notices/html5ever-AUTHORS.txt +20 -0
- package/scripts/notices/html5ever-COPYRIGHT.txt +8 -0
- package/scripts/notices/html5ever-LICENSE-APACHE.txt +201 -0
- package/scripts/notices/html5ever-LICENSE-MIT.txt +25 -0
- package/scripts/notices/htmlparser2-MIT.txt +18 -0
- package/scripts/notices/napi-rs-MIT.txt +43 -0
- package/scripts/notices/neon-MIT.txt +19 -0
- package/scripts/notices/runtime-01c266bced4a434da005.txt +3 -0
- package/scripts/notices/runtime-0a54e647fe54104658b5.txt +14 -0
- package/scripts/notices/runtime-0b74dfa0bcee5c420c6b.txt +25 -0
- package/scripts/notices/runtime-0d542e0c8804e39aa7f3.txt +177 -0
- package/scripts/notices/runtime-0f96a83840e146e43c0e.txt +21 -0
- package/scripts/notices/runtime-123a331b5dbf04c30097.txt +25 -0
- package/scripts/notices/runtime-172020dbfd5b53a226df.txt +34 -0
- package/scripts/notices/runtime-209fbbe0ad52d9235e37.txt +26 -0
- package/scripts/notices/runtime-23f18e03dc49df91622f.txt +23 -0
- package/scripts/notices/runtime-268872b9816f90fd8e85.txt +220 -0
- package/scripts/notices/runtime-35242e7a83f69875e6ed.txt +176 -0
- package/scripts/notices/runtime-378f5840b258e2779c39.txt +25 -0
- package/scripts/notices/runtime-4108245a1f2df9d4e94d.txt +25 -0
- package/scripts/notices/runtime-4455bf75a91154108304.txt +21 -0
- package/scripts/notices/runtime-553fffcd9b1cb158bc3e.txt +13 -0
- package/scripts/notices/runtime-62c7a1e35f56406896d7.txt +176 -0
- package/scripts/notices/runtime-6485b8ed310d3f0340bf.txt +25 -0
- package/scripts/notices/runtime-69fef7b0f322a6555415.txt +201 -0
- package/scripts/notices/runtime-6df43f6f4b5d4587f3d8.txt +187 -0
- package/scripts/notices/runtime-799e9ca9d179295ef372.txt +24 -0
- package/scripts/notices/runtime-7b63ecd5f1902af1b637.txt +25 -0
- package/scripts/notices/runtime-7bc7d5de2a0b793d4e1a.txt +21 -0
- package/scripts/notices/runtime-7e12e5df4bae12cb2158.txt +24 -0
- package/scripts/notices/runtime-861399f8c21c042b1105.txt +12 -0
- package/scripts/notices/runtime-8ada45cd9f843acf64e4.txt +201 -0
- package/scripts/notices/runtime-90eb64f0279b0d9432ac.txt +12 -0
- package/scripts/notices/runtime-a60eea817514531668d7.txt +201 -0
- package/scripts/notices/runtime-a7c936ff1ed8fa340172.txt +25 -0
- package/scripts/notices/runtime-ab6eec6caf0fa5775e41.txt +275 -0
- package/scripts/notices/runtime-b1181a40b2a7b25cf66f.txt +19 -0
- package/scripts/notices/runtime-b71bd43a069ca0641a9e.txt +25 -0
- package/scripts/notices/runtime-c16f8dcf1a368b83be78.txt +201 -0
- package/scripts/notices/runtime-c2cfccb812fe482101a8.txt +21 -0
- package/scripts/notices/runtime-e99d88d232bf57d70f0f.txt +25 -0
- package/scripts/notices/runtime-f32fb3b417a194167cfa.txt +9 -0
- package/scripts/notices/runtime-f5062c9a188d81dfe66b.txt +39 -0
- package/scripts/notices/runtime-f9070a832833fa7488fd.txt +4 -0
- package/scripts/notices/runtime-fab3dd6bdab226f1c086.txt +373 -0
- package/scripts/notices/runtime-fba3318d0c600380177e.txt +62 -0
- package/scripts/notices/runtime-ff8f68cb076caf8cefe7.txt +25 -0
- package/scripts/notices/runtime-ff92bed461f50338dd70.txt +74 -0
- package/scripts/notices/runtime.json +1632 -0
- package/scripts/notices/sources.json +561 -0
- package/scripts/notices/xray-MIT.txt +21 -0
- package/src/attribute-object.ts +71 -0
- package/src/attributes.ts +308 -0
- package/src/cheerio-compat/css.ts +58 -0
- package/src/cheerio-compat/render.ts +106 -0
- package/src/cheerio-compat/selectors.ts +51 -0
- package/src/cheerio-compat/types.ts +52 -0
- package/src/cheerio-compat.ts +2055 -0
- package/src/codec.ts +96 -0
- package/src/dom.ts +87 -0
- package/src/extract-plan.ts +97 -0
- package/src/extract.ts +322 -0
- package/src/hooks.ts +369 -0
- package/src/index.ts +48 -0
- package/src/io.ts +491 -0
- package/src/match.ts +207 -0
- package/src/modern.ts +259 -0
- package/src/native.ts +149 -0
- package/src/nodes.ts +831 -0
- package/src/parse.ts +53 -0
- package/src/parser-types.ts +157 -0
- package/src/router.ts +1129 -0
- package/src/selection.ts +682 -0
- package/src/slim.ts +12 -0
- package/src/snapshot.ts +291 -0
- package/src/transport.ts +113 -0
- package/src/types.ts +186 -0
- package/src/utils.ts +29 -0
- package/src/workers.ts +21 -0
- package/tsconfig.json +15 -0
- package/tsdown.config.mjs +17 -0
package/src/parse.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { requireNative } from './native.js';
|
|
2
|
+
import { getNode, importNodes, nodeBinding, operation } from './nodes.js';
|
|
3
|
+
import { routeDocument } from './router.js';
|
|
4
|
+
import { parseNativeDocument, cleanParserOptions } from './hooks.js';
|
|
5
|
+
import type { AnyNode, Document, InternalOptions, ParentNode } from './types.js';
|
|
6
|
+
|
|
7
|
+
type ParseContent = string | Buffer | Document | AnyNode | AnyNode[];
|
|
8
|
+
type Parser = (content: string, options: InternalOptions, isDocument: boolean, context: ParentNode | null) => Document;
|
|
9
|
+
|
|
10
|
+
/** Parse with the Rust HTML5 or HTML/XML engine, preserving fragment context. */
|
|
11
|
+
function parseWithNative(content: string, options: InternalOptions, isDocument: boolean, context: ParentNode | null): Document {
|
|
12
|
+
if (!isDocument && context) {
|
|
13
|
+
const document = nodeBinding(context)?.document
|
|
14
|
+
?? routeDocument(new (requireNative().NativeDocument)('', false, JSON.stringify(cleanParserOptions(options))), options);
|
|
15
|
+
const contextId = importNodes(document, [context])[0];
|
|
16
|
+
const children = operation<number[]>(document, 'create', { html: content, contextId, options });
|
|
17
|
+
const root = operation<number>(document, 'createNode', { type: 'root', options });
|
|
18
|
+
operation(document, 'setNode', { id: root, field: 'children', value: children, options });
|
|
19
|
+
return getNode(document, root) as Document;
|
|
20
|
+
}
|
|
21
|
+
const document = parseNativeDocument(content, options, isDocument);
|
|
22
|
+
return getNode(document, document.rootId()) as Document;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The HTML5 adapter uses Rust's HTML5 tree builder. */
|
|
26
|
+
export function parseWithParse5(content: string, options: InternalOptions, isDocument: boolean, context: ParentNode | null): Document {
|
|
27
|
+
return parseWithNative(content, { ...options, _useHtmlParser2: false, xml: false, xmlMode: false }, isDocument, context);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The htmlparser2-compatible adapter uses the Rust HTML/XML tokenizer. */
|
|
31
|
+
export function parseWithHtmlparser2(content: string, options: InternalOptions): Document {
|
|
32
|
+
return parseWithNative(content, { ...options, _useHtmlParser2: true }, false, null);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { parseWithHtmlparser2 as parseDocument };
|
|
36
|
+
|
|
37
|
+
/** Normalize parser inputs while keeping every DOM operation in the native arena. */
|
|
38
|
+
export function getParse(parser: Parser) {
|
|
39
|
+
return function parse(content: ParseContent, options: InternalOptions, isDocument: boolean, context: ParentNode | null): Document {
|
|
40
|
+
if (Buffer.isBuffer(content)) content = content.toString();
|
|
41
|
+
if (typeof content === 'string') return parser(content, options, isDocument, context);
|
|
42
|
+
if (!Array.isArray(content) && content.type === 'root' && nodeBinding(content)) return content;
|
|
43
|
+
const document = routeDocument(new (requireNative().NativeDocument)('', false, JSON.stringify(cleanParserOptions(options))), options);
|
|
44
|
+
const ids = importNodes(document, content);
|
|
45
|
+
if (!Array.isArray(content) && content.type === 'root') return getNode(document, ids[0]) as Document;
|
|
46
|
+
operation(document, 'setNode', { id: document.rootId(), field: 'children', value: ids, options });
|
|
47
|
+
return getNode(document, document.rootId()) as Document;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const parse = getParse((content, options, isDocument, context) => options._useHtmlParser2
|
|
52
|
+
? parseWithHtmlparser2(content, options)
|
|
53
|
+
: parseWithParse5(content, options, isDocument, context));
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { AnyNode, ParentNode, ChildNode, Document, Element, Comment, Text, ProcessingInstruction, SourceCodeLocation, TagSourceCodeLocation } from './types.js';
|
|
2
|
+
|
|
3
|
+
/** Parse5-compatible diagnostics, declared locally without a parser dependency. */
|
|
4
|
+
declare enum ERR {
|
|
5
|
+
controlCharacterInInputStream = "control-character-in-input-stream",
|
|
6
|
+
noncharacterInInputStream = "noncharacter-in-input-stream",
|
|
7
|
+
surrogateInInputStream = "surrogate-in-input-stream",
|
|
8
|
+
nonVoidHtmlElementStartTagWithTrailingSolidus = "non-void-html-element-start-tag-with-trailing-solidus",
|
|
9
|
+
endTagWithAttributes = "end-tag-with-attributes",
|
|
10
|
+
endTagWithTrailingSolidus = "end-tag-with-trailing-solidus",
|
|
11
|
+
unexpectedSolidusInTag = "unexpected-solidus-in-tag",
|
|
12
|
+
unexpectedNullCharacter = "unexpected-null-character",
|
|
13
|
+
unexpectedQuestionMarkInsteadOfTagName = "unexpected-question-mark-instead-of-tag-name",
|
|
14
|
+
invalidFirstCharacterOfTagName = "invalid-first-character-of-tag-name",
|
|
15
|
+
unexpectedEqualsSignBeforeAttributeName = "unexpected-equals-sign-before-attribute-name",
|
|
16
|
+
missingEndTagName = "missing-end-tag-name",
|
|
17
|
+
unexpectedCharacterInAttributeName = "unexpected-character-in-attribute-name",
|
|
18
|
+
unknownNamedCharacterReference = "unknown-named-character-reference",
|
|
19
|
+
missingSemicolonAfterCharacterReference = "missing-semicolon-after-character-reference",
|
|
20
|
+
unexpectedCharacterAfterDoctypeSystemIdentifier = "unexpected-character-after-doctype-system-identifier",
|
|
21
|
+
unexpectedCharacterInUnquotedAttributeValue = "unexpected-character-in-unquoted-attribute-value",
|
|
22
|
+
eofBeforeTagName = "eof-before-tag-name",
|
|
23
|
+
eofInTag = "eof-in-tag",
|
|
24
|
+
missingAttributeValue = "missing-attribute-value",
|
|
25
|
+
missingWhitespaceBetweenAttributes = "missing-whitespace-between-attributes",
|
|
26
|
+
missingWhitespaceAfterDoctypePublicKeyword = "missing-whitespace-after-doctype-public-keyword",
|
|
27
|
+
missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers = "missing-whitespace-between-doctype-public-and-system-identifiers",
|
|
28
|
+
missingWhitespaceAfterDoctypeSystemKeyword = "missing-whitespace-after-doctype-system-keyword",
|
|
29
|
+
missingQuoteBeforeDoctypePublicIdentifier = "missing-quote-before-doctype-public-identifier",
|
|
30
|
+
missingQuoteBeforeDoctypeSystemIdentifier = "missing-quote-before-doctype-system-identifier",
|
|
31
|
+
missingDoctypePublicIdentifier = "missing-doctype-public-identifier",
|
|
32
|
+
missingDoctypeSystemIdentifier = "missing-doctype-system-identifier",
|
|
33
|
+
abruptDoctypePublicIdentifier = "abrupt-doctype-public-identifier",
|
|
34
|
+
abruptDoctypeSystemIdentifier = "abrupt-doctype-system-identifier",
|
|
35
|
+
cdataInHtmlContent = "cdata-in-html-content",
|
|
36
|
+
incorrectlyOpenedComment = "incorrectly-opened-comment",
|
|
37
|
+
eofInScriptHtmlCommentLikeText = "eof-in-script-html-comment-like-text",
|
|
38
|
+
eofInDoctype = "eof-in-doctype",
|
|
39
|
+
nestedComment = "nested-comment",
|
|
40
|
+
abruptClosingOfEmptyComment = "abrupt-closing-of-empty-comment",
|
|
41
|
+
eofInComment = "eof-in-comment",
|
|
42
|
+
incorrectlyClosedComment = "incorrectly-closed-comment",
|
|
43
|
+
eofInCdata = "eof-in-cdata",
|
|
44
|
+
absenceOfDigitsInNumericCharacterReference = "absence-of-digits-in-numeric-character-reference",
|
|
45
|
+
nullCharacterReference = "null-character-reference",
|
|
46
|
+
surrogateCharacterReference = "surrogate-character-reference",
|
|
47
|
+
characterReferenceOutsideUnicodeRange = "character-reference-outside-unicode-range",
|
|
48
|
+
controlCharacterReference = "control-character-reference",
|
|
49
|
+
noncharacterCharacterReference = "noncharacter-character-reference",
|
|
50
|
+
missingWhitespaceBeforeDoctypeName = "missing-whitespace-before-doctype-name",
|
|
51
|
+
missingDoctypeName = "missing-doctype-name",
|
|
52
|
+
invalidCharacterSequenceAfterDoctypeName = "invalid-character-sequence-after-doctype-name",
|
|
53
|
+
duplicateAttribute = "duplicate-attribute",
|
|
54
|
+
nonConformingDoctype = "non-conforming-doctype",
|
|
55
|
+
missingDoctype = "missing-doctype",
|
|
56
|
+
misplacedDoctype = "misplaced-doctype",
|
|
57
|
+
endTagWithoutMatchingOpenElement = "end-tag-without-matching-open-element",
|
|
58
|
+
closingOfElementWithOpenChildElements = "closing-of-element-with-open-child-elements",
|
|
59
|
+
disallowedContentInNoscriptInHead = "disallowed-content-in-noscript-in-head",
|
|
60
|
+
openElementsLeftAfterEof = "open-elements-left-after-eof",
|
|
61
|
+
abandonedHeadElementChild = "abandoned-head-element-child",
|
|
62
|
+
misplacedStartTagForHeadElement = "misplaced-start-tag-for-head-element",
|
|
63
|
+
nestedNoscriptInHead = "nested-noscript-in-head",
|
|
64
|
+
eofInElementThatCanContainOnlyText = "eof-in-element-that-can-contain-only-text"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ParserErrorCode = ERR;
|
|
68
|
+
export interface ParserError extends SourceCodeLocation { code: ParserErrorCode }
|
|
69
|
+
export type ParserErrorHandler = (error: ParserError) => void;
|
|
70
|
+
|
|
71
|
+
declare enum NS {
|
|
72
|
+
HTML = 'http://www.w3.org/1999/xhtml',
|
|
73
|
+
MATHML = 'http://www.w3.org/1998/Math/MathML',
|
|
74
|
+
SVG = 'http://www.w3.org/2000/svg',
|
|
75
|
+
XLINK = 'http://www.w3.org/1999/xlink',
|
|
76
|
+
XML = 'http://www.w3.org/XML/1998/namespace',
|
|
77
|
+
XMLNS = 'http://www.w3.org/2000/xmlns/',
|
|
78
|
+
}
|
|
79
|
+
declare enum DOCUMENT_MODE {
|
|
80
|
+
NO_QUIRKS = 'no-quirks', QUIRKS = 'quirks', LIMITED_QUIRKS = 'limited-quirks',
|
|
81
|
+
}
|
|
82
|
+
export type NamespaceURI = NS;
|
|
83
|
+
export type DocumentMode = DOCUMENT_MODE;
|
|
84
|
+
export interface TreeAdapterAttribute { name: string; value: string; namespace?: string; prefix?: string }
|
|
85
|
+
|
|
86
|
+
/** The HTML5 adapter shape used by Cheerio's DOM representation. */
|
|
87
|
+
export interface TreeAdapter {
|
|
88
|
+
adoptAttributes(recipient: Element, attrs: TreeAdapterAttribute[]): void;
|
|
89
|
+
appendChild(parentNode: ParentNode, newNode: ChildNode): void;
|
|
90
|
+
createCommentNode(data: string): Comment;
|
|
91
|
+
createTextNode(value: string): Text;
|
|
92
|
+
createDocument(): Document;
|
|
93
|
+
createDocumentFragment(): Document;
|
|
94
|
+
createElement(tagName: string, namespaceURI: NamespaceURI, attrs: TreeAdapterAttribute[]): Element;
|
|
95
|
+
detachNode(node: ChildNode): void;
|
|
96
|
+
getAttrList(element: Element): TreeAdapterAttribute[];
|
|
97
|
+
getChildNodes(node: ParentNode): ChildNode[];
|
|
98
|
+
getCommentNodeContent(node: Comment): string;
|
|
99
|
+
getDocumentMode(document: Document): DocumentMode;
|
|
100
|
+
getDocumentTypeNodeName(node: ProcessingInstruction): string;
|
|
101
|
+
getDocumentTypeNodePublicId(node: ProcessingInstruction): string;
|
|
102
|
+
getDocumentTypeNodeSystemId(node: ProcessingInstruction): string;
|
|
103
|
+
getFirstChild(node: ParentNode): ChildNode | null;
|
|
104
|
+
getNamespaceURI(element: Element): NamespaceURI;
|
|
105
|
+
getNodeSourceCodeLocation(node: AnyNode): TagSourceCodeLocation | undefined | null;
|
|
106
|
+
getParentNode(node: AnyNode): ParentNode | null;
|
|
107
|
+
getTagName(element: Element): string;
|
|
108
|
+
getTextNodeContent(node: Text): string;
|
|
109
|
+
getTemplateContent(element: Element): Document;
|
|
110
|
+
insertBefore(parent: ParentNode, child: ChildNode, reference: ChildNode): void;
|
|
111
|
+
insertText(parent: ParentNode, text: string): void;
|
|
112
|
+
insertTextBefore(parent: ParentNode, text: string, reference: ChildNode): void;
|
|
113
|
+
isCommentNode(node: AnyNode): node is Comment;
|
|
114
|
+
isDocumentTypeNode(node: AnyNode): node is ProcessingInstruction;
|
|
115
|
+
isElementNode(node: AnyNode): node is Element;
|
|
116
|
+
isTextNode(node: AnyNode): node is Text;
|
|
117
|
+
setDocumentMode(document: Document, mode: DocumentMode): void;
|
|
118
|
+
setDocumentType(document: Document, name: string, publicId: string, systemId: string): void;
|
|
119
|
+
setNodeSourceCodeLocation(node: AnyNode, location: TagSourceCodeLocation | null): void;
|
|
120
|
+
updateNodeSourceCodeLocation(node: AnyNode, location: Partial<TagSourceCodeLocation>): void;
|
|
121
|
+
setTemplateContent(element: Element, content: Document): void;
|
|
122
|
+
onItemPush?: (item: Element) => void;
|
|
123
|
+
onItemPop?: (item: Element, newTop: ParentNode) => void;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
declare enum QuoteType { NoValue = 0, Unquoted = 1, Single = 2, Double = 3 }
|
|
127
|
+
export interface TokenizerCallbacks {
|
|
128
|
+
onattribdata(start: number, endIndex: number): void;
|
|
129
|
+
onattribentity(codepoint: number): void;
|
|
130
|
+
onattribend(quote: QuoteType, endIndex: number): void;
|
|
131
|
+
onattribname(start: number, endIndex: number): void;
|
|
132
|
+
oncdata(start: number, endIndex: number, endOffset: number): void;
|
|
133
|
+
onclosetag(start: number, endIndex: number): void;
|
|
134
|
+
oncomment(start: number, endIndex: number, endOffset: number): void;
|
|
135
|
+
ondeclaration(start: number, endIndex: number): void;
|
|
136
|
+
onend(): void;
|
|
137
|
+
onopentagend(endIndex: number): void;
|
|
138
|
+
onopentagname(start: number, endIndex: number): void;
|
|
139
|
+
onprocessinginstruction(start: number, endIndex: number): void;
|
|
140
|
+
onselfclosingtag(endIndex: number): void;
|
|
141
|
+
ontext(start: number, endIndex: number): void;
|
|
142
|
+
ontextentity(codepoint: number, endIndex: number): void;
|
|
143
|
+
}
|
|
144
|
+
export interface Tokenizer {
|
|
145
|
+
running: boolean;
|
|
146
|
+
reset(): void;
|
|
147
|
+
write(chunk: string): void;
|
|
148
|
+
end(): void;
|
|
149
|
+
pause(): void;
|
|
150
|
+
resume(): void;
|
|
151
|
+
}
|
|
152
|
+
export interface TokenizerOptions { xmlMode?: boolean; decodeEntities?: boolean }
|
|
153
|
+
export interface TokenizerConstructor {
|
|
154
|
+
new (options: TokenizerOptions, callbacks: TokenizerCallbacks): Tokenizer;
|
|
155
|
+
// The native facade accepts third-party tokenizer classes with private state.
|
|
156
|
+
new (options: TokenizerOptions, callbacks: TokenizerCallbacks): any;
|
|
157
|
+
}
|