1 |
|
2 | import buildHTML from "./buildHTML";
|
3 | import buildMathML from "./buildMathML";
|
4 | import buildCommon from "./buildCommon";
|
5 | import Options from "./Options";
|
6 | import Settings from "./Settings";
|
7 | import Style from "./Style";
|
8 |
|
9 | import type {AnyParseNode} from "./parseNode";
|
10 | import type {DomSpan} from "./domTree";
|
11 |
|
12 | const optionsFromSettings = function(settings: Settings) {
|
13 | return new Options({
|
14 | style: (settings.displayMode ? Style.DISPLAY : Style.TEXT),
|
15 | maxSize: settings.maxSize,
|
16 | });
|
17 | };
|
18 |
|
19 | const displayWrap = function(node: DomSpan, settings: Settings): DomSpan {
|
20 | if (settings.displayMode) {
|
21 | const classes = ["katex-display"];
|
22 | if (settings.leqno) {
|
23 | classes.push("leqno");
|
24 | }
|
25 | if (settings.fleqn) {
|
26 | classes.push("fleqn");
|
27 | }
|
28 | node = buildCommon.makeSpan(classes, [node]);
|
29 | }
|
30 | return node;
|
31 | };
|
32 |
|
33 | export const buildTree = function(
|
34 | tree: AnyParseNode[],
|
35 | expression: string,
|
36 | settings: Settings,
|
37 | ): DomSpan {
|
38 | const options = optionsFromSettings(settings);
|
39 | const mathMLNode = buildMathML(tree, expression, options);
|
40 | const htmlNode = buildHTML(tree, options);
|
41 |
|
42 | const katexNode = buildCommon.makeSpan(["katex"], [
|
43 | mathMLNode, htmlNode,
|
44 | ]);
|
45 |
|
46 | return displayWrap(katexNode, settings);
|
47 | };
|
48 |
|
49 | export const buildHTMLTree = function(
|
50 | tree: AnyParseNode[],
|
51 | expression: string,
|
52 | settings: Settings,
|
53 | ): DomSpan {
|
54 | const options = optionsFromSettings(settings);
|
55 | const htmlNode = buildHTML(tree, options);
|
56 | const katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
|
57 | return displayWrap(katexNode, settings);
|
58 | };
|
59 |
|
60 | export default buildTree;
|