MCPcopy Index your code
hub / github.com/TruthHun/BookStack / parseArray

Function parseArray

static/katex/katex.mjs:9205–9296  ·  view source on GitHub ↗

* Parse the body of the environment, with rows delimited by \\ and * columns delimited by &, and create a nested list in row-major order * with one group per cell. If given an optional argument style * ("text", "display", etc.), then each cell is cast into that style.

(parser, _ref, style)

Source from the content-addressed store, hash-verified

9203
9204
9205function parseArray(parser, _ref, style) {
9206 let hskipBeforeAndAfter = _ref.hskipBeforeAndAfter,
9207 addJot = _ref.addJot,
9208 cols = _ref.cols,
9209 arraystretch = _ref.arraystretch;
9210 // Parse body of array with \\ temporarily mapped to \cr
9211 parser.gullet.beginGroup();
9212 parser.gullet.macros.set("\\\\", "\\cr"); // Get current arraystretch if it's not set by the environment
9213
9214 if (!arraystretch) {
9215 const stretch = parser.gullet.expandMacroAsText("\\arraystretch");
9216
9217 if (stretch == null) {
9218 // Default \arraystretch from lttab.dtx
9219 arraystretch = 1;
9220 } else {
9221 arraystretch = parseFloat(stretch);
9222
9223 if (!arraystretch || arraystretch < 0) {
9224 throw new ParseError(`Invalid \\arraystretch: ${stretch}`);
9225 }
9226 }
9227 }
9228
9229 let row = [];
9230 const body = [row];
9231 const rowGaps = [];
9232 const hLinesBeforeRow = []; // Test for \hline at the top of the array.
9233
9234 hLinesBeforeRow.push(getHLines(parser));
9235
9236 while (true) {
9237 // eslint-disable-line no-constant-condition
9238 let cell = parser.parseExpression(false, "\\cr");
9239 cell = {
9240 type: "ordgroup",
9241 mode: parser.mode,
9242 body: cell
9243 };
9244
9245 if (style) {
9246 cell = {
9247 type: "styling",
9248 mode: parser.mode,
9249 style,
9250 body: [cell]
9251 };
9252 }
9253
9254 row.push(cell);
9255 const next = parser.nextToken.text;
9256
9257 if (next === "&") {
9258 parser.consume();
9259 } else if (next === "\\end") {
9260 // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
9261 // the last line is empty.
9262 // NOTE: Currently, `cell` is the last item added into `row`.

Callers 2

alignedHandlerFunction · 0.70
handlerFunction · 0.70

Calls 9

expandMacroAsTextMethod · 0.80
parseExpressionMethod · 0.80
consumeMethod · 0.80
parseFunctionMethod · 0.80
getHLinesFunction · 0.70
assertNodeTypeFunction · 0.70
beginGroupMethod · 0.45
setMethod · 0.45
endGroupMethod · 0.45

Tested by

no test coverage detected