#highlight_failed now accepts tag name, and proper syntax

This commit is contained in:
Parker Moore 2013-03-10 02:06:02 +01:00
parent 6c58529532
commit b456865c8c
6 changed files with 17 additions and 11 deletions

View File

@ -41,7 +41,7 @@ module BacktickCodeBlock
begin begin
highlight(code, @options) highlight(code, @options)
rescue rescue
highlight_failed(nil, code, @options[:lang]) highlight_failed('backtick_code_block', "``` [lang]\n code\n ```", code, @options[:lang])
end end
end end
end end

View File

@ -85,7 +85,7 @@ module Jekyll
code = code + context['pygments_suffix'] if context['pygments_suffix'] code = code + context['pygments_suffix'] if context['pygments_suffix']
code code
rescue rescue
highlight_failed(nil, code, @options[:lang]) highlight_failed('code_block', 'codeblock [title] [url] [link text]', code, @options[:lang])
end end
end end
end end

View File

@ -56,7 +56,7 @@ module Jekyll
begin begin
code = highlight(code, @options) code = highlight(code, @options)
rescue rescue
highlight_failed(file, code, @options[:lang]) highlight_failed('gist', 'gist gist_id [filename]', code, @options[:lang], file)
end end
end end
code || cache code || cache

View File

@ -88,7 +88,7 @@ module Jekyll
begin begin
highlight(code, @options) highlight(code, @options)
rescue rescue
highlight_failed(@file, code, @options[:lang]) highlight_failed('include_code', 'include_code path/to/file [title]', code, @options[:lang], filepath)
end end
end end
end end

View File

@ -184,13 +184,18 @@ module HighlightCode
code code
end end
def highlight_failed(file, code, lang) def highlight_failed(tag, syntax, code, lang, file = nil)
code_snippet = code.split("\n")[0..9].map{|l| ">> #{l}" }.join("\n") code_snippet = code.split("\n")[0..9].map{|l| " #{l}" }.join("\n")
fail_message = "Pygments doesn't know how to highlight your code in lang '#{lang}'." fail_message = <<-MESSAGE
fail_message += "\nFailing code from #{file}:" if file Syntax Error in tag '#{tag}' while parsing the following markup in lang '#{lang}':
fail_message += "\n\n#{code_snippet}" #{"(Failing code from #{file})" if file}
fail_message += "\n>> ..." if code.split("\n").size > 10
$stderr.puts fail_message.red #{code_snippet}
#{" ..." if code.split("\n").size > 10}
Valid syntax: #{syntax}
MESSAGE
$stderr.puts fail_message.chomp.red
raise ArgumentError raise ArgumentError
end end

View File

@ -0,0 +1 @@
Hi hi hi lolz