Pandoc: Converting markdown to HTML, syntax highlighter

柔情痞子 提交于 2019-12-04 18:24:59

问题


I'm converting markdown to HTML, and I want to include syntax-highlighted code.

I'm working from some markdown that contains syntax like:

  ~~~ {.c}
  long factorial (int n)
  {
    long result = 1;
    while (n > 1)
      result *= n--;
    return result;
  }
  ~~~

but I don't know which syntax highlighting extension was used to process this syntax. What's a good extension?


回答1:


Answer from comments, please edit before giving negative rating.

Solution

Pandoc does syntax highlighting automatically. You don't need an external extension.

Just be sure to use the -s flag so you get a standalane HTML file with the CSS needed for highlighting. You can also use the --highlight-style option to adjust the coloring scheme.

Note: These comments assume you're using the latest pandoc, 1.9.4.2.

When I add the -s option, I get this error message: pandoc -m -t -s slidy 7-functional-design.md -o 7-functional-design.hpart. I get the same error message if I try adding --highlight-style=haddock instead.

You want -s -t slidy instead of -t -s slidy.

slidy is the argument for the -t option and needs to come right after it.



来源:https://stackoverflow.com/questions/12311344/pandoc-converting-markdown-to-html-syntax-highlighter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!