2011-09-07 19:32:57 -04:00
|
|
|
require './plugins/pygments_code'
|
|
|
|
|
|
|
|
module BacktickCodeBlock
|
|
|
|
include HighlightCode
|
|
|
|
AllOptions = /([^\s]+)\s+(.+?)(https?:\/\/\S+)\s*(.+)?/i
|
|
|
|
LangCaption = /([^\s]+)\s*(.+)?/i
|
|
|
|
def render_code_block(input)
|
2012-05-11 19:59:03 -04:00
|
|
|
input.encode!("UTF-8")
|
2012-05-27 03:30:17 -04:00
|
|
|
input.gsub /^`{3}(.+?)`{3}/m do
|
|
|
|
str = $1.to_s
|
|
|
|
str.gsub /([^\n]+)?\n(.+?)\Z/m do
|
2012-05-28 05:29:18 -04:00
|
|
|
markup = $1 || ''
|
2012-05-27 03:30:17 -04:00
|
|
|
code = $2.to_s
|
2012-05-28 05:29:18 -04:00
|
|
|
|
|
|
|
linenos = get_linenos(markup)
|
|
|
|
markup = replace_linenos(markup)
|
|
|
|
|
|
|
|
marks = get_marks(markup)
|
|
|
|
markup = replace_marks(markup)
|
|
|
|
|
|
|
|
start = get_start(markup)
|
|
|
|
markup = replace_start(markup)
|
|
|
|
|
|
|
|
if markup =~ AllOptions
|
|
|
|
highlight(code, $1, {caption: $2, url: $3, anchor: $4 || 'Link', linenos: linenos, start: start, marks: marks})
|
|
|
|
elsif markup =~ LangCaption
|
2012-06-05 01:35:13 -04:00
|
|
|
highlight(code, $1, {caption: $2 || nil, linenos: linenos, start: start, marks: marks})
|
2011-09-07 19:32:57 -04:00
|
|
|
else
|
2012-05-27 03:30:17 -04:00
|
|
|
highlight(code, 'plain', {linenos: linenos, start: start})
|
2011-09-07 19:32:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|