1 |
|
2 | import {defineFunctionBuilders} from "../defineFunction";
|
3 | import buildCommon from "../buildCommon";
|
4 | import mathMLTree from "../mathMLTree";
|
5 | import ParseError from "../ParseError";
|
6 |
|
7 |
|
8 | const cssSpace: {[string]: string} = {
|
9 | "\\nobreak": "nobreak",
|
10 | "\\allowbreak": "allowbreak",
|
11 | };
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | const regularSpace: {[string]: { className?: string }} = {
|
19 | " ": {},
|
20 | "\\ ": {},
|
21 | "~": {
|
22 | className: "nobreak",
|
23 | },
|
24 | "\\space": {},
|
25 | "\\nobreakspace": {
|
26 | className: "nobreak",
|
27 | },
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 | defineFunctionBuilders({
|
33 | type: "spacing",
|
34 | htmlBuilder(group, options) {
|
35 | if (regularSpace.hasOwnProperty(group.text)) {
|
36 | const className = regularSpace[group.text].className || "";
|
37 |
|
38 |
|
39 |
|
40 | if (group.mode === "text") {
|
41 | const ord = buildCommon.makeOrd(group, options, "textord");
|
42 | ord.classes.push(className);
|
43 | return ord;
|
44 | } else {
|
45 | return buildCommon.makeSpan(["mspace", className],
|
46 | [buildCommon.mathsym(group.text, group.mode, options)],
|
47 | options);
|
48 | }
|
49 | } else if (cssSpace.hasOwnProperty(group.text)) {
|
50 |
|
51 | return buildCommon.makeSpan(
|
52 | ["mspace", cssSpace[group.text]],
|
53 | [], options);
|
54 | } else {
|
55 | throw new ParseError(`Unknown type of space "${group.text}"`);
|
56 | }
|
57 | },
|
58 | mathmlBuilder(group, options) {
|
59 | let node;
|
60 |
|
61 | if (regularSpace.hasOwnProperty(group.text)) {
|
62 | node = new mathMLTree.MathNode(
|
63 | "mtext", [new mathMLTree.TextNode("\u00a0")]);
|
64 | } else if (cssSpace.hasOwnProperty(group.text)) {
|
65 |
|
66 | return new mathMLTree.MathNode("mspace");
|
67 | } else {
|
68 | throw new ParseError(`Unknown type of space "${group.text}"`);
|
69 | }
|
70 |
|
71 | return node;
|
72 | },
|
73 | });
|