Catch all Pygments errors

An unrecognized language was generating a MentosError rather than a
PythonError. Just catch anything that goes wrong in Pygments.
This commit is contained in:
Walter Smith
2012-10-10 14:07:42 -07:00
parent be9907a0cc
commit b7cdeabbf6
2 changed files with 10 additions and 2 deletions
+2 -2
View File
@@ -558,12 +558,12 @@ module Gollum
encoding ||= 'utf-8'
begin
hl_code = Pygments.highlight(code, :lexer => lang, :options => {:encoding => encoding.to_s})
rescue ::RubyPython::PythonError
rescue
hl_code = code
end
highlighted << hl_code
end
@codemap.each do |id, spec|
body = spec[:output] || begin
if (body = highlighted.shift.to_s).size > 0
+8
View File
@@ -534,6 +534,14 @@ np.array([[2,2],[1,3]],np.float)
assert_equal %Q{<p>a\n</p><div class=\"highlight\"><pre><span class=\"nt\">&lt;p&gt;</span>a\n!rel<span class=\"nt\">&lt;/p&gt;</span>\n</pre></div>\n}, output
end
test "code block in unsupported language" do
@wiki.write_page("a", :markdown, "a\n```nonexistent\ncode\n```\nb", commit_details)
page = @wiki.page("a")
output = page.formatted_data
assert_equal %Q{<p>a\ncode\nb</p>}, output
end
#########################################################################
#
# Web Sequence Diagrams