oak_html/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum HtmlElementType {
7 TagOpen,
9 TagClose,
11 TagSlashOpen,
13 TagSelfClose,
15 TagName,
17 AttributeName,
19 AttributeValue,
21 Attribute,
23 Text,
25 Comment,
27 Equal,
29 Quote,
31 Doctype,
33 CData,
35 ProcessingInstruction,
37 EntityRef,
39 CharRef,
41 Whitespace,
43 Newline,
45 Document,
47 Element,
49 Eof,
51 Error,
53}
54
55impl ElementType for HtmlElementType {
56 type Role = UniversalElementRole;
57
58 fn role(&self) -> Self::Role {
59 match self {
60 Self::Document => UniversalElementRole::Root,
61 Self::Element => UniversalElementRole::Container,
62 Self::Attribute => UniversalElementRole::Attribute,
63 _ => UniversalElementRole::None,
64 }
65 }
66}
67
68impl From<crate::lexer::token_type::HtmlTokenType> for HtmlElementType {
69 fn from(token: crate::lexer::token_type::HtmlTokenType) -> Self {
70 unsafe { std::mem::transmute(token) }
71 }
72}