Files
q-tools/reporting/md-toc
ville rantanen 5e0afc4d09 markdown tools
2015-06-09 12:28:35 +03:00

20 lines
518 B
Bash
Executable File

#!/bin/bash
function helpexit() {
echo "Print out TOC of a markdown document"
echo "Give filename(s) as the argument"
echo " -n to number TOC elements instead of bullet"
exit
}
[[ -z "$1" ]] && helpexit
[[ "$1" = "-h" ]] && helpexit
[[ "$1" = "-n" ]] && {
NUMBER=1
shift
}
[[ "$NUMBER" -eq 1 ]] && {
grep ^# "$@" | sed -e 's,^#,1.,' -e ':loop' -e 's,1.#, 1.,' -e 't loop' | pandoc -t markdown_strict
} || {
grep ^# "$@" | sed -e 's,^#,*,' -e ':loop' -e 's,*#, *,' -e 't loop'
}