GeezerVison is showing github.com — fix(markdown): an escaped backslash before \( no longer crashes dev b… · NikitaMGrimm/t3code@27dc255
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/shared/src/markdownMath.test.ts +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -181,6 +181,15 @@ describe("chat math parsing", () => { |
181 | 181 | expect(formulas("Pay \\$$x$ now.")).toEqual([["inline", "x"]]); |
182 | 182 | }); |
183 | 183 |
|
| 184 | + it("starts a formula right after an escaped backslash", () => { |
| 185 | + const markdown = "Path \\\\\\(x^2\\) and \\\\\\[y\\]."; |
| 186 | + expect(formulas(markdown)).toEqual([ |
| 187 | + ["inline", "x^2"], |
| 188 | + ["display", "y"], |
| 189 | + ]); |
| 190 | + expect(text(markdown)).toBe("Path \\ and \\."); |
| 191 | + }); |
| 192 | + |
184 | 193 | it.each([ |
185 | 194 | ["$a`$HOME`", "$HOME"], |
186 | 195 | ["\\(a`\\)`", "\\)"], |
|
Collapse file
+10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -232,6 +232,16 @@ diff --git a/dev/lib/math-tex-text.js b/dev/lib/math-tex-text.js |
232 | 232 | effects.consume(code) |
233 | 233 | effects.exit('mathTextSequence') |
234 | 234 | 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 | + } |
235 | 245 | diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js |
236 | 246 | --- a/dev/lib/math-text.js |
237 | 247 | +++ b/dev/lib/math-text.js |
|
Collapse file
Copy file name to clipboardExpand all lines: pnpm-lock.yaml +3-3Lines changed: 3 additions & 3 deletions