hermes-agent/apps/desktop/src
emozilla 708d2a0c33 fix(desktop): polish LaTeX rendering — currency, code blocks, brackets
Five distinct bugs surfaced from a math-heavy stress test:

1. Adjacent code fences glued together. scrubBacktickNoise's
   second-pass regex /``\s*``/g matched the LAST 2 backticks of
   one fence + whitespace + FIRST 2 backticks of the next, collapsing
   two blocks into one. Fixed with lookbehind/lookahead so we only
   match exactly 2 backticks not part of a longer run.

2. Whitespace eaten between fences and following content.
   stripPreviewTargets internally calls .trim() which strips leading/
   trailing whitespace from each split-segment. For segments between
   two fences this collapsed \n\n to '', gluing fence close to next
   block. Fixed by capturing leading/trailing whitespace at the call
   site and restoring it after the transform.

3. Currency dollar signs eaten as math. With singleDollarTextMath:true
   remark-math greedy-matched any pair of $, so '$5 ... $10' became
   one inline math span. Added escapeCurrencyDollars to escape $<digit>
   patterns to \$<digit> in prose segments (not in code). Trade-off:
   math expressions starting with a digit (rare — '$5x = 10$') get
   escaped too. Mirrors the convention in ChatGPT/Claude's UIs.

4. \(...\) and \[...\] LaTeX brackets unsupported. Models often
   emit these instead of $...$ / $$...$$. Added
   rewriteLatexBracketDelimiters preprocessor pass.

5. ```latex / ```tex blocks were being routed to KaTeX via a
   rewrite to ```math. Aligns with GitHub markdown convention:
   ```math = render as math; ```latex / ```tex = LaTeX/TeX
   source code (syntax highlighted, not rendered). Conflating them
   broke teaching/showing-source use cases. MATH_FENCE_LANGUAGES
   pruned to {'math'} only.

Also flipped parseIncompleteMarkdown to true (was !isStreaming) so
the math parser can't see $ inside streaming-but-not-yet-closed code
fences. Shiki was already deferred via defer={isStreaming} so this
doesn't introduce new tokenization cost.

Test: 18/18 existing tests still pass; one test updated to expect
escaped \$ in currency-prose-with-URL case.
2026-05-12 22:13:30 -04:00
..
app fix(desktop): suppress generic provider warning in onboarding 2026-05-11 22:17:46 -04:00
components fix(desktop): polish LaTeX rendering — currency, code blocks, brackets 2026-05-12 22:13:30 -04:00
hooks feat: theme changes, composer tweaks, in app update ux, finesse 2026-05-11 15:28:45 -04:00
lib fix(desktop): polish LaTeX rendering — currency, code blocks, brackets 2026-05-12 22:13:30 -04:00
store feat(desktop): add model-confirmation step to onboarding 2026-05-11 22:01:26 -04:00
themes feat: theme changes, composer tweaks, in app update ux, finesse 2026-05-11 15:28:45 -04:00
types feat(gui): first-class Messaging page + gateway menu redesign 2026-05-08 15:59:43 -04:00
global.d.ts feat(desktop): reconcile live tool events, polish thread chrome, harden boot 2026-05-11 21:38:47 -04:00
hermes.ts feat(desktop): reconcile live tool events, polish thread chrome, harden boot 2026-05-11 21:38:47 -04:00
main.tsx feat: better composer etc 2026-05-04 22:19:16 -05:00
styles.css feat(desktop): render LaTeX math via KaTeX after streaming completes 2026-05-12 01:04:11 -04:00
vite-env.d.ts feat(desktop): add structured desktop chat app 2026-05-01 12:49:12 -05:00