UNPKG

814 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 node.setAttribute('data-value', value);
12 }
13 return node;
14 }
15
16 static value(domNode) {
17 return domNode.getAttribute('data-value');
18 }
19}
20FormulaBlot.blotName = 'formula';
21FormulaBlot.className = 'ql-formula';
22FormulaBlot.tagName = 'SPAN';
23
24
25class Formula extends Module {
26 static register() {
27 Quill.register(FormulaBlot, true);
28 }
29
30 constructor() {
31 super();
32 if (window.katex == null) {
33 throw new Error('Formula module requires KaTeX.');
34 }
35 }
36}
37
38
39export { FormulaBlot, Formula as default };