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)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7pub enum HtmlElementType {
8 TagOpen,
9 TagClose,
10 TagSlashOpen,
11 TagSelfClose,
12 TagName,
13 AttributeName,
14 AttributeValue,
15 Attribute,
16 Text,
17 Comment,
18 Equal,
19 Quote,
20 Doctype,
21 CData,
22 ProcessingInstruction,
23 EntityRef,
24 CharRef,
25 Whitespace,
26 Newline,
27 Document,
28 Element,
29 Eof,
30 Error,
31}
32
33impl ElementType for HtmlElementType {
34 type Role = UniversalElementRole;
35
36 fn role(&self) -> Self::Role {
37 match self {
38 Self::Document => UniversalElementRole::Root,
39 Self::Element => UniversalElementRole::Container,
40 Self::Attribute => UniversalElementRole::Attribute,
41 _ => UniversalElementRole::None,
42 }
43 }
44}
45
46impl From<crate::lexer::token_type::HtmlTokenType> for HtmlElementType {
47 fn from(token: crate::lexer::token_type::HtmlTokenType) -> Self {
48 unsafe { std::mem::transmute(token) }
49 }
50}