From 1306ad83b9f4ba22c609e900e3939630a22398b0 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 6 Mar 2013 01:09:40 +0100 Subject: [PATCH] Fail loudly when a pygments highlight fails. #990. --- plugins/pygments_code.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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