summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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>>,