acdc_parser/model/inlines/
text.rs1use serde::{
2 Serialize,
3 ser::{SerializeMap, Serializer},
4};
5
6use crate::{Location, Role, Substitution};
7
8use super::InlineNode;
9
10#[derive(Clone, Debug, PartialEq, Serialize)]
12#[serde(rename_all = "lowercase")]
13pub enum Form {
14 Constrained,
15 Unconstrained,
16}
17
18#[derive(Clone, Debug, PartialEq)]
20pub struct Subscript {
21 pub role: Option<Role>,
22 pub id: Option<String>,
23 pub form: Form,
24 pub content: Vec<InlineNode>,
25 pub location: Location,
26}
27
28#[derive(Clone, Debug, PartialEq)]
30pub struct Superscript {
31 pub role: Option<Role>,
32 pub id: Option<String>,
33 pub form: Form,
34 pub content: Vec<InlineNode>,
35 pub location: Location,
36}
37
38#[derive(Clone, Debug, PartialEq)]
40pub struct CurvedQuotation {
41 pub role: Option<Role>,
42 pub id: Option<String>,
43 pub form: Form,
44 pub content: Vec<InlineNode>,
45 pub location: Location,
46}
47
48#[derive(Clone, Debug, PartialEq)]
50pub struct CurvedApostrophe {
51 pub role: Option<Role>,
52 pub id: Option<String>,
53 pub form: Form,
54 pub content: Vec<InlineNode>,
55 pub location: Location,
56}
57
58#[derive(Clone, Debug, PartialEq)]
60pub struct StandaloneCurvedApostrophe {
61 pub location: Location,
62}
63
64#[derive(Clone, Debug, PartialEq)]
66pub struct Monospace {
67 pub role: Option<Role>,
68 pub id: Option<String>,
69 pub form: Form,
70 pub content: Vec<InlineNode>,
71 pub location: Location,
72}
73
74#[derive(Clone, Debug, PartialEq)]
76pub struct Highlight {
77 pub role: Option<Role>,
78 pub id: Option<String>,
79 pub form: Form,
80 pub content: Vec<InlineNode>,
81 pub location: Location,
82}
83
84#[derive(Clone, Debug, PartialEq)]
86pub struct Bold {
87 pub role: Option<Role>,
88 pub id: Option<String>,
89 pub form: Form,
90 pub content: Vec<InlineNode>,
91 pub location: Location,
92}
93
94#[derive(Clone, Debug, PartialEq)]
96pub struct Italic {
97 pub role: Option<Role>,
98 pub id: Option<String>,
99 pub form: Form,
100 pub content: Vec<InlineNode>,
101 pub location: Location,
102}
103
104#[derive(Clone, Debug, PartialEq)]
106pub struct LineBreak {
107 pub location: Location,
108}
109
110impl Serialize for LineBreak {
111 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
112 where
113 S: Serializer,
114 {
115 let mut state = serializer.serialize_map(Some(3))?;
116 state.serialize_entry("name", "linebreak")?;
117 state.serialize_entry("type", "string")?;
118 state.serialize_entry("location", &self.location)?;
119 state.end()
120 }
121}
122
123#[derive(Clone, Debug, PartialEq)]
127pub struct Plain {
128 pub content: String,
129 pub location: Location,
130 pub escaped: bool,
133}
134
135impl Serialize for Plain {
136 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
137 where
138 S: Serializer,
139 {
140 let mut state = serializer.serialize_map(Some(4))?;
141 state.serialize_entry("name", "text")?;
142 state.serialize_entry("type", "string")?;
143 state.serialize_entry("value", &self.content)?;
144 state.serialize_entry("location", &self.location)?;
145 state.end()
146 }
147}
148
149#[derive(Clone, Debug, PartialEq)]
155pub struct Raw {
156 pub content: String,
157 pub location: Location,
158 pub subs: Vec<Substitution>,
165}
166
167#[derive(Clone, Debug, PartialEq)]
176pub struct Verbatim {
177 pub content: String,
178 pub location: Location,
179}
180
181impl Serialize for StandaloneCurvedApostrophe {
182 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
183 where
184 S: Serializer,
185 {
186 let mut state = serializer.serialize_map(Some(3))?;
187 state.serialize_entry("name", "curved_apostrophe")?;
188 state.serialize_entry("type", "string")?;
189 state.serialize_entry("location", &self.location)?;
190 state.end()
191 }
192}
193
194#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
196#[serde(rename_all = "lowercase")]
197pub enum CalloutRefKind {
198 Explicit,
200 Auto,
202}
203
204#[derive(Clone, Debug, PartialEq, Eq)]
225pub struct CalloutRef {
226 pub kind: CalloutRefKind,
228 pub number: usize,
230 pub location: Location,
232}
233
234impl CalloutRef {
235 #[must_use]
237 pub fn explicit(number: usize, location: Location) -> Self {
238 Self {
239 kind: CalloutRefKind::Explicit,
240 number,
241 location,
242 }
243 }
244
245 #[must_use]
247 pub fn auto(number: usize, location: Location) -> Self {
248 Self {
249 kind: CalloutRefKind::Auto,
250 number,
251 location,
252 }
253 }
254}
255
256impl Serialize for CalloutRef {
257 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
258 where
259 S: Serializer,
260 {
261 let mut state = serializer.serialize_map(Some(5))?;
262 state.serialize_entry("name", "callout_reference")?;
263 state.serialize_entry("type", "inline")?;
264 state.serialize_entry("variant", &self.kind)?;
265 state.serialize_entry("number", &self.number)?;
266 state.serialize_entry("location", &self.location)?;
267 state.end()
268 }
269}