use crate::interface::Attribute;
use crate::tendril::StrTendril;
use crate::tokenizer::states;
use crate::LocalName;
use std::borrow::Cow;
pub use self::TagKind::{EndTag, StartTag};
pub use self::Token::{CharacterTokens, CommentToken, DoctypeToken, TagToken};
pub use self::Token::{EOFToken, NullCharacterToken, ParseError};
#[derive(PartialEq, Eq, Clone, Debug, Default)]
pub struct Doctype {
pub name: Option<StrTendril>,
pub public_id: Option<StrTendril>,
pub system_id: Option<StrTendril>,
pub force_quirks: bool,
}
#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)]
pub enum TagKind {
StartTag,
EndTag,
}
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Tag {
pub kind: TagKind,
pub name: LocalName,
pub self_closing: bool,
pub attrs: Vec<Attribute>,
}
impl Tag {
pub fn equiv_modulo_attr_order(&self, other: &Tag) -> bool {
if (self.kind != other.kind) || (self.name != other.name) {
return false;
}
let mut self_attrs = self.attrs.clone();
let mut other_attrs = other.attrs.clone();
self_attrs.sort();
other_attrs.sort();
self_attrs == other_attrs
}
}
#[derive(PartialEq, Eq, Debug)]
pub enum Token {
DoctypeToken(Doctype),
TagToken(Tag),
CommentToken(StrTendril),
CharacterTokens(StrTendril),
NullCharacterToken,
EOFToken,
ParseError(Cow<'static, str>),
}
#[derive(Debug, PartialEq)]
#[must_use]
pub enum TokenSinkResult<Handle> {
Continue,
Script(Handle),
Plaintext,
RawData(states::RawKind),
}
pub trait TokenSink {
type Handle;
fn process_token(&self, token: Token, line_number: u64) -> TokenSinkResult<Self::Handle>;
fn end(&self) {}
fn adjusted_current_node_present_but_not_in_html_namespace(&self) -> bool {
false
}
}