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

26 lines
644 B
Bash
Raw Normal View History

2025-03-03 11:31:27 +00:00
#!/bin/sh
set -e
command -v cmark >/dev/null || (echo "cmark: command not found" >&2 && exit 1)
2025-03-03 11:35:08 +00:00
test -n "$2" || (echo "Usage: $(basename "$0") \"Document title\" filename1 [filename2...]" >&2 && exit 1)
2025-03-03 11:31:27 +00:00
cat << __EOF__
<!DOCTYPE html>
<html>
<head>
2025-03-03 16:41:14 +00:00
<meta charset="utf-8">
2025-03-03 11:31:27 +00:00
<title>$1</title>
2025-03-03 16:14:00 +00:00
<style>body{font-family:sans-serif;font-size:12pt;margin:auto;width:180mm;}</style>
2025-03-03 11:31:27 +00:00
</head>
<body>
__EOF__
while shift
do
test -n "$1" || break # No more files.
echo "<article data-filename=\"$(basename "$1")\">"
cmark --to html --nobreaks --unsafe --smart --validate-utf8 $1
echo '</article>'
done
2025-03-03 11:31:27 +00:00
cat << __EOF__
</body>
</html>
__EOF__