mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-11-15 21:55:00 -05:00
Pygments error messages are now printed alongside ours.
This commit is contained in:
parent
d0e59172f3
commit
d52bf53cc7
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user