-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathmod.rs
80 lines (72 loc) · 2.02 KB
/
mod.rs
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
mod block;
mod span;
#[allow(missing_docs)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum OrderedListType {
Numeric,
Lowercase,
Uppercase,
LowercaseRoman,
UppercaseRoman,
}
impl OrderedListType {
pub fn from_str(type_str: &str) -> OrderedListType {
match type_str {
"a" => OrderedListType::Lowercase,
"A" => OrderedListType::Uppercase,
"i" => OrderedListType::LowercaseRoman,
"I" => OrderedListType::UppercaseRoman,
_ => OrderedListType::Numeric,
}
}
pub fn to_str(&self) -> &'static str {
match self {
OrderedListType::Lowercase => "a",
OrderedListType::Uppercase => "A",
OrderedListType::LowercaseRoman => "i",
OrderedListType::UppercaseRoman => "I",
OrderedListType::Numeric => "1",
}
}
}
#[allow(missing_docs)]
#[derive(Debug, PartialEq, Clone)]
pub enum Block {
Header(Vec<Span>, usize),
Paragraph(Vec<Span>),
Blockquote(Vec<Block>),
CodeBlock(Option<String>, String),
/** A link reference with the fields: (id, url, [title]) **/
LinkReference(String, String, Option<String>),
OrderedList(Vec<ListItem>, OrderedListType),
UnorderedList(Vec<ListItem>),
Raw(String),
Hr,
}
#[allow(missing_docs)]
#[derive(Debug, PartialEq, Clone)]
pub enum ListItem {
Simple(Vec<Span>),
Paragraph(Vec<Block>),
}
#[allow(missing_docs)]
#[derive(Debug, PartialEq, Clone)]
pub enum Span {
Break,
Text(String),
Code(String),
Literal(char),
Link(Vec<Span>, String, Option<String>),
/**
* A reference-style link with the fields: (content, url, raw)
* The "raw" field is used internally for falling back to the original
* markdown link if the corresponding reference is not found at render time.
**/
RefLink(Vec<Span>, String, String),
Image(String, String, Option<String>),
Emphasis(Vec<Span>),
Strong(Vec<Span>),
}
pub fn parse(md: &str) -> Vec<Block> {
block::parse_blocks(md)
}