Repository navigation
feat: render Mermaid fences as diagrams - #579
Merged
Merged
Conversation
A ```mermaid fence lays its source out to SVG with mermaid-rs-renderer and paints it through GPUI's image pipeline, themed light or dark with the shell. Source that does not parse, the usual state of a fence still streaming in, stays a code block; the diagram keeps the code block's copy-source context menu and opens in the image lightbox on click. The highlight cache's bounded LRU is shared with the diagram cache as RecentCache.
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.
What changes
A
```mermaidfence in any Markdown surface now renders as a diagram instead of highlighted code.crates/ui/src/markdown/mermaid.rslays the fence source out to SVG withmermaid-rs-renderer(pure Rust, no browser,default-features = false), picks the engine's light or dark theme from the shell theme mode, and makes its page background transparent so the fence surface shows through. The SVG goes through GPUI's ownImageSource::Imagepath, which rasterizes SVGs at 2x so the diagram is crisp on HiDPI.markdown.mermaid_diagram, added to both locales).RecentCache<K, V>and shared by the diagram cache, so a repaint never re-lays-out a diagram.Test
markdown::view::tests::mermaid_fence_paints_a_diagram_and_unparsable_source_stays_codedrives the real root list the way the app does and asserts the contract: a parsable fence paints a diagram and no code lines, and an unparsable fence stays a code block.Checks run
cargo fmt --all --check,cargo clippy -p tcode-ui --all-targets --locked -- -D warnings,cargo test -p tcode-ui --locked(285 passed, including locale parity): passcargo check -p tcode-web --target wasm32-unknown-unknown,cargo check -p tcode-ios --target aarch64-apple-ios-sim,cargo machete: passNotes
~/.cache/mmdrand later first renders take about 15 ms. Subsequent renders are sub-millisecond and cached per source text.