field/
field.rs

1use mathquill_js::{Config, MathField, MathQuill};
2
3fn check_answer(latex: String) {
4  // Whatever you want here
5}
6
7fn main() {
8  // getting this is usually the responsibility of
9  // a web framework, e.g. leptos
10  let element: web_sys::HtmlElement = todo!();
11  let mq = MathQuill::get_global_interface();
12
13  let mut config = Config::default();
14  config.handlers().on_edit_field(|| {
15    let field: Option<MathField> = MathQuill::get_global_interface().get_field(&element);
16    let latex = field.unwrap().latex();
17    check_answer(latex);
18  });
19
20  let _field = mq.mount_field(&element, &config);
21
22  // dropping config invalidates closures,
23  // read docs on Config
24}