html5ever/tokenizer/
interface.rs1use crate::interface::Attribute;
11use crate::tendril::StrTendril;
12use crate::tokenizer::states;
13use crate::LocalName;
14use std::borrow::Cow;
15
16pub use self::TagKind::{EndTag, StartTag};
17pub use self::Token::{CharacterTokens, CommentToken, DoctypeToken, TagToken};
18pub use self::Token::{EOFToken, NullCharacterToken, ParseError};
19
20#[derive(PartialEq, Eq, Clone, Debug, Default)]
23pub struct Doctype {
24    pub name: Option<StrTendril>,
25    pub public_id: Option<StrTendril>,
26    pub system_id: Option<StrTendril>,
27    pub force_quirks: bool,
28}
29
30#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)]
31pub enum TagKind {
32    StartTag,
33    EndTag,
34}
35
36#[derive(PartialEq, Eq, Clone, Debug)]
38pub struct Tag {
39    pub kind: TagKind,
40    pub name: LocalName,
41    pub self_closing: bool,
42    pub attrs: Vec<Attribute>,
43}
44
45impl Tag {
46    pub fn equiv_modulo_attr_order(&self, other: &Tag) -> bool {
49        if (self.kind != other.kind) || (self.name != other.name) {
50            return false;
51        }
52
53        let mut self_attrs = self.attrs.clone();
54        let mut other_attrs = other.attrs.clone();
55        self_attrs.sort();
56        other_attrs.sort();
57
58        self_attrs == other_attrs
59    }
60}
61
62#[derive(PartialEq, Eq, Debug)]
63pub enum Token {
64    DoctypeToken(Doctype),
65    TagToken(Tag),
66    CommentToken(StrTendril),
67    CharacterTokens(StrTendril),
68    NullCharacterToken,
69    EOFToken,
70    ParseError(Cow<'static, str>),
71}
72
73#[derive(Debug, PartialEq)]
74#[must_use]
75pub enum TokenSinkResult<Handle> {
76    Continue,
77    Script(Handle),
78    Plaintext,
79    RawData(states::RawKind),
80}
81
82pub trait TokenSink {
84    type Handle;
85
86    fn process_token(&self, token: Token, line_number: u64) -> TokenSinkResult<Self::Handle>;
88
89    fn end(&self) {}
91
92    fn adjusted_current_node_present_but_not_in_html_namespace(&self) -> bool {
97        false
98    }
99}