diff --git a/lib/github-pages/configuration.rb b/lib/github-pages/configuration.rb index 3b1932d7..f8ce274b 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, @@ -141,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] = \ + config["kramdown"][opt] == "nil" ? nil : DEFAULTS["kramdown"][opt] + end + return unless config["markdown"].to_s.casecmp("gfm").zero? config["markdown"] = "CommonMarkGhPages" 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)