UNPKG

881 BJavaScriptView Raw
1import Embed from '../blots/embed';
2import Quill from '../core/quill';
3import Module from '../core/module';
4
5
6class FormulaBlot extends Embed {
7 static create(value) {
8 let node = super.create(value);
9 if (typeof value === 'string') {
10 window.katex.render(value, node, {
11 throwOnError: false,
12 errorColor: '#f00'
13 });
14 node.setAttribute('data-value', value);
15 }
16 return node;
17 }
18
19 static value(domNode) {
20 return domNode.getAttribute('data-value');
21 }
22}
23FormulaBlot.blotName = 'formula';
24FormulaBlot.className = 'ql-formula';
25FormulaBlot.tagName = 'SPAN';
26
27
28class Formula extends Module {
29 static register() {
30 Quill.register(FormulaBlot, true);
31 }
32
33 constructor() {
34 super();
35 if (window.katex == null) {
36 throw new Error('Formula module requires KaTeX.');
37 }
38 }
39}
40
41
42export { FormulaBlot, Formula as default };