Update unit tests for Kramdown-based converter (#8014)
Merge pull request 8014
This commit is contained in:
parent
0cb0b8ad8c
commit
d65a09b1d9
|
|
@ -4,10 +4,24 @@ require "helper"
|
||||||
require "rouge"
|
require "rouge"
|
||||||
|
|
||||||
class TestKramdown < JekyllUnitTest
|
class TestKramdown < JekyllUnitTest
|
||||||
|
def fixture_converter(config)
|
||||||
|
site = fixture_site(
|
||||||
|
Utils.deep_merge_hashes(
|
||||||
|
{
|
||||||
|
"markdown" => "kramdown",
|
||||||
|
},
|
||||||
|
config
|
||||||
|
)
|
||||||
|
)
|
||||||
|
Jekyll::Cache.clear
|
||||||
|
site.find_converter_instance(
|
||||||
|
Jekyll::Converters::Markdown
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
context "kramdown" do
|
context "kramdown" do
|
||||||
setup do
|
setup do
|
||||||
@config = {
|
@config = {
|
||||||
"markdown" => "kramdown",
|
|
||||||
"kramdown" => {
|
"kramdown" => {
|
||||||
"smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
|
"smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
|
||||||
"entity_output" => "as_char",
|
"entity_output" => "as_char",
|
||||||
|
|
@ -31,9 +45,7 @@ class TestKramdown < JekyllUnitTest
|
||||||
@config["kramdown"]["syntax_highlighter_opts"].keys
|
@config["kramdown"]["syntax_highlighter_opts"].keys
|
||||||
|
|
||||||
@config = Jekyll.configuration(@config)
|
@config = Jekyll.configuration(@config)
|
||||||
@markdown = Converters::Markdown.new(@config)
|
@converter = fixture_converter(@config)
|
||||||
@markdown.setup
|
|
||||||
Jekyll::Cache.clear
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not break kramdown" do
|
should "not break kramdown" do
|
||||||
|
|
@ -43,20 +55,32 @@ class TestKramdown < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "run Kramdown" do
|
should "run Kramdown" do
|
||||||
assert_equal "<h1>Some Header</h1>", @markdown.convert("# Some Header #").strip
|
assert_equal "<h1>Some Header</h1>", @converter.convert("# Some Header #").strip
|
||||||
end
|
end
|
||||||
|
|
||||||
should "should log kramdown warnings" do
|
should "should log kramdown warnings" do
|
||||||
allow_any_instance_of(Kramdown::Document).to receive(:warnings).and_return(["foo"])
|
allow_any_instance_of(Kramdown::Document).to receive(:warnings).and_return(["foo"])
|
||||||
expect(Jekyll.logger).to receive(:warn).with("Kramdown warning:", "foo")
|
expect(Jekyll.logger).to receive(:warn).with("Kramdown warning:", "foo")
|
||||||
@markdown.convert("Something")
|
@converter.convert("Something")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render fenced code blocks with syntax highlighting" do
|
||||||
|
result = nokogiri_fragment(@converter.convert(<<~MARKDOWN))
|
||||||
|
~~~ruby
|
||||||
|
puts "Hello World"
|
||||||
|
~~~
|
||||||
|
MARKDOWN
|
||||||
|
div_highlight = ">div.highlight"
|
||||||
|
selector = "div.highlighter-rouge#{div_highlight}>pre.highlight>code"
|
||||||
|
refute(result.css(selector).empty?, result.to_html)
|
||||||
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)
|
||||||
assert_match(
|
assert_match(
|
||||||
%r!<p>(“|“)Pit(’|’)hy(”|”)<\/p>!,
|
%r!<p>(“|“)Pit(’|’)hy(”|”)<\/p>!,
|
||||||
@markdown.convert(%("Pit'hy")).strip
|
converter.convert(%("Pit'hy")).strip
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -67,36 +91,22 @@ class TestKramdown < JekyllUnitTest
|
||||||
"smart_quotes" => "lsaquo,rsaquo,laquo,raquo",
|
"smart_quotes" => "lsaquo,rsaquo,laquo,raquo",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
converter = fixture_converter(Utils.deep_merge_hashes(@config, override))
|
||||||
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
|
||||||
assert_match %r!<p>(«|«)Pit(›|›)hy(»|»)<\/p>!, \
|
assert_match %r!<p>(«|«)Pit(›|›)hy(»|»)<\/p>!, \
|
||||||
markdown.convert(%("Pit'hy")).strip
|
converter.convert(%("Pit'hy")).strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render fenced code blocks with syntax highlighting" do
|
|
||||||
result = nokogiri_fragment(@markdown.convert(<<~MARKDOWN))
|
|
||||||
~~~ruby
|
|
||||||
puts "Hello World"
|
|
||||||
~~~
|
|
||||||
MARKDOWN
|
|
||||||
div_highlight = ">div.highlight"
|
|
||||||
selector = "div.highlighter-rouge#{div_highlight}>pre.highlight>code"
|
|
||||||
refute(result.css(selector).empty?, result.to_html)
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when a custom highlighter is chosen" do
|
context "when a custom highlighter is chosen" do
|
||||||
should "use the chosen highlighter if it's available" do
|
should "use the chosen highlighter if it's available" do
|
||||||
override = {
|
override = {
|
||||||
"highlighter" => nil,
|
"highlighter" => nil,
|
||||||
"markdown" => "kramdown",
|
|
||||||
"kramdown" => {
|
"kramdown" => {
|
||||||
"syntax_highlighter" => :coderay,
|
"syntax_highlighter" => "coderay",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
converter = fixture_converter(Utils.deep_merge_hashes(@config, override))
|
||||||
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
result = nokogiri_fragment(converter.convert(<<~MARKDOWN))
|
||||||
result = nokogiri_fragment(markdown.convert(<<~MARKDOWN))
|
|
||||||
~~~ruby
|
~~~ruby
|
||||||
puts "Hello World"
|
puts "Hello World"
|
||||||
~~~
|
~~~
|
||||||
|
|
@ -108,7 +118,6 @@ class TestKramdown < JekyllUnitTest
|
||||||
|
|
||||||
should "support legacy enable_coderay... for now" do
|
should "support legacy enable_coderay... for now" do
|
||||||
override = {
|
override = {
|
||||||
"markdown" => "kramdown",
|
|
||||||
"kramdown" => {
|
"kramdown" => {
|
||||||
"enable_coderay" => true,
|
"enable_coderay" => true,
|
||||||
},
|
},
|
||||||
|
|
@ -116,8 +125,9 @@ class TestKramdown < JekyllUnitTest
|
||||||
|
|
||||||
@config.delete("highlighter")
|
@config.delete("highlighter")
|
||||||
@config["kramdown"].delete("syntax_highlighter")
|
@config["kramdown"].delete("syntax_highlighter")
|
||||||
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
|
||||||
result = nokogiri_fragment(markdown.convert(<<~MARKDOWN))
|
converter = fixture_converter(Utils.deep_merge_hashes(@config, override))
|
||||||
|
result = nokogiri_fragment(converter.convert(<<~MARKDOWN))
|
||||||
~~~ruby
|
~~~ruby
|
||||||
puts "Hello World"
|
puts "Hello World"
|
||||||
~~~
|
~~~
|
||||||
|
|
@ -129,17 +139,18 @@ class TestKramdown < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "move coderay to syntax_highlighter_opts" do
|
should "move coderay to syntax_highlighter_opts" do
|
||||||
|
override = {
|
||||||
|
"higlighter" => nil,
|
||||||
|
"kramdown" => {
|
||||||
|
"syntax_highlighter" => "coderay",
|
||||||
|
"coderay" => {
|
||||||
|
"hello" => "world",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
original = Kramdown::Document.method(:new)
|
original = Kramdown::Document.method(:new)
|
||||||
markdown = Converters::Markdown.new(
|
converter = fixture_converter(
|
||||||
Utils.deep_merge_hashes(@config,
|
Utils.deep_merge_hashes(@config, override)
|
||||||
"higlighter" => nil,
|
|
||||||
"markdown" => "kramdown",
|
|
||||||
"kramdown" => {
|
|
||||||
"syntax_highlighter" => "coderay",
|
|
||||||
"coderay" => {
|
|
||||||
"hello" => "world",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(Kramdown::Document).to receive(:new) do |arg1, hash|
|
expect(Kramdown::Document).to receive(:new) do |arg1, hash|
|
||||||
|
|
@ -147,7 +158,7 @@ class TestKramdown < JekyllUnitTest
|
||||||
original.call(arg1, hash)
|
original.call(arg1, hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
markdown.convert("hello world")
|
converter.convert("hello world")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue