Respect pygments config option in Redcarpet renderer.
This commit is contained in:
parent
3fef9607bc
commit
2114bb3c2e
|
@ -2,14 +2,16 @@ module Jekyll
|
|||
module Converters
|
||||
class Markdown
|
||||
class RedcarpetParser
|
||||
def initialize(config)
|
||||
require 'redcarpet'
|
||||
require 'pygments'
|
||||
@config = config
|
||||
@redcarpet_extensions = {}
|
||||
@config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
|
||||
|
||||
@renderer ||= Class.new(Redcarpet::Render::HTML) do
|
||||
module CommonMethods
|
||||
def add_code_tags(code, lang)
|
||||
code = code.sub(/<pre>/, "<pre><code class=\"#{lang} language-#{lang}\">")
|
||||
code = code.sub(/<\/pre>/,"</code></pre>")
|
||||
end
|
||||
end
|
||||
|
||||
class WithPygments < Redcarpet::Render::HTML
|
||||
include CommonMethods
|
||||
def block_code(code, lang)
|
||||
lang = lang && lang.split.first || "text"
|
||||
output = add_code_tags(
|
||||
|
@ -17,11 +19,29 @@ module Jekyll
|
|||
lang
|
||||
)
|
||||
end
|
||||
|
||||
def add_code_tags(code, lang)
|
||||
code = code.sub(/<pre>/, "<pre><code class=\"#{lang} language-#{lang}\">")
|
||||
code = code.sub(/<\/pre>/,"</code></pre>")
|
||||
end
|
||||
|
||||
class WithoutPygments < Redcarpet::Render::HTML
|
||||
include CommonMethods
|
||||
def block_code(code, lang)
|
||||
lang = lang && lang.split.first || "text"
|
||||
output = add_code_tags(code, lang)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(config)
|
||||
require 'redcarpet'
|
||||
require 'pygments'
|
||||
@config = config
|
||||
@redcarpet_extensions = {}
|
||||
@config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
|
||||
|
||||
@renderer ||= if @config['pygments']
|
||||
WithPygments
|
||||
else
|
||||
WithoutPygments
|
||||
end
|
||||
|
||||
end
|
||||
rescue LoadError
|
||||
STDERR.puts 'You are missing a library required for Markdown. Please run:'
|
||||
|
|
Loading…
Reference in New Issue