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
use crate::render_to_string;
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use wasm_bindgen::JsValue;
#[derive(Clone, Deserialize, Serialize)]
pub struct KaTeXOptions {
#[serde(rename = "displayMode")]
pub display_mode: bool,
#[serde(rename = "leqno")]
pub left_equation_numbers: bool,
#[serde(rename = "fleqn")]
pub flush_left_equations: bool,
#[serde(rename = "throwOnError")]
pub throw_on_error: bool,
#[serde(rename = "minRuleThickness")]
pub min_rule_thickness: f64,
#[serde(rename = "maxSize")]
pub max_size: f64,
#[serde(rename = "maxExpand")]
pub max_expand: i32,
pub strict: bool,
pub trust: bool,
#[serde(rename = "globalGroup")]
pub global_group: bool,
output: String,
macros: HashMap<String, String>,
#[serde(rename = "errorColor")]
error_color: String,
}
impl Default for KaTeXOptions {
fn default() -> Self {
Self {
display_mode: false,
output: "html".to_string(),
flush_left_equations: false,
left_equation_numbers: false,
throw_on_error: false,
error_color: "#cc0000".to_string(),
macros: Default::default(),
min_rule_thickness: 0.04,
max_size: f64::INFINITY,
max_expand: 1000,
strict: false,
trust: false,
global_group: false,
}
}
}
impl KaTeXOptions {
pub fn display_mode() -> KaTeXOptions {
KaTeXOptions { display_mode: true, ..KaTeXOptions::default() }
}
pub fn inline_mode() -> KaTeXOptions {
KaTeXOptions { display_mode: false, ..KaTeXOptions::default() }
}
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: &str) -> bool {
let set = match format.to_ascii_lowercase().as_str() {
"html" => "html",
"mathml" => "mathml",
"htmlandmathml" => "htmlAndMathml",
_ => return false,
};
self.output = String::from(set);
return true;
}
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!()
}
}