@dvaji/cheerox 0.0.0-stage → 0.1.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/CONTRIBUTING.md +74 -0
- package/Cargo.lock +1094 -0
- package/Cargo.toml +46 -0
- package/LICENSE +21 -0
- package/README.md +121 -2
- package/RELEASING.md +114 -0
- package/THIRD_PARTY_NOTICES.md +7579 -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-BS--qPzw.mjs +1648 -0
- package/dist/cheerio-compat-BS--qPzw.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-DSwBAJ1s.cjs +1719 -0
- package/dist/cheerio-compat-DSwBAJ1s.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 +4119 -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 +26 -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/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 +188 -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
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
use log::warn;
|
|
11
|
+
pub use markup5ever::serialize::{AttrRef, Serialize, Serializer, TraversalScope};
|
|
12
|
+
use markup5ever::{local_name, ns};
|
|
13
|
+
use std::io::{self, Write};
|
|
14
|
+
|
|
15
|
+
use crate::{LocalName, QualName};
|
|
16
|
+
|
|
17
|
+
pub fn serialize<Wr, T>(writer: Wr, node: &T, opts: SerializeOpts) -> io::Result<()>
|
|
18
|
+
where
|
|
19
|
+
Wr: Write,
|
|
20
|
+
T: Serialize,
|
|
21
|
+
{
|
|
22
|
+
let mut ser = HtmlSerializer::new(writer, opts.clone());
|
|
23
|
+
node.serialize(&mut ser, opts.traversal_scope)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[derive(Clone)]
|
|
27
|
+
pub struct SerializeOpts {
|
|
28
|
+
/// Is scripting enabled? Default: true
|
|
29
|
+
pub scripting_enabled: bool,
|
|
30
|
+
|
|
31
|
+
/// Serialize the root node? Default: ChildrenOnly
|
|
32
|
+
pub traversal_scope: TraversalScope,
|
|
33
|
+
|
|
34
|
+
/// If the serializer is asked to serialize an invalid tree, the default
|
|
35
|
+
/// behavior is to panic in the event that an `end_elem` is created without a
|
|
36
|
+
/// matching `start_elem`. Setting this to true will prevent those panics by
|
|
37
|
+
/// creating a default parent on the element stack. No extra start elem will
|
|
38
|
+
/// actually be written. Default: false
|
|
39
|
+
pub create_missing_parent: bool,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
impl Default for SerializeOpts {
|
|
43
|
+
fn default() -> SerializeOpts {
|
|
44
|
+
SerializeOpts {
|
|
45
|
+
scripting_enabled: true,
|
|
46
|
+
traversal_scope: TraversalScope::ChildrenOnly(None),
|
|
47
|
+
create_missing_parent: false,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[derive(Default)]
|
|
53
|
+
struct ElemInfo {
|
|
54
|
+
html_name: Option<LocalName>,
|
|
55
|
+
ignore_children: bool,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
pub struct HtmlSerializer<Wr: Write> {
|
|
59
|
+
pub writer: Wr,
|
|
60
|
+
opts: SerializeOpts,
|
|
61
|
+
stack: Vec<ElemInfo>,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fn tagname(name: &QualName) -> LocalName {
|
|
65
|
+
match name.ns {
|
|
66
|
+
ns!(html) | ns!(mathml) | ns!(svg) => (),
|
|
67
|
+
ref ns => {
|
|
68
|
+
// FIXME(#122)
|
|
69
|
+
warn!("node with weird namespace {ns:?}");
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
name.local.clone()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
impl<Wr: Write> HtmlSerializer<Wr> {
|
|
77
|
+
pub fn new(writer: Wr, opts: SerializeOpts) -> Self {
|
|
78
|
+
let html_name = match opts.traversal_scope {
|
|
79
|
+
TraversalScope::IncludeNode | TraversalScope::ChildrenOnly(None) => None,
|
|
80
|
+
TraversalScope::ChildrenOnly(Some(ref n)) => Some(tagname(n)),
|
|
81
|
+
};
|
|
82
|
+
HtmlSerializer {
|
|
83
|
+
writer,
|
|
84
|
+
opts,
|
|
85
|
+
stack: vec![ElemInfo {
|
|
86
|
+
html_name,
|
|
87
|
+
ignore_children: false,
|
|
88
|
+
}],
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
fn parent(&mut self) -> &mut ElemInfo {
|
|
93
|
+
if self.stack.is_empty() {
|
|
94
|
+
if self.opts.create_missing_parent {
|
|
95
|
+
warn!("ElemInfo stack empty, creating new parent");
|
|
96
|
+
self.stack.push(Default::default());
|
|
97
|
+
} else {
|
|
98
|
+
panic!("no parent ElemInfo")
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
self.stack.last_mut().unwrap()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fn write_escaped(&mut self, text: &str, attr_mode: bool) -> io::Result<()> {
|
|
105
|
+
for c in text.chars() {
|
|
106
|
+
match c {
|
|
107
|
+
'&' => self.writer.write_all(b"&"),
|
|
108
|
+
'\u{00A0}' => self.writer.write_all(b" "),
|
|
109
|
+
'"' if attr_mode => self.writer.write_all(b"""),
|
|
110
|
+
'<' if !attr_mode => self.writer.write_all(b"<"),
|
|
111
|
+
'>' if !attr_mode => self.writer.write_all(b">"),
|
|
112
|
+
c => self.writer.write_fmt(format_args!("{c}")),
|
|
113
|
+
}?;
|
|
114
|
+
}
|
|
115
|
+
Ok(())
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
impl<Wr: Write> Serializer for HtmlSerializer<Wr> {
|
|
120
|
+
fn start_elem<'a, AttrIter>(&mut self, name: QualName, attrs: AttrIter) -> io::Result<()>
|
|
121
|
+
where
|
|
122
|
+
AttrIter: Iterator<Item = AttrRef<'a>>,
|
|
123
|
+
{
|
|
124
|
+
let html_name = match name.ns {
|
|
125
|
+
ns!(html) => Some(name.local.clone()),
|
|
126
|
+
_ => None,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
if self.parent().ignore_children {
|
|
130
|
+
self.stack.push(ElemInfo {
|
|
131
|
+
html_name,
|
|
132
|
+
ignore_children: true,
|
|
133
|
+
});
|
|
134
|
+
return Ok(());
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
self.writer.write_all(b"<")?;
|
|
138
|
+
self.writer.write_all(tagname(&name).as_bytes())?;
|
|
139
|
+
for (name, value) in attrs {
|
|
140
|
+
self.writer.write_all(b" ")?;
|
|
141
|
+
|
|
142
|
+
match name.ns {
|
|
143
|
+
ns!() => (),
|
|
144
|
+
ns!(xml) => self.writer.write_all(b"xml:")?,
|
|
145
|
+
ns!(xmlns) => {
|
|
146
|
+
if name.local != local_name!("xmlns") {
|
|
147
|
+
self.writer.write_all(b"xmlns:")?;
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
ns!(xlink) => self.writer.write_all(b"xlink:")?,
|
|
151
|
+
ref ns => {
|
|
152
|
+
// FIXME(#122)
|
|
153
|
+
warn!("attr with weird namespace {ns:?}");
|
|
154
|
+
self.writer.write_all(b"unknown_namespace:")?;
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
self.writer.write_all(name.local.as_bytes())?;
|
|
159
|
+
self.writer.write_all(b"=\"")?;
|
|
160
|
+
self.write_escaped(value, true)?;
|
|
161
|
+
self.writer.write_all(b"\"")?;
|
|
162
|
+
}
|
|
163
|
+
self.writer.write_all(b">")?;
|
|
164
|
+
|
|
165
|
+
let ignore_children = name.ns == ns!(html)
|
|
166
|
+
&& matches!(
|
|
167
|
+
name.local,
|
|
168
|
+
local_name!("area")
|
|
169
|
+
| local_name!("base")
|
|
170
|
+
| local_name!("basefont")
|
|
171
|
+
| local_name!("bgsound")
|
|
172
|
+
| local_name!("br")
|
|
173
|
+
| local_name!("col")
|
|
174
|
+
| local_name!("embed")
|
|
175
|
+
| local_name!("frame")
|
|
176
|
+
| local_name!("hr")
|
|
177
|
+
| local_name!("img")
|
|
178
|
+
| local_name!("input")
|
|
179
|
+
| local_name!("keygen")
|
|
180
|
+
| local_name!("link")
|
|
181
|
+
| local_name!("meta")
|
|
182
|
+
| local_name!("param")
|
|
183
|
+
| local_name!("source")
|
|
184
|
+
| local_name!("track")
|
|
185
|
+
| local_name!("wbr")
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
self.stack.push(ElemInfo {
|
|
189
|
+
html_name,
|
|
190
|
+
ignore_children,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
Ok(())
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
fn end_elem(&mut self, name: QualName) -> io::Result<()> {
|
|
197
|
+
let info = match self.stack.pop() {
|
|
198
|
+
Some(info) => info,
|
|
199
|
+
None if self.opts.create_missing_parent => {
|
|
200
|
+
warn!("missing ElemInfo, creating default.");
|
|
201
|
+
Default::default()
|
|
202
|
+
},
|
|
203
|
+
_ => panic!("no ElemInfo"),
|
|
204
|
+
};
|
|
205
|
+
if info.ignore_children {
|
|
206
|
+
return Ok(());
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
self.writer.write_all(b"</")?;
|
|
210
|
+
self.writer.write_all(tagname(&name).as_bytes())?;
|
|
211
|
+
self.writer.write_all(b">")
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
fn write_text(&mut self, text: &str) -> io::Result<()> {
|
|
215
|
+
let escape = match self.parent().html_name {
|
|
216
|
+
Some(local_name!("style"))
|
|
217
|
+
| Some(local_name!("script"))
|
|
218
|
+
| Some(local_name!("xmp"))
|
|
219
|
+
| Some(local_name!("iframe"))
|
|
220
|
+
| Some(local_name!("noembed"))
|
|
221
|
+
| Some(local_name!("noframes"))
|
|
222
|
+
| Some(local_name!("plaintext")) => false,
|
|
223
|
+
|
|
224
|
+
Some(local_name!("noscript")) => !self.opts.scripting_enabled,
|
|
225
|
+
|
|
226
|
+
_ => true,
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
if escape {
|
|
230
|
+
self.write_escaped(text, false)
|
|
231
|
+
} else {
|
|
232
|
+
self.writer.write_all(text.as_bytes())
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
fn write_comment(&mut self, text: &str) -> io::Result<()> {
|
|
237
|
+
self.writer.write_all(b"<!--")?;
|
|
238
|
+
self.writer.write_all(text.as_bytes())?;
|
|
239
|
+
self.writer.write_all(b"-->")
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
fn write_doctype(&mut self, name: &str) -> io::Result<()> {
|
|
243
|
+
self.writer.write_all(b"<!DOCTYPE ")?;
|
|
244
|
+
self.writer.write_all(name.as_bytes())?;
|
|
245
|
+
self.writer.write_all(b">")
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
fn write_processing_instruction(&mut self, target: &str, data: &str) -> io::Result<()> {
|
|
249
|
+
self.writer.write_all(b"<?")?;
|
|
250
|
+
self.writer.write_all(target.as_bytes())?;
|
|
251
|
+
self.writer.write_all(b" ")?;
|
|
252
|
+
self.writer.write_all(data.as_bytes())?;
|
|
253
|
+
self.writer.write_all(b">")
|
|
254
|
+
}
|
|
255
|
+
}
|