aboutsummaryrefslogtreecommitdiff
path: root/examples/switch-state.rs
blob: e9666877fb638f0f2328989bf26b46da4ac1fc35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//! Let's you easily try out the tokenizer with e.g.
//! printf '<style><b>Hello world!</b></style>' | cargo run --example=switch-state
use html5gum::{BufReadReader, Token, Tokenizer};
use std::io::stdin;

fn main() {
    let stdin = stdin();
    let mut tokenizer = Tokenizer::new(BufReadReader::new(stdin.lock()));

    while let Some(token) = tokenizer.next() {
        let token = token.unwrap();
        println!("{:?}", token);

        if let Token::StartTag(start_tag) = token {
            // take care of switching parser state for e.g. <script> & <style>
            // this is not strictly spec-compliant but good enough most of the time
            tokenizer.set_state(start_tag.next_state(false));
        }
    }
}