From 02d4b2cf62aef5dccbfd59f15de45fad7885224f Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Thu, 27 Feb 2020 23:27:14 +0530 Subject: [PATCH 1/3] Configure default language for syntax-highlighting --- docs/_docs/configuration/default.md | 2 + lib/jekyll/configuration.rb | 1 + .../converters/markdown/kramdown_parser.rb | 1 + test/test_kramdown.rb | 54 +++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/docs/_docs/configuration/default.md b/docs/_docs/configuration/default.md index f87f71e3e7e..1caa2a6d6f5 100644 --- a/docs/_docs/configuration/default.md +++ b/docs/_docs/configuration/default.md @@ -85,4 +85,6 @@ kramdown: hard_wrap : false footnote_nr : 1 show_warnings : false + guess_lang : true + default_lang : plaintext ``` diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 9e86a560c85..1dbf1353916 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -71,6 +71,7 @@ class Configuration < Hash "smart_quotes" => "lsquo,rsquo,ldquo,rdquo", "input" => "GFM", "hard_wrap" => false, + "default_lang" => "plaintext", "guess_lang" => true, "footnote_nr" => 1, "show_warnings" => false, diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index aebd6ee7fef..6a907044f29 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -89,6 +89,7 @@ def initialize(config) def setup @config["syntax_highlighter"] ||= highlighter @config["syntax_highlighter_opts"] ||= {} + @config["syntax_highlighter_opts"]["default_lang"] ||= @config["default_lang"] @config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"] @config["coderay"] ||= {} # XXX: Legacy. modernize_coderay_config diff --git a/test/test_kramdown.rb b/test/test_kramdown.rb index 437e2a1c030..7a019b95038 100644 --- a/test/test_kramdown.rb +++ b/test/test_kramdown.rb @@ -75,6 +75,60 @@ def fixture_converter(config) refute(result.css(selector).empty?, result.to_html) end + context "when configured" do + setup do + @source = <<~TEXT + ## Code Sample + + def ruby_fu + "Hello" + end + TEXT + end + + should "have 'plaintext' as the default syntax_highlighter language" do + converter = fixture_converter(@config) + parser = converter.setup && converter.instance_variable_get(:@parser) + parser_config = parser.instance_variable_get(:@config) + + assert_equal "plaintext", parser_config.dig("syntax_highlighter_opts", "default_lang") + end + + should "accept the specified default syntax_highlighter language" do + override = { + "kramdown" => { + "default_lang" => "html", + }, + } + converter = fixture_converter(Utils.deep_merge_hashes(@config, override)) + parser = converter.setup && converter.instance_variable_get(:@parser) + parser_config = parser.instance_variable_get(:@config) + + assert_equal "html", parser_config.dig("syntax_highlighter_opts", "default_lang") + refute_match %r!
{ + "default_lang" => "html", + "syntax_highlighter_opts" => { + "default_lang" => "yaml", + }, + }, + } + converter = fixture_converter(Utils.deep_merge_hashes(@config, override)) + parser = converter.setup && converter.instance_variable_get(:@parser) + parser_config = parser.instance_variable_get(:@config) + + assert_equal "yaml", parser_config.dig("syntax_highlighter_opts", "default_lang") + refute_match %r!
Date: Thu, 27 Feb 2020 23:50:01 +0530 Subject: [PATCH 2/3] Fix failing Cucumber test --- features/collections.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/collections.feature b/features/collections.feature index 84677831d58..c0d44ed99da 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -391,7 +391,7 @@ Feature: Collections When I run jekyll build Then I should get a zero exit status Then the _site directory should exist - And I should see "Second document's output:

Use Jekyll.configuration to build a full configuration for use w/Jekyll.

\n\n

Whatever: foo.bar

" in "_site/index.html" + And I should see "Second document's output:

Use Jekyll.configuration to build a full configuration for use w/Jekyll.

\n\n

Whatever: foo.bar

" in "_site/index.html" Scenario: Documents have an output attribute, which is the converted HTML based on site.config Given I have an "index.html" page that contains "Second document's output: {{ site.documents[2].output }}" From d245ea0a04d0a038d31e18d7ae36451c9339fc4f Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 6 Apr 2020 22:28:38 +0530 Subject: [PATCH 3/3] Let there be just one way to configure setting --- docs/_docs/configuration/default.md | 2 -- lib/jekyll/configuration.rb | 1 - .../converters/markdown/kramdown_parser.rb | 2 +- test/test_kramdown.rb | 16 ---------------- 4 files changed, 1 insertion(+), 20 deletions(-) diff --git a/docs/_docs/configuration/default.md b/docs/_docs/configuration/default.md index 1caa2a6d6f5..f87f71e3e7e 100644 --- a/docs/_docs/configuration/default.md +++ b/docs/_docs/configuration/default.md @@ -85,6 +85,4 @@ kramdown: hard_wrap : false footnote_nr : 1 show_warnings : false - guess_lang : true - default_lang : plaintext ``` diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 1dbf1353916..9e86a560c85 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -71,7 +71,6 @@ class Configuration < Hash "smart_quotes" => "lsquo,rsquo,ldquo,rdquo", "input" => "GFM", "hard_wrap" => false, - "default_lang" => "plaintext", "guess_lang" => true, "footnote_nr" => 1, "show_warnings" => false, diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index 6b9b7f1445e..35b663f2e95 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -99,7 +99,7 @@ def initialize(config) def setup @config["syntax_highlighter"] ||= highlighter @config["syntax_highlighter_opts"] ||= {} - @config["syntax_highlighter_opts"]["default_lang"] ||= @config["default_lang"] + @config["syntax_highlighter_opts"]["default_lang"] ||= "plaintext" @config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"] @config["coderay"] ||= {} # XXX: Legacy. modernize_coderay_config diff --git a/test/test_kramdown.rb b/test/test_kramdown.rb index 7a019b95038..02d2b0c05e1 100644 --- a/test/test_kramdown.rb +++ b/test/test_kramdown.rb @@ -97,22 +97,6 @@ def ruby_fu should "accept the specified default syntax_highlighter language" do override = { "kramdown" => { - "default_lang" => "html", - }, - } - converter = fixture_converter(Utils.deep_merge_hashes(@config, override)) - parser = converter.setup && converter.instance_variable_get(:@parser) - parser_config = parser.instance_variable_get(:@config) - - assert_equal "html", parser_config.dig("syntax_highlighter_opts", "default_lang") - refute_match %r!
{ - "default_lang" => "html", "syntax_highlighter_opts" => { "default_lang" => "yaml", },