Skip to content

Commit ece8fd8

Browse files
fix(markdown): an escaped backslash before \( no longer crashes dev builds (#22893)
Co-authored-by: maria-rcks <[email protected]>
1 parent c78712e commit ece8fd8

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎packages/shared/src/markdownMath.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ describe("chat math parsing", () => {
193193
expect(formulas("Pay \\$$x$ now.")).toEqual([["inline", "x"]]);
194194
});
195195

196+
it("starts a formula right after an escaped backslash", () => {
197+
const markdown = "Path \\\\\\(x^2\\) and \\\\\\[y\\].";
198+
expect(formulas(markdown)).toEqual([
199+
["inline", "x^2"],
200+
["display", "y"],
201+
]);
202+
expect(text(markdown)).toBe("Path \\ and \\.");
203+
});
204+
196205
it.each([
197206
["$a`$HOME`", "$HOME"],
198207
["\\(a`\\)`", "\\)"],

‎patches/[email protected]‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ diff --git a/dev/lib/math-tex-text.js b/dev/lib/math-tex-text.js
232232
effects.consume(code)
233233
effects.exit('mathTextSequence')
234234
effects.exit('mathText')
235+
@@ -180,5 +184,8 @@
236+
*/
237+
function previous(code) {
238+
// If there is a previous code, there will always be a tail.
239+
- return code !== codes.backslash
240+
+ return (
241+
+ code !== codes.backslash ||
242+
+ this.events[this.events.length - 1][1].type === types.characterEscape
243+
+ )
244+
}
235245
diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js
236246
--- a/dev/lib/math-text.js
237247
+++ b/dev/lib/math-text.js

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)