1use crate::span::Span;
8
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub struct SegmentOffset {
12 pub text_offset: usize,
13 pub source_offset: usize,
14}
15
16impl SegmentOffset {
17 pub fn new(text_offset: usize, source_offset: usize) -> SegmentOffset {
18 SegmentOffset {
19 text_offset,
20 source_offset,
21 }
22 }
23}
24
25#[derive(Clone, Debug, PartialEq, Eq)]
27pub struct Heading {
28 pub level: usize,
29 pub text: String,
30 pub span: Span,
31}
32
33#[derive(Clone, Debug, PartialEq, Eq)]
35pub struct Paragraph {
36 pub text: String,
37 pub span: Span,
38 pub segment_map: Vec<SegmentOffset>,
39}
40
41#[derive(Clone, Debug, PartialEq, Eq)]
43pub struct ListItem {
44 pub text: String,
45 pub span: Span,
46 pub segment_map: Vec<SegmentOffset>,
47 pub ordered: bool,
48 pub marker_span: Span,
49}
50
51#[derive(Clone, Debug, PartialEq, Eq)]
53pub struct Blockquote {
54 pub text: String,
55 pub span: Span,
56 pub segment_map: Vec<SegmentOffset>,
57}
58
59#[derive(Clone, Debug, PartialEq, Eq)]
61pub struct Row {
62 pub cells: Vec<String>,
63 pub cell_spans: Vec<Span>,
64 pub span: Span,
65}
66
67#[derive(Clone, Debug, PartialEq, Eq)]
69pub struct Table {
70 pub span: Span,
71 pub header: Row,
72 pub rows: Vec<Row>,
73}
74
75#[derive(Clone, Debug, PartialEq, Eq)]
77pub struct Fence {
78 pub span: Span,
79 pub info: String,
80 pub body: String,
81 pub body_span: Span,
82}
83
84#[derive(Clone, Copy, Debug, PartialEq, Eq)]
86pub struct ThematicBreak {
87 pub span: Span,
88}
89
90#[derive(Clone, Debug, PartialEq, Eq)]
92pub enum Block {
93 Heading(Heading),
94 Paragraph(Paragraph),
95 ListItem(ListItem),
96 Blockquote(Blockquote),
97 Table(Table),
98 Fence(Fence),
99 ThematicBreak(ThematicBreak),
100}
101
102impl Block {
103 pub fn span(&self) -> Span {
105 match self {
106 Block::Heading(h) => h.span,
107 Block::Paragraph(p) => p.span,
108 Block::ListItem(l) => l.span,
109 Block::Blockquote(b) => b.span,
110 Block::Table(t) => t.span,
111 Block::Fence(f) => f.span,
112 Block::ThematicBreak(t) => t.span,
113 }
114 }
115}
116
117#[derive(Clone, Debug, PartialEq, Eq)]
119pub enum TableOrFence {
120 Table(Table),
121 Fence(Fence),
122}
123
124#[derive(Clone, Debug, PartialEq, Eq)]
127pub struct Example {
128 pub scope_stack: Vec<String>,
129 pub span: Span,
130 pub body: Vec<Block>,
131 pub preceded_by_delimiter: bool,
137}
138
139#[derive(Clone, Debug, PartialEq, Eq)]
141pub struct Doc {
142 pub path: String,
143 pub source: String,
144 pub examples: Vec<Example>,
145 pub orphan_attachments: Vec<TableOrFence>,
146}