问题
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
-soption, 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=haddockinstead.
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