Rescuing errors issued by Pygments and raising our own with helpful info

This commit is contained in:
Parker Moore 2013-03-10 01:45:05 +01:00
parent 66e7fb0bfb
commit 6c58529532
4 changed files with 25 additions and 8 deletions

View File

@ -37,7 +37,12 @@ module BacktickCodeBlock
else
@options[:lang] ||= 'plain'
end
highlight(code, @options)
begin
highlight(code, @options)
rescue
highlight_failed(nil, code, @options[:lang])
end
end
end
end

View File

@ -78,11 +78,15 @@ module Jekyll
end
def render(context)
code = super.strip
code = highlight(code, @options)
code = context['pygments_prefix'] + code if context['pygments_prefix']
code = code + context['pygments_suffix'] if context['pygments_suffix']
code
begin
code = super.strip
code = highlight(code, @options)
code = context['pygments_prefix'] + code if context['pygments_prefix']
code = code + context['pygments_suffix'] if context['pygments_suffix']
code
rescue
highlight_failed(nil, code, @options[:lang])
end
end
end
end

View File

@ -53,7 +53,11 @@ module Jekyll
unless cache
code = get_gist_from_web(gist, file)
code = get_range(code, @options[:start], @options[:end])
code = highlight(code, @options)
begin
code = highlight(code, @options)
rescue
highlight_failed(file, code, @options[:lang])
end
end
code || cache
else

View File

@ -85,7 +85,11 @@ module Jekyll
code = filepath.read
code = get_range(code, @options[:start], @options[:end])
highlight(code, @options)
begin
highlight(code, @options)
rescue
highlight_failed(@file, code, @options[:lang])
end
end
end
end