Pandoc:有哪些可用的语法荧光笔?

Pandoc: What are the available syntax highlighters?

http://pandoc.org/demos.html#examples 的要点 18 显示了如何通过向 --highlight-style 提供参数来更改使用的语法突出显示。例如:

pandoc code.text -s --highlight-style pygments -o example18a.html
pandoc code.text -s --highlight-style kate -o example18b.html
pandoc code.text -s --highlight-style monochrome -o example18c.html
pandoc code.text -s --highlight-style espresso -o example18d.html
pandoc code.text -s --highlight-style haddock -o example18e.html
pandoc code.text -s --highlight-style tango -o example18f.html
pandoc code.text -s --highlight-style zenburn -o example18g.html

我想知道这些是否是唯一可用的配色方案。如果没有,我如何加载不同的语法荧光笔?我可以自己定义吗?

Pandoc README says:

--highlight-style=STYLE|FILE

Specifies the coloring style to be used in highlighted source code. Options are pygments (the default), kate, monochrome, breezeDark, espresso, zenburn, haddock, and tango. For more information on syntax highlighting in pandoc, see Syntax highlighting, below. See also --list-highlight-styles.

Instead of a STYLE name, a JSON file with extension .theme may be supplied. This will be parsed as a KDE syntax highlighting theme and (if valid) used as the highlighting style. To see a sample theme that can be modified, pandoc --print-default-data-file default.theme.

skylighting (in older versions highlighting-kate) 用于突出显示。如果您不喜欢所提供的任何配色方案,您可以:

  • 如上所述指定一个.theme文件,
  • 导出到 HTML 时,会生成 <span> 标签,您可以使用自定义 CSS 或
  • 设置样式
  • 导出到 LaTeX/PDF 时,您需要使用自定义 Pandoc LaTeX template and replace the $highlighting-macros$ part with your custom color definitions, as described in this issue

如果您的 pandoc --version 表示 1.15.1(从 2015 年 10 月 15 日起)或更新版本,那么您可以检查 --bash-completion 参数是否适合您以获得完整的可用的内置突出显示样式列表。

运行

pandoc --bash-completion

如果成功,您会看到很多输出。它的用处将远远超出上面的原始问题...

如果 --bash-completion 有效,则将此行放在 ${HOME}/.bashrc 文件的末尾(在 Mac OS X 或 Linux -- 不Windows 还没有工作):

eval "$(pandoc --bash-completion)"

打开新终端后,可以使用 pandoc 命令和 "tab completion":

pandoc --h[tab]

会产生

--help     --highlight-style  --html-q-tags

pandoc --hi[tab]

会产生

pandoc --highlight-style

原问题的答案:

现在再按一次 [tab] 键,您会看到

espresso   haddock   kate   monochrome  pygments    tango    zenburn

这是所有可用语法高亮器的列表。要缩短程序,您还可以输入

pandoc --hi[tab][tab]

得到相同的结果。

Pandoc 的制表符补全在原始问题之外的有用性:

Pandoc 的 bash 选项卡完成也适用于所有其他命令行开关:

pandoc -h[tab]

产生这个 -- 所有可能的命令行参数的列表:

Display all 108 possibilities? (y or n)
--ascii                    --indented-code-classes    --template
--asciimathml              --jsmath                   --title-prefix
--atx-headers              --katex                    --to
--base-header-level        --katex-stylesheet         --toc
--bash-completion          --latex-engine             --toc-depth
--biblatex                 --latex-engine-opt         --trace
--bibliography             --latexmathml              --track-changes
--chapters                 --listings                 --variable
--citation-abbreviations   --mathjax                  --verbose
--columns                  --mathml                   --version
--csl                      --metadata                 --webtex
--css                      --mimetex                  --wrap
--data-dir                 --natbib                   --write
--default-image-extension  --no-highlight             -A
--dpi                      --no-tex-ligatures         -B
--dump-args                --no-wrap                  -D
--email-obfuscation        --normalize                -F
--epub-chapter-level       --number-offset            -H
--epub-cover-image         --number-sections          -M
--epub-embed-font          --old-dashes               -N
--epub-metadata            --output                   -R
--epub-stylesheet          --parse-raw                -S
--extract-media            --preserve-tabs            -T
--file-scope               --print-default-data-file  -V
--filter                   --print-default-template   -c
--from                     --read                     -f
--gladtex                  --reference-docx           -h
--help                     --reference-links          -i
--highlight-style          --reference-odt            -m
--html-q-tags              --section-divs             -o
--id-prefix                --self-contained           -p
--ignore-args              --slide-level              -r
--include-after-body       --smart                    -s
--include-before-body      --standalone               -t
--include-in-header        --tab-stop                 -v
--incremental              --table-of-contents        -w

Pandoc 制表符补全的一个有趣用例是:

pandoc --print-default-d[tab][tab]

给出pandoc --print-default-data-file的完成输出列表。此列表让您可以独特地了解您的 Pandoc 实例在执行其工作时将加载哪些数据文件。例如,您可以调查 Pandoc 的默认 ODT(OpenDocument 文本文件)输出样式的详细信息,如下所示:

pandoc --print-default-data-file odt/content.xml \
 | tr " " "\n" \
 | tr "<" "\n" \
 | grep --color "style"

如果您使用的是 Pandoc 1.18 版(2016 年 10 月发布)或更高版本,则可以使用新答案:

  pandoc --list-highlight-languages

  pandoc --list-highlight-styles

将为您提供所需的所有信息。

添加到 v1.18 的其他新信息命令行参数是:

  pandoc --list-input-formats
  pandoc --list-output-formats
  pandoc --list-extensions

pandoc 2.0.5开始,您还可以使用--print-highlight-style输出一个theme文件并进行编辑。

对我来说,使用此选项的最佳方式是

  1. 选择合适的款式

  2. 输出其theme文件

  3. 编辑 theme 文件

  4. 使用它!

1。可用款式

在已有的风格中选择你的风格:

2。输出其theme文件

一旦你决定哪种样式最符合你的需要,你就可以输出它的 theme 文件,使用(例如对于 pygments,默认样式):

pandoc --print-highlight-style pygments

以便您可以将此样式存储在一个文件中,例如,使用

pandoc --print-highlight-style pygments > my_style.theme

对于某些 shell,尤其是 Windows,使用重定向输出会导致编码问题。如果发生这种情况,请改用它:

pandoc -o my_style.theme --print-highlight-style pygments

3。编辑文件

使用 Skylighting JSON Themes 指南,根据您的需要/喜好编辑文件。

4。使用文件

在正确的文件夹中,只需使用

pandoc my_file.md --highlight-style my_style.theme -o doc.html