Class: Lines::ApplicationHelper::HTMLwithPygments

Inherits:
Redcarpet::Render::XHTML
  • Object
show all
Defined in:
app/helpers/lines/application_helper.rb

Overview

Highlights and formats code fragments with Pygments

Instance Method Summary collapse

Instance Method Details

#block_code(code, language) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/lines/application_helper.rb', line 20

def block_code(code, language)
  sha = Digest::SHA1.hexdigest(code)
  Rails.cache.fetch ["code", language, sha].join('-') do
    begin
      Pygments.highlight(code, lexer: language)
    rescue => e
      "<div class=\"highlight\"><pre>#{code}</pre></div>"
    end
  end
end