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
|
use crate::*;
pub enum BlockElement {
/// A first-level heading.
DocumentHeading(Line),
/// A second-level heading.
SectionHeading(Line),
/// A third-level heading.
ArticleHeading(Line),
Paragraph(Line),
/// A bullet-list.
List(Vec<Line>),
/// A paragraph separate from the main text.
Aside(Vec<Line>),
Table(Table),
EmbeddedFile(EmbeddedFile),
/// A non-markdown sub-document within this document.
Subdocument(Subdocument),
/// A KaTeX block
Math(String),
Break,
}
pub struct EmbeddedFile {
pub label: String,
pub target: String,
}
pub struct Subdocument {
pub language: String,
pub content: String,
}
impl std::fmt::Debug for BlockElement {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
let string = match self {
BlockElement::DocumentHeading(line) => format!("DocumentHeading ('{line}')"),
BlockElement::SectionHeading(line) => format!("SectionHeading ('{line}')"),
BlockElement::ArticleHeading(line) => format!("ArticleHeading ('{line}')"),
BlockElement::Paragraph(line) => format!("Paragraph ('{line}')"),
BlockElement::List(lines) => format!("List (len: {})", lines.len()),
BlockElement::Aside(_) => format!("Aside"),
BlockElement::Table(_) => format!("Table"),
BlockElement::EmbeddedFile(EmbeddedFile {label, target}) =>
format!("EmbeddedFile (label:'{label}', target:'{target}')"),
BlockElement::Subdocument(Subdocument {language, ..}) =>
format!("Subdocument ('{language}')"),
BlockElement::Math(string) => format!("Math ('{string}')"),
BlockElement::Break => format!("Break"),
};
f.write_str(&string)
}
}
|