Skip to content

ui: add source toggle to mermaid and svg blocks - #24652

Merged
ServeurpersoCom merged 2 commits into
ggml-org:masterfrom
ServeurpersoCom:ui/svg-mermaid-toggle-scroll
Jun 16, 2026
Merged

ServeurpersoCom merged 2 commits into
ggml-org:masterfrom
ServeurpersoCom:ui/svg-mermaid-toggle-scroll

Conversation

@ServeurpersoCom

Copy link
Copy Markdown
Contributor

Overview

Mermaid and svg diagrams render inline, but until now you could only see the result, never the code behind it. This adds a small toggle next to the copy and preview buttons that flips a diagram between its rendered view and its source, then back, so you can read or grab exactly what the model wrote and return to the picture in one click.

It works the same way on both mermaid and svg blocks, the rendered view stays the default, and the source view looks like a normal code block with the usual styling and syntax highlighting.

While at it, tall diagrams now scroll inside their block just like long code blocks do, instead of spilling over and pushing the toolbar out of reach. The toolbar stays put on top so copy, toggle and preview remain clickable no matter how far you scroll.

Additional information

Closes #24641

Mermaid-SVG-Code-Scroll.mp4

Requirements

Add a toggle button next to copy and preview that switches a rendered
mermaid or svg block to its source code and back. The button is shared by
both block types and the rendered view stays the default.

The source view reuses the code block scroll container and the highlighted
code element captured at transform time, so it matches the app code blocks
without highlighting again.

Make tall diagrams scroll like text code blocks: safe centering keeps the
diagram centered when it fits and falls back to start alignment when it
overflows, so the top stays reachable instead of clipping above.

Keep the block header opaque and layered above the scrolled diagram, and
ignore header clicks in the zoom handler, so a button click never falls
through to the zoom dialog.
@atmosfar

Copy link
Copy Markdown

I wonder if this could be added for kind of XML/SVG toggle as well? As mentioned on the other thread, models will often default to generating XML code blocks (and continue doing so even when explcitly told to use ```SVG ... )

@allozaur

Copy link
Copy Markdown
Contributor

@ServeurpersoCom one design nit — let's have the top header/bar transparent so that the scrolled content overflow ends at the edge of the box

@ServeurpersoCom

Copy link
Copy Markdown
Contributor Author

I wonder if this could be added for kind of XML/SVG toggle as well? As mentioned on the other thread, models will often default to generating XML code blocks (and continue doing so even when explcitly told to use ```SVG ... )

Already works the same way for both: an xml fence whose content is an is rendered and gets the same toggle as an svg fence, since the renderer claims both fence languages when the content starts with <svg. So models defaulting to xml are covered.

@ServeurpersoCom

Copy link
Copy Markdown
Contributor Author

@ServeurpersoCom one design nit — let's have the top header/bar transparent so that the scrolled content overflow ends at the edge of the box

That's definitely better. While still maintaining the proper functioning of the buttons.

@allozaur
allozaur requested a review from ggerganov June 16, 2026 10:11
@ServeurpersoCom
ServeurpersoCom merged commit c1304d7 into ggml-org:master Jun 16, 2026
6 checks passed
adrianhoehne pushed a commit to adrianhoehne/llama.cpp that referenced this pull request Jul 5, 2026
* ui: add source toggle to mermaid and svg blocks

Add a toggle button next to copy and preview that switches a rendered
mermaid or svg block to its source code and back. The button is shared by
both block types and the rendered view stays the default.

The source view reuses the code block scroll container and the highlighted
code element captured at transform time, so it matches the app code blocks
without highlighting again.

Make tall diagrams scroll like text code blocks: safe centering keeps the
diagram centered when it fits and falls back to start alignment when it
overflows, so the top stays reachable instead of clipping above.

Keep the block header opaque and layered above the scrolled diagram, and
ignore header clicks in the zoom handler, so a button click never falls
through to the zoom dialog.

* ui: transparent diagram block header, address review from @allozaur
zommiommy pushed a commit to zommiommy/llama.cpp that referenced this pull request Aug 18, 2026
* ui: add source toggle to mermaid and svg blocks

Add a toggle button next to copy and preview that switches a rendered
mermaid or svg block to its source code and back. The button is shared by
both block types and the rendered view stays the default.

The source view reuses the code block scroll container and the highlighted
code element captured at transform time, so it matches the app code blocks
without highlighting again.

Make tall diagrams scroll like text code blocks: safe centering keeps the
diagram centered when it fits and falls back to start alignment when it
overflows, so the top stays reachable instead of clipping above.

Keep the block header opaque and layered above the scrolled diagram, and
ignore header clicks in the zoom handler, so a button click never falls
through to the zoom dialog.

* ui: transparent diagram block header, address review from @allozaur
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
* ui: add source toggle to mermaid and svg blocks

Add a toggle button next to copy and preview that switches a rendered
mermaid or svg block to its source code and back. The button is shared by
both block types and the rendered view stays the default.

The source view reuses the code block scroll container and the highlighted
code element captured at transform time, so it matches the app code blocks
without highlighting again.

Make tall diagrams scroll like text code blocks: safe centering keeps the
diagram centered when it fits and falls back to start alignment when it
overflows, so the top stays reachable instead of clipping above.

Keep the block header opaque and layered above the scrolled diagram, and
ignore header clicks in the zoom handler, so a button click never falls
through to the zoom dialog.

* ui: transparent diagram block header, address review from @allozaur
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
* ui: add source toggle to mermaid and svg blocks

Add a toggle button next to copy and preview that switches a rendered
mermaid or svg block to its source code and back. The button is shared by
both block types and the rendered view stays the default.

The source view reuses the code block scroll container and the highlighted
code element captured at transform time, so it matches the app code blocks
without highlighting again.

Make tall diagrams scroll like text code blocks: safe centering keeps the
diagram centered when it fits and falls back to start alignment when it
overflows, so the top stays reachable instead of clipping above.

Keep the block header opaque and layered above the scrolled diagram, and
ignore header clicks in the zoom handler, so a button click never falls
through to the zoom dialog.

* ui: transparent diagram block header, address review from @allozaur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: UI toggle between rendered and source view for mermaid and svg blocks

4 participants