From 6e2beaa969d6dd68652fa2cd79ad4eb6eeeaae49 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Tue, 26 Jul 2011 23:37:31 -0400 Subject: [PATCH] added support for github style backtick code blocks --- .themes/classic/source/_layouts/default.html | 2 +- plugins/octopress_filters.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.themes/classic/source/_layouts/default.html b/.themes/classic/source/_layouts/default.html index 5b6240d..f633343 100644 --- a/.themes/classic/source/_layouts/default.html +++ b/.themes/classic/source/_layouts/default.html @@ -5,7 +5,7 @@
- {{ content | expand_urls: root_url | smart_quotes }} + {{ content | expand_urls: root_url | backtick_codeblock | smart_quotes }} {% unless page.sidebar == false %} {% endunless %} diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb index 429e505..e85466e 100644 --- a/plugins/octopress_filters.rb +++ b/plugins/octopress_filters.rb @@ -1,6 +1,8 @@ #custom filters for Octopress +require './plugins/pygments_code' module OctopressFilters + include HighlightCode # Used on the blog index to split posts on the marker def excerpt(input) if input.index(//i) @@ -19,6 +21,18 @@ module OctopressFilters end end + # for Github style codeblocks eg. + # ``` ruby + # code snippet + # ``` + def backtick_codeblock(input) + input.gsub /

`{3}\s(\w+)<\/p>.+

(.+)<\/code><\/pre>.+`{3}<\/p>/m do
+      lang = $1
+      str  = $2.gsub(/^\s{4}/, '').gsub('<','<').gsub('>','>')
+      highlight(str, lang)
+    end
+  end
+
   # Replaces relative urls with full urls
   def expand_urls(input, url='')
     url ||= '/'