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

Nil for kramdown math_engine and syntax highlighter #740

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/github-pages/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down Expand Up @@ -54,8 +56,6 @@ class Configuration
"highlighter" => "rouge",
"kramdown" => {
"template" => "",
"math_engine" => "mathjax",
"syntax_highlighter" => "rouge",
},
"gist" => {
"noscript" => false,
Expand Down Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions spec/github-pages/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down