Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/components/assistant-ui/markdown-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,18 @@ function normalizeCustomMathTags(input: string): string {
.replace(/\\{1,2}\(([\s\S]*?)\\{1,2}\)/g, (_, content) => `$$${content.trim()}$$`)
// Convert \[ ... \] to $$...$$ (block math) - streamdown needs newlines for block triggers
.replace(
/\\{1,2}\[([\s\S]*?)\\{1,2}\]/g,
(_, content) => `$$\n${content.trim()}\n$$`
));
/\\{1,2}\[([\s\S]*?)\\{1,2}\]/g,
(_, content) => `$$\n${content.trim()}\n$$`
)
// Convert single $ ... $ to $$...$$ (inline math), but avoid currency like $10 or $5.50
// Use lookbehind to avoid consuming characters and handle consecutive expressions
// Exclude escaped dollar signs (prefixed with \)
.replace(/(?<!\\)(?<!\$)\$(?!\$)([^$\n]+?)(?<!\\)(?<!\$)\$(?!\$)/g, (match, content) => {
// More precise currency pattern: matches numbers like 10, 1,000, 10.50, 1,000.50
if (/^\d{1,3}(?:,\d{3})*(?:\.\d{1,2})?$/.test(content.trim())) {

@cubic-dev-ai cubic-dev-ai Bot Jan 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Currency detection regex misses 4+ digit amounts without commas (e.g., $1000), so those get converted to math. Widen the pattern to allow plain digit sequences or properly comma-grouped numbers.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/components/assistant-ui/markdown-text.tsx, line 160:

<comment>Currency detection regex misses 4+ digit amounts without commas (e.g., `$1000`), so those get converted to math. Widen the pattern to allow plain digit sequences or properly comma-grouped numbers.</comment>

<file context>
@@ -153,15 +153,14 @@ function normalizeCustomMathTags(input: string): string {
+    // Exclude escaped dollar signs (prefixed with \)
+    .replace(/(?<!\\)(?<!\$)\$(?!\$)([^$\n]+?)(?<!\\)(?<!\$)\$(?!\$)/g, (match, content) => {
+      // More precise currency pattern: matches numbers like 10, 1,000, 10.50, 1,000.50
+      if (/^\d{1,3}(?:,\d{3})*(?:\.\d{1,2})?$/.test(content.trim())) {
         return match; // Keep as-is (currency)
       }
</file context>
Suggested change
if (/^\d{1,3}(?:,\d{3})*(?:\.\d{1,2})?$/.test(content.trim())) {
if (/^(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d{1,2})?$/.test(content.trim())) {
Fix with Cubic

return match; // Keep as-is (currency)
}
// Otherwise, convert to math
return `$$${content.trim()}$$`;
}));
Comment on lines 151 to +165

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n src/components/assistant-ui/markdown-text.tsx | head -200

Repository: ThinkEx-OSS/thinkex

Length of output: 7087


🏁 Script executed:

rg -i "markdown|normalize.*text|normaliz.*math" --type ts --type tsx -l

Repository: ThinkEx-OSS/thinkex

Length of output: 90


🏁 Script executed:

rg -i "markdown|normalize" --type ts -l

Repository: ThinkEx-OSS/thinkex

Length of output: 1596


🏁 Script executed:

cat -n src/components/assistant-ui/standalone-markdown.tsx

Repository: ThinkEx-OSS/thinkex

Length of output: 11175


Fix escaped dollar sign handling in both math normalizers

The regex pattern (^|[^\$])\$ matches backslash before a dollar sign, so escaped sequences like \$5 are incorrectly converted to \$$5$$. Both normalizeCustomMathTags functions in markdown-text.tsx (line 158) and standalone-markdown.tsx (line 71) have this issue. Update the character class to exclude backslash:

Suggested fix
-    .replace(/(^|[^\$])\$([^\$\n]+?)\$(?!\$)/g, (match, prefix, content) => {
+    .replace(/(^|[^$\\])\$([^\$\n]+?)\$(?!\$)/g, (match, prefix, content) => {

Apply this change to both functions for consistency.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.replace(
/\\{1,2}\[([\s\S]*?)\\{1,2}\]/g,
(_, content) => `$$\n${content.trim()}\n$$`
));
/\\{1,2}\[([\s\S]*?)\\{1,2}\]/g,
(_, content) => `$$\n${content.trim()}\n$$`
)
// Convert single $ ... $ to $$...$$ (inline math), but avoid currency like $10 or $5.50
// We use (^|[^\$]) to ensure it's not preceded by match (ignoring $$)
// and (?!\$) to ensure it's not followed by $ (ignoring $$)
.replace(/(^|[^\$])\$([^\$\n]+?)\$(?!\$)/g, (match, prefix, content) => {
// If content is purely numeric (with optional commas/periods), treat as currency
if (/^[\d,\.]+$/.test(content.trim())) {
return match; // Keep as-is (currency)
}
// Otherwise, convert to math.
// prefix is the character before the first $ (or empty string)
return `${prefix}$$${content.trim()}$$`;
}));
.replace(
/\\{1,2}\[([\s\S]*?)\\{1,2}\]/g,
(_, content) => `$$\n${content.trim()}\n$$`
)
// Convert single $ ... $ to $$...$$ (inline math), but avoid currency like $10 or $5.50
// We use (^|[^\$]) to ensure it's not preceded by match (ignoring $$)
// and (?!\$) to ensure it's not followed by $ (ignoring $$)
.replace(/(^|[^$\\])\$([^\$\n]+?)\$(?!\$)/g, (match, prefix, content) => {
// If content is purely numeric (with optional commas/periods), treat as currency
if (/^[\d,\.]+$/.test(content.trim())) {
return match; // Keep as-is (currency)
}
// Otherwise, convert to math.
// prefix is the character before the first $ (or empty string)
return `${prefix}$$${content.trim()}$$`;
}));
🤖 Prompt for AI Agents
In `@src/components/assistant-ui/markdown-text.tsx` around lines 151 - 166, The
inline-math regex in both normalizeCustomMathTags functions incorrectly allows a
backslash as the "prefix" so escaped dollars like `\$5` get converted; update
the regex used in normalizeCustomMathTags (in markdown-text.tsx and
standalone-markdown.tsx) to disallow backslash in the prefix by replacing the
character class [^\$] with [^\\$] (i.e., use (^|[^\\$])\$... instead of
(^|[^\$])\$...), and apply the same corrected pattern in both functions so
escaped dollar signs are preserved.

}
10 changes: 6 additions & 4 deletions src/components/assistant-ui/standalone-markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ function normalizeCustomMathTags(input: string): string {
input
// Convert [/math]...[/math] to $$...$$ (legacy block math format)
.replace(/\[\/math\]([\s\S]*?)\[\/math\]/g, (_, content) => `$$${content.trim()}$$`)
// Convert [/inline]...[/inline] to $$...$$ (legacy inline format - Streamdown uses $$ for all)
.replace(/\[\/inline\]([\s\S]*?)\[\/inline\]/g, (_, content) => `$$${content.trim()}$$`)
// Convert \( ... \) to $$...$$ (LaTeX inline math - Streamdown uses $$ for all)
.replace(/\\{1,2}\(([\s\S]*?)\\{1,2}\)/g, (_, content) => `$$${content.trim()}$$`)
// Convert [/inline]...[/inline] to $...$ (legacy inline format - ReactMarkdown uses $ for inline)
.replace(/\[\/inline\]([\s\S]*?)\[\/inline\]/g, (_, content) => `$${content.trim()}$`)
// Convert \( ... \) to $...$ (LaTeX inline math - ReactMarkdown uses $ for inline)
.replace(/\\{1,2}\(([\s\S]*?)\\{1,2}\)/g, (_, content) => `$${content.trim()}$`)
// Convert \[ ... \] to $$...$$ (LaTeX block math)
.replace(/\\{1,2}\[([\s\S]*?)\\{1,2}\]/g, (_, content) => `$$${content.trim()}$$`)
// Note: We DON'T convert $...$ to $$ here because ReactMarkdown with remark-math expects
// single dollar signs for inline math and double dollar signs for block math
);
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/workspace-canvas/QuizContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ export function QuizContent({ item, onUpdateData, isScrollLocked = false }: Quiz
)}>
{String.fromCharCode(65 + index)}
</span>
<span className="text-sm text-white/90 flex-1">{option}</span>
<div className="text-sm text-white/90 flex-1 prose prose-invert prose-sm max-w-none">
<ReactMarkdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>
{option}
</ReactMarkdown>
</div>
{showCorrectness && isCorrect && <CheckCircle2 className="w-5 h-5 text-green-400" />}
{showCorrectness && isSelected && !isCorrect && <XCircle className="w-5 h-5 text-red-400" />}
</div>
Expand Down