搭建Pandoc+Markdown写作环境

编辑器使用Notepad++,Pandoc使用目前最新的1.13.2版本。shell环境使用msys。

Notepad++配置Markdown语法高亮

下载Markdown语法规则文件,安装方法如下:

just copy the userDefineLang.xml to the npp folder

if you install the notepad++ with installer,you have to copy the userDefineLang.xml to%APPDATA%\Notepad++ ctrl+r and copy %APPDATA%\Notepad++ ,goto the floder. 😀

之后重启Notepad++即可。在语言->自定义语言格式,下拉选择Markdown,可以配置Markdown文件的扩展名。

Notepad++运行Markdown

Notepad++菜单栏,运行,输入如下命令

可以保存命令,设置名并设置快捷键。

这条借助Pandoc生成html,然后用浏览器打开。这里需要注意运行命令有长度限制,因此chrome需要加环境变量,这样就可以缩短命令长度。

Notepad++的全局变量

$(FULL_CURRENT_PATH) : E:\my Web\main\welcome.html
$(CURRENT_DIRECTORY) : E:\my Web\main
$(FILE_NAME) : welcome.html
$(NAME_PART) : welcome
$(EXT_PART) : html
$(NPP_DIRECTORY) : the full path of notepad++'s directory
$(CURRENT_WORD) : word(s) you selected in Notepad++
$(CURRENT_LINE) : current line number
$(CURRENT_COLUMN) : current column number

cmd命令相关

cmd /c dir 是执行完dir命令后关闭命令窗口。
cmd /k dir 是执行完dir命令后不关闭命令窗口。
cmd /c start dir 会打开一个新窗口后执行dir指令,原窗口会关闭。
cmd /k start dir 会打开一个新窗口后执行dir指令,原窗口不会关闭。

Pandoc环境设置

pandoc --version可以查看Pandoc支持高亮的语言及Pandoc的data-dir

data-dir中建立templates目录,模板放在data-dir/templates下就可以直接在命令行中用模板文件名引用模板,无需路径。

pandoc -D FORMAT可以导出该格式的默认模板,基于默认模板可以自己定制模板,将定制的模板放到data-dir中就可以方便的引用了。

懒人可以到网上搜模板,比如这个链接:https://github.com/tzengyuxio/pages

文件组织及转换脚本

src中放每章节的内容,Pandoc可以将多个input file连接成一个input,因此可以用这个特性更好的组织源文件:每章节一个文件,然后转换成单一的pdf或者html文件

转换脚本

托管到git服务器

参考资料

4 thoughts on “搭建Pandoc+Markdown写作环境

回复 吃虫子的橙 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注