summaryrefslogtreecommitdiff
path: root/app/helpers/blob_helper.rb
blob: 3a282803963b96321f13a07703592007b0db699e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module BlobHelper
  def highlight(blob_name, blob_content, nowrap = false)
    formatter = Rugments::Formatters::HTML.new(
      nowrap: nowrap,
      cssclass: 'code highlight',
      lineanchors: true,
      lineanchorsid: 'LC'
    )

    begin
      lexer = Rugments::Lexer.guess(filename: blob_name, source: blob_content)
    rescue Rugments::Lexer::AmbiguousGuess
      lexer = Rugments::Lexers::PlainText
    end

    formatter.format(lexer.lex(blob_content)).html_safe
  end

  def no_highlight_files
    %w(credits changelog copying copyright license authors)
  end
end