mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 19:28:39 +00:00
* Fix #946 Issue #946 identified a case in which `array.js` ate the final row of a well-written `aligned` environment. This PR modifies code from PR #479 to fix this problem and to also continue to eat a trailing `\\` submitted to any environment. * Fix bug and add tests * Add final newline to test. Doh!
This commit is contained in:
@@ -62,10 +62,10 @@ function parseArray(
|
||||
} else if (next === "\\end") {
|
||||
// Arrays terminate newlines with `\crcr` which consumes a `\cr` if
|
||||
// the last line is empty.
|
||||
const lastRow = body[body.length - 1][0].value;
|
||||
const lastRow = body[body.length - 1];
|
||||
if (body.length > 1
|
||||
&& lastRow.value.length === 1
|
||||
&& lastRow.value[0].value.length === 0) {
|
||||
&& lastRow.length === 1
|
||||
&& lastRow[0].value.value[0].value.length === 0) {
|
||||
body.pop();
|
||||
}
|
||||
break;
|
||||
|
@@ -1251,6 +1251,11 @@ describe("A begin/end parser", function() {
|
||||
it("should allow \\cr as a line terminator", function() {
|
||||
expect("\\begin{matrix}a&b\\cr c&d\\end{matrix}").toParse();
|
||||
});
|
||||
|
||||
it("should eat a final newline", function() {
|
||||
const m3 = getParsed("\\begin{matrix}a&b\\\\ c&d \\\\ \\end{matrix}")[0];
|
||||
expect(m3.value.body.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("A sqrt parser", function() {
|
||||
@@ -2409,6 +2414,10 @@ describe("An aligned environment", function() {
|
||||
.toNotParse();
|
||||
});
|
||||
|
||||
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.length).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("A parser that does not throw on unsupported commands", function() {
|
||||
|
Reference in New Issue
Block a user