Skip to content

Instantly share code, notes, and snippets.

@hafizio
Forked from abhishekkr/md2html.sh
Created August 14, 2014 09:34
Show Gist options
  • Save hafizio/079005f9d04829500931 to your computer and use it in GitHub Desktop.
Save hafizio/079005f9d04829500931 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Download HTML converted from provided Markdown, using GitHub API v3
##
md2html(){
if [[ $# -ne 2 ]]; then
echo "ERROR.\nSYNTAX: Markdown_To_HTML <markdown-filepath> <dest-html-filepath>"
return
fi
unset _markdown_filepath
unset _html_filepath
unset _github_json_filepath
unset _markdown_for_github
_markdown_filepath=$1
_html_filepath=$2
_github_json_filepath="${_markdown_filepath}.json"
sed -i 's/$/\\n/g' $_markdown_filepath
sed -i 's/"/\\"/g' $_markdown_filepath
echo "{ \"text\" : \"" > $_github_json_filepath
cat $_markdown_filepath >> $_github_json_filepath
echo "\" }" >> $_github_json_filepath
cat $_github_json_filepath | curl -sLk -X POST -d@- https://api.github.com/markdown > $_html_filepath
rm $_github_json_filepath
echo "Successful conversion of ${_markdown_filepath} to ${_html_filepath}."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment