#[derive(Clone, Debug)]
pub struct Link {
pub text: String,
pub url: String,
pub title: Option<String>,
}
impl Link {
pub fn new(text: impl Into<String>, url: impl Into<String>) -> Self {
Self {
text: text.into(),
url: url.into(),
title: None,
}
}
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
pub fn to_markdown(&self) -> String {
match &self.title {
Some(title) => format!("[{}]({} \"{}\")", self.text, self.url, title),
None => format!("[{}]({})", self.text, self.url),
}
}
}
#[derive(Clone, Debug)]
pub struct ImageRef {
pub alt: String,
pub src: String,
pub title: Option<String>,
}
impl ImageRef {
pub fn new(alt: impl Into<String>, src: impl Into<String>) -> Self {
Self {
alt: alt.into(),
src: src.into(),
title: None,
}
}
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
pub fn to_markdown(&self) -> String {
match &self.title {
Some(title) => format!("", self.alt, self.src, title),
None => format!("", self.alt, self.src),
}
}
}