Don't crash when file can't be highlighted
This commit is contained in:
parent
512bebe21d
commit
5c7259c7c3
|
@ -17,19 +17,13 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def highlight(text, continue: true)
|
def highlight(text, continue: true)
|
||||||
@formatter.format(lex(text, continue: continue)).html_safe
|
@formatter.format(@lexer.lex(text, continue: continue)).html_safe
|
||||||
|
rescue
|
||||||
|
@formatter.format(Rouge::Lexers::PlainText.lex(text)).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def lex(text, continue: true)
|
|
||||||
if @lexer == Rouge::Lexers::PlainText
|
|
||||||
@lexer.lex(text)
|
|
||||||
else
|
|
||||||
@lexer.lex(text, continue: continue)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def rouge_formatter(options = {})
|
def rouge_formatter(options = {})
|
||||||
options = options.reverse_merge(
|
options = options.reverse_merge(
|
||||||
nowrap: true,
|
nowrap: true,
|
||||||
|
|
Loading…
Reference in New Issue