1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use super::*;
use crate::helpers::safe_html_str;

impl Display for MathIdentifier {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        // maybe short form
        if !f.alternate() && self.variant == MathVariant::Italic {
            f.write_str("<mi>")?;
            safe_html_str(f, &self.identifier)?;
            f.write_str("</mi>")
        }
        else {
            f.write_str("<mi mathvariant=\"")?;
            Display::fmt(&self.variant, f)?;
            f.write_str("\">")?;
            safe_html_str(f, &self.identifier)?;
            f.write_str("</mi>")
        }
    }
}

impl Display for MathText {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        let tag = if self.is_string { "ms" } else { "mtext" };
        f.write_str("<")?;
        f.write_str(tag)?;
        f.write_str(">")?;
        safe_html_str(f, &self.text)?;
        f.write_str("</")?;
        f.write_str(tag)?;
        f.write_str(">")
    }
}

#[rustfmt::skip]
impl Display for MathVariant {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            MathVariant::Normal              => write!(f, "normal"),
            MathVariant::Italic              => write!(f, "italic"),
            MathVariant::Bold                => write!(f, "bold"),
            MathVariant::BoldItalic          => write!(f, "bold-italic"),
            MathVariant::DoubleStruck        => write!(f, "double-struck"),
            MathVariant::BoldFraktur         => write!(f, "bold-fraktur"),
            MathVariant::Script              => write!(f, "script"),
            MathVariant::BoldScript          => write!(f, "bold-script"),
            MathVariant::Fraktur             => write!(f, "fraktur"),
            MathVariant::SansSerif           => write!(f, "sans-serif"),
            MathVariant::BoldSansSerif       => write!(f, "bold-sans-serif"),
            MathVariant::SansSerifItalic     => write!(f, "sans-serif-italic"),
            MathVariant::SansSerifBoldItalic => write!(f, "sans-serif-bold-italic"),
            MathVariant::Monospace           => write!(f, "monospace"),
        }
    }
}