Move environment delimiter handling to functions/environment.js. (#1329)

This commit is contained in:
Ashish Myles
2018-05-19 21:44:36 -04:00
committed by Kevin Barabash
parent fabae7c658
commit ea7003ff6e
2 changed files with 30 additions and 19 deletions

View File

@@ -1,6 +1,5 @@
// @flow
/** Include this to ensure that all functions are defined. */
import ParseError from "./ParseError";
import {
default as _defineFunction,
ordargument,
@@ -122,24 +121,7 @@ defineFunction("xArrow", [
import "./functions/cr";
// Environment delimiters
defineFunction("environment", ["\\begin", "\\end"], {
numArgs: 1,
argTypes: ["text"],
}, function(context, args) {
const nameGroup = args[0];
if (nameGroup.type !== "ordgroup") {
throw new ParseError("Invalid environment name", nameGroup);
}
let name = "";
for (let i = 0; i < nameGroup.value.length; ++i) {
name += nameGroup.value[i].value;
}
return {
type: "environment",
name: name,
nameGroup: nameGroup,
};
});
import "./functions/environment";
// Box manipulation
defineFunction("raisebox", ["\\raisebox"], {

View File

@@ -0,0 +1,29 @@
// @flow
import defineFunction from "../defineFunction";
import ParseError from "../ParseError";
// Environment delimiters. HTML/MathML rendering is defined in the corresponding
// defineEnvironment definitions.
defineFunction({
type: "environment",
names: ["\\begin", "\\end"],
props: {
numArgs: 1,
argTypes: ["text"],
},
handler(context, args) {
const nameGroup = args[0];
if (nameGroup.type !== "ordgroup") {
throw new ParseError("Invalid environment name", nameGroup);
}
let name = "";
for (let i = 0; i < nameGroup.value.length; ++i) {
name += nameGroup.value[i].value;
}
return {
type: "environment",
name: name,
nameGroup: nameGroup,
};
},
});