diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb index 0ec5872..0744b37 100644 --- a/plugins/pygments_code.rb +++ b/plugins/pygments_code.rb @@ -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