1. 方案: marked + wkhtmltopdf

两个工具简化成一个方法如下:

1
2
3
4
5
6
7
8
9
10
11
function mk2pdf() {
if [[ ! -f $1 ]]; then
echo "Please give a markdown file."
echo "eg: mk2pdf ./source.md"
return
fi

marked $1 | wkhtmltopdf --footer-spacing 2 --footer-right '[page]/[topage]' --footer-line --footer-font-size 10 --footer-center 'Generate by Jimmy' --quiet --encoding utf-8 - "$1.pdf"

echo "PDF: $1.pdf"
}

2. 参考文档