diff options
author | Martin Fischer <martin@push-f.com> | 2023-08-19 12:52:15 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-08-19 13:41:55 +0200 |
commit | 0d96df198b1223e942abfefb7ea51ccab99638cc (patch) | |
tree | 771e2bf972311cfc728266c10973b3fa153a7c3e | |
parent | cb4e9cf7cfc1612c67f16bfabadbdf442cd380fe (diff) |
docs: add warning to DefaultEmitter
-rw-r--r-- | src/emitter.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/emitter.rs b/src/emitter.rs index 90aa4db..69e9d45 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -160,6 +160,22 @@ pub trait Emitter<O> { } /// The default implementation of [`Emitter`], used to produce tokens. +/// +/// # Warning +/// +/// * Using the DefaultEmitter without calling [`Tokenizer::set_state`] +/// results in wrong state transitions: +/// +/// ``` +/// # use html5tokenizer::{DefaultEmitter, Tokenizer, Token}; +/// let emitter = DefaultEmitter::default(); +/// let html = "<script><b>"; +/// let mut tokens = Tokenizer::new(html, emitter).flatten(); +/// assert!(matches!(tokens.next().unwrap(), Token::StartTag(tag) if tag.name == "script")); +/// assert!(matches!(tokens.next().unwrap(), Token::StartTag(tag) if tag.name == "b")); +/// ``` +/// +/// [`Tokenizer::set_state`]: crate::Tokenizer::set_state pub struct DefaultEmitter<O = NoopOffset> { current_characters: String, current_token: Option<Token<O>>, |