Skip to content

Instantly share code, notes, and snippets.

@j5bot
Last active November 9, 2016 18:08
Show Gist options
  • Save j5bot/07216966b66a5899ebc94dad1f56aa0f to your computer and use it in GitHub Desktop.
Save j5bot/07216966b66a5899ebc94dad1f56aa0f to your computer and use it in GitHub Desktop.
wrapper bash script around macdown to add support for generating diagrams from code blocks using mermaid
#! /bin/bash
TEMPLATE_PATH="/Applications/MacDown.app/Contents/Resources/Templates/Default.handlebars"
if [[ ! -f ${TEMPLATE_PATH}-original ]]; then
cp "${TEMPLATE_PATH}" "${TEMPLATE_PATH}-original"
else
cp "${TEMPLATE_PATH}-original" "${TEMPLATE_PATH}"
fi
sed -i '-original' -e 's|^</body>$||g' $TEMPLATE_PATH
sed -i '' -e 's|^</html>$||g' $TEMPLATE_PATH
cat >> $TEMPLATE_PATH << EOF
<script src="https://cdn.rawgit.com/knsv/mermaid/0.5.1/dist/mermaid.js"></script>
<script>
!function(){
var uml,containerElement,
umlElement=document.querySelector(".language-mermaid-uml");
while(umlElement){
uml=umlElement.innerHTML;
containerElement = umlElement.parentNode.parentNode;
containerElement.className = "mermaid";
containerElement.innerHTML=uml;
umlElement=document.querySelector(".language-mermaid-uml");
}
}();
mermaid.initialize({startOnLoad:true});
</script>
</body>
</html>
EOF
open "/Applications/MacDown.app"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment