Last active
October 22, 2021 10:58
-
-
Save abhishekkr/f3ebf2ce6058c13bf619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
GitHub has a "raw" version of this endpoint just to make this sort of thing easier. So this whole thing could be replaced with the following alias:
Usage:
Of course, to use it more like this script, you could read and write files: