Merge pull request #2148 from jekyll/error-when-pygments-errors
This commit is contained in:
commit
cf37591200
|
@ -56,10 +56,20 @@ eos
|
|||
|
||||
@options[:encoding] = 'utf-8'
|
||||
|
||||
output = add_code_tags(
|
||||
Pygments.highlight(code, :lexer => @lang, :options => @options),
|
||||
@lang.to_s.gsub("+", "-")
|
||||
)
|
||||
highlighted_code = Pygments.highlight(code, :lexer => @lang, :options => @options)
|
||||
|
||||
if highlighted_code.nil?
|
||||
Jekyll.logger.error "There was an error highlighting your code:"
|
||||
puts
|
||||
Jekyll.logger.error code
|
||||
puts
|
||||
Jekyll.logger.error "While attempting to convert the above code, Pygments.rb" +
|
||||
" returned an unacceptable value."
|
||||
Jekyll.logger.error "This is usually a timeout problem solved by running `jekyll build` again."
|
||||
raise ArgumentError.new("Pygments.rb returned an unacceptable value when attempting to highlight some code.")
|
||||
end
|
||||
|
||||
output = add_code_tags(highlighted_code, @lang)
|
||||
|
||||
output = context["highlighter_prefix"] + output if context["highlighter_prefix"]
|
||||
output << context["highlighter_suffix"] if context["highlighter_suffix"]
|
||||
|
@ -89,14 +99,14 @@ eos
|
|||
#The div is required because RDiscount blows ass
|
||||
<<-HTML
|
||||
<div>
|
||||
<pre><code class='#{@lang}'>#{h(code).strip}</code></pre>
|
||||
<pre><code class='#{@lang.to_s.gsub("+", "-")}'>#{h(code).strip}</code></pre>
|
||||
</div>
|
||||
HTML
|
||||
end
|
||||
|
||||
def add_code_tags(code, lang)
|
||||
# Add nested <code> tags to code blocks
|
||||
code = code.sub(/<pre>/,'<pre><code class="' + lang + '">')
|
||||
code = code.sub(/<pre>/,'<pre><code class="' + lang.to_s.gsub("+", "-") + '">')
|
||||
code = code.sub(/<\/pre>/,"</code></pre>")
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue