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 2e5819d commit 6068291
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/api/lib/obsapi/markdown_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ def link(link, title, content)
end

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

0 comments on commit 6068291

Please sign in to comment.