|
|
|
@ -1,11 +1,29 @@
|
|
|
|
|
use crate::elements::literal::{Number, PlainText, Symbol};
|
|
|
|
|
use crate::tokens::{Arrow, FontCommand, Function, Greek, Logical, Misc, Relation};
|
|
|
|
|
use crate::elements::literal::{Literal, Number, PlainText, Symbol};
|
|
|
|
|
use crate::tokens::{Arrow, FontCommand, Function, Greek, Logical, Misc, Operation, Relation};
|
|
|
|
|
use htmlescape::encode_minimal;
|
|
|
|
|
|
|
|
|
|
pub trait ToMathML {
|
|
|
|
|
fn to_mathml(&self) -> String;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ToMathML for Literal {
|
|
|
|
|
fn to_mathml(&self) -> String {
|
|
|
|
|
match self {
|
|
|
|
|
Literal::Text(t) => t.to_mathml(),
|
|
|
|
|
Literal::Symbol(s) => s.to_mathml(),
|
|
|
|
|
Literal::Number(n) => n.to_mathml(),
|
|
|
|
|
Literal::Greek(g) => g.to_mathml(),
|
|
|
|
|
Literal::FontCommand(f) => f.to_mathml(),
|
|
|
|
|
Literal::Relation(r) => r.to_mathml(),
|
|
|
|
|
Literal::Function(f) => f.to_mathml(),
|
|
|
|
|
Literal::Logical(l) => l.to_mathml(),
|
|
|
|
|
Literal::Arrow(a) => a.to_mathml(),
|
|
|
|
|
Literal::Misc(m) => m.to_mathml(),
|
|
|
|
|
Literal::Operation(o) => o.to_mathml(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ToMathML for Greek {
|
|
|
|
|
fn to_mathml(&self) -> String {
|
|
|
|
|
let inner = match self {
|
|
|
|
@ -234,3 +252,36 @@ impl ToMathML for Misc {
|
|
|
|
|
format!("<mi>{}</mi>", inner)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ToMathML for Operation {
|
|
|
|
|
fn to_mathml(&self) -> String {
|
|
|
|
|
let inner = match self {
|
|
|
|
|
Operation::Plus => "+",
|
|
|
|
|
Operation::Minus => "−",
|
|
|
|
|
Operation::CDot => "∙",
|
|
|
|
|
Operation::Ast => "∗",
|
|
|
|
|
Operation::Star => "⋆",
|
|
|
|
|
Operation::Slash => "/",
|
|
|
|
|
Operation::Backslash => "∖",
|
|
|
|
|
Operation::Times => "×",
|
|
|
|
|
Operation::Div => "÷",
|
|
|
|
|
Operation::LTimes => "⋉",
|
|
|
|
|
Operation::RTimes => "⋊",
|
|
|
|
|
Operation::Bowtie => "⋈",
|
|
|
|
|
Operation::Circ => "∘",
|
|
|
|
|
Operation::OPlus => "⊕",
|
|
|
|
|
Operation::OTimes => "⊗",
|
|
|
|
|
Operation::ODot => "⊙",
|
|
|
|
|
Operation::Wedge => "∧",
|
|
|
|
|
Operation::BidWedge => "⋀",
|
|
|
|
|
Operation::Vee => "∨",
|
|
|
|
|
Operation::BigVee => "⋁",
|
|
|
|
|
Operation::Cap => "∩",
|
|
|
|
|
Operation::BigCap => "⋂",
|
|
|
|
|
Operation::Cup => "∪",
|
|
|
|
|
Operation::BigCup => "⋃",
|
|
|
|
|
_ => "",
|
|
|
|
|
};
|
|
|
|
|
format!("<mo>{}</mo>", inner)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|