mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-11-16 06:05:00 -05:00
Fail loudly when a pygments highlight fails. #990.
This commit is contained in:
parent
81ea4ae9bb
commit
1306ad83b9
@ -15,9 +15,15 @@ module HighlightCode
|
||||
include TemplateWrapper
|
||||
include SiteConfig
|
||||
def pygments(code, lang)
|
||||
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
|
||||
highlighted_code = highlighted_code.gsub(/{{/, '{{').gsub(/{%/, '{%')
|
||||
highlighted_code.to_s
|
||||
begin
|
||||
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
|
||||
highlighted_code = highlighted_code.gsub(/{{/, '{{').gsub(/{%/, '{%')
|
||||
highlighted_code.to_s
|
||||
rescue
|
||||
fail_message = "Pygments couldn't highlight your code in lang '#{lang}':"
|
||||
fail_message += "\n\n#{code}\n"
|
||||
raise ArgumentError, fail_message
|
||||
end
|
||||
rescue
|
||||
puts $!,$@
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user