Skip to main content

oak_markdown/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5/// Element types for the Markdown language.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8#[repr(u16)]
9pub enum MarkdownElementType {
10    /// The root of the document.
11    Root,
12    /// A paragraph of text.
13    Paragraph,
14    /// A table.
15    Table,
16    /// Heading level 1.
17    Heading1,
18    /// Heading level 2.
19    Heading2,
20    /// Heading level 3.
21    Heading3,
22    /// Heading level 4.
23    Heading4,
24    /// Heading level 5.
25    Heading5,
26    /// Heading level 6.
27    Heading6,
28    /// A blockquote.
29    Blockquote,
30    /// A code block.
31    CodeBlock,
32    /// A list.
33    List,
34    /// A list item.
35    ListItem,
36    /// A horizontal rule.
37    HorizontalRule,
38    /// A math block.
39    MathBlock,
40    /// Front matter.
41    FrontMatter,
42    /// A footnote definition.
43    FootnoteDefinition,
44    /// Plain text.
45    Text,
46    /// Whitespace.
47    Whitespace,
48    /// A newline.
49    Newline,
50    /// The text of a heading.
51    HeadingText,
52    /// Emphasized text.
53    Emphasis,
54    /// Strong text.
55    Strong,
56    /// Strikethrough text.
57    Strikethrough,
58    /// Inline code.
59    InlineCode,
60    /// A code fence.
61    CodeFence,
62    /// A code language identifier.
63    CodeLanguage,
64    /// A link.
65    Link,
66    /// The text of a link.
67    LinkText,
68    /// The URL of a link.
69    LinkUrl,
70    /// The title of a link.
71    LinkTitle,
72    /// An image.
73    Image,
74    /// The alt text of an image.
75    ImageAlt,
76    /// The URL of an image.
77    ImageUrl,
78    /// The title of an image.
79    ImageTitle,
80    /// An unordered list.
81    UnorderedList,
82    /// An ordered list.
83    OrderedList,
84    /// A list marker.
85    ListMarker,
86    /// A task list.
87    TaskList,
88    /// A task marker.
89    TaskMarker,
90    /// A blockquote marker.
91    BlockquoteMarker,
92    /// A table row.
93    TableRow,
94    /// A table cell.
95    TableCell,
96    /// A table header cell.
97    TableHeader,
98    /// A table separator.
99    TableSeparator,
100    /// Table alignment information.
101    TableAlignment,
102    /// Inline math.
103    MathInline,
104    /// A footnote reference.
105    FootnoteReference,
106    /// A definition list.
107    DefinitionList,
108    /// A definition term.
109    DefinitionTerm,
110    /// A definition description.
111    DefinitionDescription,
112    /// Superscript text.
113    Superscript,
114    /// Subscript text.
115    Subscript,
116    /// An abbreviation.
117    Abbreviation,
118    /// An HTML tag.
119    HtmlTag,
120    /// An HTML comment.
121    HtmlComment,
122    /// An XML tag.
123    XmlTag,
124    /// An XML comment.
125    XmlComment,
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::Error => MarkdownElementType::Error,
199            _ => MarkdownElementType::Error,
200        }
201    }
202}