mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-10 05:28:41 +00:00
Flatten "styling", "text", and "array" ParseNodes. (#1559)
* Flatten "styling" ParseNode. * Flatten "text" ParseNode. * Flatten "array" ParseNode.
This commit is contained in:
@@ -4,145 +4,130 @@ exports[`A begin/end parser should grab \\arraystretch 1`] = `
|
||||
[
|
||||
{
|
||||
"type": "array",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "array",
|
||||
"arraystretch": 1.5,
|
||||
"body": [
|
||||
[
|
||||
{
|
||||
"type": "styling",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "styling",
|
||||
"style": "text",
|
||||
"arraystretch": 1.5,
|
||||
"body": [
|
||||
[
|
||||
{
|
||||
"type": "styling",
|
||||
"body": [
|
||||
{
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "ordgroup",
|
||||
"type": "mathord",
|
||||
"loc": {
|
||||
"end": 37,
|
||||
"lexer": {
|
||||
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
|
||||
"lastIndex": 56
|
||||
},
|
||||
"start": 36
|
||||
},
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"loc": {
|
||||
"end": 37,
|
||||
"lexer": {
|
||||
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
|
||||
"lastIndex": 56
|
||||
},
|
||||
"start": 36
|
||||
},
|
||||
"mode": "math",
|
||||
"value": "a"
|
||||
}
|
||||
]
|
||||
"value": "a"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "styling",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "styling",
|
||||
"style": "text",
|
||||
],
|
||||
"mode": "math",
|
||||
"style": "text"
|
||||
},
|
||||
{
|
||||
"type": "styling",
|
||||
"body": [
|
||||
{
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "ordgroup",
|
||||
"type": "mathord",
|
||||
"loc": {
|
||||
"end": 39,
|
||||
"lexer": {
|
||||
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
|
||||
"lastIndex": 56
|
||||
},
|
||||
"start": 38
|
||||
},
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"loc": {
|
||||
"end": 39,
|
||||
"lexer": {
|
||||
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
|
||||
"lastIndex": 56
|
||||
},
|
||||
"start": 38
|
||||
},
|
||||
"mode": "math",
|
||||
"value": "b"
|
||||
}
|
||||
]
|
||||
"value": "b"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"type": "styling",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "styling",
|
||||
"style": "text",
|
||||
"value": [
|
||||
{
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"loc": {
|
||||
"end": 42,
|
||||
"lexer": {
|
||||
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
|
||||
"lastIndex": 56
|
||||
},
|
||||
"start": 41
|
||||
},
|
||||
"mode": "math",
|
||||
"value": "c"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "styling",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "styling",
|
||||
"style": "text",
|
||||
"value": [
|
||||
{
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"loc": {
|
||||
"end": 44,
|
||||
"lexer": {
|
||||
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
|
||||
"lastIndex": 56
|
||||
},
|
||||
"start": 43
|
||||
},
|
||||
"mode": "math",
|
||||
"value": "d"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"mode": "math",
|
||||
"style": "text"
|
||||
}
|
||||
],
|
||||
"hLinesBeforeRow": [
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
]
|
||||
],
|
||||
"hskipBeforeAndAfter": false,
|
||||
"rowGaps": [
|
||||
null
|
||||
[
|
||||
{
|
||||
"type": "styling",
|
||||
"body": [
|
||||
{
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"loc": {
|
||||
"end": 42,
|
||||
"lexer": {
|
||||
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
|
||||
"lastIndex": 56
|
||||
},
|
||||
"start": 41
|
||||
},
|
||||
"mode": "math",
|
||||
"value": "c"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"mode": "math",
|
||||
"style": "text"
|
||||
},
|
||||
{
|
||||
"type": "styling",
|
||||
"body": [
|
||||
{
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"loc": {
|
||||
"end": 44,
|
||||
"lexer": {
|
||||
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
|
||||
"lastIndex": 56
|
||||
},
|
||||
"start": 43
|
||||
},
|
||||
"mode": "math",
|
||||
"value": "d"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"mode": "math",
|
||||
"style": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"hLinesBeforeRow": [
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
]
|
||||
],
|
||||
"hskipBeforeAndAfter": false,
|
||||
"mode": "math",
|
||||
"rowGaps": [
|
||||
null
|
||||
]
|
||||
}
|
||||
]
|
||||
`;
|
||||
@@ -660,18 +645,15 @@ exports[`An implicit group parser within optional groups should work style comma
|
||||
"value": [
|
||||
{
|
||||
"type": "styling",
|
||||
"body": [
|
||||
{
|
||||
"type": "textord",
|
||||
"mode": "math",
|
||||
"value": "3"
|
||||
}
|
||||
],
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "styling",
|
||||
"style": "text",
|
||||
"value": [
|
||||
{
|
||||
"type": "textord",
|
||||
"mode": "math",
|
||||
"value": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
"style": "text"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@@ -666,12 +666,12 @@ describe("A text parser", function() {
|
||||
const parse = getParsed(textExpression)[0];
|
||||
|
||||
expect(parse.type).toEqual("text");
|
||||
expect(parse.value).toBeDefined();
|
||||
expect(parse.body).toBeDefined();
|
||||
});
|
||||
|
||||
it("should produce textords instead of mathords", function() {
|
||||
const parse = getParsed(textExpression)[0];
|
||||
const group = parse.value.body;
|
||||
const group = parse.body;
|
||||
|
||||
expect(group[0].type).toEqual("textord");
|
||||
});
|
||||
@@ -694,7 +694,7 @@ describe("A text parser", function() {
|
||||
|
||||
it("should contract spaces", function() {
|
||||
const parse = getParsed(spaceTextExpression)[0];
|
||||
const group = parse.value.body;
|
||||
const group = parse.body;
|
||||
|
||||
expect(group[0].type).toEqual("spacing");
|
||||
expect(group[1].type).toEqual("textord");
|
||||
@@ -709,10 +709,8 @@ describe("A text parser", function() {
|
||||
it("should ignore a space before the text group", function() {
|
||||
const parse = getParsed(leadingSpaceTextExpression)[0];
|
||||
// [m, o, o]
|
||||
expect(parse.value.body).toHaveLength(3);
|
||||
expect(
|
||||
parse.value.body.map(function(n) { return n.value; }).join("")
|
||||
).toBe("moo");
|
||||
expect(parse.body).toHaveLength(3);
|
||||
expect(parse.body.map(n => n.value).join("")).toBe("moo");
|
||||
});
|
||||
|
||||
it("should parse math within text group", function() {
|
||||
@@ -860,14 +858,14 @@ describe("A tie parser", function() {
|
||||
|
||||
it("should produce spacing in text mode", function() {
|
||||
const text = getParsed(textTie)[0];
|
||||
const parse = text.value.body;
|
||||
const parse = text.body;
|
||||
|
||||
expect(parse[1].type).toEqual("spacing");
|
||||
});
|
||||
|
||||
it("should not contract with spaces in text mode", function() {
|
||||
const text = getParsed(textTie)[0];
|
||||
const parse = text.value.body;
|
||||
const parse = text.body;
|
||||
|
||||
expect(parse[2].type).toEqual("spacing");
|
||||
});
|
||||
@@ -1241,7 +1239,7 @@ describe("A begin/end parser", function() {
|
||||
|
||||
it("should eat a final newline", function() {
|
||||
const m3 = getParsed`\begin{matrix}a&b\\ c&d \\ \end{matrix}`[0];
|
||||
expect(m3.value.body).toHaveLength(2);
|
||||
expect(m3.body).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("should grab \\arraystretch", function() {
|
||||
@@ -1440,10 +1438,10 @@ describe("A style change parser", function() {
|
||||
|
||||
it("should produce the correct style", function() {
|
||||
const displayParse = getParsed`\displaystyle x`[0];
|
||||
expect(displayParse.value.style).toEqual("display");
|
||||
expect(displayParse.style).toEqual("display");
|
||||
|
||||
const scriptscriptParse = getParsed`\scriptscriptstyle x`[0];
|
||||
expect(scriptscriptParse.value.style).toEqual("scriptscript");
|
||||
expect(scriptscriptParse.style).toEqual("scriptscript");
|
||||
});
|
||||
|
||||
it("should only change the style within its group", function() {
|
||||
@@ -1454,7 +1452,7 @@ describe("A style change parser", function() {
|
||||
|
||||
expect(displayNode.type).toEqual("styling");
|
||||
|
||||
const displayBody = displayNode.value.value;
|
||||
const displayBody = displayNode.body;
|
||||
|
||||
expect(displayBody).toHaveLength(2);
|
||||
expect(displayBody[0].value).toEqual("e");
|
||||
@@ -2407,7 +2405,7 @@ describe("An array environment", function() {
|
||||
it("should accept a single alignment character", function() {
|
||||
const parse = getParsed`\begin{array}r1\\20\end{array}`;
|
||||
expect(parse[0].type).toBe("array");
|
||||
expect(parse[0].value.cols).toEqual([
|
||||
expect(parse[0].cols).toEqual([
|
||||
{type: "align", align: "r"},
|
||||
]);
|
||||
});
|
||||
@@ -2415,7 +2413,7 @@ describe("An array environment", function() {
|
||||
it("should accept vertical separators", function() {
|
||||
const parse = getParsed`\begin{array}{|l||c:r::}\end{array}`;
|
||||
expect(parse[0].type).toBe("array");
|
||||
expect(parse[0].value.cols).toEqual([
|
||||
expect(parse[0].cols).toEqual([
|
||||
{type: "separator", separator: "|"},
|
||||
{type: "align", align: "l"},
|
||||
{type: "separator", separator: "|"},
|
||||
@@ -2455,7 +2453,7 @@ describe("An aligned environment", function() {
|
||||
|
||||
it("should not eat the last row when its first cell is empty", function() {
|
||||
const ae = getParsed`\begin{aligned}&E_1 & (1)\\&E_2 & (2)\\&E_3 & (3)\end{aligned}`[0];
|
||||
expect(ae.value.body).toHaveLength(3);
|
||||
expect(ae.body).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user