14

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?

Rose Perrone
  • 61,572
  • 58
  • 208
  • 243
  • 10
    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. – John MacFarlane Sep 07 '12 at 16:35
  • Thanks, do you know why a $HOME/.pandoc folder wasn't automatically generated? When I try to use either option, I get the error `pandoc: slidy: openFile: does not exist`. – Rose Perrone Sep 07 '12 at 17:10
  • `$HOME/.pandoc` is not automatically generated. You can add it if you want it, but it is not needed for normal operation. What command did you use to get the error message you quote? – John MacFarlane Sep 08 '12 at 19:11
  • 1
    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. – Rose Perrone Sep 08 '12 at 19:19
  • 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. – John MacFarlane Sep 09 '12 at 03:29
  • Thanks, but I discovered that broke the formatting (the words would hover on top of the bullet points. Also, is there a way I can specify the syntax highlighting for different languages? – Rose Perrone Sep 09 '12 at 14:50
  • 3
    The syntax highlighting specified in command line when using pandoc is served as a on/off switch. Don't confuse it with the syntax highlighting for different languages. To set syntax highlighting for different language, write the language name in your **file**, something like this: `~~~~ruby` – AZ. Mar 15 '13 at 20:52

1 Answers1

3

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.

Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29