From 7cd56b5b1a19a091d27e9762b4be691cc052b6b4 Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Tue, 4 Jun 2019 13:44:02 -0400 Subject: [PATCH 1/3] fixes #545: allow +nil+ for kramdown math_engine and syntax_highlighter --- lib/github-pages/configuration.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/github-pages/configuration.rb b/lib/github-pages/configuration.rb index 3b1932d7..60b8f80e 100644 --- a/lib/github-pages/configuration.rb +++ b/lib/github-pages/configuration.rb @@ -22,6 +22,8 @@ class Configuration "input" => "GFM", "hard_wrap" => false, "gfm_quirks" => "paragraph_end", + "math_engine" => "mathjax", + "syntax_highlighter" => "rouge", "syntax_highlighter_opts" => { "default_lang" => "plaintext", }, @@ -54,8 +56,6 @@ class Configuration "highlighter" => "rouge", "kramdown" => { "template" => "", - "math_engine" => "mathjax", - "syntax_highlighter" => "rouge", }, "gist" => { "noscript" => false, @@ -107,6 +107,14 @@ def effective_config(user_config) # Allow theme to be explicitly disabled via "theme: null" config["theme"] = user_config["theme"] if user_config.key?("theme") + # Override non-nil values for kramdown options math_engine and syntax_highlighter + unless config["kramdown"]["math_engine"].nil? + config["kramdown"]["math_engine"] = DEFAULTS["kramdown"]["math_engine"] + end + unless config["kramdown"]["syntax_highlighter"].nil? + config["kramdown"]["syntax_highlighter"] = DEFAULTS["kramdown"]["syntax_highlighter"] + end + exclude_cname(config) # Merge overwrites into user config From d0c2cfacff5d70b715ef460b1cd42b17e2bfcdca Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Tue, 4 Jun 2019 16:32:12 -0400 Subject: [PATCH 2/3] fixed linter errors --- lib/github-pages/configuration.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/github-pages/configuration.rb b/lib/github-pages/configuration.rb index 60b8f80e..9b17e8fd 100644 --- a/lib/github-pages/configuration.rb +++ b/lib/github-pages/configuration.rb @@ -107,14 +107,6 @@ def effective_config(user_config) # Allow theme to be explicitly disabled via "theme: null" config["theme"] = user_config["theme"] if user_config.key?("theme") - # Override non-nil values for kramdown options math_engine and syntax_highlighter - unless config["kramdown"]["math_engine"].nil? - config["kramdown"]["math_engine"] = DEFAULTS["kramdown"]["math_engine"] - end - unless config["kramdown"]["syntax_highlighter"].nil? - config["kramdown"]["syntax_highlighter"] = DEFAULTS["kramdown"]["syntax_highlighter"] - end - exclude_cname(config) # Merge overwrites into user config @@ -149,12 +141,20 @@ def set!(site) # Ensure we're using Kramdown or GFM. Force to Kramdown if # neither of these. # + # Also override non-nil values for kramdown options math_engine and + # syntax_highlighter. + # # This can get called multiply on the same config, so try to # be idempotentish. def restrict_and_config_markdown_processor(config) config["markdown"] = "kramdown" unless \ %w(kramdown gfm commonmarkghpages).include?(config["markdown"].to_s.downcase) + %w(math_engine syntax_highlighter).each do |opt| + config["kramdown"][opt] = DEFAULTS["kramdown"][opt] unless \ + config["kramdown"][opt].nil? + end + return unless config["markdown"].to_s.casecmp("gfm").zero? config["markdown"] = "CommonMarkGhPages" From d46390ff280b4e6b5310bd52fa773258a5a017b0 Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Wed, 5 Jun 2019 21:55:16 -0400 Subject: [PATCH 3/3] added test coverage and minor change --- lib/github-pages/configuration.rb | 4 ++-- spec/github-pages/configuration_spec.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/github-pages/configuration.rb b/lib/github-pages/configuration.rb index 9b17e8fd..f8ce274b 100644 --- a/lib/github-pages/configuration.rb +++ b/lib/github-pages/configuration.rb @@ -151,8 +151,8 @@ def restrict_and_config_markdown_processor(config) %w(kramdown gfm commonmarkghpages).include?(config["markdown"].to_s.downcase) %w(math_engine syntax_highlighter).each do |opt| - config["kramdown"][opt] = DEFAULTS["kramdown"][opt] unless \ - config["kramdown"][opt].nil? + config["kramdown"][opt] = \ + config["kramdown"][opt] == "nil" ? nil : DEFAULTS["kramdown"][opt] end return unless config["markdown"].to_s.casecmp("gfm").zero? diff --git a/spec/github-pages/configuration_spec.rb b/spec/github-pages/configuration_spec.rb index c13e2dc7..df99e7f1 100644 --- a/spec/github-pages/configuration_spec.rb +++ b/spec/github-pages/configuration_spec.rb @@ -49,6 +49,25 @@ expect(effective_config["quiet"]).to eql(true) end + it "has default values for math_engine and syntax_highlighter" do + expect(effective_config["kramdown"]["math_engine"]).to eql("mathjax") + expect(effective_config["kramdown"]["syntax_highlighter"]).to eql("rouge") + end + + it "respects 'nil' for math_engine and syntax_highlighter" do + config = configuration.merge("kramdown" => { "math_engine" => "nil", "syntax_highlighter" => "nil" }) + effective_config = described_class.effective_config(config) + expect(effective_config["kramdown"]["math_engine"]).to be_nil + expect(effective_config["kramdown"]["syntax_highlighter"]).to be_nil + end + + it "overrides non-'nil' for math_engine and syntax_highlighter" do + config = configuration.merge("kramdown" => { "math_engine" => "foo", "syntax_highlighter" => "bar" }) + effective_config = described_class.effective_config(config) + expect(effective_config["kramdown"]["math_engine"]).to eql("mathjax") + expect(effective_config["kramdown"]["syntax_highlighter"]).to eql("rouge") + end + it "passes passthroughs" do expect(effective_config["quiet"]).to eql(true) expect(effective_config["source"]).to eql(fixture_dir)