pandoc讲html转换为pdf,mac下利用Pandoc、LaTeX 转换markdown成html,pdf
環(huán)境所使用的插件有pandoc,tlmgr,fc-listcss
brew?install?pandoc
由于mac ox 系統(tǒng)生成pdf 須要找到對(duì)應(yīng)的編碼集 全部還須要去下載LaTeX,進(jìn)行安裝html5
使用tlmgr工具安裝全部要的包先進(jìn)行更新,若是提示所須要的字體沒有找到安裝git
sudo?tlmgr?update?--self
tlmgr?install?collection-fontsrecommended
安裝fontconfig使用fc-list查看mac中可用的中文集,由于os x 10.8之后已經(jīng)不安裝x11
github
brew?install?fontconfig
fc-list?:lang=zh-cn
字符集放在/Library/Fonts 下面已宋體為例?web
/Library/Fonts/Songti.ttc: 宋體\-簡(jiǎn),宋體\-簡(jiǎn),Songti SC:style=粗體,粗體,Boldshell
pandoc?--latex-engine=xelatex?-V?mainfont='
Songti?SC
'?--template=./pandoc.template?xxx.md?-o?xxx.pdf
下面是markdown轉(zhuǎn)換的工具
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文件內(nèi)容以下,若是你markdown 是分文件模塊進(jìn)行編譯的能夠使用cat進(jìn)行合并 分別生成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
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的pandoc讲html转换为pdf,mac下利用Pandoc、LaTeX 转换markdown成html,pdf的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 配 ISOCELL HP2SX,消息称三
- 下一篇: 微信4.0电脑版(微信电脑版3.3.0)