Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandoc: Converting markdown to HTML, syntax highlighter

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?

like image 753
Rose Perrone Avatar asked Sep 07 '12 03:09

Rose Perrone


People also ask

Can Pandoc convert HTML to markdown?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.

Can Pandoc convert PDF to HTML?

You can use the program pandoc on the SCF Linux and Mac machines (via the terminal window) to convert from formats such as HTML, LaTeX and Markdown to formats such as HTML, LaTeX, Word, OpenOffice, and PDF, among others.

Can Pandoc convert from PDF?

How can I convert PDFs to other formats using pandoc? You can't. You can try opening the PDF in Word or Google Docs and saving in a format from which pandoc can convert directly.

What is Pandoc used for?

Pandoc is a command-line tool for converting files from one markup language to another. Markup languages use tags to annotate sections of a document. Commonly used markup languages include Markdown, ReStructuredText, HTML, LaTex, ePub, and Microsoft Word DOCX.


1 Answers

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.

like image 94
Nicolás Alarcón Rapela Avatar answered Sep 23 '22 04:09

Nicolás Alarcón Rapela