Merge pull request #4428 from jekyll/bug/make-config-symbol-accessible

Merge pull request 4428
This commit is contained in:
jekyllbot 2016-02-02 14:01:59 -08:00
commit 27535e2b3c
1 changed files with 38 additions and 8 deletions

View File

@ -12,11 +12,11 @@ module Jekyll
"line_number_start" => 1, "line_number_start" => 1,
"tab_width" => 4, "tab_width" => 4,
"wrap" => "div" "wrap" => "div"
} }.freeze
def initialize(config) def initialize(config)
Jekyll::External.require_with_graceful_fail "kramdown" Jekyll::External.require_with_graceful_fail "kramdown"
@main_fallback_highlighter = config["highlighter"] || "rogue" @main_fallback_highlighter = config["highlighter"] || "rouge"
@config = config["kramdown"] || {} @config = config["kramdown"] || {}
setup setup
end end
@ -32,22 +32,44 @@ module Jekyll
@config["syntax_highlighter_opts"] ||= {} @config["syntax_highlighter_opts"] ||= {}
@config["coderay"] ||= {} # XXX: Legacy. @config["coderay"] ||= {} # XXX: Legacy.
modernize_coderay_config modernize_coderay_config
make_accessible
end end
def convert(content) def convert(content)
Kramdown::Document.new(content, @config).to_html Kramdown::Document.new(content, @config).to_html
end end
private
def make_accessible(hash = @config)
proc_ = proc { |hash_, key| hash_[key.to_s] if key.is_a?(Symbol) }
hash.default_proc = proc_
hash.each do |_, val|
make_accessible val if val.is_a?(
Hash
)
end
end
# config[kramdown][syntax_higlighter] > config[kramdown][enable_coderay] > config[highlighter] # config[kramdown][syntax_higlighter] > config[kramdown][enable_coderay] > config[highlighter]
# Where `enable_coderay` is now deprecated because Kramdown # Where `enable_coderay` is now deprecated because Kramdown
# supports Rouge now too. # supports Rouge now too.
private private
def highlighter def highlighter
@highlighter ||= begin return @highlighter if @highlighter
if highlighter = @config["syntax_highlighter"] then highlighter
elsif @config.key?("enable_coderay") && @config["enable_coderay"] if @config["syntax_highlighter"]
Jekyll::Deprecator.deprecation_message "You are using 'enable_coderay', use syntax_highlighter: coderay in your configuration file." return @highlighter = @config[
"syntax_highlighter"
]
end
@highlighter = begin
if @config.key?("enable_coderay") && @config["enable_coderay"]
Jekyll::Deprecator.deprecation_message "You are using 'enable_coderay', " \
"use syntax_highlighter: coderay in your configuration file."
"coderay" "coderay"
else else
@main_fallback_highlighter @main_fallback_highlighter
@ -59,7 +81,13 @@ module Jekyll
def strip_coderay_prefix(hash) def strip_coderay_prefix(hash)
hash.each_with_object({}) do |(key, val), hsh| hash.each_with_object({}) do |(key, val), hsh|
cleaned_key = key.gsub(/\Acoderay_/, "") cleaned_key = key.gsub(/\Acoderay_/, "")
Jekyll::Deprecator.deprecation_message "You are using '#{key}'. Normalizing to #{cleaned_key}." if key != cleaned_key
if key != cleaned_key
Jekyll::Deprecator.deprecation_message(
"You are using '#{key}'. Normalizing to #{cleaned_key}."
)
end
hsh[cleaned_key] = val hsh[cleaned_key] = val
end end
end end
@ -71,7 +99,9 @@ module Jekyll
private private
def modernize_coderay_config def modernize_coderay_config
if highlighter == "coderay" if highlighter == "coderay"
Jekyll::Deprecator.deprecation_message "You are using 'kramdown.coderay' in your configuration, please use 'syntax_highlighter_opts' instead." Jekyll::Deprecator.deprecation_message "You are using 'kramdown.coderay' in your configuration, " \
"please use 'syntax_highlighter_opts' instead."
@config["syntax_highlighter_opts"] = begin @config["syntax_highlighter_opts"] = begin
strip_coderay_prefix( strip_coderay_prefix(
@config["syntax_highlighter_opts"] \ @config["syntax_highlighter_opts"] \