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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use crate::render_to_string;
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use wasm_bindgen::{prelude::*, JsValue};
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
pub enum OutputType {
Html,
Mathml,
HtmlAndMathml,
}
#[wasm_bindgen]
#[derive(Clone, Deserialize, Serialize)]
#[allow(non_snake_case)]
pub struct KaTeXOptions {
displayMode: bool,
output: String,
leqno: bool,
fleqn: bool,
throwOnError: bool,
errorColor: String,
macros: HashMap<String, String>,
minRuleThickness: f64,
maxSize: f64,
maxExpand: i32,
strict: String,
trust: bool,
globalGroup: bool,
}
impl Default for KaTeXOptions {
fn default() -> Self {
Self {
displayMode: false,
output: "html".to_string(),
leqno: false,
fleqn: false,
throwOnError: false,
errorColor: "#cc0000".to_string(),
macros: Default::default(),
minRuleThickness: 0.04,
maxSize: f64::INFINITY,
maxExpand: 1000,
strict: "warn".to_string(),
trust: false,
globalGroup: false,
}
}
}
impl KaTeXOptions {
pub fn display_mode() -> KaTeXOptions {
let mut o = KaTeXOptions::default();
o.displayMode = true;
return o;
}
pub fn inline_mode() -> KaTeXOptions {
let mut o = KaTeXOptions::default();
o.displayMode = false;
return o;
}
pub fn render(&self, input: &str) -> String {
render_to_string(input, &JsValue::from_serde(self).unwrap())
}
}
impl KaTeXOptions {
pub fn set_output_format(&mut self, format: &OutputType) -> bool {
let set = match format {
OutputType::Html => "html",
OutputType::Mathml => "mathml",
OutputType::HtmlAndMathml => "htmlAndMathml",
};
self.output = String::from(set);
return true;
}
pub fn set_max_size(&mut self) -> bool {
unimplemented!()
}
pub fn set_max_expand(&mut self) -> bool {
unimplemented!()
}
pub fn set_strict_mode(&mut self) -> bool {
unimplemented!()
}
pub fn set_error_color(&mut self) -> bool {
unimplemented!()
}
pub fn set_macro_rules(&mut self) -> bool {
unimplemented!()
}
pub fn insert_macro_rule(&mut self) -> bool {
unimplemented!()
}
}