From 63e977721acb1ab14f6537bc95bea4695db06f7b Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 16 Mar 2014 13:22:55 -0400 Subject: [PATCH 1/2] Add a message and error out when Pygments returns nil. --- lib/jekyll/tags/highlight.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index f07e98b1..0b39e11e 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -56,10 +56,20 @@ eos @options[:encoding] = 'utf-8' - output = add_code_tags( - Pygments.highlight(code, :lexer => @lang, :options => @options), - @lang.to_s.gsub("+", "-") - ) + highlighted_code = Pygments.highlight(code, :lexer => @lang, :options => @options) + + if highlighted_code.nil? + Jekyll.logger.error "There was an error highlighting your code:" + puts + Jekyll.logger.error code + puts + Jekyll.logger.error "While attempting to convert the above code, Pygments.rb" + + " returned an unacceptable value." + Jekyll.logger.error "This is usually solved by running `jekyll build` again." + raise ArgumentError.new("Pygments.rb returned an unacceptable value when attempting to highlight some code.") + end + + output = add_code_tags(highlighted_code, @lang) output = context["highlighter_prefix"] + output if context["highlighter_prefix"] output << context["highlighter_suffix"] if context["highlighter_suffix"] @@ -89,14 +99,14 @@ eos #The div is required because RDiscount blows ass <<-HTML
-
#{h(code).strip}
+
#{h(code).strip}
HTML end def add_code_tags(code, lang) # Add nested tags to code blocks - code = code.sub(/
/,'
')
+        code = code.sub(/
/,'
')
         code = code.sub(/<\/pre>/,"
") end From 1b8205245e7ecc9090449e3e0fdcc5ea2967814b Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 19 Mar 2014 00:49:50 -0400 Subject: [PATCH 2/2] Went with @stomar's suggestion --- lib/jekyll/tags/highlight.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 0b39e11e..eb128d32 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -65,7 +65,7 @@ eos puts Jekyll.logger.error "While attempting to convert the above code, Pygments.rb" + " returned an unacceptable value." - Jekyll.logger.error "This is usually solved by running `jekyll build` again." + Jekyll.logger.error "This is usually a timeout problem solved by running `jekyll build` again." raise ArgumentError.new("Pygments.rb returned an unacceptable value when attempting to highlight some code.") end