aboutsummaryrefslogtreecommitdiff
path: root/src/machine.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/machine.rs')
-rw-r--r--src/machine.rs37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/machine.rs b/src/machine.rs
index c5bf021..509dae5 100644
--- a/src/machine.rs
+++ b/src/machine.rs
@@ -1,6 +1,7 @@
use crate::attr::AttrValueSyntax;
use crate::entities::try_read_character_reference;
use crate::offset::{Offset, Position};
+use crate::tokenizer::CdataAction;
use crate::utils::{
ascii_digit_pat, control_pat, ctostr, noncharacter_pat, surrogate_pat, whitespace_pat, State,
};
@@ -9,6 +10,7 @@ use crate::{reader::Reader, Emitter, Error, Tokenizer};
pub enum ControlToken {
Eof,
Continue,
+ CdataOpen,
}
// Note: This is not implemented as a method on Tokenizer because there's fields on Tokenizer that
@@ -942,21 +944,7 @@ where
slf.doctype_offset = slf.reader.position() - b"<!doctype".len();
Ok(ControlToken::Continue)
}
- Some('[') if slf.try_read_string("CDATA[", true)? => {
- if slf
- .emitter
- .adjusted_current_node_present_and_not_in_html_namespace()
- {
- slf.state = State::CdataSection;
- } else {
- slf.emit_error(Error::CdataInHtmlContent);
-
- slf.emitter.init_comment(slf.reader.position());
- slf.emitter.push_comment("[CDATA[");
- slf.state = State::BogusComment;
- }
- Ok(ControlToken::Continue)
- }
+ Some('[') if slf.try_read_string("CDATA[", true)? => Ok(ControlToken::CdataOpen),
c => {
slf.emit_error(Error::IncorrectlyOpenedComment);
slf.emitter.init_comment(slf.reader.position() - 1);
@@ -1897,3 +1885,22 @@ where
}
}
}
+
+#[inline]
+pub fn handle_cdata_open<O, R, E>(slf: &mut Tokenizer<R, O, E>, action: CdataAction)
+where
+ O: Offset,
+ R: Reader + Position<O>,
+ E: Emitter<O>,
+{
+ match action {
+ CdataAction::Cdata => slf.state = State::CdataSection,
+ CdataAction::BogusComment => {
+ slf.emit_error(Error::CdataInHtmlContent);
+
+ slf.emitter.init_comment(slf.reader.position());
+ slf.emitter.push_comment("[CDATA[");
+ slf.state = State::BogusComment;
+ }
+ }
+}