| OLD | NEW |
| (Empty) | |
| 1 require 'fileutils' |
| 2 require 'digest/md5' |
| 3 |
| 4 PYGMENTS_CACHE_DIR = File.expand_path('../../_cache', __FILE__) |
| 5 FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) |
| 6 |
| 7 Jekyll::HighlightBlock.class_eval do |
| 8 def render_pygments(context, code) |
| 9 if defined?(PYGMENTS_CACHE_DIR) |
| 10 path = File.join(PYGMENTS_CACHE_DIR, "#{@lang}-#{Digest::MD5.hexdigest(cod
e)}.html") |
| 11 if File.exist?(path) |
| 12 highlighted_code = File.read(path) |
| 13 else |
| 14 highlighted_code = Albino.new(code, @lang).to_s(@options) |
| 15 File.open(path, 'w') {|f| f.print(highlighted_code) } |
| 16 end |
| 17 else |
| 18 highlighted_code = Albino.new(code, @lang).to_s(@options) |
| 19 end |
| 20 output = add_code_tags(highlighted_code, @lang) |
| 21 output = context["pygments_prefix"] + output if context["pygments_prefix"] |
| 22 output = output + context["pygments_suffix"] if context["pygments_suffix"] |
| 23 output |
| 24 end |
| 25 |
| 26 end |
| OLD | NEW |