summaryrefslogtreecommitdiff
path: root/lib/gitlab/highlight.rb
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-04-14 12:44:35 +0200
committerZeger-Jan van de Weg <zegerjan@gitlab.com>2016-04-28 21:28:39 +0200
commitad99404d2588e182a115d89b0b457d957e8ca7b6 (patch)
tree527619b709363e1515c41c0d8f861995389a58d4 /lib/gitlab/highlight.rb
parent3fd0f5374447f0763c60d5b10b35d4a6f6981497 (diff)
downloadgitlab-ce-ad99404d2588e182a115d89b0b457d957e8ca7b6.tar.gz
Properly handle bigger files
Diffstat (limited to 'lib/gitlab/highlight.rb')
-rw-r--r--lib/gitlab/highlight.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb
index cac76442321..280120b0f9e 100644
--- a/lib/gitlab/highlight.rb
+++ b/lib/gitlab/highlight.rb
@@ -1,7 +1,8 @@
module Gitlab
class Highlight
- def self.highlight(blob_name, blob_content, nowrap: true)
- new(blob_name, blob_content, nowrap: nowrap).highlight(blob_content, continue: false)
+ def self.highlight(blob_name, blob_content, nowrap: true, plain: false)
+ new(blob_name, blob_content, nowrap: nowrap).
+ highlight(blob_content, continue: false, plain: plain)
end
def self.highlight_lines(repository, ref, file_name)
@@ -17,8 +18,12 @@ module Gitlab
@lexer = Rouge::Lexer.guess(filename: blob_name, source: blob_content).new rescue Rouge::Lexers::PlainText
end
- def highlight(text, continue: true)
- @formatter.format(@lexer.lex(text, continue: continue)).html_safe
+ def highlight(text, continue: true, plain: false)
+ if plain
+ @formatter.format(Rouge::Lexers::PlainText.lex(text)).html_safe
+ else
+ @formatter.format(@lexer.lex(text, continue: continue)).html_safe
+ end
rescue
@formatter.format(Rouge::Lexers::PlainText.lex(text)).html_safe
end