class Rouge::Lexer
def find_fancy(str, code=nil, additional_options={})
markdown lexer for highlighting internal code blocks.
This is used in the Redcarpet plugin as well as Rouge's own
Lexer.find_fancy('guess', "#!/bin/bash\necho Hello, world")
and you can pass a second argument of the code to guess by
* You can pass the special name 'guess' so we guess for you,
Lexer.find_fancy('erb?parent=tex')
* The string you pass can include CGI-style options
Find a lexer, with fancy shiny features.
def find_fancy(str, code=nil, additional_options={}) if str && !str.include?('?') && str != 'guess' lexer_class = find(str) return lexer_class && lexer_class.new(additional_options) end name, opts = str ? str.split('?', 2) : [nil, ''] # parse the options hash from a cgi-style string opts = CGI.parse(opts || '').map do |k, vals| val = case vals.size when 0 then true when 1 then vals[0] else vals end [ k.to_s, val ] end opts = additional_options.merge(Hash[opts]) lexer_class = case name when 'guess', nil self.guess(:source => code, :mimetype => opts['mimetype']) when String self.find(name) end lexer_class && lexer_class.new(opts) end