aboutsummaryrefslogtreecommitdiff
path: root/src/tokenizer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tokenizer.rs')
-rw-r--r--src/tokenizer.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 96d1c34..5b11db0 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -79,6 +79,38 @@ impl<R: Reader + Position<O>, O: Offset, E: Emitter<O>> Tokenizer<R, O, E> {
naively_switch_state: false,
}
}
+
+ /// To be called when the tokenizer iterator implementation yields [`Event::CdataOpen`].
+ ///
+ /// For spec-compliant parsing *action* must be [`CdataAction::Cdata`],
+ /// if there is an _adjusted current node_ and it is not an element in
+ /// the HTML namespace, or [`CdataAction::BogusComment`] otherwise
+ /// (as per the third condition under [Markup declaration open state]).
+ ///
+ /// [Markup declaration open state]: https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
+ pub fn handle_cdata_open(&mut self, action: CdataAction) {
+ machine::handle_cdata_open(self, action);
+ }
+}
+
+/// Used by [`Tokenizer::handle_cdata_open`] to determine how to process `<![CDATA[`
+///
+/// (Since as per the spec this depends on the _adjusted current node_).
+pub enum CdataAction {
+ /// Process it as CDATA.
+ Cdata,
+ /// Process it as a bogus comment.
+ BogusComment,
+}
+
+/// An event yielded by the [`Iterator`] implementation for the [`Tokenizer`].
+#[derive(Debug)]
+pub enum Event<T> {
+ /// A token emitted by the [`Emitter`].
+ Token(T),
+ /// The state machine encountered `<![CDATA[`. You must call [`Tokenizer::handle_cdata_open`],
+ /// before advancing the tokenizer iterator again.
+ CdataOpen,
}
/// The states you can set the tokenizer to.
@@ -307,12 +339,12 @@ where
R: Reader + Position<O>,
E: Emitter<O>,
{
- type Item = Result<E::Token, R::Error>;
+ type Item = Result<Event<E::Token>, R::Error>;
fn next(&mut self) -> Option<Self::Item> {
loop {
if let Some(token) = self.emitter.pop_token() {
- return Some(Ok(token));
+ return Some(Ok(Event::Token(token)));
}
if self.eof {
@@ -326,6 +358,7 @@ where
self.eof = true;
self.emitter.emit_eof();
}
+ Ok(ControlToken::CdataOpen) => return Some(Ok(Event::CdataOpen)),
}
}
}