use crate::ast::Ast;
mod html;
mod markdown;
#[cfg(feature = "macros")] mod macros;
fn safe_link_target(target: &str) -> bool {
if target.is_empty()
|| target.chars().any(|character| {
character.is_whitespace() || character.is_control() || character == '\\'
})
{
return false;
}
match target.find([':', '/', '?', '#']) {
Some(index) if target.as_bytes()[index] == b':' => matches!(
target[..index].to_ascii_lowercase().as_str(),
"gemini" | "gopher" | "http" | "https" | "mailto" | "ftp"
),
_ => true,
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Target {
HTML,
Markdown,
}
#[must_use]
pub fn from_ast(source: &Ast, target: &Target) -> String {
match target {
Target::Markdown => markdown::convert(source.inner()),
Target::HTML => html::convert(source.inner()),
}
}
#[must_use]
pub fn from_string(source: impl AsRef<str>, target: &Target) -> String {
from_ast(&Ast::from_string(source), target)
}