require './plugins/pygments_code' module BacktickCodeBlock AllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i LangCaption = /([^\s]+)\s*(.+)?/i def self.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 || '' str = $2 if @options =~ AllOptions @lang = $1 @caption = "
#{$2}#{$4 || 'link'}
" elsif @options =~ LangCaption @lang = $1 @caption = "
#{$2}
" end if str.match(/\A( {4}|\t)/) str = str.gsub(/^( {4}|\t)/, '') end if @lang.nil? || @lang == 'plain' code = HighlightCode::tableize_code(str.gsub('<','<').gsub('>','>')) "
#{@caption}#{code}
" else if @lang.include? "-raw" raw = "``` #{@options.sub('-raw', '')}\n" raw += str raw += "\n```\n" else code = HighlightCode::highlight(str, @lang) "
#{@caption}#{code}
" end end end end end