1 |
|
2 | import defineFunction, {ordargument} from "../defineFunction";
|
3 | import buildCommon from "../buildCommon";
|
4 | import mathMLTree from "../mathMLTree";
|
5 | import {assertNodeType} from "../parseNode";
|
6 |
|
7 | import * as html from "../buildHTML";
|
8 | import * as mml from "../buildMathML";
|
9 |
|
10 | const htmlBuilder = (group, options) => {
|
11 | const elements = html.buildExpression(
|
12 | group.body,
|
13 | options.withColor(group.color),
|
14 | false
|
15 | );
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | return buildCommon.makeFragment(elements);
|
22 | };
|
23 |
|
24 | const mathmlBuilder = (group, options) => {
|
25 | const inner = mml.buildExpression(group.body,
|
26 | options.withColor(group.color));
|
27 |
|
28 | const node = new mathMLTree.MathNode("mstyle", inner);
|
29 |
|
30 | node.setAttribute("mathcolor", group.color);
|
31 |
|
32 | return node;
|
33 | };
|
34 |
|
35 | defineFunction({
|
36 | type: "color",
|
37 | names: ["\\textcolor"],
|
38 | props: {
|
39 | numArgs: 2,
|
40 | allowedInText: true,
|
41 | greediness: 3,
|
42 | argTypes: ["color", "original"],
|
43 | },
|
44 | handler({parser}, args) {
|
45 | const color = assertNodeType(args[0], "color-token").color;
|
46 | const body = args[1];
|
47 | return {
|
48 | type: "color",
|
49 | mode: parser.mode,
|
50 | color,
|
51 | body: ordargument(body),
|
52 | };
|
53 | },
|
54 | htmlBuilder,
|
55 | mathmlBuilder,
|
56 | });
|
57 |
|
58 | defineFunction({
|
59 | type: "color",
|
60 | names: ["\\color"],
|
61 | props: {
|
62 | numArgs: 1,
|
63 | allowedInText: true,
|
64 | greediness: 3,
|
65 | argTypes: ["color"],
|
66 | },
|
67 | handler({parser, breakOnTokenText}, args) {
|
68 | const color = assertNodeType(args[0], "color-token").color;
|
69 |
|
70 |
|
71 | const body = parser.parseExpression(true, breakOnTokenText);
|
72 |
|
73 | return {
|
74 | type: "color",
|
75 | mode: parser.mode,
|
76 | color,
|
77 | body,
|
78 | };
|
79 | },
|
80 | htmlBuilder,
|
81 | mathmlBuilder,
|
82 | });
|