#!/bin/sh

if test $# -ne 1
then	echo "Usage: md2man [in]"
	exit 1
fi

sed -e 's/<!-- MANOFF -->.*<!-- MANON -->//g' \
	-e '/<!-- MANOFF -->/,/<!-- MANON -->/d' \
	"$1" | {
	read -r line;
	line=${line#"<!-- "}
	line=${line%" -->"}
	title=${line%' '*}
	section=${line##*' '}
	$PANDOC -p -t man --standalone -V title="$title" -V section="$section"
} | sed -E '/^\.TH/s/""//g;/^\.TH/s/ *$//'
