Class: CabbageDoc::Highlighter

Inherits:
Object
  • Object
show all
Defined in:
lib/cabbage_doc/highlighter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Highlighter

Returns a new instance of Highlighter.



7
8
9
10
# 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

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



5
6
7
# File 'lib/cabbage_doc/highlighter.rb', line 5

def formatter
  @formatter
end

#lexersObject

Returns the value of attribute lexers.



5
6
7
# File 'lib/cabbage_doc/highlighter.rb', line 5

def lexers
  @lexers
end

Instance Method Details

#format(text, type = 'txt') ⇒ Object



12
13
14
# File 'lib/cabbage_doc/highlighter.rb', line 12

def format(text, type = 'txt')
  formatter.format(find_lexer(text, type).lex(text))
end