#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
highlight(code, @options)
rescue
highlight_failed(nil, code, @options[:lang])
highlight_failed('backtick_code_block', "``` [lang]\n code\n ```", code, @options[:lang])
end
end
end

View File

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

View File

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

View File

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

View File

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

View File

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