Skip to main content

sciforge_parser/markdown/
value.rs

1#[derive(Clone, Copy, Debug, PartialEq)]
2pub enum MdValue<'a> {
3    Document,
4    Heading(u8),
5    Paragraph,
6    CodeBlock,
7    ThematicBreak,
8    BlockQuote,
9    List,
10    Table,
11    Text(&'a str),
12}
13
14impl<'a> MdValue<'a> {
15    pub const fn is_document(&self) -> bool {
16        matches!(self, MdValue::Document)
17    }
18
19    pub const fn is_heading(&self) -> bool {
20        matches!(self, MdValue::Heading(..))
21    }
22
23    pub const fn heading_level(&self) -> Option<u8> {
24        match self {
25            MdValue::Heading(lvl) => Some(*lvl),
26            _ => None,
27        }
28    }
29
30    pub const fn is_code_block(&self) -> bool {
31        matches!(self, MdValue::CodeBlock)
32    }
33
34    pub const fn is_list(&self) -> bool {
35        matches!(self, MdValue::List)
36    }
37
38    pub const fn is_table(&self) -> bool {
39        matches!(self, MdValue::Table)
40    }
41
42    pub const fn as_text(&self) -> Option<&str> {
43        match self {
44            MdValue::Text(v) => Some(v),
45            _ => None,
46        }
47    }
48}