The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 13:15 UTC
fix(markdown): formulas ending in a comma render (#22883)
Co-authored-by: maria-rcks <maria@kuuro.net>
Nikita Maximilian Grimm committed
Oct 29, 2026 at 18:45 UTC
1d631342b01d0231cd1380606a0a0c5180322762
3 files changed
+32
-5
packages/shared/src/markdownMath.test.ts
+21
@@ -124,8 +124,18 @@ describe("chat math parsing", () => {
124
"It costs $5 and $10.",
125
"Budget $5-$10 per seat, or $20,000-$30,000 a year.",
126
"Plans are $5/$10 monthly.",
127
+ "Pay $5,$10 now.",
128
"Run $browser then $deploy on it.",
129
"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
+ "Set $HOME,${PATH} before running.",
135
+ "Set $HOME,$? before running.",
136
+ "Set $HOME,$@ before running.",
137
+ "Set $HOME,$(pwd) before running.",
138
+ "Pay $1,000,$2,000 now.",
139
]) {
140
expect(formulas(prose), prose).toEqual([]);
141
expect(text(prose), prose).toBe(prose);
@@ -143,6 +153,17 @@ describe("chat math parsing", () => {
153
}
154
});
155
156
+ it("reads formulas that end in a comma", () => {
157
+ for (const boundary of ["", " ", "\n", ".", ",", ";", ":", ")", "]", "}"]) {
158
+ expect(formulas(`$x,$${boundary}`)).toEqual([["inline", "x,"]]);
159
+ }
160
+ expect(formulas("Where $x = 1,$ with $$a,$$ and $$ b,$$.")).toEqual([
161
+ ["inline", "x = 1,"],
162
+ ["display", "a,"],
163
+ ["display", " b,"],
164
+ ]);
165
+ });
166
+
167
it("leaves code, escapes, links, and citations alone", () => {
168
for (const [markdown, rendered] of [
169
["Use `$x$` in code.", "Use in code."],
patches/micromark-extension-llm-math@3.1.0.patch
+8
-2
@@ -235,6 +235,9 @@ diff --git a/dev/lib/math-tex-text.js b/dev/lib/math-tex-text.js
235
diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js
236
--- a/dev/lib/math-text.js
237
+++ b/dev/lib/math-text.js
238
+@@ -10 +10 @@
239
+-import {markdownLineEnding} from 'micromark-util-character'
240
++import {markdownLineEnding, markdownLineEndingOrSpace} from 'micromark-util-character'
241
@@ -42,6 +42,13 @@
242
let size
243
/** @type {Token} */
@@ -299,7 +302,7 @@ diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js
302
if (
303
code === codes.eof ||
304
code === codes.space ||
302
-@@ -179,9 +207,26 @@
305
+@@ -179,9 +207,29 @@
306
307
// Done!
308
if (size === sizeOpen) {
@@ -314,11 +317,14 @@ diff --git a/dev/lib/math-text.js b/dev/lib/math-text.js
317
+ if (code !== null && code >= codes.digit0 && code <= codes.digit9) {
318
+ return nok(code)
319
+ }
320
++ if (charBeforeClose === codes.comma && !openWhitespace && code !== codes.eof && !markdownLineEndingOrSpace(code) && !/[.,;:)\]}]/.test(String.fromCharCode(code))) {
321
++ return nok(code)
322
++ }
323
+ // Check if closing sequence has matching whitespace pattern
324
+ const closeWhitespace =
325
+ charBeforeClose === codes.space ||
326
+ charBeforeClose === codes.horizontalTab ||
321
-+ charBeforeClose === codes.comma
327
++ (charBeforeClose === codes.comma && openWhitespace)
328
+ if (openWhitespace === closeWhitespace) {
329
+ effects.exit('mathTextSequence')
330
+ effects.exit('mathText')
pnpm-lock.yaml
+3
-3
@@ -380,7 +380,7 @@ patchedDependencies:
380
expo-widgets@58.0.20: 8bf49067f93742855e15f29559ac75c8b50230b47069060993c9ea01dac11171
381
mdast-util-math@3.0.0: afe6b2c89e1eaddfd3c90cf2723f12c9a17d513e65beff51653781486013251c
382
micromark-extension-gfm-table@2.1.1: 9ad23a530e45d9f83cba1da8654fe16d5af8b59d5c73d5c7a7c91fd25b9be1d8
383
- micromark-extension-llm-math@3.1.0: 49ab4815c18b003f6af998dcc6c258c17a21b50b2cc87745f12d4bd8b6d591f9
383
+ micromark-extension-llm-math@3.1.0: 7beb6ac4ba52166286593a494531aace81547e55fdddecf892824c25bd84d15a
384
node-pty@1.2.0-beta.15: f1e680afec85f650699ea756f91f469844ec4c976f4f168492a45c6b3f67d651
385
react-native-gesture-handler@3.3.0: abe20e1d1c23549297cbbc818e14fe479b41455930d9663135d6b40fe359b626
386
react-native-image-viewing@0.2.2: 419f35ee91eac88ced9438058281db5eb09d9c799d8974c1172926068c9448cf
@@ -20056,7 +20056,7 @@ snapshots:
20056
micromark-util-combine-extensions: 2.0.1
20057
micromark-util-types: 2.0.2
20058
20059
- micromark-extension-llm-math@3.1.0(patch_hash=49ab4815c18b003f6af998dcc6c258c17a21b50b2cc87745f12d4bd8b6d591f9):
20059
+ micromark-extension-llm-math@3.1.0(patch_hash=7beb6ac4ba52166286593a494531aace81547e55fdddecf892824c25bd84d15a):
20060
dependencies:
20061
'@types/katex': 0.16.8
20062
devlop: 1.1.0
@@ -21348,7 +21348,7 @@ snapshots:
21348
dependencies:
21349
'@types/mdast': 4.0.4
21350
mdast-util-math: 3.0.0(patch_hash=afe6b2c89e1eaddfd3c90cf2723f12c9a17d513e65beff51653781486013251c)(supports-color@8.1.1)
21351
- micromark-extension-math: micromark-extension-llm-math@3.1.0(patch_hash=49ab4815c18b003f6af998dcc6c258c17a21b50b2cc87745f12d4bd8b6d591f9)
21351
+ micromark-extension-math: micromark-extension-llm-math@3.1.0(patch_hash=7beb6ac4ba52166286593a494531aace81547e55fdddecf892824c25bd84d15a)
21352
unified: 11.0.5
21353
transitivePeerDependencies:
21354
- supports-color