環境所使用的插件有pandoc,tlmgr,fc-listcss
使用brew進行pandoc的安裝,也能夠去pandoc官網下載http://www.pandoc.org/installing.htmlhtml
brew install pandoc
由於mac ox 系統生成pdf 須要找到對應的編碼集 全部還須要去下載LaTeX,進行安裝html5
使用tlmgr工具安裝全部要的包先進行更新,若是提示所須要的字體沒有找到安裝git
sudo tlmgr update --self tlmgr install collection-fontsrecommended
安裝fontconfig使用fc-list查看mac中可用的中文集,由於os x 10.8之後已經不安裝x11
github
brew install fontconfig fc-list :lang=zh-cn
字符集放在/Library/Fonts 下面已宋體爲例 web
/Library/Fonts/Songti.ttc: 宋體\-簡,宋體\-簡,Songti SC:style=粗體,粗體,Boldshell
pandoc --latex-engine=xelatex -V mainfont=' Songti SC ' --template=./pandoc.template xxx.md -o xxx.pdf
下面是markdown轉換的工具
ruby
安裝makemarkdown
建立shell文件名爲md2pdf,能夠指定使用字體集app
#!/bin/sh # Wrapper script around pandoc / markdown2pdf # Provides templates to apply with pdf processing # Copyright Claes Holmerson 2010, GPL licensed (see COPYING for details) #Find this directory # template_home=$(dirname $(readlink -f $0)) template_home=$(cd `dirname $0`; pwd) paper=a4paper hmargin=3cm vmargin=3.5cm fontsize=12pt #fontsize=11pt #fontsize=12pt # mainfont=SimSun # sansfont=Corbel # monofont=Consolas # mainfont="WenQuanYi Zen Hei Sharp" # sansfont="WenQuanYi Zen Hei Sharp" # monofont="WenQuanYi Zen Hei Mono" language=english #language=swedish nohyphenation=false columns=onecolumn #columns=twocolumn geometry=portrait #geometry=landscape alignment=flushleft #alignment=flushright #alignment=center toc=3 pandoc --latex-engine=xelatex --template=$template_home/pandoc.template \ -V language=$language -V paper=$paper -V hmargin=$hmargin -V vmargin=$vmargin \ -V mainfont="$mainfont" -V sansfont="$sansfont" -V monofont="$monofont" \ -V geometry=$geometry -V alignment=$alignment -V columns=$columns \ -V fontsize=$fontsize -V nohyphenation=$nohyphenation \ -V toc=$toc \ $@
建立markdown.css
@font-face { font-family: "AR PL New Sung"; src: url("/usr/share/fonts/TTF/odosung.ttc"); } body { background-color: #fcfcfc; color: #3c3c3c; } a { color: #308bd8; text-decoration:none; } a:hover { text-decoration: underline; } p { margin:0 0 24px 0; } p:last-child { margin:0; } hr { width: 100%; margin: 1em auto; border: 0; color: #eee; background-color: #ccc; height: 1px; -webkit-box-shadow:0px 1px 0px rgba(255, 255, 255, 0.75); } blockquote { margin-left: 0; margin-right: auto; width: 96%; padding: 10px 10px; border-left: 3px solid #ddd; color: #777; background-color: #f2f2f2; } table { margin-left: 0; margin-right: auto; margin-bottom: 24px; border-bottom: 1px solid #ddd; border-right: 1px solid #ddd; border-spacing: 0; } table th { padding: 3px 10px; background-color: #eee; border-top: 1px solid #ddd; border-left: 1px solid #ddd; } table tr { } table td { padding: 3px 10px; border-top: 1px solid #ddd; border-left: 1px solid #ddd; } caption { font-size: 1.2em; font-weight: bold; margin-bottom: 5px; } @page { size: A4; margin: 1cm auto; } @media print { body { font-family: "Arial Black", Arial, sans-serif; -webkit-print-color-adjust: exact; } img, pre, blockquote, table, figure { page-break-inside: avoid; } .footnotes { page-break-before: always; } header.onlyprint, footer.onlyprint{ display: none; } } /* fix pandoc default style */ code { } code > span.dt { text-decoration: none; }
建立Makefile文件內容以下,若是你markdown 是分文件模塊進行編譯的能夠使用cat進行合併 分別生成html,pdf
main : # cat 00*.md > xxx.md pandoc -f markdown_github-autolink_bare_uris -s --highlight-style espresso -t html5 -c "./markdown.css" -o xxx.html xxx.md # cat 00*.md > xxx.md ./md2pdf xxx.md -o xxx.pdf
生成pdf
./md2pdf xxx.md -o xxx.pdf
生成html 和pdf
make