katex_wasmbind/options/
mod.rs1use crate::render_to_string;
2use serde_derive::{Deserialize, Serialize};
3use std::collections::HashMap;
4use wasm_bindgen::JsValue;
5
6#[derive(Debug, Clone, Deserialize, Serialize)]
7pub struct KaTeXOptions {
9 #[serde(rename = "displayMode")]
11 pub display_mode: bool,
12
13 #[serde(rename = "leqno")]
16 pub left_equation_numbers: bool,
17 #[serde(rename = "fleqn")]
20 pub flush_left_equations: bool,
21 #[serde(rename = "throwOnError")]
23 pub throw_on_error: bool,
24 #[serde(rename = "minRuleThickness")]
28 pub min_rule_thickness: f64,
29 #[serde(rename = "maxSize")]
32 pub max_size: f64,
33 #[serde(rename = "maxExpand")]
36 pub max_expand: i32,
37 pub strict: bool,
39 pub trust: bool,
42 #[serde(rename = "globalGroup")]
44 pub global_group: bool,
45
46 output: String,
48 macros: HashMap<String, String>,
50 #[serde(rename = "errorColor")]
51 error_color: String,
52}
53
54impl Default for KaTeXOptions {
55 fn default() -> Self {
56 Self {
57 display_mode: false,
58 output: "html".to_string(),
59 flush_left_equations: false,
60 left_equation_numbers: false,
61 throw_on_error: false,
62 error_color: "#cc0000".to_string(),
63 macros: Default::default(),
64 min_rule_thickness: 0.04,
65 max_size: f64::INFINITY,
66 max_expand: 1000,
67 strict: false,
68 trust: false,
69 global_group: false,
70 }
71 }
72}
73
74impl KaTeXOptions {
75 pub fn display_mode() -> KaTeXOptions {
77 KaTeXOptions { display_mode: true, ..KaTeXOptions::default() }
78 }
79 pub fn inline_mode() -> KaTeXOptions {
81 KaTeXOptions { display_mode: false, ..KaTeXOptions::default() }
82 }
83 pub fn render(&self, input: &str) -> String {
85 render_to_string(input, &JsValue::from_serde(self).unwrap())
86 }
87}
88
89impl KaTeXOptions {
90 pub fn set_output_format(&mut self, format: &str) -> bool {
96 let set = match format.to_ascii_lowercase().as_str() {
97 "html" => "html",
98 "mathml" => "mathml",
99 "htmlandmathml" => "htmlAndMathml",
100 _ => return false,
101 };
102 self.output = String::from(set);
103 return true;
104 }
105 pub fn set_error_color(&mut self) -> bool {
107 unimplemented!()
108 }
109 pub fn insert_macro_rule(&mut self) -> bool {
111 unimplemented!()
112 }
113}