aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-30 16:16:47 +0100
committerMartin Fischer <martin@push-f.com>2021-12-05 02:45:31 +0100
commit7e400c29bf14bd75154c74e2dd9ba0814f83bec7 (patch)
tree4933b5142214972abaf055b0532ce288768a223b /src
parent2a6e3bf05c419eb21cb7a4db141ed6a319e98622 (diff)
introduce StartTag::next_state
Closes #11.
Diffstat (limited to 'src')
-rw-r--r--src/emitter.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/emitter.rs b/src/emitter.rs
index 8c8976d..0a80544 100644
--- a/src/emitter.rs
+++ b/src/emitter.rs
@@ -4,6 +4,7 @@ use std::collections::VecDeque;
use std::mem;
use crate::Error;
+use crate::State;
/// An emitter is an object providing methods to the tokenizer to produce tokens.
///
@@ -431,6 +432,23 @@ pub struct StartTag {
pub attributes: BTreeMap<String, String>,
}
+impl StartTag {
+ /// Returns the next tokenizer state according to
+ /// [Parsing HTML fragments](https://html.spec.whatwg.org/multipage/parsing.html#concept-frag-parse-context).
+ /// If `scripting` is set to true [`State::RawText`] is returned if this is a `<noscript>` tag,
+ /// otherwise [`State::Data`] is returned (as with any other regular tag).
+ pub fn next_state(&self, scripting: bool) -> State {
+ match self.name.as_str() {
+ "title" | "textarea" => State::RcData,
+ "style" | "xmp" | "iframe" | "noembed" | "noframes" => State::RawText,
+ "script" => State::ScriptData,
+ "noscript" if scripting => State::RawText,
+ "plaintext" => State::PlainText,
+ _other => State::Data,
+ }
+ }
+}
+
/// A HTML end/close tag, such as `</p>` or `</a>`.
#[derive(Debug, Default, Eq, PartialEq)]
pub struct EndTag {