Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Unified Diff: src/site/_plugins/pygments_cache.rb

Issue 10788006: new site (Closed) Base URL: https://code.google.com/p/dartlang-site/@master
Patch Set: final patch Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/site/_plugins/asset_bundler.rb ('k') | src/site/_plugins/sitemap_generator.rb » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/site/_plugins/pygments_cache.rb
diff --git a/src/site/_plugins/pygments_cache.rb b/src/site/_plugins/pygments_cache.rb
new file mode 100644
index 0000000000000000000000000000000000000000..06ae22323585214ccb2510ce49dfbaecbf23db73
--- /dev/null
+++ b/src/site/_plugins/pygments_cache.rb
@@ -0,0 +1,26 @@
+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
« no previous file with comments | « src/site/_plugins/asset_bundler.rb ('k') | src/site/_plugins/sitemap_generator.rb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698