Created
April 1, 2012 08:32
-
-
Save Takazudo/2273450 to your computer and use it in GitHub Desktop.
pygments cache plugin for jekyll. from https://github.com/rsim/blog.rayapps.com/blob/master/_plugins/pygments_cache_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.