Copy button for all diagram types
What does this MR do and why?
This MR adds copy-to-clipboard functionality for PlantUML and Kroki diagrams, matching the existing behavior for Mermaid diagrams.
Currently, when users hover over a Mermaid diagram in comments or issues, a copy button appears in the upper right corner that copies the diagram's source code. However, this functionality was missing for PlantUML and Kroki diagrams, making it difficult for users to reuse or modify existing diagrams.
This change implements the same copy button pattern for all diagram types by:
- Preserving the diagram source in a screen-reader-accessible hidden element
- Wrapping rendered diagrams in a
markdown-code-blockcontainer - Adding copy buttons that appear on hover
This improves the user experience by providing consistent diagram handling across all supported formats.
References
- Closes #409451
- Related to !83202 (merged) (Fix copy to clipboard for Mermaid diagrams)
- Related to !75433 (merged) (Adds copy button to every markdown code block)
Screenshots or screen recordings
| Before | After |
|---|---|
| PlantUML and Kroki diagrams had no copy button | Copy button appears on hover, copies diagram source |
How to set up and validate locally
Setup
-
Ensure PlantUML is enabled in your local instance:
# In Rails console settings = ApplicationSetting.current settings.update(plantuml_enabled: true, plantuml_url: 'http://localhost:8080') -
Optionally enable Kroki for additional diagram types:
# In Rails console settings = ApplicationSetting.current settings.update(kroki_enabled: true, kroki_url: 'https://kroki.io')
Validation
-
Create or navigate to an issue/merge request
-
Add a comment with a PlantUML diagram:
```plantuml @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response @enduml ``` -
Add a Kroki diagram (e.g., GraphViz):
```graphviz digraph G { A -> B; B -> C; A -> C; } ``` -
Save the comment and verify:
- Diagrams render correctly as images
- Hovering over each diagram reveals a copy button in the upper right corner
- Clicking the copy button copies the diagram source to clipboard
- Pasting shows the original source code (not the image)
-
Verify Mermaid diagrams still work:
```mermaid graph TD; A-->B; A-->C; ``` -
Verify accessibility:
- Source code is present in the DOM (hidden with
gl-sr-onlyclass) - Screen readers can access the diagram source
- Source code is present in the DOM (hidden with
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
- All existing tests pass
- Added/updated tests for PlantUML filter changes
- Added/updated tests for Kroki filter changes
- Added/updated frontend tests for diagram copy button
- Documentation updated if needed
- Verified accessibility (keyboard navigation, screen readers)
- No performance impact (minimal DOM changes)