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,422 @@
|
|
|
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
|
+
//! Types for tag and attribute names, and tree-builder functionality.
|
|
10
|
+
|
|
11
|
+
use std::cell::Ref;
|
|
12
|
+
use std::fmt;
|
|
13
|
+
use tendril::StrTendril;
|
|
14
|
+
use web_atoms::{LocalName, Namespace, Prefix};
|
|
15
|
+
|
|
16
|
+
pub use self::tree_builder::{create_element, AppendNode, AppendText, ElementFlags, NodeOrText};
|
|
17
|
+
pub use self::tree_builder::{ElemName, Tracer, TreeSink};
|
|
18
|
+
pub use self::tree_builder::{LimitedQuirks, NoQuirks, Quirks, QuirksMode};
|
|
19
|
+
|
|
20
|
+
/// An [expanded name], containing the tag and the namespace.
|
|
21
|
+
///
|
|
22
|
+
/// [expanded name]: https://www.w3.org/TR/REC-xml-names/#dt-expname
|
|
23
|
+
#[derive(Copy, Clone, Eq, Hash, PartialEq)]
|
|
24
|
+
pub struct ExpandedName<'a> {
|
|
25
|
+
pub ns: &'a Namespace,
|
|
26
|
+
pub local: &'a LocalName,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
impl ElemName for ExpandedName<'_> {
|
|
30
|
+
#[inline(always)]
|
|
31
|
+
fn ns(&self) -> &Namespace {
|
|
32
|
+
self.ns
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[inline(always)]
|
|
36
|
+
fn local_name(&self) -> &LocalName {
|
|
37
|
+
self.local
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
impl<'a> ElemName for Ref<'a, ExpandedName<'a>> {
|
|
42
|
+
#[inline(always)]
|
|
43
|
+
fn ns(&self) -> &Namespace {
|
|
44
|
+
self.ns
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#[inline(always)]
|
|
48
|
+
fn local_name(&self) -> &LocalName {
|
|
49
|
+
self.local
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
impl fmt::Debug for ExpandedName<'_> {
|
|
54
|
+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
55
|
+
if self.ns.is_empty() {
|
|
56
|
+
write!(f, "{}", self.local)
|
|
57
|
+
} else {
|
|
58
|
+
write!(f, "{{{}}}:{}", self.ns, self.local)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#[must_use]
|
|
64
|
+
#[derive(Debug, PartialEq)]
|
|
65
|
+
pub enum TokenizerResult<Handle> {
|
|
66
|
+
Done,
|
|
67
|
+
Script(Handle),
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// Helper to quickly create an expanded name.
|
|
71
|
+
///
|
|
72
|
+
/// Can be used with no namespace as `expanded_name!("", "some_name")`
|
|
73
|
+
/// or with a namespace as `expanded_name!(ns "some_name")`. In the
|
|
74
|
+
/// latter case, `ns` is one of the symbols which the [`ns!`][ns]
|
|
75
|
+
/// macro accepts; note the lack of a comma between the `ns` and
|
|
76
|
+
/// `"some_name"`.
|
|
77
|
+
///
|
|
78
|
+
/// [ns]: macro.ns.html
|
|
79
|
+
///
|
|
80
|
+
/// # Examples
|
|
81
|
+
///
|
|
82
|
+
/// ```
|
|
83
|
+
/// # #[macro_use] extern crate markup5ever;
|
|
84
|
+
///
|
|
85
|
+
/// # fn main() {
|
|
86
|
+
/// use markup5ever::ExpandedName;
|
|
87
|
+
///
|
|
88
|
+
/// assert_eq!(
|
|
89
|
+
/// expanded_name!("", "div"),
|
|
90
|
+
/// ExpandedName {
|
|
91
|
+
/// ns: &ns!(),
|
|
92
|
+
/// local: &local_name!("div")
|
|
93
|
+
/// }
|
|
94
|
+
/// );
|
|
95
|
+
///
|
|
96
|
+
/// assert_eq!(
|
|
97
|
+
/// expanded_name!(html "div"),
|
|
98
|
+
/// ExpandedName {
|
|
99
|
+
/// ns: &ns!(html),
|
|
100
|
+
/// local: &local_name!("div")
|
|
101
|
+
/// }
|
|
102
|
+
/// );
|
|
103
|
+
/// # }
|
|
104
|
+
#[macro_export]
|
|
105
|
+
macro_rules! expanded_name {
|
|
106
|
+
("", $local: tt) => {
|
|
107
|
+
$crate::interface::ExpandedName {
|
|
108
|
+
ns: &ns!(),
|
|
109
|
+
local: &local_name!($local),
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
($ns: ident $local: tt) => {
|
|
113
|
+
$crate::interface::ExpandedName {
|
|
114
|
+
ns: &ns!($ns),
|
|
115
|
+
local: &local_name!($local),
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
pub mod tree_builder;
|
|
121
|
+
|
|
122
|
+
/// A fully qualified name (with a namespace), used to depict names of tags and attributes.
|
|
123
|
+
///
|
|
124
|
+
/// Namespaces can be used to differentiate between similar XML fragments. For example:
|
|
125
|
+
///
|
|
126
|
+
/// ```text
|
|
127
|
+
/// // HTML
|
|
128
|
+
/// <table>
|
|
129
|
+
/// <tr>
|
|
130
|
+
/// <td>Apples</td>
|
|
131
|
+
/// <td>Bananas</td>
|
|
132
|
+
/// </tr>
|
|
133
|
+
/// </table>
|
|
134
|
+
///
|
|
135
|
+
/// // Furniture XML
|
|
136
|
+
/// <table>
|
|
137
|
+
/// <name>African Coffee Table</name>
|
|
138
|
+
/// <width>80</width>
|
|
139
|
+
/// <length>120</length>
|
|
140
|
+
/// </table>
|
|
141
|
+
/// ```
|
|
142
|
+
///
|
|
143
|
+
/// Without XML namespaces, we can't use those two fragments in the same document
|
|
144
|
+
/// at the same time. However if we declare a namespace we could instead say:
|
|
145
|
+
///
|
|
146
|
+
/// ```text
|
|
147
|
+
///
|
|
148
|
+
/// // Furniture XML
|
|
149
|
+
/// <furn:table xmlns:furn="https://furniture.rs">
|
|
150
|
+
/// <furn:name>African Coffee Table</furn:name>
|
|
151
|
+
/// <furn:width>80</furn:width>
|
|
152
|
+
/// <furn:length>120</furn:length>
|
|
153
|
+
/// </furn:table>
|
|
154
|
+
/// ```
|
|
155
|
+
///
|
|
156
|
+
/// and bind the prefix `furn` to a different namespace.
|
|
157
|
+
///
|
|
158
|
+
/// For this reason we parse names that contain a colon in the following way:
|
|
159
|
+
///
|
|
160
|
+
/// ```text
|
|
161
|
+
/// <furn:table>
|
|
162
|
+
/// | |
|
|
163
|
+
/// | +- local name
|
|
164
|
+
/// |
|
|
165
|
+
/// prefix (when resolved gives namespace_url `https://furniture.rs`)
|
|
166
|
+
/// ```
|
|
167
|
+
///
|
|
168
|
+
/// NOTE: `Prefix`, `LocalName` and `Prefix` all implement `Deref<str>`.
|
|
169
|
+
///
|
|
170
|
+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)]
|
|
171
|
+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
|
|
172
|
+
pub struct QualName {
|
|
173
|
+
/// The prefix of qualified (e.g. `furn` in `<furn:table>` above).
|
|
174
|
+
/// Optional (since some namespaces can be empty or inferred), and
|
|
175
|
+
/// only useful for namespace resolution (since different prefix
|
|
176
|
+
/// can still resolve to same namespace)
|
|
177
|
+
///
|
|
178
|
+
/// ```
|
|
179
|
+
///
|
|
180
|
+
/// # fn main() {
|
|
181
|
+
/// use markup5ever::{QualName, Namespace, LocalName, Prefix};
|
|
182
|
+
///
|
|
183
|
+
/// let qual = QualName::new(
|
|
184
|
+
/// Some(Prefix::from("furn")),
|
|
185
|
+
/// Namespace::from("https://furniture.rs"),
|
|
186
|
+
/// LocalName::from("table"),
|
|
187
|
+
/// );
|
|
188
|
+
///
|
|
189
|
+
/// assert_eq!("furn", &qual.prefix.unwrap());
|
|
190
|
+
///
|
|
191
|
+
/// # }
|
|
192
|
+
/// ```
|
|
193
|
+
pub prefix: Option<Prefix>,
|
|
194
|
+
/// The namespace after resolution (e.g. `https://furniture.rs` in example above).
|
|
195
|
+
///
|
|
196
|
+
/// ```
|
|
197
|
+
/// # use markup5ever::{QualName, Namespace, LocalName, Prefix};
|
|
198
|
+
///
|
|
199
|
+
/// # fn main() {
|
|
200
|
+
/// # let qual = QualName::new(
|
|
201
|
+
/// # Some(Prefix::from("furn")),
|
|
202
|
+
/// # Namespace::from("https://furniture.rs"),
|
|
203
|
+
/// # LocalName::from("table"),
|
|
204
|
+
/// # );
|
|
205
|
+
///
|
|
206
|
+
/// assert_eq!("https://furniture.rs", &qual.ns);
|
|
207
|
+
/// # }
|
|
208
|
+
/// ```
|
|
209
|
+
///
|
|
210
|
+
/// When matching namespaces used by HTML we can use `ns!` macro.
|
|
211
|
+
/// Although keep in mind that ns! macro only works with namespaces
|
|
212
|
+
/// that are present in HTML spec (like `html`, `xmlns`, `svg`, etc.).
|
|
213
|
+
///
|
|
214
|
+
/// ```
|
|
215
|
+
/// #[macro_use] extern crate markup5ever;
|
|
216
|
+
///
|
|
217
|
+
/// # use markup5ever::{QualName, Namespace, LocalName, Prefix};
|
|
218
|
+
///
|
|
219
|
+
/// let html_table = QualName::new(
|
|
220
|
+
/// None,
|
|
221
|
+
/// ns!(html),
|
|
222
|
+
/// LocalName::from("table"),
|
|
223
|
+
/// );
|
|
224
|
+
///
|
|
225
|
+
/// assert!(
|
|
226
|
+
/// match html_table.ns {
|
|
227
|
+
/// ns!(html) => true,
|
|
228
|
+
/// _ => false,
|
|
229
|
+
/// }
|
|
230
|
+
/// );
|
|
231
|
+
///
|
|
232
|
+
/// ```
|
|
233
|
+
pub ns: Namespace,
|
|
234
|
+
/// The local name (e.g. `table` in `<furn:table>` above).
|
|
235
|
+
///
|
|
236
|
+
/// ```
|
|
237
|
+
/// # use markup5ever::{QualName, Namespace, LocalName, Prefix};
|
|
238
|
+
///
|
|
239
|
+
/// # fn main() {
|
|
240
|
+
/// # let qual = QualName::new(
|
|
241
|
+
/// # Some(Prefix::from("furn")),
|
|
242
|
+
/// # Namespace::from("https://furniture.rs"),
|
|
243
|
+
/// # LocalName::from("table"),
|
|
244
|
+
/// # );
|
|
245
|
+
///
|
|
246
|
+
/// assert_eq!("table", &qual.local);
|
|
247
|
+
/// # }
|
|
248
|
+
/// ```
|
|
249
|
+
/// When matching local name we can also use the `local_name!` macro:
|
|
250
|
+
///
|
|
251
|
+
/// ```
|
|
252
|
+
/// #[macro_use] extern crate markup5ever;
|
|
253
|
+
///
|
|
254
|
+
/// # use markup5ever::{QualName, Namespace, LocalName, Prefix};
|
|
255
|
+
///
|
|
256
|
+
/// # let qual = QualName::new(
|
|
257
|
+
/// # Some(Prefix::from("furn")),
|
|
258
|
+
/// # Namespace::from("https://furniture.rs"),
|
|
259
|
+
/// # LocalName::from("table"),
|
|
260
|
+
/// # );
|
|
261
|
+
///
|
|
262
|
+
/// // Initialize qual to furniture example
|
|
263
|
+
///
|
|
264
|
+
/// assert!(
|
|
265
|
+
/// match qual.local {
|
|
266
|
+
/// local_name!("table") => true,
|
|
267
|
+
/// _ => false,
|
|
268
|
+
/// }
|
|
269
|
+
/// );
|
|
270
|
+
///
|
|
271
|
+
/// ```
|
|
272
|
+
pub local: LocalName,
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
impl ElemName for Ref<'_, QualName> {
|
|
276
|
+
#[inline(always)]
|
|
277
|
+
fn ns(&self) -> &Namespace {
|
|
278
|
+
&self.ns
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
#[inline(always)]
|
|
282
|
+
fn local_name(&self) -> &LocalName {
|
|
283
|
+
&self.local
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
impl ElemName for &QualName {
|
|
288
|
+
#[inline(always)]
|
|
289
|
+
fn ns(&self) -> &Namespace {
|
|
290
|
+
&self.ns
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
#[inline(always)]
|
|
294
|
+
fn local_name(&self) -> &LocalName {
|
|
295
|
+
&self.local
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
impl QualName {
|
|
300
|
+
/// Basic constructor function.
|
|
301
|
+
///
|
|
302
|
+
/// First let's try it for the following example where `QualName`
|
|
303
|
+
/// is defined as:
|
|
304
|
+
/// ```text
|
|
305
|
+
/// <furn:table> <!-- namespace url is https://furniture.rs -->
|
|
306
|
+
/// ```
|
|
307
|
+
///
|
|
308
|
+
/// Given this definition, we can define `QualName` using strings.
|
|
309
|
+
///
|
|
310
|
+
/// ```
|
|
311
|
+
/// use markup5ever::{QualName, Namespace, LocalName, Prefix};
|
|
312
|
+
///
|
|
313
|
+
/// # fn main() {
|
|
314
|
+
/// let qual_name = QualName::new(
|
|
315
|
+
/// Some(Prefix::from("furn")),
|
|
316
|
+
/// Namespace::from("https://furniture.rs"),
|
|
317
|
+
/// LocalName::from("table"),
|
|
318
|
+
/// );
|
|
319
|
+
/// # }
|
|
320
|
+
/// ```
|
|
321
|
+
///
|
|
322
|
+
/// If we were instead to construct this element instead:
|
|
323
|
+
///
|
|
324
|
+
/// ```text
|
|
325
|
+
///
|
|
326
|
+
/// <table>
|
|
327
|
+
/// ^^^^^---- no prefix and thus default html namespace
|
|
328
|
+
///
|
|
329
|
+
/// ```
|
|
330
|
+
///
|
|
331
|
+
/// Or could define it using macros, like so:
|
|
332
|
+
///
|
|
333
|
+
/// ```
|
|
334
|
+
/// #[macro_use] extern crate markup5ever;
|
|
335
|
+
/// use markup5ever::{QualName, Namespace, LocalName, Prefix};
|
|
336
|
+
///
|
|
337
|
+
/// # fn main() {
|
|
338
|
+
/// let qual_name = QualName::new(
|
|
339
|
+
/// None,
|
|
340
|
+
/// ns!(html),
|
|
341
|
+
/// local_name!("table")
|
|
342
|
+
/// );
|
|
343
|
+
/// # }
|
|
344
|
+
/// ```
|
|
345
|
+
///
|
|
346
|
+
/// Let's analyse the above example.
|
|
347
|
+
/// Since we have no prefix its value is None. Second we have html namespace.
|
|
348
|
+
/// In html5ever html namespaces are supported out of the box,
|
|
349
|
+
/// we can write `ns!(html)` instead of typing `Namespace::from("http://www.w3.org/1999/xhtml")`.
|
|
350
|
+
/// Local name is also one of the HTML elements local names, so can
|
|
351
|
+
/// use `local_name!("table")` macro.
|
|
352
|
+
///
|
|
353
|
+
#[inline]
|
|
354
|
+
pub fn new(prefix: Option<Prefix>, ns: Namespace, local: LocalName) -> QualName {
|
|
355
|
+
QualName { prefix, ns, local }
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/// Take a reference of `self` as an `ExpandedName`, dropping the unresolved prefix.
|
|
359
|
+
///
|
|
360
|
+
/// In XML and HTML prefixes are only used to extract the relevant namespace URI.
|
|
361
|
+
/// Expanded name only contains resolved namespace and tag name, which are only
|
|
362
|
+
/// relevant parts of an XML or HTML tag and attribute name respectively.
|
|
363
|
+
///
|
|
364
|
+
/// In lieu of our XML Namespace example
|
|
365
|
+
///
|
|
366
|
+
/// ```text
|
|
367
|
+
/// <furn:table> <!-- namespace url is https://furniture.rs -->
|
|
368
|
+
/// ```
|
|
369
|
+
/// For it the expanded name would become roughly equivalent to:
|
|
370
|
+
///
|
|
371
|
+
/// ```text
|
|
372
|
+
/// ExpandedName {
|
|
373
|
+
/// ns: "https://furniture.rs",
|
|
374
|
+
/// local: "table",
|
|
375
|
+
/// }
|
|
376
|
+
/// ```
|
|
377
|
+
///
|
|
378
|
+
#[inline]
|
|
379
|
+
pub fn expanded(&self) -> ExpandedName<'_> {
|
|
380
|
+
ExpandedName {
|
|
381
|
+
ns: &self.ns,
|
|
382
|
+
local: &self.local,
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/// A tag attribute, e.g. `class="test"` in `<div class="test" ...>`.
|
|
388
|
+
///
|
|
389
|
+
/// The namespace on the attribute name is almost always ns!("").
|
|
390
|
+
/// The tokenizer creates all attributes this way, but the tree
|
|
391
|
+
/// builder will adjust certain attribute names inside foreign
|
|
392
|
+
/// content (MathML, SVG).
|
|
393
|
+
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
|
|
394
|
+
pub struct Attribute {
|
|
395
|
+
/// The name of the attribute (e.g. the `class` in `<div class="test">`)
|
|
396
|
+
pub name: QualName,
|
|
397
|
+
/// The value of the attribute (e.g. the `"test"` in `<div class="test">`)
|
|
398
|
+
pub value: StrTendril,
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
#[cfg(test)]
|
|
402
|
+
mod tests {
|
|
403
|
+
use web_atoms::{ns, Namespace};
|
|
404
|
+
|
|
405
|
+
#[test]
|
|
406
|
+
fn ns_macro() {
|
|
407
|
+
assert_eq!(ns!(), Namespace::from(""));
|
|
408
|
+
|
|
409
|
+
assert_eq!(ns!(html), Namespace::from("http://www.w3.org/1999/xhtml"));
|
|
410
|
+
assert_eq!(
|
|
411
|
+
ns!(xml),
|
|
412
|
+
Namespace::from("http://www.w3.org/XML/1998/namespace")
|
|
413
|
+
);
|
|
414
|
+
assert_eq!(ns!(xmlns), Namespace::from("http://www.w3.org/2000/xmlns/"));
|
|
415
|
+
assert_eq!(ns!(xlink), Namespace::from("http://www.w3.org/1999/xlink"));
|
|
416
|
+
assert_eq!(ns!(svg), Namespace::from("http://www.w3.org/2000/svg"));
|
|
417
|
+
assert_eq!(
|
|
418
|
+
ns!(mathml),
|
|
419
|
+
Namespace::from("http://www.w3.org/1998/Math/MathML")
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
}
|