class CabbageDoc::Highlighter

Attributes

formatter[RW]
lexers[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/cabbage_doc/highlighter.rb, line 7
def initialize(options = {})
  self.formatter = Rouge::Formatters::HTMLLegacy.new({ css_class: 'highlight' }.merge(options))
  self.lexers = {}
end

Public Instance Methods

format(text, type = 'txt') click to toggle source
# File lib/cabbage_doc/highlighter.rb, line 12
def format(text, type = 'txt')
  formatter.format(find_lexer(text, type).lex(text))
end

Private Instance Methods

find_lexer(text, type) click to toggle source
# File lib/cabbage_doc/highlighter.rb, line 18
def find_lexer(text, type)
  self.lexers[type.to_sym] ||= Rouge::Lexer.guess(source: text,
                                                  filename: "highlight.#{type}").new
end