Skip to content

Instantly share code, notes, and snippets.

@raghavkarol
Created January 15, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raghavkarol/c779009fa93ae8d130e9d97682183ab8 to your computer and use it in GitHub Desktop.
Save raghavkarol/c779009fa93ae8d130e9d97682183ab8 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -u
# ----------------------------------------------------------
# Helpers
function html() {
contents="none"
case $1 in
ok)
contents="<div class='content'><img src=$2></div>"
;;
error)
shift
contents="<div class='error'>$*</div>"
;;
esac
cat <<EOF
<html>
<style>
* {
font-family: courier;
}
body {
margin: 0;
}
.error {
font-size: 32px;
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
background: pink
}
</style>
<body>
${contents}
</body>
</html>
EOF
}
# ----------------------------------------------------------
# Main
readonly dot_file=$1
readonly svg_file=${dot_file/%.dot/.svg}
readonly out=$2
readonly error=`mktemp`
rm -f $out
trap "{ rm -f $error; }" EXIT
exec > $out
exec 2> $error
dot -Nfontname=courier -Efontname=courier -Tsvg -o $svg_file $dot_file
if [[ $? != 0 || -s $error ]]
then
html error $(cat $error)
exit 1
fi
echo $svg_file
html ok $svg_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment