From 5905cfc2cc06a0ea2a8b15d12744ad97e38bb15f Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 26 Jul 2017 18:03:01 -0400 Subject: [PATCH 1/4] Write test to confirm kramdown gets symbol-compatible keys --- test/test_kramdown.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/test_kramdown.rb b/test/test_kramdown.rb index d8f886a4c1a..aef46bb197e 100644 --- a/test/test_kramdown.rb +++ b/test/test_kramdown.rb @@ -22,9 +22,14 @@ class TestKramdown < JekyllUnitTest } @config = Jekyll.configuration(@config) - @markdown = Converters::Markdown.new( - @config - ) + @markdown = Converters::Markdown.new(@config) + @markdown.setup + end + + should "allow keys to be strings when kramdown wants symbols" do + kramdown_config = @markdown.instance_variable_get(:@parser).instance_variable_get(:@config) + 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 From 68a7c061879972caa3e3f78a013dfd2c8a908241 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 26 Jul 2017 18:09:01 -0400 Subject: [PATCH 2/4] KramdownParser#make_accessible: don't use default_proc --- lib/jekyll/converters/markdown/kramdown_parser.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index a7252f1a689..d1f93c63f09 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -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] + make_accessible(hash[key]) if hash[key].is_a?(Hash) end end @@ -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( From e861c41d23ab443681ca273d3bf57fe4042d197a Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 26 Jul 2017 18:30:46 -0400 Subject: [PATCH 3/4] Ensure the symbolized key is in the hash proper --- test/test_kramdown.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/test_kramdown.rb b/test/test_kramdown.rb index aef46bb197e..e500bf2fde7 100644 --- a/test/test_kramdown.rb +++ b/test/test_kramdown.rb @@ -20,14 +20,25 @@ 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.setup end - should "allow keys to be strings when kramdown wants symbols" do + 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 From 5e4f4860bcf3010e5068e763fd9e7ec43c7294b8 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 26 Jul 2017 20:23:44 -0400 Subject: [PATCH 4/4] Fix rubocop errors in test/test_kramdown.rb --- test/test_kramdown.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/test_kramdown.rb b/test/test_kramdown.rb index e500bf2fde7..6396d67201b 100644 --- a/test/test_kramdown.rb +++ b/test/test_kramdown.rb @@ -21,7 +21,8 @@ class TestKramdown < JekyllUnitTest }, } @kramdown_config_keys = @config["kramdown"].keys - @syntax_highlighter_opts_config_keys = @config["kramdown"]["syntax_highlighter_opts"].keys + @syntax_highlighter_opts_config_keys = \ + @config["kramdown"]["syntax_highlighter_opts"].keys @config = Jekyll.configuration(@config) @markdown = Converters::Markdown.new(@config) @@ -29,18 +30,23 @@ class TestKramdown < JekyllUnitTest 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 = @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}" + 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}" + 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] + assert_equal kramdown_config["syntax_highlighter_opts"]["css"], + kramdown_config[:syntax_highlighter_opts][:css] end should "run Kramdown" do