adf2html/marks/
link.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, Serialize, Deserialize)]
4#[serde(rename_all = "camelCase")]
5pub struct Link {
6    #[serde(rename = "attrs")]
7    pub attributes: Attributes,
8}
9
10#[derive(Clone, Debug, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct Attributes {
13    pub href: String,
14    pub collection: Option<String>,
15    pub id: Option<String>,
16    pub occurrence_key: Option<String>,
17    pub title: Option<String>,
18}
19
20impl Link {
21    pub(crate) fn html_a_tag_attributes(&self) -> String {
22        let mut html = format!(r#"href="{}""#, self.attributes.href);
23
24        if let Some(id) = &self.attributes.id {
25            html.push_str(&format!(r#" id="{id}""#));
26        }
27
28        if let Some(title) = &self.attributes.title {
29            html.push_str(&format!(r#" title="{title}""#));
30        }
31
32        html
33    }
34}