use super::SourceSpan;
use crate::NodeId;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(
tag = "type",
rename_all = "kebab-case",
rename_all_fields = "camelCase"
)]
pub enum Inline {
Text {
value: String,
},
Strong {
children: Vec<Inline>,
},
Emphasis {
children: Vec<Inline>,
},
Code {
value: String,
},
Link {
target: LinkTarget,
#[serde(skip_serializing_if = "Option::is_none")]
title: Option<String>,
children: Vec<Inline>,
},
Anchor {
id: NodeId,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
fragment_aliases: Vec<crate::FragmentAlias>,
#[serde(skip_serializing_if = "Option::is_none")]
owner_source: Option<SourceSpan>,
},
LineBreak,
}
impl Inline {
#[must_use]
pub fn anchor(id: impl Into<NodeId>) -> Self {
Self::Anchor {
id: id.into(),
fragment_aliases: Vec::new(),
owner_source: None,
}
}
#[must_use]
pub fn anchor_at(id: impl Into<NodeId>, owner_source: Option<SourceSpan>) -> Self {
Self::Anchor {
id: id.into(),
fragment_aliases: Vec::new(),
owner_source,
}
}
#[must_use]
pub fn anchor_with_aliases(
id: impl Into<NodeId>,
fragment_aliases: Vec<crate::FragmentAlias>,
) -> Self {
Self::Anchor {
id: id.into(),
fragment_aliases,
owner_source: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(
tag = "kind",
rename_all = "kebab-case",
rename_all_fields = "camelCase",
deny_unknown_fields
)]
pub enum LinkTarget {
External {
uri: String,
},
Email {
address: String,
},
Document {
name: String,
#[serde(skip_serializing_if = "Option::is_none")]
fragment: Option<String>,
},
Manual {
name: String,
#[serde(skip_serializing_if = "Option::is_none")]
manual_section: Option<String>,
},
Section {
id: NodeId,
},
}