| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
use crate::interface::Attribute; |
| 11 |
use crate::tendril::StrTendril; |
| 12 |
use crate::tokenizer::states; |
| 13 |
use crate::LocalName; |
| 14 |
use std::borrow::Cow; |
| 15 |
|
| 16 |
pub use self::TagKind::{EndTag, StartTag}; |
| 17 |
pub use self::Token::{CharacterTokens, CommentToken, DoctypeToken, TagToken}; |
| 18 |
pub use self::Token::{EOFToken, NullCharacterToken, ParseError}; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#[derive(PartialEq, Eq, Clone, Debug, Default)] |
| 23 |
pub 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)] |
| 31 |
pub enum TagKind { |
| 32 |
StartTag, |
| 33 |
EndTag, |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
#[derive(PartialEq, Eq, Clone, Debug)] |
| 38 |
pub struct Tag { |
| 39 |
pub kind: TagKind, |
| 40 |
pub name: LocalName, |
| 41 |
pub self_closing: bool, |
| 42 |
pub attrs: Vec<Attribute>, |
| 43 |
} |
| 44 |
|
| 45 |
impl Tag { |
| 46 |
|
| 47 |
|
| 48 |
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)] |
| 63 |
pub 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] |
| 75 |
pub enum TokenSinkResult<Handle> { |
| 76 |
Continue, |
| 77 |
Script(Handle), |
| 78 |
Plaintext, |
| 79 |
RawData(states::RawKind), |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
pub trait TokenSink { |
| 84 |
type Handle; |
| 85 |
|
| 86 |
|
| 87 |
fn process_token(&self, token: Token, line_number: u64) -> TokenSinkResult<Self::Handle>; |
| 88 |
|
| 89 |
|
| 90 |
fn end(&self) {} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
fn adjusted_current_node_present_but_not_in_html_namespace(&self) -> bool { |
| 97 |
false |
| 98 |
} |
| 99 |
} |