Module: Rouge::Plugins::Redcarpet

Defined in:
lib/rouge/plugins/redcarpet.rb

Instance Method Summary collapse

Instance Method Details

#block_code(code, language) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rouge/plugins/redcarpet.rb', line 11

def block_code(code, language)
  lexer =
    begin
      Lexer.find_fancy(language, code)
    rescue Guesser::Ambiguous => e
      e.alternatives.first
    end
  lexer ||= Lexers::PlainText

  # XXX HACK: Redcarpet strips hard tabs out of code blocks,
  # so we assume you're not using leading spaces that aren't tabs,
  # and just replace them here.
  if lexer.tag == 'make'
    code.gsub! %r/^    /, "\t"
  end

  formatter = rouge_formatter(lexer)
  formatter.format(lexer.lex(code))
end

#rouge_formatter(lexer) ⇒ Object

override this method for custom formatting behavior



32
33
34
# File 'lib/rouge/plugins/redcarpet.rb', line 32

def rouge_formatter(lexer)
  Formatters::HTMLLegacy.new(:css_class => "highlight #{lexer.tag}")
end