acdc_parser/model/inlines/
macros.rs1use serde::Serialize;
2
3use crate::{ElementAttributes, InlineNode, Location, Source, StemNotation, Substitution};
4
5pub const ICON_SIZES: &[&str] = &["1x", "2x", "3x", "4x", "5x", "lg", "fw"];
6
7#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
9#[non_exhaustive]
10pub struct Pass<'a> {
11 #[serde(default, skip_serializing_if = "Option::is_none")]
12 pub text: Option<&'a str>,
13 #[serde(default, skip_serializing_if = "Vec::is_empty")]
14 pub substitutions: Vec<Substitution>,
15 pub location: Location,
16 #[serde(skip)]
17 pub kind: PassthroughKind,
18}
19
20#[derive(Clone, Debug, Eq, PartialEq, Serialize, Default)]
21pub enum PassthroughKind {
22 #[default]
23 Single,
24 Double,
25 Triple,
26 Macro,
27 AttributeRef,
30}
31
32#[derive(Clone, Debug, PartialEq, Serialize)]
34#[non_exhaustive]
35pub struct Footnote<'a> {
36 #[serde(default, skip_serializing_if = "Option::is_none")]
37 pub id: Option<&'a str>,
38 #[serde(default, skip_serializing_if = "Vec::is_empty")]
39 pub content: Vec<InlineNode<'a>>,
40 #[serde(skip)]
41 pub number: u32,
42 pub location: Location,
43}
44
45#[derive(Clone, Debug, PartialEq, Serialize)]
47#[non_exhaustive]
48pub struct Icon<'a> {
49 pub target: Source<'a>,
50 pub attributes: ElementAttributes<'a>,
51 pub location: Location,
52}
53
54#[derive(Clone, Debug, PartialEq, Serialize)]
56#[non_exhaustive]
57pub struct Link<'a> {
58 #[serde(skip_serializing)]
59 pub text: Vec<InlineNode<'a>>,
60 pub target: Source<'a>,
61 pub attributes: ElementAttributes<'a>,
62 pub location: Location,
63}
64
65impl<'a> Link<'a> {
66 #[must_use]
68 pub fn new(target: Source<'a>, location: Location) -> Self {
69 Self {
70 text: Vec::new(),
71 target,
72 attributes: ElementAttributes::default(),
73 location,
74 }
75 }
76
77 #[must_use]
79 pub fn with_text(mut self, text: Vec<InlineNode<'a>>) -> Self {
80 self.text = text;
81 self
82 }
83
84 #[must_use]
86 pub fn with_attributes(mut self, attributes: ElementAttributes<'a>) -> Self {
87 self.attributes = attributes;
88 self
89 }
90}
91
92#[derive(Clone, Debug, PartialEq, Serialize)]
94#[non_exhaustive]
95pub struct Url<'a> {
96 #[serde(skip_serializing)]
97 pub text: Vec<InlineNode<'a>>,
98 pub target: Source<'a>,
99 pub attributes: ElementAttributes<'a>,
100 pub location: Location,
101}
102
103#[derive(Clone, Debug, PartialEq, Serialize)]
105#[non_exhaustive]
106pub struct Mailto<'a> {
107 #[serde(skip_serializing)]
108 pub text: Vec<InlineNode<'a>>,
109 pub target: Source<'a>,
110 pub attributes: ElementAttributes<'a>,
111 pub location: Location,
112}
113
114#[derive(Clone, Debug, PartialEq, Serialize)]
116#[non_exhaustive]
117pub struct Button<'a> {
118 pub label: &'a str,
119 pub location: Location,
120}
121
122#[derive(Clone, Debug, PartialEq, Serialize)]
124#[non_exhaustive]
125pub struct Menu<'a> {
126 pub target: &'a str,
127 #[serde(default, skip_serializing_if = "Vec::is_empty")]
128 pub items: Vec<&'a str>,
129 pub location: Location,
130}
131
132#[derive(Clone, Debug, PartialEq, Serialize)]
134#[non_exhaustive]
135pub struct Keyboard<'a> {
136 pub keys: Vec<Key<'a>>,
137 pub location: Location,
138}
139
140impl<'a> Keyboard<'a> {
141 #[must_use]
143 pub fn new(keys: Vec<Key<'a>>, location: Location) -> Self {
144 Self { keys, location }
145 }
146}
147
148pub type Key<'a> = &'a str;
150
151#[derive(Clone, Debug, PartialEq, Serialize)]
153#[non_exhaustive]
154pub struct CrossReference<'a> {
155 pub target: &'a str,
156 #[serde(skip_serializing)]
157 pub text: Vec<InlineNode<'a>>,
158 pub location: Location,
159}
160
161impl<'a> CrossReference<'a> {
162 #[must_use]
164 pub fn new(target: &'a str, location: Location) -> Self {
165 Self {
166 target,
167 text: Vec::new(),
168 location,
169 }
170 }
171
172 #[must_use]
174 pub fn with_text(mut self, text: Vec<InlineNode<'a>>) -> Self {
175 self.text = text;
176 self
177 }
178}
179
180#[derive(Clone, Debug, PartialEq, Serialize)]
182#[non_exhaustive]
183pub struct Autolink<'a> {
184 pub url: Source<'a>,
185 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
188 pub bracketed: bool,
189 pub location: Location,
190}
191
192#[derive(Clone, Debug, PartialEq, Serialize)]
194#[non_exhaustive]
195pub struct Stem<'a> {
196 pub content: &'a str,
197 pub notation: StemNotation,
198 pub location: Location,
199}
200
201#[derive(Clone, Debug, PartialEq, Serialize)]
203#[non_exhaustive]
204pub enum IndexTermKind<'a> {
205 Flow(&'a str),
207 Concealed {
209 term: &'a str,
210 #[serde(default, skip_serializing_if = "Option::is_none")]
211 secondary: Option<&'a str>,
212 #[serde(default, skip_serializing_if = "Option::is_none")]
213 tertiary: Option<&'a str>,
214 },
215}
216
217#[derive(Clone, Debug, PartialEq, Serialize)]
219#[non_exhaustive]
220pub struct IndexTerm<'a> {
221 pub kind: IndexTermKind<'a>,
223 pub location: Location,
224}
225
226impl IndexTerm<'_> {
227 #[must_use]
229 pub fn term(&self) -> &str {
230 match &self.kind {
231 IndexTermKind::Flow(term) | IndexTermKind::Concealed { term, .. } => term,
232 }
233 }
234
235 #[must_use]
237 pub fn secondary(&self) -> Option<&str> {
238 match &self.kind {
239 IndexTermKind::Flow(_) => None,
240 IndexTermKind::Concealed { secondary, .. } => *secondary,
241 }
242 }
243
244 #[must_use]
246 pub fn tertiary(&self) -> Option<&str> {
247 match &self.kind {
248 IndexTermKind::Flow(_) => None,
249 IndexTermKind::Concealed { tertiary, .. } => *tertiary,
250 }
251 }
252
253 #[must_use]
255 pub fn is_visible(&self) -> bool {
256 matches!(self.kind, IndexTermKind::Flow(_))
257 }
258}