Gangmax Blog

Convert markdown to PDF using gimli gem

使用markdown编写文档,一个很自然的问题是:如何把markdown格式的文档转换为其它格式,比如PDF?可以想象一定有很多开源工具可以做这件事,比如我从这里知道的,Ruby世界的gimli

首先安装gimli gem:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ gem install gimli
Fetching: github-markup-0.5.3.gem (100%)
Fetching: redcarpet-1.17.2.gem (100%)
Building native extensions. This could take a while...
Fetching: org-ruby-0.5.3.gem (100%)
Fetching: creole-0.4.2.gem (100%)
Fetching: expression_parser-0.9.0.gem (100%)
Fetching: wikicloth-0.6.3.gem (100%)
Fetching: nokogiri-1.4.7.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing gimli:
ERROR: Failed to build gem native extension.

/home/user/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for libxml/parser.h... no
-----
libxml2 is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.

从错误信息里可以看出,在安装被依赖的”nokogiri-1.4.7.gem”时,由于缺少相应的文件导致编译本地扩展出错。从错误提示中给出的网址找到如下解决方法:

1
sudo apt-get install libxml2-dev libxslt-dev

再次运行”gem install gimli”则安装成功。

此时可以运行gimli命令将指定markdown文件转换为PDF:

1
gimli -removefrontmatter -file 2012-04-12-pdk-plug-in-users-guide.markdown -outputfilename test

运行之前可以使用”gimli -h”了解该命令各个参数的含义。

Comments