workstation/roles/home-cli/files/markdown.sh

24 lines
602 B
Bash

#!/bin/sh
set -e
command -v cmark >/dev/null || (echo "cmark: command not found" >&2 && exit 1)
test -n "$2" || (echo "Usage: $(basename "$0") \"Document title\" filename1 [filename2...]" >&2 && exit 1)
cat << __EOF__
<!DOCTYPE html>
<html>
<head>
<title>$1</title>
<style>body{font-family:sans-serif;margin:auto;width:260mm;}</style>
</head>
<body>
__EOF__
shift # Drop the first argument (document title).
for i in $(seq 1 $#)
do
echo '<article>'
cmark --to html --nobreaks --unsafe --smart --validate-utf8 $(eval echo \$$i)
echo '</article>'
done
cat << __EOF__
</body>
</html>
__EOF__