1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use super::utils::LC;
use derive_more::{Constructor, From};
use serde::{Deserialize, Serialize};

mod blockquotes;
pub use blockquotes::*;

mod comments;
pub use comments::*;

mod definitions;
pub use definitions::*;

mod dividers;
pub use dividers::*;

mod headers;
pub use headers::*;

mod links;
pub use links::*;

mod lists;
pub use lists::*;

mod math;
pub use math::*;

mod paragraphs;
pub use paragraphs::*;

mod preformatted;
pub use preformatted::*;

mod tables;
pub use tables::*;

mod tags;
pub use tags::*;

mod typefaces;
pub use typefaces::*;

mod inline;
pub use inline::*;

/// Represents a full page containing different components
#[derive(
    Constructor, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize,
)]
pub struct Page {
    pub components: Vec<LC<BlockComponent>>,
}

/// Represents components that are standalone (metaphorically a block element in CSS)
#[derive(Clone, Debug, From, Eq, PartialEq, Serialize, Deserialize)]
pub enum BlockComponent {
    Header(Header),
    Paragraph(Paragraph),
    DefinitionList(DefinitionList),
    List(List),
    Table(Table),
    PreformattedText(PreformattedText),
    Math(MathBlock),
    Blockquote(Blockquote),
    Divider(Divider),
    Tags(Tags),
    NonBlankLine(String),
    BlankLine,
}

macro_rules! lc_mapping {
    ($type:ty) => {
        impl From<LC<$type>> for LC<BlockComponent> {
            fn from(component: LC<$type>) -> Self {
                component.map(BlockComponent::from)
            }
        }
    };
}

lc_mapping!(Header);
lc_mapping!(Paragraph);
lc_mapping!(DefinitionList);
lc_mapping!(List);
lc_mapping!(Table);
lc_mapping!(PreformattedText);
lc_mapping!(MathBlock);
lc_mapping!(Blockquote);
lc_mapping!(Divider);
lc_mapping!(Tags);
lc_mapping!(String);