Skip to content

Add Embedded Source Schema (ESS) Support for SVG Output #2132

Description

@ReSearchITEng

Overview

Implement support for the Embedded Source Schema (ESS) standard in Kroki to embed the original diagram source code directly into generated SVG files as XMP metadata. This makes diagrams self-documenting and immediately editable, very similar to draw.io's abilities where source is embedded.

Problem Statement

Currently, when users generate diagrams using Kroki, the source code used to create the diagram is not retained in the output file (save for exceptions like PlantUML).
Currently users must:

  1. Keep the source code in a separate file
  2. Re-upload source if they want to edit the diagram
  3. Maintain separate versioning for source and rendered assets

Solution

Embed the diagram source as standardized XMP metadata within SVG files using the Embedded Source Schema (ESS) v1.1 specification. This allows:

  • Self-contained diagrams: Source is embedded in the output
  • Immediate editability: Standard metadata extraction tools can extract and regenerate
  • Markdown integration: Works seamlessly with diagram-heavy documentation
  • Zero breaking changes: Non-SVG formats and existing API behavior remain unchanged

Implementation Scope (Phase 1)

  • Format Support: SVG output only (initial)
  • Metadata Standard: XMP/RDF with ESS namespace
  • Encoding: gzip+base64 (matches Kroki's existing URL encoding)
  • No Infrastructure Changes: Minimal code additions, no new dependencies

Technical Details

The XMP metadata will include:

<metadata>
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
           xmlns:ess="http://ns.embedded-source.org/1.0/">
    <rdf:Description rdf:about="">
      <ess:Format>mermaid</ess:Format>
      <ess:Payload>H4sIAAAAAAAC/...</ess:Payload>
      <ess:Encoding>gzip+base64</ess:Encoding>
      <ess:Tool>kroki/1.0.0</ess:Tool>
    </rdf:Description>
  </rdf:RDF>
</metadata>

References

Expected Outcome

All SVG diagrams generated by Kroki will automatically include their source code as XMP metadata, making them self-contained, auditable, and immediately editable.

Future Enhancements

  • PNG metadata injection (iTXt chunks)
  • PDF metadata streams
  • Configuration options (enable/disable per endpoint)
  • Alternative encoding schemes

Labels: enhancement, feature-request

Assignees: None (open for community contribution)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions