Browse code

added support for github style backtick code blocks

Brandon Mathis authored on 27/07/2011 at 03:37:31
Showing 2 changed files
... ...
@@ -5,7 +5,7 @@
5 5
   <nav role=navigation>{% include navigation.html %}</nav>
6 6
   <div id="main">
7 7
     <div id="content">
8
-      {{ content | expand_urls: root_url | smart_quotes  }}
8
+      {{ content | expand_urls: root_url | backtick_codeblock | smart_quotes }}
9 9
       {% unless page.sidebar == false %}
10 10
         <aside role=sidebar>{% include sidebar.html %}</aside>
11 11
       {% endunless %}
... ...
@@ -1,6 +1,8 @@
1 1
 #custom filters for Octopress
2
+require './plugins/pygments_code'
2 3
 
3 4
 module OctopressFilters
5
+  include HighlightCode
4 6
   # Used on the blog index to split posts on the <!--more--> marker
5 7
   def excerpt(input)
6 8
     if input.index(/<!--\s*more\s*-->/i)
... ...
@@ -19,6 +21,18 @@ module OctopressFilters
19 19
     end
20 20
   end
21 21
 
22
+  # for Github style codeblocks eg.
23
+  # ``` ruby
24
+  #     code snippet
25
+  # ```
26
+  def backtick_codeblock(input)
27
+    input.gsub /<p>`{3}\s(\w+)<\/p>.+<pre><code>(.+)<\/code><\/pre>.+`{3}<\/p>/m do
28
+      lang = $1
29
+      str  = $2.gsub(/^\s{4}/, '').gsub('&lt;','<').gsub('&gt;','>')
30
+      highlight(str, lang)
31
+    end
32
+  end
33
+
22 34
   # Replaces relative urls with full urls
23 35
   def expand_urls(input, url='')
24 36
     url ||= '/'