Render LaTeX math in chat via vendored KaTeX 0.18.1 - #222
Open
leonidasbarkas98-cpu wants to merge 8 commits into
Open
leonidasbarkas98-cpu wants to merge 8 commits into
leonidasbarkas98-cpu wants to merge 8 commits into
Conversation
…1 and build/test infrastructure Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… toggle Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replacement strings containing $&, $`, $' or $$ were interpreted as special replacement patterns by String.replace, corrupting restored code blocks. Extract the restore loop into markdown-restore.ts using a function replacement (same pattern as restoreMathSegments, introduced for the LaTeX-rendering feature), add test:markdown-restore (9 tests, red-green verified) and a check-webview-syntax assertion guarding the call site. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…nal tracker references Cleans up leftover German-language documentation and comments plus bare internal issue-tracker references (andrepimenta#47/andrepimenta#55) that do not belong in a PR against an English upstream repo. Pure text change, no behavior affected.
…plan references
math-segments.test.ts had German-language test titles and fixtures that
escaped an earlier umlaut-based grep because they used ASCII transliteration
("fuer", "beruehmt"). Translated all of them to English, recomputing the one
offset-based assertion whose expected start/end positions changed because the
replacement prose has a different length than the German original.
Also removes internal review-round shorthand labels from math-segments.ts,
math-segments.test.ts and ui-styles.ts comments and suite/test names,
replacing them with neutral descriptions of what each guard actually
verifies. Pure text change, no behavior affected (71/71 tests still
passing, same count as before).
script.ts had four comments still carrying an internal planning label with no meaning for readers outside this fork. Removed it; text-only change, no behavior affected.
Several comments cited neighbouring-file analogies (diff-utils.ts, shell-utils.ts, auto-model-switch.ts, collapse-rules.ts, html-escape.ts) that don't exist on this branch -- leftovers from a shared comment template reused across branches. Corrected each to name only modules that actually exist here (model-updater.ts, math-segments.ts, math-script.ts) or dropped the file list where a neutral description was clearer. Text-only change, no behavior affected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Renders LaTeX math in chat messages using vendored KaTeX 0.18.1, toggleable via a new
claudeCodeChat.ui.renderMathsetting.findMathSegments) locates$...$,$$...$$,\(...\)and\[...\]math spans in message text before markdown processing runs, guarding against common false positives (price mentions like "$5 and $10", shell variables like$PATH/$$, and math spans that overlap a fenced code block, which are left untouched).katex.renderToStringwithtrust: falseandthrowOnError: false(no HTML injection through LaTeX macros; a render failure falls back to the escaped raw source instead of breaking the message).assets/katex/and copied intoout/katex/at build time; served through the webview's own resource URI scheme, which the existinglocalResourceRootsalready covers.build/check-webview-syntax.jsgate (new,npm run check-webview-syntax) parses the generated webview<script>block with a real AST parser and asserts a few load-bearing invariants (e.g. that the code-block-restore call site is present and safe) that no other check would otherwise catch on a.toString()-spliced script.parseSimpleMarkdown) usedString.prototype.replace(placeholder, htmlString), which interprets$-sequences in the replacement text ($&,$`,$',$$) as replacement patterns — a code block containing one of these sequences could splice already-rendered HTML from elsewhere in the message across block boundaries. Fixed by switching to a function replacer, which performs a literal substitution.This is one of several PRs from our fork submitted together as part of a broader, thematically grouped series (permission/session handling, settings/UI, security hardening, rendering, etc. split across separate branches/PRs). This branch is based directly on current
main(ab6e307) and does not stack on any other PR in the series, thoughsrc/markdown-restore.ts(introduced here) also appears independently, with slightly different content, in the security-hardening PR of this series — a merge conflict is expected if both are merged.tsc --noEmitclean, no new runtime dependencies (KaTeX is vendored, not an npm dependency).🤖 Generated with Claude Code