Skip to content

Instantly share code, notes, and snippets.

@Takazudo
Created April 1, 2012 08:32
Show Gist options
  • Save Takazudo/2273450 to your computer and use it in GitHub Desktop.
Save Takazudo/2273450 to your computer and use it in GitHub Desktop.
require 'fileutils'
require 'digest/md5'
PYGMENTS_CACHE_DIR = File.expand_path('../../_cache', __FILE__)
FileUtils.mkdir_p(PYGMENTS_CACHE_DIR)
Jekyll::HighlightBlock.class_eval do
def render_pygments(context, code)
if defined?(PYGMENTS_CACHE_DIR)
path = File.join(PYGMENTS_CACHE_DIR, "#{@lang}-#{Digest::MD5.hexdigest(code)}.html")
if File.exist?(path)
highlighted_code = File.read(path)
else
highlighted_code = Albino.new(code, @lang).to_s(@options)
File.open(path, 'w') {|f| f.print(highlighted_code) }
end
else
highlighted_code = Albino.new(code, @lang).to_s(@options)
end
output = add_code_tags(highlighted_code, @lang)
output = context["pygments_prefix"] + output if context["pygments_prefix"]
output = output + context["pygments_suffix"] if context["pygments_suffix"]
output
end
end
@caiogondim
Copy link

I can't use the plugin since i upgrade jekyll. I guess it's because jekyll is no longer using Albino.
They are using pygments.rb instead.jekyll/jekyll#569

Does it make sense? =P

I am having some troubles trying to use your plugin, because it's barely usable without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment