diff --git a/plugins/backtick_code_block.rb b/plugins/backtick_code_block.rb index c1e6a84..3f5db1d 100644 --- a/plugins/backtick_code_block.rb +++ b/plugins/backtick_code_block.rb @@ -40,9 +40,9 @@ module BacktickCodeBlock begin highlight(code, @options) - rescue + rescue MentosError => e markup = "```#{original_markup}" - highlight_failed("```[language] [title] [url] [link text] [linenos:false] [start:#] [mark:#,#-#]\ncode\n```", markup, code) + highlight_failed(e, "```[language] [title] [url] [link text] [linenos:false] [start:#] [mark:#,#-#]\ncode\n```", markup, code) end end end diff --git a/plugins/code_block.rb b/plugins/code_block.rb index 6ad801e..90b0d0e 100644 --- a/plugins/code_block.rb +++ b/plugins/code_block.rb @@ -85,9 +85,9 @@ module Jekyll code = context['pygments_prefix'] + code if context['pygments_prefix'] code = code + context['pygments_suffix'] if context['pygments_suffix'] code - rescue + rescue MentosError => e markup = "{% codeblock #{@original_markup} %}" - highlight_failed("{% codeblock [lang:language] [title] [url] [link text] [start:#] [mark:#,#-#] [linenos:false] %}\ncode\n{% endcodeblock %}", markup, code) + highlight_failed(e, "{% codeblock [lang:language] [title] [url] [link text] [start:#] [mark:#,#-#] [linenos:false] %}\ncode\n{% endcodeblock %}", markup, code) end end end diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb index 553014a..331cc76 100644 --- a/plugins/gist_tag.rb +++ b/plugins/gist_tag.rb @@ -56,9 +56,9 @@ module Jekyll code = get_range(code, @options[:start], @options[:end]) begin code = highlight(code, @options) - rescue + rescue MentosError => e markup = "{% gist #{@original_markup} %}" - highlight_failed("{% gist gist_id [filename] [lang:language] [title:title] [start:#] [end:#] [range:#-#] [mark:#,#-#] [linenos:false] %}", markup, code, file) + highlight_failed(e, "{% gist gist_id [filename] [lang:language] [title:title] [start:#] [end:#] [range:#-#] [mark:#,#-#] [linenos:false] %}", markup, code, file) end end code || cache diff --git a/plugins/include_code.rb b/plugins/include_code.rb index b9dde9e..6315cf7 100644 --- a/plugins/include_code.rb +++ b/plugins/include_code.rb @@ -88,9 +88,9 @@ module Jekyll code = get_range(code, @options[:start], @options[:end]) begin highlight(code, @options) - rescue + rescue MentosError => e markup = "{% include_code #{@original_markup} %}" - highlight_failed("{% include_code [title] [lang:language] path/to/file [start:#] [end:#] [range:#-#] [mark:#,#-#] [linenos:false] %}", markup, code, filepath) + highlight_failed(e, "{% include_code [title] [lang:language] path/to/file [start:#] [end:#] [range:#-#] [mark:#,#-#] [linenos:false] %}", markup, code, filepath) end end end diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb index d0fe907..b06b153 100644 --- a/plugins/pygments_code.rb +++ b/plugins/pygments_code.rb @@ -184,12 +184,13 @@ module HighlightCode code end - def highlight_failed(syntax, markup, code, file = nil) + def highlight_failed(error, syntax, markup, code, file = nil) code_snippet = code.split("\n")[0..9].map{|l| " #{l}" }.join("\n") - fail_message = "\nSyntax Error while parsing the following markup#{ " in #{file}" if file}:\n\n".red + fail_message = "\nPygments Error while parsing the following markup#{" in #{file}" if file}:\n\n".red fail_message += " #{markup}\n#{code_snippet}\n" fail_message += "#{" ..." if code.split("\n").size > 10}\n" - fail_message += "\nValid syntax:\n\n#{syntax}\n".yellow + fail_message += "\nValid Syntax:\n\n#{syntax}\n".yellow + fail_message += "\nPygments Error:\n\n#{error.message}".red $stderr.puts fail_message.chomp raise ArgumentError end