flams_web_utils/
mathml.rs

1#![allow(clippy::must_use_candidate)]
2const MML_TAGS: [&str; 31] = [
3    "math",
4    "mi",
5    "mn",
6    "mo",
7    "ms",
8    "mspace",
9    "mtext",
10    "menclose",
11    "merror",
12    "mfenced",
13    "mfrac",
14    "mpadded",
15    "mphantom",
16    "mroot",
17    "mrow",
18    "msqrt",
19    "mstyle",
20    "mmultiscripts",
21    "mover",
22    "mprescripts",
23    "msub",
24    "msubsup",
25    "msup",
26    "munder",
27    "munderover",
28    "mtable",
29    "mtd",
30    "mtr",
31    "maction",
32    "annotation",
33    "semantics",
34];
35
36#[must_use]
37pub fn is(tag: &str) -> Option<&'static str> {
38    MML_TAGS
39        .iter()
40        .find(|e| tag.eq_ignore_ascii_case(e))
41        .copied()
42}
43
44use leptos::prelude::*;
45
46#[component]
47pub fn MathMLTag<Ch:IntoView+'static>(tag: &'static str, children: TypedChildren<Ch>) -> impl IntoView {
48    let children = children.into_inner();
49    match tag {
50        "math" => view!(<math>{children()}</math>).into_any(),
51        "mi" => view!(<mi>{children()}</mi>).into_any(),
52        "mn" => view!(<mn>{children()}</mn>).into_any(),
53        "mo" => view!(<mo>{children()}</mo>).into_any(),
54        "ms" => view!(<ms>{children()}</ms>).into_any(),
55        "mspace" => view!(<mspace>{children()}</mspace>).into_any(),
56        "mtext" => view!(<mtext>{children()}</mtext>).into_any(),
57        "menclose" => view!(<menclose>{children()}</menclose>).into_any(),
58        "merror" => view!(<merror>{children()}</merror>).into_any(),
59        "mfenced" => view!(<mfenced>{children()}</mfenced>).into_any(),
60        "mfrac" => view!(<mfrac>{children()}</mfrac>).into_any(),
61        "mpadded" => view!(<mpadded>{children()}</mpadded>).into_any(),
62        "mphantom" => view!(<mphantom>{children()}</mphantom>).into_any(),
63        "mroot" => view!(<mroot>{children()}</mroot>).into_any(),
64        //"mrow" => view!(<mrow>{children()}</mrow>).into_any(),
65        "msqrt" => view!(<msqrt>{children()}</msqrt>).into_any(),
66        "mstyle" => view!(<mstyle>{children()}</mstyle>).into_any(),
67        "mmultiscripts" => view!(<mmultiscripts>{children()}</mmultiscripts>).into_any(),
68        "mover" => view!(<mover>{children()}</mover>).into_any(),
69        "mprescripts" => view!(<mprescripts>{children()}</mprescripts>).into_any(),
70        "msub" => view!(<msub>{children()}</msub>).into_any(),
71        "msubsup" => view!(<msubsup>{children()}</msubsup>).into_any(),
72        "msup" => view!(<msup>{children()}</msup>).into_any(),
73        "munder" => view!(<munder>{children()}</munder>).into_any(),
74        "munderover" => view!(<munderover>{children()}</munderover>).into_any(),
75        "mtable" => view!(<mtable>{children()}</mtable>).into_any(),
76        "mtd" => view!(<mtd>{children()}</mtd>).into_any(),
77        "mtr" => view!(<mtr>{children()}</mtr>).into_any(),
78        "maction" => view!(<maction>{children()}</maction>).into_any(),
79        "annotation" => view!(<annotation>{children()}</annotation>).into_any(),
80        "semantics" => view!(<semantics>{children()}</semantics>).into_any(),
81        _ => view!(<mrow>{children()}</mrow>).into_any(),
82    }
83}