rusteerio 0.0.0-stage → 0.1.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/CONTRIBUTING.md +73 -0
- package/Cargo.lock +1051 -0
- package/Cargo.toml +36 -0
- package/LICENSE +21 -0
- package/README.md +252 -2
- package/RELEASING.md +138 -0
- package/THIRD_PARTY_NOTICES.md +7443 -0
- package/build.rs +3 -0
- package/dist/chunk-DKULX6VO.mjs +3185 -0
- package/dist/chunk-DKULX6VO.mjs.map +1 -0
- package/dist/chunk-OHPGEY3E.mjs +32 -0
- package/dist/chunk-OHPGEY3E.mjs.map +1 -0
- package/dist/index.cjs +3230 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +113 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.mjs +38 -0
- package/dist/index.mjs.map +1 -0
- package/dist/slim.cjs +2441 -0
- package/dist/slim.cjs.map +1 -0
- package/dist/slim.d.mts +11 -0
- package/dist/slim.d.ts +11 -0
- package/dist/slim.mjs +19 -0
- package/dist/slim.mjs.map +1 -0
- package/dist/types-BP6TpxE5.d.mts +532 -0
- package/dist/types-BP6TpxE5.d.ts +532 -0
- package/dist/utils.cjs +61 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.mts +13 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.mjs +17 -0
- package/dist/utils.mjs.map +1 -0
- package/native/src/arena.rs +1781 -0
- package/native/src/attributes.rs +923 -0
- package/native/src/codec.rs +172 -0
- package/native/src/diagnostics.rs +1249 -0
- package/native/src/extraction.rs +226 -0
- package/native/src/gc.rs +166 -0
- package/native/src/hook_sink.rs +727 -0
- package/native/src/hook_stream.rs +513 -0
- package/native/src/lib.rs +2095 -0
- package/native/src/location.rs +392 -0
- package/native/src/runtime.rs +189 -0
- package/native/src/selector.rs +1287 -0
- package/native/src/sink.rs +261 -0
- package/native/src/stream.rs +334 -0
- package/native/src/tokenizer.rs +355 -0
- package/native/src/tracker.rs +232 -0
- package/native/vendor/README.md +25 -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 +451 -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 +2305 -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/package.json +137 -4
- package/rusteerio.darwin-arm64.node +0 -0
- package/rusteerio.darwin-x64.node +0 -0
- package/rusteerio.linux-arm64-gnu.node +0 -0
- package/rusteerio.linux-arm64-musl.node +0 -0
- package/rusteerio.linux-x64-gnu.node +0 -0
- package/rusteerio.linux-x64-musl.node +0 -0
- package/rusteerio.win32-arm64-msvc.node +0 -0
- package/rusteerio.win32-x64-msvc.node +0 -0
- package/scripts/check-native.mjs +15 -0
- package/scripts/check-release.mjs +235 -0
- package/scripts/fix-declarations.mjs +27 -0
- package/scripts/generate-notices.mjs +176 -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/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 +555 -0
- package/scripts/notices/xray-MIT.txt +21 -0
- package/src/attributes.ts +271 -0
- package/src/codec.ts +74 -0
- package/src/dom.ts +87 -0
- package/src/extract-plan.ts +97 -0
- package/src/extract.ts +130 -0
- package/src/hooks.ts +220 -0
- package/src/index.ts +223 -0
- package/src/io.ts +491 -0
- package/src/native.ts +135 -0
- package/src/nodes.ts +290 -0
- package/src/parse.ts +53 -0
- package/src/parser-types.ts +157 -0
- package/src/router.ts +327 -0
- package/src/selection.ts +566 -0
- package/src/slim.ts +12 -0
- package/src/transport.ts +104 -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/tsup.config.ts +16 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// Copyright 2014-2017 The html5ever Project Developers. See the
|
|
2
|
+
// COPYRIGHT file at the top-level directory of this distribution.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
5
|
+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
6
|
+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
7
|
+
// option. This file may not be copied, modified, or distributed
|
|
8
|
+
// except according to those terms.
|
|
9
|
+
|
|
10
|
+
//! This module contains functionality for managing the DOM, including adding/removing nodes.
|
|
11
|
+
//!
|
|
12
|
+
//! It can be used by a parser to create the DOM graph structure in memory.
|
|
13
|
+
|
|
14
|
+
use crate::interface::{Attribute, ExpandedName, QualName};
|
|
15
|
+
use std::borrow::Cow;
|
|
16
|
+
use std::fmt::Debug;
|
|
17
|
+
use tendril::StrTendril;
|
|
18
|
+
use web_atoms::{LocalName, Namespace};
|
|
19
|
+
|
|
20
|
+
pub use self::NodeOrText::{AppendNode, AppendText};
|
|
21
|
+
pub use self::QuirksMode::{LimitedQuirks, NoQuirks, Quirks};
|
|
22
|
+
|
|
23
|
+
/// Something which can be inserted into the DOM.
|
|
24
|
+
///
|
|
25
|
+
/// Adjacent sibling text nodes are merged into a single node, so
|
|
26
|
+
/// the sink may not want to allocate a `Handle` for each.
|
|
27
|
+
pub enum NodeOrText<Handle> {
|
|
28
|
+
AppendNode(Handle),
|
|
29
|
+
AppendText(StrTendril),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// A document's quirks mode, for compatibility with old browsers. See [quirks mode on wikipedia]
|
|
33
|
+
/// for more information.
|
|
34
|
+
///
|
|
35
|
+
/// [quirks mode on wikipedia]: https://en.wikipedia.org/wiki/Quirks_mode
|
|
36
|
+
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
|
|
37
|
+
pub enum QuirksMode {
|
|
38
|
+
/// Full quirks mode
|
|
39
|
+
Quirks,
|
|
40
|
+
/// Almost standards mode
|
|
41
|
+
LimitedQuirks,
|
|
42
|
+
/// Standards mode
|
|
43
|
+
NoQuirks,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Special properties of an element, useful for tagging elements with this information.
|
|
47
|
+
#[derive(Default)]
|
|
48
|
+
#[non_exhaustive]
|
|
49
|
+
pub struct ElementFlags {
|
|
50
|
+
/// A document fragment should be created, associated with the element,
|
|
51
|
+
/// and returned in TreeSink::get_template_contents.
|
|
52
|
+
///
|
|
53
|
+
/// See [template-contents in the whatwg spec][whatwg template-contents].
|
|
54
|
+
///
|
|
55
|
+
/// [whatwg template-contents]: https://html.spec.whatwg.org/multipage/#template-contents
|
|
56
|
+
pub template: bool,
|
|
57
|
+
|
|
58
|
+
/// This boolean should be recorded with the element and returned
|
|
59
|
+
/// in TreeSink::is_mathml_annotation_xml_integration_point
|
|
60
|
+
///
|
|
61
|
+
/// See [html-integration-point in the whatwg spec][whatwg integration-point].
|
|
62
|
+
///
|
|
63
|
+
/// [whatwg integration-point]: https://html.spec.whatwg.org/multipage/#html-integration-point
|
|
64
|
+
pub mathml_annotation_xml_integration_point: bool,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// A constructor for an element.
|
|
68
|
+
///
|
|
69
|
+
/// # Examples
|
|
70
|
+
///
|
|
71
|
+
/// Create an element like `<div class="test-class-name"></div>`:
|
|
72
|
+
pub fn create_element<Sink>(sink: &Sink, name: QualName, attrs: Vec<Attribute>) -> Sink::Handle
|
|
73
|
+
where
|
|
74
|
+
Sink: TreeSink,
|
|
75
|
+
{
|
|
76
|
+
let mut flags = ElementFlags::default();
|
|
77
|
+
match name.expanded() {
|
|
78
|
+
expanded_name!(html "template") => flags.template = true,
|
|
79
|
+
expanded_name!(mathml "annotation-xml") => {
|
|
80
|
+
flags.mathml_annotation_xml_integration_point = attrs.iter().any(|attr| {
|
|
81
|
+
attr.name.expanded() == expanded_name!("", "encoding")
|
|
82
|
+
&& (attr.value.eq_ignore_ascii_case("text/html")
|
|
83
|
+
|| attr.value.eq_ignore_ascii_case("application/xhtml+xml"))
|
|
84
|
+
})
|
|
85
|
+
},
|
|
86
|
+
_ => {},
|
|
87
|
+
}
|
|
88
|
+
sink.create_element(name, attrs, flags)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// An abstraction over any type that can represent an element's local name and namespace.
|
|
92
|
+
pub trait ElemName: Debug {
|
|
93
|
+
fn ns(&self) -> &Namespace;
|
|
94
|
+
fn local_name(&self) -> &LocalName;
|
|
95
|
+
|
|
96
|
+
#[inline(always)]
|
|
97
|
+
fn expanded(&self) -> ExpandedName<'_> {
|
|
98
|
+
ExpandedName {
|
|
99
|
+
ns: self.ns(),
|
|
100
|
+
local: self.local_name(),
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/// Methods a parser can use to create the DOM. The DOM provider implements this trait.
|
|
106
|
+
///
|
|
107
|
+
/// Having this as a trait potentially allows multiple implementations of the DOM to be used with
|
|
108
|
+
/// the same parser.
|
|
109
|
+
pub trait TreeSink {
|
|
110
|
+
/// `Handle` is a reference to a DOM node. The tree builder requires
|
|
111
|
+
/// that a `Handle` implements `Clone` to get another reference to
|
|
112
|
+
/// the same node.
|
|
113
|
+
type Handle: Clone;
|
|
114
|
+
|
|
115
|
+
/// The overall result of parsing.
|
|
116
|
+
///
|
|
117
|
+
/// This should default to Self, but default associated types are not stable yet.
|
|
118
|
+
/// [rust-lang/rust#29661](https://github.com/rust-lang/rust/issues/29661)
|
|
119
|
+
type Output;
|
|
120
|
+
|
|
121
|
+
//
|
|
122
|
+
type ElemName<'a>: ElemName
|
|
123
|
+
where
|
|
124
|
+
Self: 'a;
|
|
125
|
+
|
|
126
|
+
/// Consume this sink and return the overall result of parsing.
|
|
127
|
+
///
|
|
128
|
+
/// TODO:This should default to `fn finish(self) -> Self::Output { self }`,
|
|
129
|
+
/// but default associated types are not stable yet.
|
|
130
|
+
/// [rust-lang/rust#29661](https://github.com/rust-lang/rust/issues/29661)
|
|
131
|
+
fn finish(self) -> Self::Output;
|
|
132
|
+
|
|
133
|
+
/// Signal a parse error.
|
|
134
|
+
fn parse_error(&self, msg: Cow<'static, str>);
|
|
135
|
+
|
|
136
|
+
/// Get a handle to the `Document` node.
|
|
137
|
+
fn get_document(&self) -> Self::Handle;
|
|
138
|
+
|
|
139
|
+
/// What is the name of this element?
|
|
140
|
+
///
|
|
141
|
+
/// Should never be called on a non-element node;
|
|
142
|
+
/// feel free to `panic!`.
|
|
143
|
+
fn elem_name<'a>(&'a self, target: &'a Self::Handle) -> Self::ElemName<'a>;
|
|
144
|
+
|
|
145
|
+
/// Create an element.
|
|
146
|
+
///
|
|
147
|
+
/// When creating a template element (`name.ns.expanded() == expanded_name!(html "template")`),
|
|
148
|
+
/// an associated document fragment called the "template contents" should
|
|
149
|
+
/// also be created. Later calls to self.get_template_contents() with that
|
|
150
|
+
/// given element return it.
|
|
151
|
+
/// See [the template element in the whatwg spec][whatwg template].
|
|
152
|
+
///
|
|
153
|
+
/// [whatwg template]: https://html.spec.whatwg.org/multipage/#the-template-element
|
|
154
|
+
fn create_element(
|
|
155
|
+
&self,
|
|
156
|
+
name: QualName,
|
|
157
|
+
attrs: Vec<Attribute>,
|
|
158
|
+
flags: ElementFlags,
|
|
159
|
+
) -> Self::Handle;
|
|
160
|
+
|
|
161
|
+
/// Create a comment node.
|
|
162
|
+
fn create_comment(&self, text: StrTendril) -> Self::Handle;
|
|
163
|
+
|
|
164
|
+
/// Create a Processing Instruction node.
|
|
165
|
+
fn create_pi(&self, target: StrTendril, data: StrTendril) -> Self::Handle;
|
|
166
|
+
|
|
167
|
+
/// Append a node as the last child of the given node. If this would
|
|
168
|
+
/// produce adjacent sibling text nodes, it should concatenate the text
|
|
169
|
+
/// instead.
|
|
170
|
+
///
|
|
171
|
+
/// The child node will not already have a parent.
|
|
172
|
+
fn append(&self, parent: &Self::Handle, child: NodeOrText<Self::Handle>);
|
|
173
|
+
|
|
174
|
+
/// When the insertion point is decided by the existence of a parent node of the
|
|
175
|
+
/// element, we consider both possibilities and send the element which will be used
|
|
176
|
+
/// if a parent node exists, along with the element to be used if there isn't one.
|
|
177
|
+
fn append_based_on_parent_node(
|
|
178
|
+
&self,
|
|
179
|
+
element: &Self::Handle,
|
|
180
|
+
prev_element: &Self::Handle,
|
|
181
|
+
child: NodeOrText<Self::Handle>,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
/// Append a `DOCTYPE` element to the `Document` node.
|
|
185
|
+
fn append_doctype_to_document(
|
|
186
|
+
&self,
|
|
187
|
+
name: StrTendril,
|
|
188
|
+
public_id: StrTendril,
|
|
189
|
+
system_id: StrTendril,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
/// Mark a HTML `<script>` as "already started".
|
|
193
|
+
fn mark_script_already_started(&self, _node: &Self::Handle) {}
|
|
194
|
+
|
|
195
|
+
/// Observer for insertion onto the actual stack of open elements.
|
|
196
|
+
/// Added by rusteerio for parse5-compatible user tree adapters.
|
|
197
|
+
fn on_stack_push(&self, _node: &Self::Handle) {}
|
|
198
|
+
|
|
199
|
+
/// Observer after a parser-driven removal from the stack. EOF teardown is
|
|
200
|
+
/// intentionally excluded: parse5 leaves its open-element stack intact.
|
|
201
|
+
fn on_stack_pop(&self, _node: &Self::Handle, _current: Option<&Self::Handle>) {}
|
|
202
|
+
|
|
203
|
+
/// Indicate that a node was popped off the stack of open elements.
|
|
204
|
+
fn pop(&self, _node: &Self::Handle) {}
|
|
205
|
+
|
|
206
|
+
/// Get a handle to a template's template contents. The tree builder
|
|
207
|
+
/// promises this will never be called with something else than
|
|
208
|
+
/// a template element.
|
|
209
|
+
fn get_template_contents(&self, target: &Self::Handle) -> Self::Handle;
|
|
210
|
+
|
|
211
|
+
/// Do two handles refer to the same node?
|
|
212
|
+
fn same_node(&self, x: &Self::Handle, y: &Self::Handle) -> bool;
|
|
213
|
+
|
|
214
|
+
/// Set the document's quirks mode.
|
|
215
|
+
fn set_quirks_mode(&self, mode: QuirksMode);
|
|
216
|
+
|
|
217
|
+
/// Append a node as the sibling immediately before the given node.
|
|
218
|
+
///
|
|
219
|
+
/// The tree builder promises that `sibling` is not a text node. However its
|
|
220
|
+
/// old previous sibling, which would become the new node's previous sibling,
|
|
221
|
+
/// could be a text node. If the new node is also a text node, the two should
|
|
222
|
+
/// be merged, as in the behavior of `append`.
|
|
223
|
+
///
|
|
224
|
+
/// NB: `new_node` may have an old parent, from which it should be removed.
|
|
225
|
+
fn append_before_sibling(&self, sibling: &Self::Handle, new_node: NodeOrText<Self::Handle>);
|
|
226
|
+
|
|
227
|
+
/// Add each attribute to the given element, if no attribute with that name
|
|
228
|
+
/// already exists. The tree builder promises this will never be called
|
|
229
|
+
/// with something else than an element.
|
|
230
|
+
fn add_attrs_if_missing(&self, target: &Self::Handle, attrs: Vec<Attribute>);
|
|
231
|
+
|
|
232
|
+
/// Associate the given form-associatable element with the form element
|
|
233
|
+
fn associate_with_form(
|
|
234
|
+
&self,
|
|
235
|
+
_target: &Self::Handle,
|
|
236
|
+
_form: &Self::Handle,
|
|
237
|
+
_nodes: (&Self::Handle, Option<&Self::Handle>),
|
|
238
|
+
) {
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/// Detach the given node from its parent.
|
|
242
|
+
fn remove_from_parent(&self, target: &Self::Handle);
|
|
243
|
+
|
|
244
|
+
/// Remove all the children from node and append them to new_parent.
|
|
245
|
+
fn reparent_children(&self, node: &Self::Handle, new_parent: &Self::Handle);
|
|
246
|
+
|
|
247
|
+
/// Returns true if the adjusted current node is an HTML integration point
|
|
248
|
+
/// and the token is a start tag.
|
|
249
|
+
fn is_mathml_annotation_xml_integration_point(&self, _handle: &Self::Handle) -> bool {
|
|
250
|
+
false
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/// Called whenever the line number changes.
|
|
254
|
+
fn set_current_line(&self, _line_number: u64) {}
|
|
255
|
+
|
|
256
|
+
fn allow_declarative_shadow_roots(&self, _intended_parent: &Self::Handle) -> bool {
|
|
257
|
+
true
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/// Attempt to attach a declarative shadow root at the given location.
|
|
261
|
+
///
|
|
262
|
+
/// Returns a boolean indicating whether the operation succeeded or not.
|
|
263
|
+
fn attach_declarative_shadow(
|
|
264
|
+
&self,
|
|
265
|
+
_location: &Self::Handle,
|
|
266
|
+
_template: &Self::Handle,
|
|
267
|
+
_attrs: &[Attribute],
|
|
268
|
+
) -> bool {
|
|
269
|
+
false
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/// Trace hooks for a garbage-collected DOM.
|
|
274
|
+
pub trait Tracer {
|
|
275
|
+
type Handle;
|
|
276
|
+
|
|
277
|
+
/// Upon a call to `trace_handles`, the tree builder will call this method
|
|
278
|
+
/// for each handle in its internal state.
|
|
279
|
+
fn trace_handle(&self, node: &Self::Handle);
|
|
280
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright 2014-2017 The html5ever Project Developers. See the
|
|
2
|
+
// COPYRIGHT file at the top-level directory of this distribution.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
5
|
+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
6
|
+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
7
|
+
// option. This file may not be copied, modified, or distributed
|
|
8
|
+
// except according to those terms.
|
|
9
|
+
|
|
10
|
+
#![allow(unexpected_cfgs)]
|
|
11
|
+
// This error is coming from code generated by PHF which we cannot directly fix
|
|
12
|
+
#![allow(clippy::empty_line_after_doc_comments)]
|
|
13
|
+
|
|
14
|
+
pub use tendril;
|
|
15
|
+
|
|
16
|
+
#[macro_use]
|
|
17
|
+
extern crate web_atoms;
|
|
18
|
+
|
|
19
|
+
/// Create a [`SmallCharSet`], with each space-separated number stored in the set.
|
|
20
|
+
///
|
|
21
|
+
/// # Examples
|
|
22
|
+
///
|
|
23
|
+
/// ```
|
|
24
|
+
/// # #[macro_use] extern crate markup5ever;
|
|
25
|
+
/// # fn main() {
|
|
26
|
+
/// let set = small_char_set!(12 54 42);
|
|
27
|
+
/// assert_eq!(set.bits,
|
|
28
|
+
/// 0b00000000_01000000_00000100_00000000_00000000_00000000_00010000_00000000);
|
|
29
|
+
/// # }
|
|
30
|
+
/// ```
|
|
31
|
+
///
|
|
32
|
+
/// [`SmallCharSet`]: struct.SmallCharSet.html
|
|
33
|
+
#[macro_export]
|
|
34
|
+
macro_rules! small_char_set ( ($($e:expr)+) => (
|
|
35
|
+
$ crate ::SmallCharSet {
|
|
36
|
+
bits: $( (1 << ($e as usize)) )|+
|
|
37
|
+
}
|
|
38
|
+
));
|
|
39
|
+
|
|
40
|
+
pub use web_atoms::{
|
|
41
|
+
local_name, namespace_prefix, namespace_url, ns, LocalName, LocalNameStaticSet, Namespace,
|
|
42
|
+
NamespaceStaticSet, Prefix, PrefixStaticSet,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
pub mod data {
|
|
46
|
+
pub use web_atoms::C1_REPLACEMENTS;
|
|
47
|
+
pub use web_atoms::NAMED_ENTITIES;
|
|
48
|
+
}
|
|
49
|
+
#[macro_use]
|
|
50
|
+
pub mod interface;
|
|
51
|
+
pub mod serialize;
|
|
52
|
+
mod util {
|
|
53
|
+
pub mod buffer_queue;
|
|
54
|
+
pub mod smallcharset;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
pub use interface::{Attribute, ExpandedName, QualName, TokenizerResult};
|
|
58
|
+
pub use util::smallcharset::SmallCharSet;
|
|
59
|
+
pub use util::*;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright 2014-2017 The html5ever Project Developers. See the
|
|
2
|
+
// COPYRIGHT file at the top-level directory of this distribution.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
5
|
+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
6
|
+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
7
|
+
// option. This file may not be copied, modified, or distributed
|
|
8
|
+
// except according to those terms.
|
|
9
|
+
//! Traits for serializing elements.
|
|
10
|
+
//!
|
|
11
|
+
//! The serializer expects the data to be xml-like (with a name,
|
|
12
|
+
//! and optional children, attrs, text, comments, doctypes, and [processing instructions]). It uses
|
|
13
|
+
//! the visitor pattern, where the serializer and the serializable objects are decoupled and
|
|
14
|
+
//! implement their own traits.
|
|
15
|
+
//!
|
|
16
|
+
//! [processing instructions]: https://en.wikipedia.org/wiki/Processing_Instruction
|
|
17
|
+
|
|
18
|
+
use crate::QualName;
|
|
19
|
+
use std::io;
|
|
20
|
+
|
|
21
|
+
//§ serializing-html-fragments
|
|
22
|
+
/// Used as a parameter to `serialize`, telling it if we want to skip the parent.
|
|
23
|
+
#[derive(Clone, PartialEq)]
|
|
24
|
+
pub enum TraversalScope {
|
|
25
|
+
/// Include the parent node when serializing.
|
|
26
|
+
IncludeNode,
|
|
27
|
+
/// Only serialize the children of the node, treating any provided qualified name as the
|
|
28
|
+
/// parent while serializing.
|
|
29
|
+
///
|
|
30
|
+
/// This is used in the implementation of [`html5ever::serialize::serialize`]
|
|
31
|
+
///
|
|
32
|
+
/// [`html5ever::serialize::serialize`]: ../../html5ever/serialize/fn.serialize.html
|
|
33
|
+
ChildrenOnly(Option<QualName>),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Types that can be serialized (according to the xml-like scheme in `Serializer`) implement this
|
|
37
|
+
/// trait.
|
|
38
|
+
pub trait Serialize {
|
|
39
|
+
/// Take the serializer and call its methods to serialize this type. The type will dictate
|
|
40
|
+
/// which methods are called and with what parameters.
|
|
41
|
+
fn serialize<S>(&self, serializer: &mut S, traversal_scope: TraversalScope) -> io::Result<()>
|
|
42
|
+
where
|
|
43
|
+
S: Serializer;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Types that are capable of serializing implement this trait
|
|
47
|
+
pub trait Serializer {
|
|
48
|
+
/// Serialize the start of an element, for example `<div class="test">`.
|
|
49
|
+
fn start_elem<'a, AttrIter>(&mut self, name: QualName, attrs: AttrIter) -> io::Result<()>
|
|
50
|
+
where
|
|
51
|
+
AttrIter: Iterator<Item = AttrRef<'a>>;
|
|
52
|
+
|
|
53
|
+
/// Serialize the end of an element, for example `</div>`.
|
|
54
|
+
fn end_elem(&mut self, name: QualName) -> io::Result<()>;
|
|
55
|
+
|
|
56
|
+
/// Serialize a plain text node.
|
|
57
|
+
fn write_text(&mut self, text: &str) -> io::Result<()>;
|
|
58
|
+
|
|
59
|
+
/// Serialize a comment node, for example `<!-- comment -->`.
|
|
60
|
+
fn write_comment(&mut self, text: &str) -> io::Result<()>;
|
|
61
|
+
|
|
62
|
+
/// Serialize a doctype node, for example `<!doctype html>`.
|
|
63
|
+
fn write_doctype(&mut self, name: &str) -> io::Result<()>;
|
|
64
|
+
|
|
65
|
+
/// Serialize a processing instruction node, for example
|
|
66
|
+
/// `<?xml-stylesheet type="text/xsl" href="style.xsl"?>`.
|
|
67
|
+
fn write_processing_instruction(&mut self, target: &str, data: &str) -> io::Result<()>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// A type alias for an attribute name and value (e.g. the `class="test"` in `<div class="test">`
|
|
71
|
+
/// is represented as `(<QualName of type class>, "test")`.
|
|
72
|
+
///
|
|
73
|
+
/// This is used in [`Serializer::start_elem`] where the value being serialized must supply an
|
|
74
|
+
/// iterator over the attributes for the current element
|
|
75
|
+
///
|
|
76
|
+
/// [`Serializer::start_elem`]: trait.Serializer.html#tymethod.start_elem
|
|
77
|
+
pub type AttrRef<'a> = (&'a QualName, &'a str);
|