| import {defineFunctionBuilders} from "../defineFunction"; |
| import {mathsym, makeOrd, makeSpan} from "../buildCommon"; |
| import {MathNode, TextNode} from "../mathMLTree"; |
| import ParseError from "../ParseError"; |
|
|
| |
| const cssSpace: Record<string, string> = { |
| "\\nobreak": "nobreak", |
| "\\allowbreak": "allowbreak", |
| }; |
|
|
| |
| |
| |
| |
| |
| const regularSpace: Record<string, {className?: string}> = { |
| " ": {}, |
| "\\ ": {}, |
| "~": { |
| className: "nobreak", |
| }, |
| "\\space": {}, |
| "\\nobreakspace": { |
| className: "nobreak", |
| }, |
| }; |
|
|
| |
| |
| defineFunctionBuilders({ |
| type: "spacing", |
| htmlBuilder(group, options) { |
| if (regularSpace.hasOwnProperty(group.text)) { |
| const className = regularSpace[group.text].className || ""; |
| |
| |
| |
| if (group.mode === "text") { |
| const ord = makeOrd(group, options); |
| ord.classes.push(className); |
| return ord; |
| } else { |
| return makeSpan(["mspace", className], |
| [mathsym(group.text, group.mode, options)], |
| options); |
| } |
| } else if (cssSpace.hasOwnProperty(group.text)) { |
| |
| return makeSpan( |
| ["mspace", cssSpace[group.text]], |
| [], options); |
| } else { |
| throw new ParseError(`Unknown type of space "${group.text}"`); |
| } |
| }, |
| mathmlBuilder(group, options) { |
| let node; |
|
|
| if (regularSpace.hasOwnProperty(group.text)) { |
| node = new MathNode( |
| "mtext", [new TextNode("\u00a0")]); |
| } else if (cssSpace.hasOwnProperty(group.text)) { |
| |
| return new MathNode("mspace"); |
| } else { |
| throw new ParseError(`Unknown type of space "${group.text}"`); |
| } |
|
|
| return node; |
| }, |
| }); |
|
|