forge_doc/writer/
markdown.rsuse crate::{AsDoc, AsDocResult};
#[derive(Debug)]
pub enum Markdown<'a> {
H1(&'a str),
H2(&'a str),
H3(&'a str),
Italic(&'a str),
Bold(&'a str),
Link(&'a str, &'a str),
Code(&'a str),
CodeBlock(&'a str, &'a str),
}
impl AsDoc for Markdown<'_> {
fn as_doc(&self) -> AsDocResult {
let doc = match self {
Self::H1(val) => format!("# {val}"),
Self::H2(val) => format!("## {val}"),
Self::H3(val) => format!("### {val}"),
Self::Italic(val) => format!("*{val}*"),
Self::Bold(val) => format!("**{val}**"),
Self::Link(val, link) => format!("[{val}]({link})"),
Self::Code(val) => format!("`{val}`"),
Self::CodeBlock(lang, val) => format!("```{lang}\n{val}\n```"),
};
Ok(doc)
}
}
impl std::fmt::Display for Markdown<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}", self.as_doc()?))
}
}