aboutsummaryrefslogtreecommitdiff
path: root/src/naive_parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/naive_parser.rs')
-rw-r--r--src/naive_parser.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/naive_parser.rs b/src/naive_parser.rs
index 2626209..f126dfd 100644
--- a/src/naive_parser.rs
+++ b/src/naive_parser.rs
@@ -1,7 +1,8 @@
use crate::emitter::DefaultEmitter;
use crate::offset::{Offset, Position};
use crate::reader::{IntoReader, Reader};
-use crate::{Emitter, State, Tokenizer};
+use crate::tokenizer::CdataAction;
+use crate::{Emitter, Event, State, Tokenizer};
/// A naive HTML parser (**not** spec-compliant since it doesn't do tree construction).
///
@@ -53,9 +54,21 @@ impl<R: Reader + Position<O>, O: Offset, E: Emitter<O>> Iterator for NaiveParser
type Item = Result<E::Token, R::Error>;
fn next(&mut self) -> Option<Self::Item> {
- // A proper parser would follow the steps described under section '13.2.6 Tree construction'
- // of the spec. Since this parser is naive, we directly return the token instead.
- self.tokenizer.next()
+ loop {
+ let event = self.tokenizer.next()?;
+ match event {
+ Err(e) => return Some(Err(e)),
+ Ok(Event::Token(t)) => {
+ // A proper parser would follow the steps described under section '13.2.6 Tree construction'
+ // of the spec. Since this parser is naive, we directly return the token instead.
+ return Some(Ok(t));
+ }
+ Ok(Event::CdataOpen) => {
+ // Naively parse any CDATA sections as bogus comments.
+ self.tokenizer.handle_cdata_open(CdataAction::BogusComment)
+ }
+ }
+ }
}
}