Fail loudly when a pygments highlight fails. #990.

This commit is contained in:
Parker Moore 2013-03-06 01:09:40 +01:00
parent 81ea4ae9bb
commit 1306ad83b9

View File

@ -15,9 +15,15 @@ module HighlightCode
include TemplateWrapper
include SiteConfig
def pygments(code, lang)
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
highlighted_code = highlighted_code.gsub(/{{/, '{{').gsub(/{%/, '{%')
highlighted_code.to_s
begin
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
highlighted_code = highlighted_code.gsub(/{{/, '{{').gsub(/{%/, '{%')
highlighted_code.to_s
rescue
fail_message = "Pygments couldn't highlight your code in lang '#{lang}':"
fail_message += "\n\n#{code}\n"
raise ArgumentError, fail_message
end
rescue
puts $!,$@
end