note_mark/model/
tree.rs

1//! The tree structure of the parsed markdown document.
2
3use std::borrow::Cow;
4
5/// The struct to represent a root markdown document.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct MarkdownTree<'a> {
8    pub root: BlockTree<'a>,
9}
10
11/// The struct to represent a block tree.
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct BlockTree<'a> {
14    pub root: Vec<BlockItem<'a>>,
15}
16
17/// The enum to represent a block item.
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum BlockItem<'a> {
20    Paragraph(InlineTree<'a>),
21    Headline(u8, InlineTree<'a>),
22    BulletList(ListTree<'a>),
23    OrderedList(ListTree<'a>),
24    BlockQuote(BlockTree<'a>),
25    Container(Vec<String>, BlockTree<'a>),
26}
27
28/// The struct to represent a list tree.
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct ListTree<'a> {
31    pub root: Vec<ListItem<'a>>,
32}
33
34/// The struct to represent a list item.
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub struct ListItem<'a> {
37    /// A label of the list item.
38    pub name: InlineTree<'a>,
39    /// Children of the list item.
40    pub children: Vec<BlockItem<'a>>,
41}
42
43/// The struct to represent an inline tree.
44#[derive(Debug, Clone, PartialEq, Eq)]
45pub struct InlineTree<'a> {
46    pub root: Vec<InlineItem<'a>>,
47}
48
49/// The enum to represent an inline item.
50#[derive(Debug, Clone, PartialEq, Eq)]
51pub enum InlineItem<'a> {
52    Text(Cow<'a, str>),
53    Italic(InlineTree<'a>),
54    Strong(InlineTree<'a>),
55    Break,
56}