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 use html_escape::encode_quoted_attribute;
23 let mut html = format!(r#"href="{}""#, encode_quoted_attribute(&self.attributes.href));
24
25 if let Some(id) = &self.attributes.id {
26 html.push_str(&format!(r#" id="{}""#, encode_quoted_attribute(id)));
27 }
28
29 if let Some(title) = &self.attributes.title {
30 html.push_str(&format!(r#" title="{}""#, encode_quoted_attribute(title)));
31 }
32
33 html
34 }
35}