Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
improved backtick codeblock's handling of the raw option
Browse files Browse the repository at this point in the history
  • Loading branch information
imathis committed Sep 8, 2011
1 parent 3d2d1a8 commit a289c90
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions plugins/backtick_code_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ module BacktickCodeBlock
AllOptions = /([^\s]+)\s+(.+?)(https?:\/\/\S+)\s*(.+)?/i
LangCaption = /([^\s]+)\s*(.+)?/i
def render_code_block(input)
@options = nil
@caption = nil
@lang = nil
@url = nil
@title = nil
input.gsub /^`{3} *([^\n]+)?\n(.+?)\n`{3}/m do
options = $1
@options = $1 || ''
str = $2

if options =~ AllOptions
if @options =~ AllOptions
@lang = $1
@caption = "<figcaption><span>#{$2}</span><a href='#{$3}'>#{$4 || 'link'}</a></figcaption>"
elsif options =~ LangCaption
elsif @options =~ LangCaption
@lang = $1
@caption = "<figcaption><span>#{$2}</span></figcaption>"
end
Expand All @@ -29,7 +30,7 @@ def render_code_block(input)
"<figure role=code>#{@caption}#{code}</figure>"
else
if @lang.include? "-raw"
raw = "``` #{@lang.sub('-raw', '')}\n"
raw = "``` #{@options.sub('-raw', '')}\n"
raw += str
raw += "\n```\n"
else
Expand Down

0 comments on commit a289c90

Please sign in to comment.