Skip to content

Commit

Permalink
Merge pull request #990 from sjml/patch-1
Browse files Browse the repository at this point in the history
Generate can fail if Pygments can't parse a code block
  • Loading branch information
parkr committed Mar 6, 2013
2 parents 524e337 + 35e23f5 commit 392e32b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugins/pygments_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def pygments(code, lang)
if File.exist?(path)
highlighted_code = File.read(path)
else
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
begin
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
rescue MentosError
raise "Pygments can't parse unknown language: #{lang}."
end
File.open(path, 'w') {|f| f.print(highlighted_code) }
end
else
Expand Down

0 comments on commit 392e32b

Please sign in to comment.