Skip to content

Commit

Permalink
Merge branch '4.0-stable' into this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmaroli committed Apr 26, 2020
2 parents ca9989a + 94f60cb commit 830c1e6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 42 deletions.
4 changes: 4 additions & 0 deletions History.markdown
Expand Up @@ -4,6 +4,10 @@

* Attain Ruby 3.0 compatibility (#8124)

### Development Fixes

* Fix Kramdown converter based tests for v4.0.x (#8143)

## 4.0.0 / 2019-08-19

### Major Enhancements
Expand Down
4 changes: 2 additions & 2 deletions features/post_excerpts.feature
Expand Up @@ -108,7 +108,7 @@ Feature: Post excerpts
Then I should get a zero exit status
And I should not see "Kramdown warning" in the build output
But I should see exactly "<p>Install Jekyll</p>" in "_site/just-text-excerpt.html"
And I should see "<p>Alpha <sup id=\"fnref:1\"><a href=\"#fn:1\" class=\"footnote\">1</a></sup></p>" in "_site/text-and-footnote.html"
And I should see "<p>Omega sigma <a href=\"#fnref:1\" class=\"reversefootnote\">&#8617;</a></p>" in "_site/text-and-footnote.html"
And I should see "<p>Alpha <sup id=\"fnref:1\" role=\"doc-noteref\"><a href=\"#fn:1\" class=\"footnote\">1</a></sup></p>" in "_site/text-and-footnote.html"
And I should see "<p>Omega sigma <a href=\"#fnref:1\" class=\"reversefootnote\" role=\"doc-backlink\">&#8617;</a></p>" in "_site/text-and-footnote.html"
And I should see "<p>Read <a href=\"docs.jekyll.com\">docs</a></p>" in "_site/text-and-reference-link.html"
And I should see "<p>Check out <a href=\"jekyllrb.com\">jekyll</a></p>" in "_site/text-and-self-refencing-link.html"
91 changes: 51 additions & 40 deletions test/test_kramdown.rb
Expand Up @@ -4,10 +4,24 @@
require "rouge"

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
setup do
@config = {
"markdown" => "kramdown",
"kramdown" => {
"smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
"entity_output" => "as_char",
Expand All @@ -31,9 +45,7 @@ class TestKramdown < JekyllUnitTest
@config["kramdown"]["syntax_highlighter_opts"].keys

@config = Jekyll.configuration(@config)
@markdown = Converters::Markdown.new(@config)
@markdown.setup
Jekyll::Cache.clear
@converter = fixture_converter(@config)
end

should "not break kramdown" do
Expand All @@ -43,20 +55,32 @@ class TestKramdown < JekyllUnitTest
end

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

should "should log kramdown warnings" do
allow_any_instance_of(Kramdown::Document).to receive(:warnings).and_return(["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

context "when asked to convert smart quotes" do
should "convert" do
converter = fixture_converter(@config)
assert_match(
%r!<p>(&#8220;|“)Pit(&#8217;|’)hy(&#8221;|”)<\/p>!,
@markdown.convert(%("Pit'hy")).strip
converter.convert(%("Pit'hy")).strip
)
end

Expand All @@ -67,36 +91,22 @@ class TestKramdown < JekyllUnitTest
"smart_quotes" => "lsaquo,rsaquo,laquo,raquo",
},
}

markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
converter = fixture_converter(Utils.deep_merge_hashes(@config, override))
assert_match %r!<p>(&#171;|«)Pit(&#8250;|›)hy(&#187;|»)<\/p>!, \
markdown.convert(%("Pit'hy")).strip
converter.convert(%("Pit'hy")).strip
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
should "use the chosen highlighter if it's available" do
override = {
"highlighter" => nil,
"markdown" => "kramdown",
"kramdown" => {
"syntax_highlighter" => :coderay,
"syntax_highlighter" => "coderay",
},
}

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
puts "Hello World"
~~~
Expand All @@ -108,16 +118,16 @@ class TestKramdown < JekyllUnitTest

should "support legacy enable_coderay... for now" do
override = {
"markdown" => "kramdown",
"kramdown" => {
"enable_coderay" => true,
},
}

@config.delete("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
puts "Hello World"
~~~
Expand All @@ -129,25 +139,26 @@ class TestKramdown < JekyllUnitTest
end

should "move coderay to syntax_highlighter_opts" do
override = {
"higlighter" => nil,
"kramdown" => {
"syntax_highlighter" => "coderay",
"coderay" => {
"hello" => "world",
},
},
}
original = Kramdown::Document.method(:new)
markdown = Converters::Markdown.new(
Utils.deep_merge_hashes(@config,
"higlighter" => nil,
"markdown" => "kramdown",
"kramdown" => {
"syntax_highlighter" => "coderay",
"coderay" => {
"hello" => "world",
},
})
converter = fixture_converter(
Utils.deep_merge_hashes(@config, override)
)

expect(Kramdown::Document).to receive(:new) do |arg1, hash|
assert_equal "world", hash["syntax_highlighter_opts"]["hello"]
original.call(arg1, hash)
end

markdown.convert("hello world")
converter.convert("hello world")
end
end
end

0 comments on commit 830c1e6

Please sign in to comment.