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