use super::DiscordComponent;
pub trait ToHtml {
fn to_html(&self) -> String;
}
impl<'a> ToHtml for DiscordComponent<'a> {
fn to_html(&self) -> String {
match self {
DiscordComponent::Plain(s) => s.to_string(), // TODO: Escape
DiscordComponent::Literal(c) => c.to_string(),
DiscordComponent::Link(target) => format!(r#"{0}"#, target),
DiscordComponent::Bold(children) => {
format!("{}", children.to_html())
}
DiscordComponent::Italic(children) => {
format!("{}", children.to_html())
}
DiscordComponent::Strikethrough(children) => {
format!("{}", children.to_html())
}
DiscordComponent::Underline(children) => {
format!("{}", children.to_html())
}
DiscordComponent::Code(source) => format!("{}
", source),
DiscordComponent::CodeBlock { lang, source } => {
let language_class = lang
.map(|l| " class=\"language-".to_owned() + l + "\"")
.unwrap_or_else(String::new);
format!("
{}
", language_class, source)
}
DiscordComponent::Spoiler(children) => {
format!("{}", children.to_html())
}
DiscordComponent::LineBreak => "{}", children.to_html()) } } } } impl<'a> ToHtml for Vec