php pandoc,搭建Pandoc+Markdown写作环境

宇文卓
2023-12-01

编辑器使用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++菜单栏,运行,输入如下命令

cmd /c pandoc -s "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)\$(NAME_PART).html" --toc --smart --highlight-style=tango --template=pm-template.html5 & cmd /c chrome "$(CURRENT_DIRECTORY)\$(NAME_PART).html"

1

cmd/cpandoc-s"$(FULL_CURRENT_PATH)"-o"$(CURRENT_DIRECTORY)\$(NAME_PART).html"--toc--smart--highlight-style=tango--template=pm-template.html5&cmd/cchrome"$(CURRENT_DIRECTORY)\$(NAME_PART).html"

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

这条借助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

$ pandoc --version

pandoc.exe 1.13.2

Compiled with texmath 0.8.0.1, highlighting-kate 0.5.11.1.

Syntax highlighting is supported for the following languages:

abc, actionscript, ada, agda, apache, asn1, asp, awk, bash, bibtex, boo, c,

changelog, clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css,

curry, d, diff, djangotemplate, dockerfile, dot, doxygen, doxygenlua, dtd,

eiffel, email, erlang, fasm, fortran, fsharp, gcc, glsl, gnuassembler, go,

haskell, haxe, html, ini, isocpp, java, javadoc, javascript, json, jsp,

julia, latex, lex, lilypond, literatecurry, literatehaskell, lua, m4,

makefile, mandoc, markdown, mathematica, matlab, maxima, mediawiki,

metafont, mips, modelines, modula2, modula3, monobasic, nasm, noweb,

objectivec, objectivecpp, ocaml, octave, opencl, pascal, perl, php, pike,

postscript, prolog, pure, python, r, relaxng, relaxngcompact, rest, rhtml,

roff, ruby, rust, scala, scheme, sci, sed, sgml, sql, sqlmysql,

sqlpostgresql, tcl, tcsh, texinfo, verilog, vhdl, xml, xorg, xslt, xul,

yacc, yaml, zsh

Default user data directory: C:\Users\admin\AppData\Roaming\pandoc

Copyright (C) 2006-2014 John MacFarlane

Web: http://johnmacfarlane.net/pandoc

This is free software; see the source for copying conditions.

There is no warranty, not even for merchantability or fitness

for a particular purpose.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

$pandoc--version

pandoc.exe1.13.2

Compiledwithtexmath0.8.0.1,highlighting-kate0.5.11.1.

Syntaxhighlightingissupportedforthefollowinglanguages:

abc,actionscript,ada,agda,apache,asn1,asp,awk,bash,bibtex,boo,c,

changelog,clojure,cmake,coffee,coldfusion,commonlisp,cpp,cs,css,

curry,d,diff,djangotemplate,dockerfile,dot,doxygen,doxygenlua,dtd,

eiffel,email,erlang,fasm,fortran,fsharp,gcc,glsl,gnuassembler,go,

haskell,haxe,html,ini,isocpp,java,javadoc,javascript,json,jsp,

julia,latex,lex,lilypond,literatecurry,literatehaskell,lua,m4,

makefile,mandoc,markdown,mathematica,matlab,maxima,mediawiki,

metafont,mips,modelines,modula2,modula3,monobasic,nasm,noweb,

objectivec,objectivecpp,ocaml,octave,opencl,pascal,perl,php,pike,

postscript,prolog,pure,python,r,relaxng,relaxngcompact,rest,rhtml,

roff,ruby,rust,scala,scheme,sci,sed,sgml,sql,sqlmysql,

sqlpostgresql,tcl,tcsh,texinfo,verilog,vhdl,xml,xorg,xslt,xul,

yacc,yaml,zsh

Defaultuserdatadirectory:C:\Users\admin\AppData\Roaming\pandoc

Copyright(C)2006-2014JohnMacFarlane

Web:http://johnmacfarlane.net/pandoc

Thisisfreesoftware;seethesourceforcopyingconditions.

Thereisnowarranty,notevenformerchantabilityorfitness

foraparticularpurpose.

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

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

文件组织及转换脚本

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

E:.

│ convert.sh

│ push

│ sinadoc.html

│ sinadoc.pdf

└─src

1-int-jumper.md

2-int-cf.md

1

2

3

4

5

6

7

8

E:.

│convert.sh

│push

│sinadoc.html

│sinadoc.pdf

└─src

1-int-jumper.md

2-int-cf.md

转换脚本

#!/bin/bash

chapters=`ls src/*.md`

function getPDF()

{

pandoc $chapters -o sinadoc.pdf --toc --smart --highlight-style=tango --template=pm-template.latex --latex-engine=xelatex

}

function getHTML()

{

pandoc $chapters -o sinadoc.html --toc --smart --highlight-style=tango --template=pm-template.html5

}

if [ $# -eq 0 ];then

getHTML

getPDF

elif [ "$1"x = "pdf"x ];then

getPDF

elif [ "$1"x = "html"x ];then

getHTML

fi

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

#!/bin/bash

chapters=`lssrc/*.md`

functiongetPDF()

{

pandoc$chapters-osinadoc.pdf--toc--smart--highlight-style=tango--template=pm-template.latex--latex-engine=xelatex

}

functiongetHTML()

{

pandoc$chapters-osinadoc.html--toc--smart--highlight-style=tango--template=pm-template.html5

}

if[$# -eq 0 ];then

getHTML

getPDF

elif["$1"x="pdf"x];then

getPDF

elif["$1"x="html"x];then

getHTML

fi

托管到git服务器

#!/bin/bash

[ $# -lt 1 ] && echo "comment needed.." && exit 1

git add -A

commit=$1

[ "$commit"x = ""x ] && commit=commit

git commit -m "$commit"

git push origin

1

2

3

4

5

6

7

#!/bin/bash

[$# -lt 1 ] && echo "comment needed.." && exit 1

gitadd-A

commit=$1

["$commit"x=""x]&&commit=commit

gitcommit-m"$commit"

gitpushorigin

参考资料

[1]. https://github.com/jumplee/nppMarkdown

[2]. http://www.cnblogs.com/maxupeng/archive/2011/05/04/2036136.html

[3]. http://blog.csdn.net/liuyukuan/article/details/5974517

[4]. https://github.com/tzengyuxio/pages

[5]. http://pandoc.org/demos.html

1

2

3

4

5

[1].https://github.com/jumplee/nppMarkdown

[2].http://www.cnblogs.com/maxupeng/archive/2011/05/04/2036136.html

[3].http://blog.csdn.net/liuyukuan/article/details/5974517

[4].https://github.com/tzengyuxio/pages

[5].http://pandoc.org/demos.html

 类似资料: