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

Function parseArray

static/katex/katex.js:9354–9445  ·  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

9352
9353
9354function parseArray(parser, _ref, style) {
9355 var hskipBeforeAndAfter = _ref.hskipBeforeAndAfter,
9356 addJot = _ref.addJot,
9357 cols = _ref.cols,
9358 arraystretch = _ref.arraystretch;
9359 // Parse body of array with \\ temporarily mapped to \cr
9360 parser.gullet.beginGroup();
9361 parser.gullet.macros.set("\\\\", "\\cr"); // Get current arraystretch if it's not set by the environment
9362
9363 if (!arraystretch) {
9364 var stretch = parser.gullet.expandMacroAsText("\\arraystretch");
9365
9366 if (stretch == null) {
9367 // Default \arraystretch from lttab.dtx
9368 arraystretch = 1;
9369 } else {
9370 arraystretch = parseFloat(stretch);
9371
9372 if (!arraystretch || arraystretch < 0) {
9373 throw new src_ParseError("Invalid \\arraystretch: " + stretch);
9374 }
9375 }
9376 }
9377
9378 var row = [];
9379 var body = [row];
9380 var rowGaps = [];
9381 var hLinesBeforeRow = []; // Test for \hline at the top of the array.
9382
9383 hLinesBeforeRow.push(getHLines(parser));
9384
9385 while (true) {
9386 // eslint-disable-line no-constant-condition
9387 var cell = parser.parseExpression(false, "\\cr");
9388 cell = {
9389 type: "ordgroup",
9390 mode: parser.mode,
9391 body: cell
9392 };
9393
9394 if (style) {
9395 cell = {
9396 type: "styling",
9397 mode: parser.mode,
9398 style: style,
9399 body: [cell]
9400 };
9401 }
9402
9403 row.push(cell);
9404 var next = parser.nextToken.text;
9405
9406 if (next === "&") {
9407 parser.consume();
9408 } else if (next === "\\end") {
9409 // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
9410 // the last line is empty.
9411 // NOTE: Currently, `cell` is the last item added into `row`.

Callers 2

array_alignedHandlerFunction · 0.70
katex.jsFile · 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