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-block container
  • Adding copy buttons that appear on hover

This improves the user experience by providing consistent diagram handling across all supported formats.

References

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

  1. Ensure PlantUML is enabled in your local instance:

    # In Rails console
    settings = ApplicationSetting.current
    settings.update(plantuml_enabled: true, plantuml_url: 'http://localhost:8080')
  2. Optionally enable Kroki for additional diagram types:

    # In Rails console
    settings = ApplicationSetting.current
    settings.update(kroki_enabled: true, kroki_url: 'https://kroki.io')

Validation

  1. Create or navigate to an issue/merge request

  2. Add a comment with a PlantUML diagram:

    ```plantuml
    @startuml
    Alice -> Bob: Authentication Request
    Bob --> Alice: Authentication Response
    @enduml
    ```
  3. Add a Kroki diagram (e.g., GraphViz):

    ```graphviz
    digraph G {
      A -> B;
      B -> C;
      A -> C;
    }
    ```
  4. 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)
  5. Verify Mermaid diagrams still work:

    ```mermaid
    graph TD;
        A-->B;
        A-->C;
    ```
  6. Verify accessibility:

    • Source code is present in the DOM (hidden with gl-sr-only class)
    • Screen readers can access the diagram source

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)

Merge request reports

Loading