aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-08-19 12:52:15 +0200
committerMartin Fischer <martin@push-f.com>2023-08-19 13:41:55 +0200
commit0d96df198b1223e942abfefb7ea51ccab99638cc (patch)
tree771e2bf972311cfc728266c10973b3fa153a7c3e /src
parentcb4e9cf7cfc1612c67f16bfabadbdf442cd380fe (diff)
docs: add warning to DefaultEmitter
Diffstat (limited to 'src')
-rw-r--r--src/emitter.rs16
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>>,