Pandoc是由John MacFarlane開發(fā)的標記語言轉(zhuǎn)換工具,可實現(xiàn)不同標記語言間的格式轉(zhuǎn)換,堪稱該領(lǐng)域中的“瑞士軍刀”。
Pandoc使用Haskell語言編寫,以命令行形式實現(xiàn)與用戶的交互,可支持多種操作系統(tǒng)。
通俗來說,pandoc是一個實現(xiàn)文件格式轉(zhuǎn)換的工具,比如可以把html文件轉(zhuǎn)換為txt文件,markdown文件,或各種pandoc支持的文件類型。pandoc支持的文件類型非常的多,常見的類型肯定是包含進去的,可以看下圖。

pandoc格式轉(zhuǎn)換映射圖
安裝
- windows下載地址
- Mac上直接使用brew安裝
brew install pandoc
- Linux上在主流的發(fā)行版本上,可以直接使用包管理器安裝。也可以下載二進制版本。下載地址,在Centos上可直接安裝。
yum install pandoc
案例
- 查看pandoc支持的格式
pandoc -h #help的開頭部分, linux
# mac版本
pandoc --list-input-formats
pandoc --list-output-formats
- 轉(zhuǎn)換為html片段
pandoc demo.txt -o demo.html

pandoc demo
- 轉(zhuǎn)換為完整的html文件,同時追加頭部與樣式
pandoc -s --toc -c demo.css -A footer.html demo.txt -o demo.html

image.png
- 使用pandoc創(chuàng)建電子書
鏈接
pandoc -o progit.epub title.txt \
01-introduction/01-chapter1.markdown \
02-git-basics/01-chapter2.markdown \
03-git-branching/01-chapter3.markdown \
04-git-server/01-chapter4.markdown \
05-distributed-git/01-chapter5.markdown \
06-git-tools/01-chapter6.markdown \
07-customizing-git/01-chapter7.markdown \
08-git-and-other-scms/01-chapter8.markdown \
09-git-internals/01-chapter9.markdown
- html文件轉(zhuǎn)換為markdown文件
pandoc -s demo.html -t markdown

image.png
額外
pandoc還提供了一些常用的輕量級編輯器的擴展,sublime-pandoc,atom-pandoc等等。
最后
pandoc可以解決平時我們在文件格式上處理的問題,它還提供了一個在線的轉(zhuǎn)換demo。