draw.io, available at https://app.diagrams.net, is an easy-to-use diagramming tool. However, the exporting of *.drawio
files needs to be taken care of most of the times.
As for PNG exporting, currently the default setting may generates blurring image. Fortunately, this can be fixed by scaling the diagram into a larger one. 1
As for the SVG, things become a bit complicated.
When user viewing the software exported SVG files in a web browser, everything seems just fine. But when they try importing these SVGs into softwares like Word or Inkscape, users may see a "Viewer does not support full SVG 1.1" (now changed to "Text is not SVG - cannot display") text on their image.
Usually this is because draw.io uses HTML code to markup text (and maybe other items) in textboxes and directly embeds them into SVG's <foreignObject>
tags. Unfortunately, these "foreign" HTML code cannot be understood by SVG-specific softwares like Inkscape. So, the dev of draw.io insert a info text to prompt the user when the <foreignObject>
s are not supported.
As you can see, it's not that these viewers "not supporting full SVG 1.1", but the SVG file contains non-SVG parts which can't be interpreted by softwares other than web browers.
Actually, it is the SVG code that is foreign to the Web browsers.
As for the fallback, draw.io simply trims these text whether the text is too long or broken into multiple line manually by the user, at least for now.
One current workaround provided by draw.io is that user can manually disable 'Word Wrap' and 'Formatted Text' of all textboxes, and draw.io will produce clean SVG on exporting.
See Why text in exported SVG images may not display correctly (diagrams.net).
There are some relative discussions, which happened at:
- Issue #774 · jgraph/drawio;
- Inkscape "Viewer does not support full SVG 1.1" - Using Inkscape with Other Programs - Inkscape Forum (Also mentioned about XSLT)
- Truly Headless Draw.io Exports - Hacker News (ycombinator.com) (Also mentioned about exporting, darkmode, etc.)
Note that after disabling "Word Wrap", user needs to manually break long text into multiple lines. Also, the text's style must be adjusted as a whole in a textbox when "Formatted Text" is disabled.
Since draw.io is easy-to-use, I'm trying to find or develop a solution to get native SVG code from its exported SVG or original .drawio
file.
For now, we have these desirable solutions:
- For simple SVG diagrams (which doesn't contain complex formatted text), just follow the methods mentioned above (or try my silly Python Script below...);
- Try exporting the SVG to PDF (using web broswers), then use Inkscape to generate SVG from PDF.
- remove
<switch>
for 'unsupporting' text - remove all
<foreignObjects>
- xml.etree.ElementTree — The ElementTree XML API — Python 3.10.4 documentation
- 20.5. xml.etree.ElementTree — The ElementTree XML API — Python 3.6.3 documentation
- Is SVG tag with xmlns required? - StackOverflow XML - Declaration - tutorialspoint.com
- How to create <!DOCTYPE> with Python's cElementTree - StackOverflow
- Write XML file with default namespace - StackOverflow
- Saving XML files using ElementTree - StackOverflow
These articles might be useful:
-
Things you need to know about working with SVG in VS Code (freecodecamp.org)
-
How I use draw.io at the command line | Tom Donohue and comments:
- Diagrams as code: Structurizr;
- A web-based editor of PlantUML: http://www.plantuml.com/plantuml;
- ...
-
Dealing with compressed
.drawio
file (can be turned off in 'properties'): Text-editing a draw.io file exported as SVG with embedded drawing - Stack Overflow -
4. Multiline SVG Text - SVG Text Layout [Book] (oreilly.com);
-
SVG element reference - SVG: Scalable Vector Graphics | MDN and
<text>
element;