Skip to content
TypeScript

fix(markdown): an escaped backslash before \( no longer crashes dev builds (#22893)

Nikita Maximilian Grimmece8fd8e8c6f
diff --git a/packages/shared/src/markdownMath.test.ts b/packages/shared/src/markdownMath.test.ts
index 0bc6941e494..e34dde0e9e2 100644
--- a/packages/shared/src/markdownMath.test.ts
+++ b/packages/shared/src/markdownMath.test.ts
@@ -193,6 +193,15 @@ describe("chat math parsing", () => {
expect(formulas("Pay \\$$x$ now.")).toEqual([["inline", "x"]]);
});
+ it("starts a formula right after an escaped backslash", () => {
+ const markdown = "Path \\\\\\(x^2\\) and \\\\\\[y\\].";
+ expect(formulas(markdown)).toEqual([
+ ["inline", "x^2"],
+ ["display", "y"],
+ ]);
+ expect(text(markdown)).toBe("Path \\ and \\.");
+ });
+
it.each([
["$a`$HOME`", "$HOME"],
["\\(a`\\)`", "\\)"],
diff --git a/patches/[email protected] b/patches/[email protected]
index 25da4f5f477..e09a8d4d889 100644
--- a/patches/[email protected]
+++ b/patches/[email protected]
@@ -232,6 +232,16 @@ diff --git a/dev/lib/math-tex-text.js b/dev/lib/math-tex-text.js
effects.consume(code)
effects.exit('mathTextSequence')
effects.exit('mathText')
+@@ -180,5 +184,8 @@
+ */
+ function previous(code) {
+ // If there is a previous code, there will always be a tail.
+- return code !== codes.backslash
++ return (
++ code !== codes.backslash ||
++ this.events[this.events.length - 1][1].type === types.characterEscape
++ )
+ }
diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js
--- a/dev/lib/math-text.js
+++ b/dev/lib/math-text.js
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 39c062c66db..3dce27954d2 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -383,7 +383,7 @@ patchedDependencies:
[email protected]: afe6b2c89e1eaddfd3c90cf2723f12c9a17d513e65beff51653781486013251c
[email protected]: 57ea46c73aea3c876ab8d351fe0482ddd081dcb4a0610576e399dbe5eb59d2b1
[email protected]: 9ad23a530e45d9f83cba1da8654fe16d5af8b59d5c73d5c7a7c91fd25b9be1d8
- [email protected]: 7beb6ac4ba52166286593a494531aace81547e55fdddecf892824c25bd84d15a
+ [email protected]: 4eeb9d9e27ebc75e98795e21c0719005483dad7d233055698257f7d10e91603b
[email protected]: cb79edde7eca83bbcaaafb6ceb7b044b81b987314cde4910823b15257ecada67
[email protected]: f1e680afec85f650699ea756f91f469844ec4c976f4f168492a45c6b3f67d651
[email protected]: abe20e1d1c23549297cbbc818e14fe479b41455930d9663135d6b40fe359b626
@@ -20161,7 +20161,7 @@ snapshots:
micromark-util-combine-extensions: 2.0.1
micromark-util-types: 2.0.2
- [email protected](patch_hash=7beb6ac4ba52166286593a494531aace81547e55fdddecf892824c25bd84d15a):
+ [email protected](patch_hash=4eeb9d9e27ebc75e98795e21c0719005483dad7d233055698257f7d10e91603b):
dependencies:
'@types/katex': 0.16.8
devlop: 1.1.0
@@ -21453,7 +21453,7 @@ snapshots:
dependencies:
'@types/mdast': 4.0.4
mdast-util-math: 3.0.0(patch_hash=afe6b2c89e1eaddfd3c90cf2723f12c9a17d513e65beff51653781486013251c)([email protected])
- micromark-extension-math: [email protected](patch_hash=7beb6ac4ba52166286593a494531aace81547e55fdddecf892824c25bd84d15a)
+ micromark-extension-math: [email protected](patch_hash=4eeb9d9e27ebc75e98795e21c0719005483dad7d233055698257f7d10e91603b)
unified: 11.0.5
transitivePeerDependencies:
- supports-color