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 | 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 | }
|
23 | FormulaBlot.blotName = 'formula';
|
24 | FormulaBlot.className = 'ql-formula';
|
25 | FormulaBlot.tagName = 'SPAN';
|
26 |
|
27 |
|
28 | class 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 |
|
42 | export { FormulaBlot, Formula as default };
|