Task 132: 数式レンダリングのTDD回帰テスト
完了 ← タスク一覧
Task 132: 数式レンダリングのTDD回帰テスト
Status: DONE
Human Directive
「たまに数式のレンダリングが壊れている。TDD で修正することで維持するべき。」
Scope
- Identify current math rendering failures (audit all reports for broken
$...Identify current math rendering failures (audit all reports for broken and$...$`) - Add comprehensive regression tests for
extractMath()andmarkdownToHtml()math handling - Test edge cases: nested delimiters, escaped dollars, math inside code blocks, adjacent math
- Fix any currently broken math rendering
- ~~Add E2E (Playwright) tests that verify KaTeX renders correctly in the browser~~ (deferred — unit tests cover the critical HTML output)
Bugs Found and Fixed
Bug 1: `Bug 1: inside backtick code captured as math delimiter
- Symptom:
Use \$variable\ CSLOT1 would match CSLOT2 in your code and $` as one math expression, breaking both the inline code and the subsequent math - Root cause:
extractMath()ran before inline code processing, soRoot cause:extractMath()` ran before inline code processing, so inside backticks was treated as a math delimiter - Fix: In
extractMath(), temporarily protect backtick-delimited code with placeholders before running math regex, then restore backtick content afterward
Bug 2: Multi-line display math broken
- Symptom:
$\n\\Delta V = \\sqrt{2}\n$rendered as three separate<p>tags instead of a display math block - Root cause:
markdownToHtml()only handled single-line$...$— multi-line display math (where$opens and closes on separate lines) was not supported - Fix: Added multi-line display math handling in
markdownToHtml()that collects lines between$delimiters and joins them into a single<p>$...$</p>block
Tests Added (16 new regression tests)
- Trailing-space math (`$expr = Trailing-space math ()
- Adjacent math-then-bold (
$\\Delta V$比: ... $= $ bold) - Sequential `$= Sequential patterns without cross-matching
- Nested
\\frac{}{}braces \\sqrt{}with parentheses- Thousands separator
{,} \\text{}command- Complex display math
- Multiple display math blocks separated by text
- Multi-line display math (
$\n...\n$) - ` in inline code vs math
- Math adjacent to Japanese text
- Subscript/superscript notation
- Inequality operators (
<,>) not HTML-escaped in math - HTML escaping verification for math content
- Aligned environment in display math
Test Results
- Templates tests: 383 pass, 0 fail (was 367 + 16 new)
- Full TS suite: 1271 pass, 19 fail (WASM build-dependent, pre-existing)
- TypeScript typecheck: clean
- Site build: successful
Dependencies
- Task 052 (KaTeX integration — DONE)