acdc_parser/model/
anchor.rs1use serde::{
4 Serialize,
5 ser::{SerializeMap, Serializer},
6};
7
8use super::location::Location;
9use super::title::Title;
10
11pub const UNNUMBERED_SECTION_STYLES: &[&str] = &[
17 "preface",
18 "abstract",
19 "dedication",
20 "colophon",
21 "bibliography",
22 "glossary",
23 "index",
24 "appendix",
25];
26
27#[derive(Clone, Debug, Default, PartialEq, Serialize)]
31#[non_exhaustive]
32pub struct Anchor {
33 pub id: String,
34 #[serde(default, skip_serializing_if = "Option::is_none")]
35 pub xreflabel: Option<String>,
36 pub location: Location,
37}
38
39impl Anchor {
40 #[must_use]
42 pub fn new(id: String, location: Location) -> Self {
43 Self {
44 id,
45 xreflabel: None,
46 location,
47 }
48 }
49
50 #[must_use]
52 pub fn with_xreflabel(mut self, xreflabel: Option<String>) -> Self {
53 self.xreflabel = xreflabel;
54 self
55 }
56}
57
58#[derive(Clone, Debug, PartialEq)]
62#[non_exhaustive]
63pub struct TocEntry {
64 pub id: String,
66 pub title: Title,
68 pub level: u8,
70 pub xreflabel: Option<String>,
72 pub numbered: bool,
76}
77
78impl Serialize for TocEntry {
79 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
80 where
81 S: Serializer,
82 {
83 let mut state = serializer.serialize_map(None)?;
84 state.serialize_entry("id", &self.id)?;
85 state.serialize_entry("title", &self.title)?;
86 state.serialize_entry("level", &self.level)?;
87 if self.xreflabel.is_some() {
88 state.serialize_entry("xreflabel", &self.xreflabel)?;
89 }
90 state.end()
91 }
92}