use auk::{HtmlElement, With, WithChildren};
#[derive(Debug)]
pub struct AProps {
pub href: String,
pub title: Option<String>,
}
#[derive(Debug)]
pub struct CodeProps {
pub language: Option<String>,
}
#[derive(Debug)]
pub struct ImgProps {
pub src: String,
pub alt: Option<String>,
pub title: Option<String>,
}
#[derive(Debug)]
pub struct PreProps {
pub language: Option<String>,
}
pub trait MarkdownComponents: Send + Sync {
fn div(&self) -> HtmlElement {
auk::div()
}
fn p(&self) -> HtmlElement {
auk::p()
}
fn h1(&self) -> HtmlElement {
auk::h1()
}
fn h2(&self) -> HtmlElement {
auk::h2()
}
fn h3(&self) -> HtmlElement {
auk::h3()
}
fn h4(&self) -> HtmlElement {
auk::h4()
}
fn h5(&self) -> HtmlElement {
auk::h5()
}
fn h6(&self) -> HtmlElement {
auk::h6()
}
fn table(&self) -> HtmlElement {
auk::table()
}
fn thead(&self) -> HtmlElement {
auk::thead()
}
fn tbody(&self) -> HtmlElement {
auk::tbody()
}
fn tr(&self) -> HtmlElement {
auk::tr()
}
fn th(&self) -> HtmlElement {
auk::th()
}
fn td(&self) -> HtmlElement {
auk::td()
}
fn blockquote(&self) -> HtmlElement {
auk::blockquote()
}
fn pre(&self, props: PreProps) -> HtmlElement {
auk::pre().with(|parent| {
if let Some(language) = props.language {
parent
.class(format!("language-{language}"))
.attr("data-lang", &language)
} else {
parent
}
})
}
fn code(&self, props: CodeProps) -> HtmlElement {
auk::code().with(|parent| {
if let Some(language) = props.language {
parent
.class(format!("language-{language}"))
.attr("data-lang", &language)
} else {
parent
}
})
}
fn on_code_block_end(&self, pre: HtmlElement, code: HtmlElement) -> HtmlElement {
pre.child(code)
}
fn ol(&self) -> HtmlElement {
auk::ol()
}
fn ul(&self) -> HtmlElement {
auk::ul()
}
fn li(&self) -> HtmlElement {
auk::li()
}
fn em(&self) -> HtmlElement {
auk::em()
}
fn strong(&self) -> HtmlElement {
auk::strong()
}
fn del(&self) -> HtmlElement {
auk::del()
}
fn a(&self, props: AProps) -> HtmlElement {
auk::a().href(props.href).title::<String>(props.title)
}
fn img(&self, props: ImgProps) -> HtmlElement {
auk::img()
.src(props.src)
.alt::<String>(props.alt)
.title::<String>(props.title)
}
fn br(&self) -> HtmlElement {
auk::br()
}
fn hr(&self) -> HtmlElement {
auk::hr()
}
fn sup(&self) -> HtmlElement {
auk::sup()
}
}
#[allow(unused)]
#[derive(Debug, Clone, Copy)]
pub(crate) struct DefaultMarkdownComponents;
impl DefaultMarkdownComponents {
#[cfg(test)]
pub fn boxed(self) -> Box<dyn MarkdownComponents> {
Box::new(self)
}
}
impl MarkdownComponents for DefaultMarkdownComponents {}