Skip to content

Instantly share code, notes, and snippets.

@wknapik
Last active December 29, 2017 13:56
Show Gist options
  • Save wknapik/d4c3c662cbc79d2739725b34e088f545 to your computer and use it in GitHub Desktop.
Save wknapik/d4c3c662cbc79d2739725b34e088f545 to your computer and use it in GitHub Desktop.
draw.io xml to html
#!/usr/bin/env bash
# USAGE: drawioxml2html.sh diagram.xml >diagram.html
# html encoding from https://stackoverflow.com/questions/12873682/#answer-12873723
diag="$(sed 's,.*<\(diagram [^>]*\)>\(.*\)<\(/diagram\)>.*,\1FOO\2BAR\3,g' <"$1"|\
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'|\
sed 's/&/\\&/g; s/FOO/\&gt;/; s/BAR/\&lt;/')"
cat <<EOF
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->
<!DOCTYPE html>
<html>
<head>
<title>diagram</title>
<meta charset="utf-8"/>
</head>
<body><div class="mxgraph" style="max-width:100%;border:1px solid transparent;" data-mxgraph="{&quot;highlight&quot;:&quot;#0000ff&quot;,&quot;nav&quot;:true,&quot;resize&quot;:true,&quot;toolbar&quot;:&quot;zoom layers lightbox&quot;,&quot;edit&quot;:&quot;_blank&quot;,&quot;xml&quot;:&quot;&lt;mxfile userAgent=\&quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36\&quot; version=\&quot;7.3.5\&quot; editor=\&quot;www.draw.io\&quot; type=\&quot;device\&quot;&gt;&lt;$diag&gt;&lt;/mxfile&gt;&quot;}"></div>
<script type="text/javascript" src="https://www.draw.io/embed2.js?s=aws3;mscae/enterprise;gcp/networking;citrix&"></script>
</body>
</html>
EOF
@Zaijo
Copy link

Zaijo commented Oct 16, 2017

Thanks, but this only works for one diagram. Is there a way to export all tabs?

@wknapik
Copy link
Author

wknapik commented Oct 16, 2017

Hi @Zaijo. This was just a quick hack to get me going. I didn't even realize you could have multiple tabs, I've only ever used one.

If you need this now, you could diff what the regular export produces with what my script produces and it would probably be clear how to improve it. Otherwise, I'd suggest getting your team to give the issue a thumbs up and hope the draw.io team gets around to implementing the feature.

Sorry I wasn't more helpful, but the draw.io-related stuff has fallen so low on my list of priorities by now, I can't afford to devote time to it.

@wknapik
Copy link
Author

wknapik commented Dec 28, 2017

Hey @Zaijo. As @josefstr mentioned in the github issue, there's apparently a proper converter now - drawio-batch.

@thexavier666
Copy link

Is it possible to generate pdf or any other format?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment