Skip to content

Commit

Permalink
Catch CodeRay exception for invalid language
Browse files Browse the repository at this point in the history
CodeRay throws an exception if you give it a language it doesn't find a plugin
for. Reported as rubychan/coderay#245

Fixes openSUSE#6960

Co-authored-by: Dany Marcoux <dmarcoux@suse.com>
  • Loading branch information
hennevogel and Dany Marcoux committed Jan 10, 2020
1 parent 8a5cefd commit e271268
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/api/lib/obsapi/markdown_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def link(link, title, content)

def block_code(code, language)
language ||= :plaintext
CodeRay.scan(code, language).div(css: :class)
CodeRay.scan(code, language).div
rescue ArgumentError
CodeRay.scan("```#{language}#{code}", :plaintext).div unless language == :plaintext
end
end
end

0 comments on commit e271268

Please sign in to comment.