Skip to main content

oak_markdown/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2
3/// Element types for the Markdown language.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u16)]
7pub enum MarkdownElementType {
8    /// The root of the document.
9    Root,
10    /// A paragraph of text.
11    Paragraph,
12    /// A table.
13    Table,
14    /// Heading level 1.
15    Heading1,
16    /// Heading level 2.
17    Heading2,
18    /// Heading level 3.
19    Heading3,
20    /// Heading level 4.
21    Heading4,
22    /// Heading level 5.
23    Heading5,
24    /// Heading level 6.
25    Heading6,
26    /// A blockquote.
27    Blockquote,
28    /// A code block.
29    CodeBlock,
30    /// A list.
31    List,
32    /// A list item.
33    ListItem,
34    /// A horizontal rule.
35    HorizontalRule,
36    /// A math block.
37    MathBlock,
38    /// Front matter.
39    FrontMatter,
40    /// A footnote definition.
41    FootnoteDefinition,
42    /// Plain text.
43    Text,
44    /// Whitespace.
45    Whitespace,
46    /// A newline.
47    Newline,
48    /// The text of a heading.
49    HeadingText,
50    /// Emphasized text.
51    Emphasis,
52    /// Strong text.
53    Strong,
54    /// Strikethrough text.
55    Strikethrough,
56    /// Inline code.
57    InlineCode,
58    /// A code fence.
59    CodeFence,
60    /// A code language identifier.
61    CodeLanguage,
62    /// A link.
63    Link,
64    /// The text of a link.
65    LinkText,
66    /// The URL of a link.
67    LinkUrl,
68    /// The title of a link.
69    LinkTitle,
70    /// An image.
71    Image,
72    /// The alt text of an image.
73    ImageAlt,
74    /// The URL of an image.
75    ImageUrl,
76    /// The title of an image.
77    ImageTitle,
78    /// An unordered list.
79    UnorderedList,
80    /// An ordered list.
81    OrderedList,
82    /// A list marker.
83    ListMarker,
84    /// A task list.
85    TaskList,
86    /// A task marker.
87    TaskMarker,
88    /// A blockquote marker.
89    BlockquoteMarker,
90    /// A table row.
91    TableRow,
92    /// A table cell.
93    TableCell,
94    /// A table header cell.
95    TableHeader,
96    /// A table separator.
97    TableSeparator,
98    /// Table alignment information.
99    TableAlignment,
100    /// Inline math.
101    MathInline,
102    /// A footnote reference.
103    FootnoteReference,
104    /// A definition list.
105    DefinitionList,
106    /// A definition term.
107    DefinitionTerm,
108    /// A definition description.
109    DefinitionDescription,
110    /// Superscript text.
111    Superscript,
112    /// Subscript text.
113    Subscript,
114    /// An abbreviation.
115    Abbreviation,
116    /// An HTML tag.
117    HtmlTag,
118    /// An HTML comment.
119    HtmlComment,
120    /// An XML tag.
121    XmlTag,
122    /// An XML comment.
123    XmlComment,
124    /// An automatic link (HTTP/HTTPS URL).
125    AutoLink,
126    /// An error element.
127    Error,
128}
129
130impl ElementType for MarkdownElementType {
131    type Role = UniversalElementRole;
132
133    fn role(&self) -> Self::Role {
134        match self {
135            _ => UniversalElementRole::None,
136        }
137    }
138}
139
140impl From<crate::lexer::token_type::MarkdownTokenType> for MarkdownElementType {
141    fn from(token: crate::lexer::token_type::MarkdownTokenType) -> Self {
142        match token {
143            crate::lexer::token_type::MarkdownTokenType::Text => MarkdownElementType::Text,
144            crate::lexer::token_type::MarkdownTokenType::Whitespace => MarkdownElementType::Whitespace,
145            crate::lexer::token_type::MarkdownTokenType::Newline => MarkdownElementType::Newline,
146            crate::lexer::token_type::MarkdownTokenType::Heading1 => MarkdownElementType::Heading1,
147            crate::lexer::token_type::MarkdownTokenType::Heading2 => MarkdownElementType::Heading2,
148            crate::lexer::token_type::MarkdownTokenType::Heading3 => MarkdownElementType::Heading3,
149            crate::lexer::token_type::MarkdownTokenType::Heading4 => MarkdownElementType::Heading4,
150            crate::lexer::token_type::MarkdownTokenType::Heading5 => MarkdownElementType::Heading5,
151            crate::lexer::token_type::MarkdownTokenType::Heading6 => MarkdownElementType::Heading6,
152            crate::lexer::token_type::MarkdownTokenType::HeadingText => MarkdownElementType::HeadingText,
153            crate::lexer::token_type::MarkdownTokenType::Emphasis => MarkdownElementType::Emphasis,
154            crate::lexer::token_type::MarkdownTokenType::Strong => MarkdownElementType::Strong,
155            crate::lexer::token_type::MarkdownTokenType::Strikethrough => MarkdownElementType::Strikethrough,
156            crate::lexer::token_type::MarkdownTokenType::InlineCode => MarkdownElementType::InlineCode,
157            crate::lexer::token_type::MarkdownTokenType::CodeBlock => MarkdownElementType::CodeBlock,
158            crate::lexer::token_type::MarkdownTokenType::CodeFence => MarkdownElementType::CodeFence,
159            crate::lexer::token_type::MarkdownTokenType::CodeLanguage => MarkdownElementType::CodeLanguage,
160            crate::lexer::token_type::MarkdownTokenType::Link => MarkdownElementType::Link,
161            crate::lexer::token_type::MarkdownTokenType::LinkText => MarkdownElementType::LinkText,
162            crate::lexer::token_type::MarkdownTokenType::LinkUrl => MarkdownElementType::LinkUrl,
163            crate::lexer::token_type::MarkdownTokenType::LinkTitle => MarkdownElementType::LinkTitle,
164            crate::lexer::token_type::MarkdownTokenType::Image => MarkdownElementType::Image,
165            crate::lexer::token_type::MarkdownTokenType::ImageAlt => MarkdownElementType::ImageAlt,
166            crate::lexer::token_type::MarkdownTokenType::ImageUrl => MarkdownElementType::ImageUrl,
167            crate::lexer::token_type::MarkdownTokenType::ImageTitle => MarkdownElementType::ImageTitle,
168            crate::lexer::token_type::MarkdownTokenType::UnorderedList => MarkdownElementType::UnorderedList,
169            crate::lexer::token_type::MarkdownTokenType::OrderedList => MarkdownElementType::OrderedList,
170            crate::lexer::token_type::MarkdownTokenType::ListItem => MarkdownElementType::ListItem,
171            crate::lexer::token_type::MarkdownTokenType::ListMarker => MarkdownElementType::ListMarker,
172            crate::lexer::token_type::MarkdownTokenType::TaskList => MarkdownElementType::TaskList,
173            crate::lexer::token_type::MarkdownTokenType::TaskMarker => MarkdownElementType::TaskMarker,
174            crate::lexer::token_type::MarkdownTokenType::Blockquote => MarkdownElementType::Blockquote,
175            crate::lexer::token_type::MarkdownTokenType::BlockquoteMarker => MarkdownElementType::BlockquoteMarker,
176            crate::lexer::token_type::MarkdownTokenType::HorizontalRule => MarkdownElementType::HorizontalRule,
177            crate::lexer::token_type::MarkdownTokenType::Table => MarkdownElementType::Table,
178            crate::lexer::token_type::MarkdownTokenType::TableRow => MarkdownElementType::TableRow,
179            crate::lexer::token_type::MarkdownTokenType::TableCell => MarkdownElementType::TableCell,
180            crate::lexer::token_type::MarkdownTokenType::TableHeader => MarkdownElementType::TableHeader,
181            crate::lexer::token_type::MarkdownTokenType::TableSeparator => MarkdownElementType::TableSeparator,
182            crate::lexer::token_type::MarkdownTokenType::TableAlignment => MarkdownElementType::TableAlignment,
183            crate::lexer::token_type::MarkdownTokenType::MathInline => MarkdownElementType::MathInline,
184            crate::lexer::token_type::MarkdownTokenType::MathBlock => MarkdownElementType::MathBlock,
185            crate::lexer::token_type::MarkdownTokenType::FootnoteDefinition => MarkdownElementType::FootnoteDefinition,
186            crate::lexer::token_type::MarkdownTokenType::FootnoteReference => MarkdownElementType::FootnoteReference,
187            crate::lexer::token_type::MarkdownTokenType::FrontMatter => MarkdownElementType::FrontMatter,
188            crate::lexer::token_type::MarkdownTokenType::DefinitionList => MarkdownElementType::DefinitionList,
189            crate::lexer::token_type::MarkdownTokenType::DefinitionTerm => MarkdownElementType::DefinitionTerm,
190            crate::lexer::token_type::MarkdownTokenType::DefinitionDescription => MarkdownElementType::DefinitionDescription,
191            crate::lexer::token_type::MarkdownTokenType::Superscript => MarkdownElementType::Superscript,
192            crate::lexer::token_type::MarkdownTokenType::Subscript => MarkdownElementType::Subscript,
193            crate::lexer::token_type::MarkdownTokenType::Abbreviation => MarkdownElementType::Abbreviation,
194            crate::lexer::token_type::MarkdownTokenType::HtmlTag => MarkdownElementType::HtmlTag,
195            crate::lexer::token_type::MarkdownTokenType::HtmlComment => MarkdownElementType::HtmlComment,
196            crate::lexer::token_type::MarkdownTokenType::XmlTag => MarkdownElementType::XmlTag,
197            crate::lexer::token_type::MarkdownTokenType::XmlComment => MarkdownElementType::XmlComment,
198            crate::lexer::token_type::MarkdownTokenType::AutoLink => MarkdownElementType::AutoLink,
199            crate::lexer::token_type::MarkdownTokenType::Error => MarkdownElementType::Error,
200            _ => MarkdownElementType::Error,
201        }
202    }
203}