Jekyll code highlighting on Heroku

The built in code highlighter in Jekyll doesn't work on Heroku due to some issues with Python. I came up with a work around by using the Pygmentize gem instead.


Add the Pygmentize gem to your gemfile:

gem 'pygmentize'

And run bundle install


Create a new file in the _plugins directory with the name highlight.rb. Paste the following code to make the built in code highlighter use the new Pygmentize gem:

require 'pygmentize'
class Jekyll::HighlightBlock < Liquid::Block
def render_pygments(context, code)
@options[:encoding] = 'utf-8'
output = add_code_tags(
Pygmentize.process(code, @lang),

output = context["pygments_prefix"] + output if context["pygments_prefix"]
output = output + context["pygments_suffix"] if context["pygments_suffix"]


Just use the standard highlight blocks as usual:

``` ruby gem 'pygmentize' ```