Repository navigation
feat(core): render mermaid diagrams with zoom, pan, and copy controls - #192
Merged
Merged
Conversation
Render ```mermaid fences as diagrams in every read-only Markdown view (PR bodies, PR and review comments, Markdown previews, shared plans). Editors keep showing the fenced code. - Register a code-block descriptor that outranks CodeMirror for the `mermaid` language, only when `renderDiagrams` is set. - Load `mermaid` lazily on the first diagram, render one diagram at a time, and cache the last 50 results per theme. - Render with `securityLevel: 'strict'` and the `dagre` layout, so the 1.5 MB ELK chunk only loads when a diagram asks for it. - Show the SVG through an `<img>` data URL, so no script inside it can run; fall back to the code block plus an error note on failure. Claude-Session: https://claude.ai/code/session_014TASJcnCpJt1rDvM2zAE71
Rendered diagrams gain GitHub's viewer controls: zoom in, zoom out, reset, and four pan arrows in a 3x3 grid at the bottom right. Drag pans, Cmd/Ctrl+scroll or a trackpad pinch zooms around the cursor, and double-click resets. Plain scrolling still scrolls the page. A top-right cluster adds Copy code and a Show source toggle that swaps the diagram for its read-only code block. Both clusters appear on hover or keyboard focus. The view is a CSS transform on the existing img data URL, so zooming never changes layout height. CopyCodeButton moves into its own module so collapsibles and diagrams share it. Claude-Session: https://claude.ai/code/session_014TASJcnCpJt1rDvM2zAE71
Ctrl+wheel gets a 10x boost so trackpad pinches feel responsive, but a Ctrl+mouse-wheel notch on Windows or Linux sends a delta of about 100, which zoomed 4x per notch. Each wheel event now zooms at most 2x in or out. Claude-Session: https://claude.ai/code/session_014TASJcnCpJt1rDvM2zAE71
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.
Why
GitHub renders
```mermaidfences as diagrams, so PR descriptions and comments often include them. Codiff shows them as raw code.What changed
This PR renders them as diagrams in PR/MR descriptions, comments, and shared plans. Markdown editors keep showing the code.
flowchart LR A[mermaid fence] --> B{Read-only view?} B -- No --> C[Code block] B -- Yes --> D[Lazy-load Mermaid and render] D -- SVG --> E[Diagram with controls] D -- Parse error --> F[Code block plus error note]mermaidlanguage. OnlyReadOnlyMarkdownViewturns it on, through arenderDiagramsprop.Security
Each diagram is an
<img>with an SVG data URL, so nothing inside the SVG can run. Comments come from any GitHub user and the renderer can reach the preload bridge, so this sits on top of Mermaid'ssecurityLevel: 'strict'instead of relying on it.Bundle size
Nothing loads until a page has a Mermaid fence. Incremental cost, measured on
dist/assetsfromvpr build:Mermaid 12 lays diagrams out with ELK by default, which adds 1,468 kB (451 kB gzip). The renderer sets
layout: 'dagre', so ELK loads only for diagrams that ask for it, such asflowchart-elk.Verification
vp test: 1,314 passed, 4 skipped. The new tests incore/__tests__/mermaid.test.tsandcore/__tests__/ReadOnlyMarkdownView.test.tsxmock onlymermaid.vp checkandvpr buildpass.Preview
Screen.Recording.2026-10-30.at.14.09.31.mov