Skip to content

Commit 3d2f9dd

Browse files
committed
fix(markdown): preserve comma math closing boundaries
1 parent 4b24223 commit 3d2f9dd

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ describe("chat math parsing", () => {
127127
"Pay $5,$10 now.",
128128
"Run $browser then $deploy on it.",
129129
"Set $HOME before running.",
130+
"Set $HOME,$PATH before running.",
131+
"Set $HOME, $PATH before running.",
132+
"Set $HOME,$_PATH before running.",
133+
"Set $home,$path before running.",
134+
"Pay $1,000,$2,000 now.",
130135
]) {
131136
expect(formulas(prose), prose).toEqual([]);
132137
expect(text(prose), prose).toBe(prose);

‎patches/[email protected]‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ diff --git a/dev/lib/math-tex-text.js b/dev/lib/math-tex-text.js
235235
diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js
236236
--- a/dev/lib/math-text.js
237237
+++ b/dev/lib/math-text.js
238+
@@ -10 +10 @@
239+
-import {markdownLineEnding} from 'micromark-util-character'
240+
+import {asciiAlpha, markdownLineEnding} from 'micromark-util-character'
238241
@@ -42,6 +42,13 @@
239242
let size
240243
/** @type {Token} */
@@ -299,7 +302,7 @@ diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js
299302
if (
300303
code === codes.eof ||
301304
code === codes.space ||
302-
@@ -179,9 +207,28 @@
305+
@@ -179,9 +207,29 @@
303306

304307
// Done!
305308
if (size === sizeOpen) {
@@ -314,12 +317,13 @@ diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js
314317
+ if (code !== null && code >= codes.digit0 && code <= codes.digit9) {
315318
+ return nok(code)
316319
+ }
320+
+ if (charBeforeClose === codes.comma && !openWhitespace && (asciiAlpha(code) || code === codes.underscore)) {
321+
+ return nok(code)
322+
+ }
317323
+ // Check if closing sequence has matching whitespace pattern
318324
+ const closeWhitespace =
319325
+ charBeforeClose === codes.space ||
320326
+ charBeforeClose === codes.horizontalTab ||
321-
+ // A formula can end in a comma, as it can in `.` or `;`. The comma
322-
+ // still matches an opening space, as in `$$ x,$$`.
323327
+ (charBeforeClose === codes.comma && openWhitespace)
324328
+ if (openWhitespace === closeWhitespace) {
325329
+ effects.exit('mathTextSequence')

‎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)