render () {
InPath="$1"
InFile="${InPath##*/}"
InFileExt="${InPath##*.}"
InBase="${InFile%.*}"
InDir="${InPath%/*}"
if [ "$InDir" = "$InPath" ] ; then
InDir="."
fi
OutPath="$2"
OutFile="${OutPath##*/}"
OutBase="${OutFile%.*}"
OutDir="${OutPath%/*}"
if [ "$OutDir" = "$OutPath" ] ; then
OutDir="."
fi
mkdir -p "$OutDir"
cp -r -L "$InDir/assets/" "$OutDir"
cp "$InDir/print.css" "$OutDir"
cp "$InPath" "$OutDir"
pushd "$OutDir"
pandoc "$InFile" --from=markdown+yaml_metadata_block --to=pdf \
--pdf-engine=weasyprint --pdf-engine-opt="-s" \
--pdf-engine-opt="print.css" --number-sections -o "$OutFile"
rm -r "assets"
rm "$InFile"
rm "print.css"
popd
}
if [[ -n "${2/[ ]*\n/}" ]] ; then
OutPath="$2"
else
OutPath="${1%.*}.html" fi
render "$1" "$OutPath"