Don't crash when file can't be highlighted
This commit is contained in:
parent
512bebe21d
commit
5c7259c7c3
1 changed files with 3 additions and 9 deletions
|
@ -17,19 +17,13 @@ module Gitlab
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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 = {})
|
||||
options = options.reverse_merge(
|
||||
nowrap: true,
|
||||
|
|
Loading…
Reference in a new issue