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
use html5ever::rcdom::{Handle, NodeData};
use tok::Tok;

/// Toks convenience type alias to Vec of Tok's.
pub type Toks<'s> = Vec<&'s mut Tok>;

/// Helper function which walks through `html5ever::rcdom::Handle`
/// `NodeData::Element` branch recursively and fires `Tok``process`
/// function if `QualName` is found by `is_match`.
pub fn recursion(toks: &mut Toks, handle: Handle) {
    match handle.data {
        NodeData::Element {
            ref name,
            ref attrs,
            ..
        } => {
            for tok in toks.iter_mut() {
                if tok.is_match(name) {
                    tok.process(attrs.clone(), handle.children.clone())
                }
            }
        }
        _ => {}
    }

    for child in handle.children.borrow().iter() {
        recursion(toks, child.clone());
    }
}