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
93
94
95
|
use std::collections::HashMap;
pub mod parser;
pub mod renderer;
pub struct MarkdownAST {
pub root: Layer,
}
pub type Level = u8;
pub type Lang = String;
pub type Title = String;
pub type Url = String;
pub struct Layer {
pub range_row_begin: u32,
pub range_row_end: u32,
pub lines: Vec<Line>,
}
pub struct Line {
pub row: u32,
pub tokens: Vec<Token>,
}
pub struct Token {
pub begin_row: u32,
pub begin_col: u16,
pub end_row: u32,
pub end_col: u16,
pub token: TokenData,
}
pub enum TokenData {
Normal(Fragment),
Newline,
Newlayer(Layer),
// Headings
Heading(Level, Line, Layer),
// Emphasis
Emphasis(Vec<TokenData>, EmphasisStyle),
// Lists
UnorderedList(Line, UnorderedListPrefix),
OrderedList(Line, u32),
// Links
Link(Vec<Fragment>, Url, Option<Title>, LinkType),
// Code
InlineCode(Vec<Fragment>),
CodeBlock(Vec<Line>, Option<Lang>),
// Blockquotes
Blockquotes(Layer),
// HorizontalRule
HorizontalRule(HorizontalRuleType),
// Table
Table(Table),
}
pub struct Fragment {
pub str: String,
}
pub struct EmphasisStyle {
pub bold: bool,
pub italic: bool,
pub strikethrough: bool,
}
pub enum UnorderedListPrefix {
Star,
Dash,
Plus,
}
pub enum LinkType {
Image,
Url,
}
pub enum HorizontalRuleType {
Stars,
Dashes,
Underscores,
}
pub struct Table {
pub contents: HashMap<(u32, u32), Vec<Fragment>>,
}
|