mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 19:28:39 +00:00
Move environment delimiter handling to functions/environment.js. (#1329)
This commit is contained in:
committed by
Kevin Barabash
parent
fabae7c658
commit
ea7003ff6e
@@ -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"], {
|
||||
|
29
src/functions/environment.js
Normal file
29
src/functions/environment.js
Normal 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,
|
||||
};
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user