Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
0fe36374
Commit
0fe36374
authored
Mar 13, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better language detection
parent
b73a33ed
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
29 deletions
+9
-29
lib/utils.rb
lib/utils.rb
+9
-29
No files found.
lib/utils.rb
View file @
0fe36374
...
@@ -22,40 +22,20 @@ module Utils
...
@@ -22,40 +22,20 @@ module Utils
end
end
def
system_colorize
(
data
,
file_name
)
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
)
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
end
def
handle_file_type
(
file_name
,
mime_type
=
nil
)
def
handle_file_type
(
file_name
)
case
file_name
case
file_name
when
/(\.pl|\.scala|\.java|\.haml|\.jade|\.scaml|\.html|\.sass|\.scss|\.php|\.erb)$/
when
/(\.ru|Gemfile)$/
$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)$/
:ruby
: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
else
:text
:text
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment