diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-30 16:16:47 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-12-05 02:45:31 +0100 |
commit | 7e400c29bf14bd75154c74e2dd9ba0814f83bec7 (patch) | |
tree | 4933b5142214972abaf055b0532ce288768a223b /examples/switch-state.rs | |
parent | 2a6e3bf05c419eb21cb7a4db141ed6a319e98622 (diff) |
introduce StartTag::next_state
Closes #11.
Diffstat (limited to 'examples/switch-state.rs')
-rw-r--r-- | examples/switch-state.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/switch-state.rs b/examples/switch-state.rs new file mode 100644 index 0000000..e966687 --- /dev/null +++ b/examples/switch-state.rs @@ -0,0 +1,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)); + } + } +} |