1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Efficient tokens for `rcdom::RcDom` `Handle` parsing
//! aiming for O(1) HTML DOM walking.
//!
//! This library aims to provide convenient and efficient handling of
//! HTML DOM elements.
//!
//! ## Examples
//!
//!```
//! extern crate toks;
//! #[macro_use]
//! extern crate html5ever;
//!
//! use html5ever::parse_document;
//! use html5ever::rcdom::{RcDom, Handle};
//! use html5ever::tendril::TendrilSink;
//!
//! use toks::{Tok, recursion};
//! use toks::prelude::*;
//! use std::io::{self, Read};
//!
//! pub struct LinkTok {
//! total: u32,
//! }
//!
//! impl Tok for LinkTok {
//! fn is_match(&self, qn: &QualName) -> bool {
//! qn.local == local_name!("a")
//! }
//!
//! fn process(&mut self, _: RefCell<Vec<Attribute>>, _: RefCell<Vec<Handle>>) {
//! self.total += 1;
//! }
//! }
//!
//! // How to use
//! // $ cargo build --example count_links
//! // $ cat your.html | ./target/debug/examples/count_links
//! // Link <a> count 9
//! fn main() {
//! let mut chunk = String::new();
//! io::stdin().read_to_string(&mut chunk).unwrap();
//!
//! let dom = parse_document(RcDom::default(), Default::default()).one(chunk);
//!
//! let mut lt = LinkTok { total: 0 };
//!
//! // Dropping mut reference
//! {
//! recursion(&mut vec![&mut lt], dom.document);
//! }
//!
//! println!("Link <a> count {}", lt.total);
//! }
//!```
extern crate html5ever;
pub use Tok;
pub use *;
/// Prelude module contains several important traits that provide many
/// of the convenience imports in advance.