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
@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