2

I customarily export draw.io drawings as SVG with the option to "include a copy of my diagram" selected. This enables me to display them in a SVG-capable browser, and then open and modify them further in draw.io.

I'd like to do some scripted editing of the SVG file, such as modifying the href of a link I've added to a shape, but generally anything. In my limited testing I've found that I can open one of these SVG files in a text editor, change the href, save, and still reopen the file both in a browser and in draw.io.

What worries me is the chunk of base-64 text inside the SVG file, which I assume is the embedded "copy of my diagram". Am I risking throwing the SVG out of synch with the embedded diagram, or is it safe to do this?

Chap
  • 3,649
  • 2
  • 46
  • 84

1 Answers1

5

You are throwing the SVG out of synch with the embedded diagram. The base64 encoded text is just a GZIP compressed representation of the XML data. This example demonstrates how to uncompress/compress the XML: https://github.com/jgraph/drawio-tools/blob/master/tools/convert.html (the SVG output is that of the first page, ie the first diagram tag in the mxfile). You can see it in action at https://jgraph.github.io/drawio-tools/tools/convert.html Finally, to link the SVG output to the XML data, there is a plugin that embeds the cell ID (and metadata) in the SVG output (see https://github.com/jgraph/drawio/blob/master/war/plugins/svgdata.js or https://www.draw.io?p=svgdata).

user1084282
  • 1,003
  • 7
  • 6