Configure default language for syntax-highlighting (#8035)
Merge pull request 8035
This commit is contained in:
parent
8de0762923
commit
c0e5541468
|
@ -391,7 +391,7 @@ Feature: Collections
|
||||||
When I run jekyll build
|
When I run jekyll build
|
||||||
Then I should get a zero exit status
|
Then I should get a zero exit status
|
||||||
Then the _site directory should exist
|
Then the _site directory should exist
|
||||||
And I should see "Second document's output: <p>Use <code class=\"highlighter-rouge\">Jekyll.configuration</code> to build a full configuration for use w/Jekyll.</p>\n\n<p>Whatever: foo.bar</p>" in "_site/index.html"
|
And I should see "Second document's output: <p>Use <code class=\"language-plaintext highlighter-rouge\">Jekyll.configuration</code> to build a full configuration for use w/Jekyll.</p>\n\n<p>Whatever: foo.bar</p>" in "_site/index.html"
|
||||||
|
|
||||||
Scenario: Documents have an output attribute, which is the converted HTML based on site.config
|
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 }}"
|
Given I have an "index.html" page that contains "Second document's output: {{ site.documents[2].output }}"
|
||||||
|
|
|
@ -99,6 +99,7 @@ module Jekyll
|
||||||
def setup
|
def setup
|
||||||
@config["syntax_highlighter"] ||= highlighter
|
@config["syntax_highlighter"] ||= highlighter
|
||||||
@config["syntax_highlighter_opts"] ||= {}
|
@config["syntax_highlighter_opts"] ||= {}
|
||||||
|
@config["syntax_highlighter_opts"]["default_lang"] ||= "plaintext"
|
||||||
@config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"]
|
@config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"]
|
||||||
@config["coderay"] ||= {} # XXX: Legacy.
|
@config["coderay"] ||= {} # XXX: Legacy.
|
||||||
modernize_coderay_config
|
modernize_coderay_config
|
||||||
|
|
|
@ -75,6 +75,44 @@ class TestKramdown < JekyllUnitTest
|
||||||
refute(result.css(selector).empty?, result.to_html)
|
refute(result.css(selector).empty?, result.to_html)
|
||||||
end
|
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" => {
|
||||||
|
"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!<div class="language-plaintext!, converter.convert(@source)
|
||||||
|
refute_match %r!<div class="language-html!, converter.convert(@source)
|
||||||
|
assert_match %r!<div class="language-yaml!, converter.convert(@source)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when asked to convert smart quotes" do
|
context "when asked to convert smart quotes" do
|
||||||
should "convert" do
|
should "convert" do
|
||||||
converter = fixture_converter(@config)
|
converter = fixture_converter(@config)
|
||||||
|
|
Loading…
Reference in New Issue