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
56
57
58
59
60
61
62
63
use std::fmt::{Display, Formatter};
mod display;
use crate::MathML;
use html_escape::encode_text;

/// math identifier, `<mi>`
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MathIdentifier {
    identifier: String,
    variant: MathVariant,
}

/// mi mathvariant attribute
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MathVariant {
    Normal,
    Italic,
    Bold,
    BoldItalic,
    DoubleStruck,
    BoldFraktur,
    Script,
    BoldScript,
    Fraktur,
    SansSerif,
    BoldSansSerif,
    SansSerifItalic,
    SansSerifBoldItalic,
    Monospace,
}

impl From<MathIdentifier> for MathML {
    fn from(value: MathIdentifier) -> Self {
        MathML::Letter(Box::new(value))
    }
}

impl MathIdentifier {
    pub fn new<S>(text: S, variant: MathVariant) -> Self
    where
        S: ToString,
    {
        Self { identifier: text.to_string(), variant }
    }
    pub fn normal<S>(text: S) -> Self
    where
        S: ToString,
    {
        Self { identifier: text.to_string(), variant: MathVariant::Normal }
    }
    pub fn italic<S>(text: S) -> Self
    where
        S: ToString,
    {
        Self { identifier: text.to_string(), variant: MathVariant::Italic }
    }
    pub fn get_variant(&self) -> MathVariant {
        self.variant
    }
    pub fn get_identifier(&self) -> &str {
        &self.identifier
    }
}