2011-09-07 19:32:57 -04:00
|
|
|
require './plugins/pygments_code'
|
|
|
|
|
|
|
|
module BacktickCodeBlock
|
|
|
|
include HighlightCode
|
2012-11-26 21:18:12 -05:00
|
|
|
AllOptions = /([^\s]+)\s+(.+?)(https?:\/\/\S+|\/\S+)\s*(.+)?/i
|
2011-09-07 19:32:57 -04:00
|
|
|
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
|
|
|
|
2012-12-23 01:38:01 -05:00
|
|
|
options = parse_markup(markup)
|
|
|
|
@lang = options[:lang]
|
|
|
|
@title = options[:title]
|
|
|
|
@lineos = options[:lineos]
|
|
|
|
@marks = options[:marks]
|
|
|
|
@url = options[:url]
|
|
|
|
@link_text = options[:link_text]
|
|
|
|
@start = options[:start]
|
|
|
|
markup = clean_markup(markup)
|
2012-05-28 05:29:18 -04:00
|
|
|
|
|
|
|
if markup =~ AllOptions
|
2012-12-23 01:38:01 -05:00
|
|
|
@lang ||= $1
|
|
|
|
@title ||= $2
|
|
|
|
@url ||= $3
|
|
|
|
@link_text ||= $4
|
2012-05-28 05:29:18 -04:00
|
|
|
elsif markup =~ LangCaption
|
2012-12-23 01:38:01 -05:00
|
|
|
@lang ||= $1
|
|
|
|
@title ||= $2
|
2011-09-07 19:32:57 -04:00
|
|
|
else
|
2012-12-23 01:38:01 -05:00
|
|
|
@lang = 'plain'
|
2011-09-07 19:32:57 -04:00
|
|
|
end
|
2012-12-23 01:38:01 -05:00
|
|
|
highlight(code, @lang, {title: @title, url: @url, link_text: @link_text, linenos: @linenos, marks: @marks, start: @start })
|
2011-09-07 19:32:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|