Repository navigation
ui: add source toggle to mermaid and svg blocks - #24652
ServeurpersoCom merged 2 commits into
Conversation
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.
|
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 |
|
@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 |
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. |
That's definitely better. While still maintaining the proper functioning of the buttons. |
* 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
* 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
* 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
* 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
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