1use crate::prelude::*;
2
3impl From<&str> for TextType {
4 fn from(value: &str) -> Self {
5 match value {
6 "normal" => Self::Normal,
7 "italic" | "emph" => Self::Italic,
8 "bold" | "strongemph" => Self::Bold,
9 "teletype" | "tt" => Self::Teletype,
10 "mathbold" | "mbf" => Self::MathBold,
11 "mathcal" | "mcal" => Self::MathCal,
12 "mathbb" | "mbb" => Self::MathBb,
13 "mathrm" | "mrm" => Self::MathRm,
14 "underline" => Self::Underlined,
15 "inline" | "math" | "dollar" => Self::InlineMath,
16 "display" | "dollardollar" => Self::DisplayMath,
17 "scope" => Self::Scope,
18 "verbatim" => Self::Verbatim,
19 "strikethrough" | "ss" => Self::Strikethrough,
20
21 _ => Self::Normal,
22 }
23 }
24}
25
26impl From<Part> for Component {
27 fn from(value: Part) -> Self {
28 Self::Part(value)
29 }
30}
31
32impl From<Chapter> for Component {
33 fn from(value: Chapter) -> Self {
34 Self::Chapter(value)
35 }
36}
37
38impl From<Section> for Component {
39 fn from(value: Section) -> Self {
40 Self::Section(value)
41 }
42}
43
44impl From<Paragraph> for Component {
45 fn from(value: Paragraph) -> Self {
46 Self::Paragraph(value)
47 }
48}
49
50impl From<Line> for Component {
51 fn from(value: Line) -> Self {
52 Self::Line(value)
53 }
54}
55
56impl From<List> for Component {
57 fn from(value: List) -> Self {
58 Self::List(value)
59 }
60}
61
62impl From<Input> for Component {
63 fn from(value: Input) -> Self {
64 Self::Input(value)
65 }
66}
67
68impl From<TextChunk> for Component {
69 fn from(value: TextChunk) -> Self {
70 Self::TextChunk(value)
71 }
72}
73
74impl From<Subsection> for Component {
75 fn from(value: Subsection) -> Self {
76 Self::Subsection(value)
77 }
78}
79
80impl From<Image> for Component {
81 fn from(value: Image) -> Self {
82 Self::Image(value)
83 }
84}
85
86impl From<Environment> for Component {
87 fn from(value: Environment) -> Self {
88 Component::Environment(value)
89 }
90}
91
92impl From<Frame> for Component {
101 fn from(value: Frame) -> Self {
102 Component::Frame(value)
103 }
104}
105
106impl From<Block> for Component {
107 fn from(value: Block) -> Self {
108 Component::Block(value)
109 }
110}
111
112impl From<Figure> for Component {
113 fn from(value: Figure) -> Self {
114 Component::Figure(value)
115 }
116}
117
118impl From<Table> for Component {
119 fn from(value: Table) -> Self {
120 Component::Table(value)
121 }
122}
123
124impl From<Row> for Component {
125 fn from(value: Row) -> Self {
126 Component::Row(value)
127 }
128}
129
130impl From<Builtin> for Component {
131 fn from(value: Builtin) -> Self {
132 Component::Builtin(value)
133 }
134}
135impl From<Label> for Component {
136 fn from(value: Label) -> Self {
137 Component::Label(value)
138 }
139}
140impl From<Reference> for Component {
141 fn from(value: Reference) -> Self {
142 Component::Reference(value)
143 }
144}
145
146impl From<&str> for Label {
147 fn from(value: &str) -> Self {
148 let q = value.find(":").unwrap_or(0);
149 let typ = &value[..q];
150 let lbl = &value[q + 1..];
151 match typ {
152 "ch" => Self::Chapter(lbl.to_string()),
153 "sec" => Self::Section(lbl.to_string()),
154 "subsec" => Self::Subsection(lbl.to_string()),
155 "eq" => Self::Equation(lbl.to_string()),
156 "tab" => Self::Table(lbl.to_string()),
157 "fig" => Self::Figure(lbl.to_string()),
158 "lst" => Self::Code(lbl.to_string()),
159 "itm" => Self::Item(lbl.to_string()),
160 "alg" => Self::Algorithm(lbl.to_string()),
161 _ => Self::Standard(value.to_string()),
162 }
163 }
164}
165
166impl From<&str> for Reference {
167 fn from(value: &str) -> Self {
168 let q = value.find(":").unwrap_or(0);
169 let typ = &value[..q];
170 let lbl = &value[q + 1..];
171 match typ {
172 "ch" => Self::Chapter(lbl.to_string()),
173 "sec" => Self::Section(lbl.to_string()),
174 "subsec" => Self::Subsection(lbl.to_string()),
175 "eq" => Self::Equation(lbl.to_string()),
176 "tab" => Self::Table(lbl.to_string()),
177 "fig" => Self::Figure(lbl.to_string()),
178 "lst" => Self::Code(lbl.to_string()),
179 "itm" => Self::Item(lbl.to_string()),
180 "alg" => Self::Algorithm(lbl.to_string()),
181 _ => Self::Standard(value.to_string()),
182 }
183 }
184}