1 | import Embed from '../blots/embed';
|
2 | import Quill from '../core/quill';
|
3 | import Module from '../core/module';
|
4 |
|
5 |
|
6 | class 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 | }
|
20 | FormulaBlot.blotName = 'formula';
|
21 | FormulaBlot.className = 'ql-formula';
|
22 | FormulaBlot.tagName = 'SPAN';
|
23 |
|
24 |
|
25 | class 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 |
|
39 | export { FormulaBlot, Formula as default };
|