Sha256: 22c472cc976f11c0083523a4a439a87f83331c20b86c1fa26e9f017dd03d41de
Contents?: true
Size: 965 Bytes
Versions: 5
Compression:
Stored size: 965 Bytes
Contents
# this file is not require'd from the root. To use this plugin, run: # # require 'rouge/plugins/redcarpet' # this plugin depends on redcarpet require 'redcarpet' # stdlib require 'cgi' module Rouge module Plugins module Redcarpet def block_code(code, language) name, opts = language ? language.split('?', 2) : [nil, ''] # parse the options hash from a cgi-style string opts = CGI.parse(opts || '').map do |k, vals| [ k.to_sym, vals.empty? ? true : vals[0] ] end opts = Hash[opts] lexer_class = case name when 'guess', nil lexer = Lexer.guess(:source => code, :mimetype => opts[:mimetype]) when String Lexer.find(name) end || Lexers::Text lexer = lexer_class.new(opts) formatter = Formatters::HTML.new(:css_class => "highlight #{lexer_class.tag}") Rouge.highlight(code, lexer, formatter) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems