Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kramdown: symbolize keys in-place #6247

Merged
merged 4 commits into from Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions lib/jekyll/converters/markdown/kramdown_parser.rb
Expand Up @@ -43,13 +43,9 @@ def convert(content)

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
)
hash.keys.each do |key|
hash[key.to_sym] = hash[key]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash[key.to_sym] = hash[key] unless key.is_a?(Symbol)

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a no-op since Symbol#to_sym returns self, right?

make_accessible(hash[key]) if hash[key].is_a?(Hash)
end
end

Expand Down Expand Up @@ -86,7 +82,7 @@ def highlighter
private
def strip_coderay_prefix(hash)
hash.each_with_object({}) do |(key, val), hsh|
cleaned_key = key.gsub(%r!\Acoderay_!, "")
cleaned_key = key.to_s.gsub(%r!\Acoderay_!, "")

if key != cleaned_key
Jekyll::Deprecator.deprecation_message(
Expand Down
28 changes: 25 additions & 3 deletions test/test_kramdown.rb
Expand Up @@ -20,11 +20,33 @@ class TestKramdown < JekyllUnitTest
},
},
}
@kramdown_config_keys = @config["kramdown"].keys
@syntax_highlighter_opts_config_keys = \
@config["kramdown"]["syntax_highlighter_opts"].keys

@config = Jekyll.configuration(@config)
@markdown = Converters::Markdown.new(
@config
)
@markdown = Converters::Markdown.new(@config)
@markdown.setup
end

should "fill symbolized keys into config for compatibility with kramdown" do
kramdown_config = @markdown.instance_variable_get(:@parser)
.instance_variable_get(:@config)

@kramdown_config_keys.each do |key|
assert kramdown_config.key?(key.to_sym),
"Expected #{kramdown_config} to include key #{key.to_sym.inspect}"
end

@syntax_highlighter_opts_config_keys.each do |key|
assert kramdown_config["syntax_highlighter_opts"].key?(key.to_sym),
"Expected #{kramdown_config["syntax_highlighter_opts"]} to include " \
"key #{key.to_sym.inspect}"
end

assert_equal kramdown_config["smart_quotes"], kramdown_config[:smart_quotes]
assert_equal kramdown_config["syntax_highlighter_opts"]["css"],
kramdown_config[:syntax_highlighter_opts][:css]
end

should "run Kramdown" do
Expand Down