Skip to content

Instantly share code, notes, and snippets.

@josuecau
Last active Mar 23, 2019
Embed
What would you like to do?
#!/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