Browse code

improved backtick codeblock's handling of the raw option

Brandon Mathis authored on 08/09/2011 at 04:29:54
Showing 1 changed files
... ...
@@ -5,18 +5,19 @@ module BacktickCodeBlock
5 5
   AllOptions = /([^\s]+)\s+(.+?)(https?:\/\/\S+)\s*(.+)?/i
6 6
   LangCaption = /([^\s]+)\s*(.+)?/i
7 7
   def render_code_block(input)
8
+    @options = nil
8 9
     @caption = nil
9 10
     @lang = nil
10 11
     @url = nil
11 12
     @title = nil
12 13
     input.gsub /^`{3} *([^\n]+)?\n(.+?)\n`{3}/m do
13
-      options = $1
14
+      @options = $1 || ''
14 15
       str = $2
15 16
 
16
-      if options =~ AllOptions
17
+      if @options =~ AllOptions
17 18
         @lang = $1
18 19
         @caption = "<figcaption><span>#{$2}</span><a href='#{$3}'>#{$4 || 'link'}</a></figcaption>"
19
-      elsif options =~ LangCaption
20
+      elsif @options =~ LangCaption
20 21
         @lang = $1
21 22
         @caption = "<figcaption><span>#{$2}</span></figcaption>"
22 23
       end
... ...
@@ -29,7 +30,7 @@ module BacktickCodeBlock
29 29
         "<figure role=code>#{@caption}#{code}</figure>"
30 30
       else
31 31
         if @lang.include? "-raw"
32
-          raw = "``` #{@lang.sub('-raw', '')}\n"
32
+          raw = "``` #{@options.sub('-raw', '')}\n"
33 33
           raw += str
34 34
           raw += "\n```\n"
35 35
         else