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
Léo-Paul Géneau
gitlab-ce
Commits
3a1d0535
Commit
3a1d0535
authored
Jan 14, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplication around highlighting.
parent
c881627d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
27 deletions
+25
-27
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+1
-15
lib/gitlab/diff/highlight.rb
lib/gitlab/diff/highlight.rb
+1
-12
lib/gitlab/highlight.rb
lib/gitlab/highlight.rb
+23
-0
No files found.
app/helpers/blob_helper.rb
View file @
3a1d0535
module
BlobHelper
def
rouge_formatter
(
options
=
{})
default_options
=
{
nowrap:
false
,
cssclass:
'code highlight'
,
lineanchors:
true
,
lineanchorsid:
'LC'
}
Rouge
::
Formatters
::
HTMLGitlab
.
new
(
default_options
.
merge!
(
options
))
end
def
highlight
(
blob_name
,
blob_content
,
nowrap:
false
,
continue:
false
)
formatter
=
rouge_formatter
(
nowrap:
nowrap
)
@lexer
||=
Rouge
::
Lexer
.
guess
(
filename:
blob_name
,
source:
blob_content
).
new
rescue
Rouge
::
Lexers
::
PlainText
formatter
.
format
(
@lexer
.
lex
(
blob_content
,
continue:
continue
)).
html_safe
Gitlab
::
Highlight
.
highlight
(
blob_name
,
blob_content
,
nowrap:
nowrap
,
continue:
continue
)
end
def
no_highlight_files
...
...
lib/gitlab/diff/highlight.rb
View file @
3a1d0535
...
...
@@ -20,18 +20,7 @@ module Gitlab
blob
=
repository
.
blob_at
(
ref
,
file_name
)
return
[]
unless
blob
content
=
blob
.
data
lexer
=
Rouge
::
Lexer
.
guess
(
filename:
file_name
,
source:
content
).
new
rescue
Rouge
::
Lexers
::
PlainText
.
new
formatter
.
format
(
lexer
.
lex
(
content
)).
lines
.
map!
(
&
:html_safe
)
end
def
self
.
formatter
@formatter
||=
Rouge
::
Formatters
::
HTMLGitlab
.
new
(
nowrap:
true
,
cssclass:
'code highlight'
,
lineanchors:
true
,
lineanchorsid:
'LC'
)
Gitlab
::
Highlight
.
highlight
(
file_name
,
blob
.
data
).
lines
.
map!
(
&
:html_safe
)
end
def
initialize
(
diff_file
)
...
...
lib/gitlab/highlight.rb
0 → 100644
View file @
3a1d0535
module
Gitlab
class
Highlight
def
self
.
highlight
(
blob_name
,
blob_content
,
nowrap:
true
,
continue:
false
)
formatter
=
rouge_formatter
(
nowrap:
nowrap
)
lexer
=
Rouge
::
Lexer
.
guess
(
filename:
blob_name
,
source:
blob_content
).
new
rescue
Rouge
::
Lexers
::
PlainText
formatter
.
format
(
lexer
.
lex
(
blob_content
,
continue:
continue
)).
html_safe
end
private
def
self
.
rouge_formatter
(
options
=
{})
options
=
options
.
reverse_merge
(
nowrap:
true
,
cssclass:
'code highlight'
,
lineanchors:
true
,
lineanchorsid:
'LC'
)
Rouge
::
Formatters
::
HTMLGitlab
.
new
(
options
)
end
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