fraudTech commited on
Commit
d946175
·
verified ·
1 Parent(s): e0d611a

remove user input latext rendering

Browse files
Files changed (1) hide show
  1. web/src/App.tsx +2 -58
web/src/App.tsx CHANGED
@@ -355,62 +355,6 @@ const splitStreamingContent = (content: string): { safe: string; tail: string }
355
  return { safe: content, tail: '' };
356
  };
357
 
358
- const normalizeUserLatex = (content: string): string => {
359
- if (!content) {
360
- return content;
361
- }
362
-
363
- let normalized = content;
364
-
365
- // Auto-close dangling $$ display-math blocks so KaTeX can render.
366
- // Convert explicit LaTeX delimiters \( ... \) and \[ ... \].
367
- normalized = normalized.replace(/\\\(([\s\S]*?)\\\)/g, (_m, expr) => `$${expr.trim()}$`);
368
- normalized = normalized.replace(/\\\[([\s\S]*?)\\\]/g, (_m, expr) => `$$${expr.trim()}$$`);
369
-
370
- // Wrap common block environments if user forgot $$ delimiters.
371
- normalized = normalized.replace(
372
- /\\begin\{(aligned|align\*?|equation\*?|gather\*?|multline\*?|array|matrix|pmatrix|bmatrix|vmatrix|Vmatrix|cases|split|eqnarray\*?)\}[\s\S]*?\\end\{\1\}/g,
373
- (m) => `$$${m}$$`
374
- );
375
-
376
- // Wrap bare parenthesized chunks that look like LaTeX, e.g. (\mathbb{R}) or (x_n).
377
- normalized = normalized.replace(
378
- /\(([^()\n]*(?:\\[A-Za-z]+|[A-Za-z0-9]+_[A-Za-z0-9]+|[A-Za-z0-9]+\^[A-Za-z0-9]+)[^()\n]*)\)/g,
379
- (_m, expr) => `$${expr.trim()}$`
380
- );
381
-
382
- // If any rule above introduced delimiters, stop here to avoid double-wrapping
383
- // in subsequent regex passes.
384
- if (normalized.includes('$')) {
385
- // Repair malformed "$$(...latex...)" into "$...latex...$" for user input.
386
- // This can appear from odd delimiter interactions in partially-normalized text.
387
- normalized = normalized.replace(
388
- /\$\$\((\\[A-Za-z][^)\n]*)\)/g,
389
- (_m, expr) => `$${expr.trim()}$`
390
- );
391
-
392
- // Repair malformed "$(...latex...)" into "$...latex...$".
393
- normalized = normalized.replace(
394
- /\$\((\\[A-Za-z][^)\n]*)\)/g,
395
- (_m, expr) => `$${expr.trim()}$`
396
- );
397
-
398
- const displayDelimiters = normalized.match(/\$\$/g);
399
- if (displayDelimiters && displayDelimiters.length % 2 === 1) {
400
- normalized = `${normalized}\n$$`;
401
- }
402
- return normalized;
403
- }
404
-
405
- // Wrap common inline commands if user forgot $ delimiters.
406
- normalized = normalized.replace(
407
- /\\(?:frac|sqrt|sum|int|prod|lim|alpha|beta|gamma|delta|theta|lambda|pi|sigma|mu|partial|cdot|times|leq|geq|neq|infty|forall|exists|sin|cos|tan|log|ln|mathbb|mathbf|mathcal|mathrm|to)(?:\s*\{[^{}]*\}){0,3}(?:\s*\^[^\s{}]+)?(?:\s*_[^\s{}]+)?/g,
408
- (m) => `$${m}$`
409
- );
410
-
411
- return normalized;
412
- };
413
-
414
  const PlotImage: React.FC<{ src?: string; alt?: string }> = ({ src, alt, ...props }) => {
415
  const [currentSrc, setCurrentSrc] = useState<string | undefined>(src);
416
  const [fallbackSrc, setFallbackSrc] = useState<string | undefined>(undefined);
@@ -746,7 +690,7 @@ const MessageItem = React.memo(function MessageItem({
746
  img({ src, alt, ...props }: any) { return <PlotImage src={src} alt={alt} {...props} />; },
747
  }}
748
  >
749
- {message.role === 'user' ? normalizeUserLatex(message.content) : message.content}
750
  </ReactMarkdown>
751
  )}
752
  </div>
@@ -2049,4 +1993,4 @@ function App() {
2049
  );
2050
  }
2051
 
2052
- export default App;
 
355
  return { safe: content, tail: '' };
356
  };
357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  const PlotImage: React.FC<{ src?: string; alt?: string }> = ({ src, alt, ...props }) => {
359
  const [currentSrc, setCurrentSrc] = useState<string | undefined>(src);
360
  const [fallbackSrc, setFallbackSrc] = useState<string | undefined>(undefined);
 
690
  img({ src, alt, ...props }: any) { return <PlotImage src={src} alt={alt} {...props} />; },
691
  }}
692
  >
693
+ {message.content}
694
  </ReactMarkdown>
695
  )}
696
  </div>
 
1993
  );
1994
  }
1995
 
1996
+ export default App;