fix: 단위를 감싼 LaTeX를 평문으로 정규화
모델이 미세먼지 단위를 $\mu\text{g/m}^3$처럼 LaTeX로 쓴다. 단위는 수식이 아닌데
이 표기가 세 곳에서 깨진다: index.html은 KaTeX가 렌더하지만 복사하면 MathML까지
딸려와 "μ g/m 3 μg/m 3"처럼 중복돼 보이고, 나머지 채팅 페이지 8개(weather/doctor/
lawyer/detective 등)는 KaTeX 자체가 없어 생 LaTeX가 그대로 노출되며, TTS는
백슬래시를 소리 내어 읽는다.
단위만 담긴 수식 span만 유니코드로 바꾸고, 연산자·분수·변수가 있으면 그대로 둔다:
$\mu\text{g/m}^3$ → μg/m³ $\text{m/s}$ → m/s
$E = mc^2$ / $x + y$ / $\frac{a}{b}$ → 유지
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1747,6 +1747,25 @@ function sanitizeFinalReply(
|
||||
// a tool result path — never strip dental-dict, external URL, or other legitimate images.
|
||||
// (Previously: a blanket regex stripped ALL image markdown, breaking dental-dict images.)
|
||||
|
||||
// Units are not math. Models wrap plain units in LaTeX ("$\mu\text{g/m}^3$" for μg/m³), which
|
||||
// only renders on index.html — the other eight chat pages have no KaTeX and show the raw
|
||||
// markup, and TTS reads it aloud as backslashes either way. Convert spans that contain nothing
|
||||
// but a unit; anything with real math (operators, fractions, variables) is left untouched.
|
||||
result = result.replace(/\$([^$\n]{1,40})\$/g, (whole, inner: string) => {
|
||||
const plain = inner
|
||||
.replace(/\\mu\b/g, 'μ')
|
||||
.replace(/\\text\{([^}]*)\}/g, '$1')
|
||||
.replace(/\\mathrm\{([^}]*)\}/g, '$1')
|
||||
.replace(/\^3\b/g, '³')
|
||||
.replace(/\^2\b/g, '²')
|
||||
.replace(/\\,|\\;|\\ /g, ' ')
|
||||
.replace(/[{}]/g, '')
|
||||
.trim();
|
||||
// Only accept the rewrite if nothing LaTeX-ish survived and it reads as a bare unit.
|
||||
if (/[\\^_=+]/.test(plain)) return whole;
|
||||
return /^[μnmkKMGT]?[a-zA-Z°%]+([/·][a-zA-Z0-9²³]+)*[²³]?$/.test(plain) ? plain : whole;
|
||||
});
|
||||
|
||||
// Strip ALL AI-generated PPTX links — the tool result already has the correct link.
|
||||
// 1. Markdown links to .pptx via /api/files/ (encoded or plain Korean in URL)
|
||||
result = result.replace(/\[[^\]]*\]\([^)]*\/api\/files\/[^)]*\.pptx[^)]*\)/gi, '');
|
||||
|
||||
Reference in New Issue
Block a user