diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-03-13 23:07:30 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-03-13 23:07:30 +0400 |
commit | 0fe36374d88005379001460a74dc4d6359a35d16 (patch) | |
tree | 296bb7c6d8f998f47f7e9842805466ef19118c3b /lib | |
parent | b73a33ed4de67167572bb000b369acb991bf8ec2 (diff) |
Better language detection
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils.rb | 38 |
1 files changed, 9 insertions, 29 deletions
diff --git a/lib/utils.rb b/lib/utils.rb index 82463f9ec0c..52f3ee2e195 100644 --- a/lib/utils.rb +++ b/lib/utils.rb @@ -22,40 +22,20 @@ module Utils end def system_colorize(data, file_name) + options = { :encoding => 'utf-8', :linenos => 'True' } + + # Try detect language with pygments + Pygments.highlight data, :filename => file_name, :options => options + rescue + # if it fails use manual detection ft = handle_file_type(file_name) - Pygments.highlight(data, :lexer => ft, :options => { :encoding => 'utf-8', :linenos => 'True' }) + Pygments.highlight(data, :lexer => ft, :options => options) end - def handle_file_type(file_name, mime_type = nil) + def handle_file_type(file_name) case file_name - when /(\.pl|\.scala|\.java|\.haml|\.jade|\.scaml|\.html|\.sass|\.scss|\.php|\.erb)$/ - $1[1..-1].to_sym - when /(\.c|\.h|\.idc)$/ - :c - when /(\.cpp|\.hpp|\.c++|\.h++|\.cc|\.hh|\.cxx|\.hxx)$/ - :cpp - when /(\.d|\.di)$/ - :d - when /(\.hs|\.lhs)$/ - :haskell - when /(\.rb|\.ru|\.rake|Rakefile|\.gemspec|\.rbx|Gemfile)$/ + when /(\.ru|Gemfile)$/ :ruby - when /(\.py|\.pyw|\.sc|SConstruct|SConscript|\.tac)$/ - :python - when /(\.js|\.json)$/ - :javascript - when /(\.xml|\.xsl|\.rss|\.xslt|\.xsd|\.wsdl)$/ - :xml - when /(\.vm|\.fhtml)$/ - :velocity - when /\.sh$/ - :bash - when /\.coffee$/ - :coffeescript - when /(\.yml|\.yaml)$/ - :yaml - when /\.md$/ - :minid else :text end |