Skip to content

Instantly share code, notes, and snippets.

@josuecau
Last active March 23, 2019 08:03
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 josuecau/066be0995d0c968830908b62669489c9 to your computer and use it in GitHub Desktop.
Save josuecau/066be0995d0c968830908b62669489c9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Description: convert a Markdown file to a HTML file using pandoc(1)
# Usage: markdown INPUT_FILE.md"
# Version: 1.0.2
# Author: Josué Cau <me@josuecau.com>
set -e
if [ $# -eq 0 ]
then
echo "Usage: $(basename "$0") INPUT_FILE.md"
exit 1
fi
if ! type pandoc >/dev/null 2>&1; then
echo 'pandoc(1) not found'
exit 1
fi
input="$1"
input_path=$(realpath "$input")
input_dir=$(dirname "$input_path")
input_basename=$(basename "$input" .md)
output_path="$input_dir/$input_basename.html"
pandoc --from=markdown --to=html --metadata=pagetitle:"$input_basename" \
--standalone --output="$output_path" "$input_path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment