环境所使用的插件有pandoc,tlmgr,fc-listcss
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