mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-07 20:28:38 +00:00
Make mode part of the internal state of the parser
This is the first step towards #266.
This commit is contained in:
@@ -10,11 +10,11 @@ var ParseResult = parseData.ParseResult;
|
||||
* columns delimited by &, and create a nested list in row-major order
|
||||
* with one group per cell.
|
||||
*/
|
||||
function parseArray(parser, pos, mode, result) {
|
||||
function parseArray(parser, pos, result) {
|
||||
var row = [], body = [row], rowGaps = [];
|
||||
while (true) {
|
||||
var cell = parser.parseExpression(pos, mode, false, null);
|
||||
row.push(new ParseNode("ordgroup", cell.result, mode));
|
||||
var cell = parser.parseExpression(pos, false, null);
|
||||
row.push(new ParseNode("ordgroup", cell.result, parser.mode));
|
||||
pos = cell.position;
|
||||
var next = cell.peek.text;
|
||||
if (next === "&") {
|
||||
@@ -22,7 +22,7 @@ function parseArray(parser, pos, mode, result) {
|
||||
} else if (next === "\\end") {
|
||||
break;
|
||||
} else if (next === "\\\\" || next === "\\cr") {
|
||||
var cr = parser.parseFunction(pos, mode);
|
||||
var cr = parser.parseFunction(pos);
|
||||
rowGaps.push(cr.result.value.size);
|
||||
pos = cr.position;
|
||||
row = [];
|
||||
@@ -34,7 +34,8 @@ function parseArray(parser, pos, mode, result) {
|
||||
}
|
||||
result.body = body;
|
||||
result.rowGaps = rowGaps;
|
||||
return new ParseResult(new ParseNode(result.type, result, mode), pos);
|
||||
return new ParseResult(
|
||||
new ParseNode(result.type, result, parser.mode), pos);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -55,7 +56,6 @@ function parseArray(parser, pos, mode, result) {
|
||||
* - args: an array of arguments passed to \begin{name}
|
||||
* The context contains the following properties:
|
||||
* - pos: the current position of the parser.
|
||||
* - mode: the current parsing mode.
|
||||
* - envName: the name of the environment, one of the listed names.
|
||||
* - parser: the parser object
|
||||
* - lexer: the lexer object
|
||||
@@ -115,7 +115,7 @@ defineEnvironment("array", {
|
||||
cols: cols,
|
||||
hskipBeforeAndAfter: true // \@preamble in lttab.dtx
|
||||
};
|
||||
res = parseArray(context.parser, context.pos, context.mode, res);
|
||||
res = parseArray(context.parser, context.pos, res);
|
||||
return res;
|
||||
});
|
||||
|
||||
@@ -142,7 +142,7 @@ defineEnvironment([
|
||||
type: "array",
|
||||
hskipBeforeAndAfter: false // \hskip -\arraycolsep in amsmath
|
||||
};
|
||||
res = parseArray(context.parser, context.pos, context.mode, res);
|
||||
res = parseArray(context.parser, context.pos, res);
|
||||
if (delimiters) {
|
||||
res.result = new ParseNode("leftright", {
|
||||
body: [res.result],
|
||||
@@ -173,7 +173,7 @@ defineEnvironment("cases", {
|
||||
postgap: 0
|
||||
}]
|
||||
};
|
||||
res = parseArray(context.parser, context.pos, context.mode, res);
|
||||
res = parseArray(context.parser, context.pos, res);
|
||||
res.result = new ParseNode("leftright", {
|
||||
body: [res.result],
|
||||
left: "\\{",
|
||||
|
Reference in New Issue
Block a user