use super::{Debug, Content, Section, FmlValue, FmlColor, FmlCodeBlockValue};
macro_rules! debug_inner {
($name:expr, $inner:expr, $fmt:expr) => {{
$fmt.write_str($name)?;
$fmt.write_str(" ")?;
$fmt.debug_list().entries($inner.iter()).finish()
}};
}
macro_rules! debug_inline {
($name:expr, $inner:expr, $fmt:expr) => {{
$fmt.write_str($name)?;
$fmt.write_str("(\"")?;
$fmt.write_str($inner)?;
$fmt.write_str("\")")
}};
}
impl Debug for Content {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
debug_inner!("Content", &self.0, f)
}
}
impl Debug for Section {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
debug_inner!("Section", &self.0, f)
}
}
impl Debug for FmlValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Linebreak => write!(f, "Linebreak"),
Self::Heading1(x) => debug_inner!("Header1", x, f),
Self::Heading2(x) => debug_inner!("Header2", x, f),
Self::Heading3(x) => debug_inner!("Header3", x, f),
Self::Superline(x) => debug_inner!("Superline", x, f),
Self::Subline(x) => debug_inner!("Subline", x, f),
Self::Bold(x) => debug_inner!("Bold", x, f),
Self::Italic(x) => debug_inner!("Italic", x, f),
Self::Strikethrough(x) => debug_inner!("Strikethrough", x, f),
Self::Quote(x) => debug_inner!("Quote", x, f),
Self::ListItem(x) => debug_inner!("ListItem", x, f),
Self::Function(x) => f.debug_tuple("Function").field(x).finish(),
Self::Superscript(x) => debug_inner!("Superscript", x, f),
Self::Subscript(x) => debug_inner!("Subscript", x, f),
Self::Underline(x) => debug_inner!("Underline", x, f),
Self::ColorFg(FmlColor { color, body }) => f
.debug_struct("ColorFg")
.field("color", color)
.field("body", body)
.finish(),
Self::ColorBg(FmlColor { color, body }) => f
.debug_struct("ColorBg")
.field("color", color)
.field("body", body)
.finish(),
Self::ContentWarning { reason, body } => f
.debug_struct("CW")
.field("reason", reason)
.field("body", body)
.finish(),
Self::CodeBlock { lang, body } => f
.debug_struct("CodeBlock")
.field("lang", lang)
.field("body", body)
.finish(),
Self::Hyperlink { fml, uri } => f
.debug_struct("Hyperlink")
.field("fml", fml)
.field("uri", uri)
.finish(),
Self::CodeInline(x) => debug_inline!("CodeInline", x, f),
Self::Typst(x) => debug_inline!("Typst", x, f),
Self::Text(x) => debug_inline!("Text", x, f),
}
}
}
impl Debug for FmlCodeBlockValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Str(x) => debug_inline!("Str", x, f),
Self::Linebreak => write!(f, "Linebreak"),
}
}
}