Hakyll uses Pandoc to process markdown and code snippets. It’s very easy to integrate Kate to Hakyll for code highlighting. But I choose to switch to Pygments due to its support for many programming languages.
I found (this blog)[http://www.blaenkdenum.com/posts/the-switch-to-hakyll/], which briefly describes how Pandoc should be integrated with Pygments. Roughly speaking, Pandoc is an abstract syntax tree. A code highlighting process is a tree transformation. In Pandoc’s AST, the CodeBlock element is for code snippets. We match its patterns to supply our transformations:
The Pygment can be invoked with Pipe. Below is my code. It looks messy but it works. It’s by no means efficient as I did a bit list concatenations over strings.
As the last piece, Hakyll includes a functions pandocCompilerWithTransform that allows you to plug in your transformations.
Now we can use Pygment to highlight the code. You’d probably want to grab some code highlighting css files. Note that Pygments indeed runs slower than Kate, but it’s not a big deal for me.