acdc_parser/model/inlines/
text.rs1use serde::{
2 Serialize,
3 ser::{SerializeMap, Serializer},
4};
5
6use crate::{Location, Role};
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}
159
160#[derive(Clone, Debug, PartialEq)]
169pub struct Verbatim {
170 pub content: String,
171 pub location: Location,
172}
173
174impl Serialize for StandaloneCurvedApostrophe {
175 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
176 where
177 S: Serializer,
178 {
179 let mut state = serializer.serialize_map(Some(3))?;
180 state.serialize_entry("name", "curved_apostrophe")?;
181 state.serialize_entry("type", "string")?;
182 state.serialize_entry("location", &self.location)?;
183 state.end()
184 }
185}
186
187#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
189#[serde(rename_all = "lowercase")]
190pub enum CalloutRefKind {
191 Explicit,
193 Auto,
195}
196
197#[derive(Clone, Debug, PartialEq, Eq)]
218pub struct CalloutRef {
219 pub kind: CalloutRefKind,
221 pub number: usize,
223 pub location: Location,
225}
226
227impl CalloutRef {
228 #[must_use]
230 pub fn explicit(number: usize, location: Location) -> Self {
231 Self {
232 kind: CalloutRefKind::Explicit,
233 number,
234 location,
235 }
236 }
237
238 #[must_use]
240 pub fn auto(number: usize, location: Location) -> Self {
241 Self {
242 kind: CalloutRefKind::Auto,
243 number,
244 location,
245 }
246 }
247}
248
249impl Serialize for CalloutRef {
250 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
251 where
252 S: Serializer,
253 {
254 let mut state = serializer.serialize_map(Some(5))?;
255 state.serialize_entry("name", "callout_reference")?;
256 state.serialize_entry("type", "inline")?;
257 state.serialize_entry("variant", &self.kind)?;
258 state.serialize_entry("number", &self.number)?;
259 state.serialize_entry("location", &self.location)?;
260 state.end()
261 }
262}