From c1e8893577e442d131121fc5e87d48f6e1f05bcf Mon Sep 17 00:00:00 2001 From: 1shCha Date: Thu, 5 Feb 2026 18:34:47 -0500 Subject: [PATCH 1/2] minor quiz UI changes --- .../workspace-canvas/QuizContent.tsx | 30 ++++++++--- src/lib/utils/normalize-math-markdown.ts | 27 ++++++++++ src/lib/utils/sanitize-math-latex.ts | 51 +++++++++++++++++++ 3 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 src/lib/utils/normalize-math-markdown.ts create mode 100644 src/lib/utils/sanitize-math-latex.ts diff --git a/src/components/workspace-canvas/QuizContent.tsx b/src/components/workspace-canvas/QuizContent.tsx index 373024e7..ced34b6e 100644 --- a/src/components/workspace-canvas/QuizContent.tsx +++ b/src/components/workspace-canvas/QuizContent.tsx @@ -178,6 +178,15 @@ export function QuizContent({ item, onUpdateData, isScrollLocked = false }: Quiz } }; + // Arrow navigation - only moves between questions, never shows results + const handleArrowNext = () => { + if (currentIndex < totalQuestions - 1) { + const nextIndex = currentIndex + 1; + setCurrentIndex(nextIndex); + persistSession({ currentIndex: nextIndex }); + } + }; + const handlePrevious = () => { if (currentIndex > 0) { const prevIndex = currentIndex - 1; @@ -464,9 +473,10 @@ export function QuizContent({ item, onUpdateData, isScrollLocked = false }: Quiz @@ -490,11 +500,11 @@ export function QuizContent({ item, onUpdateData, isScrollLocked = false }: Quiz - {/* Right: Check */} + {/* Right: Check/Next Button */}
- {!isSubmitted && ( + {!isSubmitted ? ( + ) : ( + )}
diff --git a/src/lib/utils/normalize-math-markdown.ts b/src/lib/utils/normalize-math-markdown.ts new file mode 100644 index 00000000..ff7e399d --- /dev/null +++ b/src/lib/utils/normalize-math-markdown.ts @@ -0,0 +1,27 @@ +export function normalizeMathMarkdown(input: string): string { + return ( + input + // Fix quadruple dollar signs (often generated by AI) to double dollar signs + .replace(/\${4}/g, "$$") + // Convert legacy [/math]...[/math] blocks to $$...$$ + .replace(/\[\/math\]([\s\S]*?)\[\/math\]/g, (_, content) => `$$${content.trim()}$$`) + // Convert legacy [/inline]...[/inline] to $$...$$ (Streamdown inline math) + .replace(/\[\/inline\]([\s\S]*?)\[\/inline\]/g, (_, content) => `$$${content.trim()}$$`) + // Convert \( ... \) to $$...$$ (inline math) + .replace(/\\{1,2}\(([\s\S]*?)\\{1,2}\)/g, (_, content) => `$$${content.trim()}$$`) + // Convert \[ ... \] to $$...$$ (block math) + .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 + // Exclude escaped dollar signs (prefixed with \) + .replace( + /(? { + // 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 currency as-is + } + return `$$${content.trim()}$$`; + } + ) + ); +} diff --git a/src/lib/utils/sanitize-math-latex.ts b/src/lib/utils/sanitize-math-latex.ts new file mode 100644 index 00000000..a2b97033 --- /dev/null +++ b/src/lib/utils/sanitize-math-latex.ts @@ -0,0 +1,51 @@ +export function sanitizeMathLatex(input: string): string { + if (!input) return ""; + + let latex = input.trim(); + + // Strip any HTML tags that might have leaked into the latex string. + latex = latex.replace(/<[^>]*>/g, ""); + + // Normalize LaTeX wrapper delimiters to raw latex. + let updated = true; + while (updated) { + updated = false; + const trimmed = latex.trim(); + + const parenMatch = trimmed.match(/^\\\(([\s\S]*?)\\\)$/); + if (parenMatch) { + latex = parenMatch[1].trim(); + updated = true; + continue; + } + + const bracketMatch = trimmed.match(/^\\\[([\s\S]*?)\\\]$/); + if (bracketMatch) { + latex = bracketMatch[1].trim(); + updated = true; + continue; + } + + if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) { + const inner = trimmed.slice(2, -2); + // Only strip if no other $$ remain inside. + if (!inner.includes("$$")) { + latex = inner.trim(); + updated = true; + continue; + } + } + + if (trimmed.startsWith("$") && trimmed.endsWith("$")) { + const inner = trimmed.slice(1, -1); + // Only strip if no other $ remain inside. + if (!inner.includes("$")) { + latex = inner.trim(); + updated = true; + continue; + } + } + } + + return latex; +} From da701bd66e0e7ca1fc373a25ad9ec0c4410a6ab8 Mon Sep 17 00:00:00 2001 From: Urjit Chakraborty <135136842+urjitc@users.noreply.github.com> Date: Thu, 5 Feb 2026 19:07:59 -0500 Subject: [PATCH 2/2] fixes --- src/lib/utils/normalize-math-markdown.ts | 27 ------------- src/lib/utils/sanitize-math-latex.ts | 51 ------------------------ 2 files changed, 78 deletions(-) delete mode 100644 src/lib/utils/normalize-math-markdown.ts delete mode 100644 src/lib/utils/sanitize-math-latex.ts diff --git a/src/lib/utils/normalize-math-markdown.ts b/src/lib/utils/normalize-math-markdown.ts deleted file mode 100644 index ff7e399d..00000000 --- a/src/lib/utils/normalize-math-markdown.ts +++ /dev/null @@ -1,27 +0,0 @@ -export function normalizeMathMarkdown(input: string): string { - return ( - input - // Fix quadruple dollar signs (often generated by AI) to double dollar signs - .replace(/\${4}/g, "$$") - // Convert legacy [/math]...[/math] blocks to $$...$$ - .replace(/\[\/math\]([\s\S]*?)\[\/math\]/g, (_, content) => `$$${content.trim()}$$`) - // Convert legacy [/inline]...[/inline] to $$...$$ (Streamdown inline math) - .replace(/\[\/inline\]([\s\S]*?)\[\/inline\]/g, (_, content) => `$$${content.trim()}$$`) - // Convert \( ... \) to $$...$$ (inline math) - .replace(/\\{1,2}\(([\s\S]*?)\\{1,2}\)/g, (_, content) => `$$${content.trim()}$$`) - // Convert \[ ... \] to $$...$$ (block math) - .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 - // Exclude escaped dollar signs (prefixed with \) - .replace( - /(? { - // 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 currency as-is - } - return `$$${content.trim()}$$`; - } - ) - ); -} diff --git a/src/lib/utils/sanitize-math-latex.ts b/src/lib/utils/sanitize-math-latex.ts deleted file mode 100644 index a2b97033..00000000 --- a/src/lib/utils/sanitize-math-latex.ts +++ /dev/null @@ -1,51 +0,0 @@ -export function sanitizeMathLatex(input: string): string { - if (!input) return ""; - - let latex = input.trim(); - - // Strip any HTML tags that might have leaked into the latex string. - latex = latex.replace(/<[^>]*>/g, ""); - - // Normalize LaTeX wrapper delimiters to raw latex. - let updated = true; - while (updated) { - updated = false; - const trimmed = latex.trim(); - - const parenMatch = trimmed.match(/^\\\(([\s\S]*?)\\\)$/); - if (parenMatch) { - latex = parenMatch[1].trim(); - updated = true; - continue; - } - - const bracketMatch = trimmed.match(/^\\\[([\s\S]*?)\\\]$/); - if (bracketMatch) { - latex = bracketMatch[1].trim(); - updated = true; - continue; - } - - if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) { - const inner = trimmed.slice(2, -2); - // Only strip if no other $$ remain inside. - if (!inner.includes("$$")) { - latex = inner.trim(); - updated = true; - continue; - } - } - - if (trimmed.startsWith("$") && trimmed.endsWith("$")) { - const inner = trimmed.slice(1, -1); - // Only strip if no other $ remain inside. - if (!inner.includes("$")) { - latex = inner.trim(); - updated = true; - continue; - } - } - } - - return latex; -}