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