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
Boxiang Sun
gitlab-ce
Commits
b468672d
Commit
b468672d
authored
Jul 14, 2016
by
http://jneen.net/
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style: factor out `@lexer` into a method
parent
822304b1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
lib/gitlab/highlight.rb
lib/gitlab/highlight.rb
+13
-9
No files found.
lib/gitlab/highlight.rb
View file @
b468672d
...
@@ -17,26 +17,30 @@ module Gitlab
...
@@ -17,26 +17,30 @@ module Gitlab
@formatter
=
Rouge
::
Formatters
::
HTMLGitlab
.
new
@formatter
=
Rouge
::
Formatters
::
HTMLGitlab
.
new
@repository
=
repository
@repository
=
repository
@blob_name
=
blob_name
@blob_name
=
blob_name
@lexer
=
custom_language
||
begin
@blob_content
=
blob_content
Rouge
::
Lexer
.
guess
(
filename:
blob_name
,
source:
blob_content
).
new
rescue
Rouge
::
Lexer
::
AmbiguousGuess
=>
e
e
.
alternatives
.
sort_by
(
&
:tag
).
first
end
end
end
def
highlight
(
text
,
continue:
true
,
plain:
false
)
def
highlight
(
text
,
continue:
true
,
plain:
false
)
lexer
=
@lexer
if
plain
if
plain
lexer
=
Rouge
::
Lexers
::
PlainText
hl_
lexer
=
Rouge
::
Lexers
::
PlainText
continue
=
false
continue
=
false
else
hl_lexer
=
self
.
lexer
end
end
@formatter
.
format
(
lexer
.
lex
(
text
,
continue:
continue
)).
html_safe
@formatter
.
format
(
hl_
lexer
.
lex
(
text
,
continue:
continue
)).
html_safe
rescue
rescue
@formatter
.
format
(
Rouge
::
Lexers
::
PlainText
.
lex
(
text
)).
html_safe
@formatter
.
format
(
Rouge
::
Lexers
::
PlainText
.
lex
(
text
)).
html_safe
end
end
def
lexer
@lexer
||=
custom_language
||
begin
Rouge
::
Lexer
.
guess
(
filename:
blob_name
,
source:
blob_content
).
new
rescue
Rouge
::
Lexer
::
AmbiguousGuess
=>
e
e
.
alternatives
.
sort_by
(
&
:tag
).
first
end
end
private
private
def
custom_language
def
custom_language
...
...
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