From 9b09d8a8e810bca2c528cbe44beb6a333ea4797b Mon Sep 17 00:00:00 2001 From: Eloy Espinaco Date: Mon, 8 Aug 2016 11:28:53 -0300 Subject: [PATCH] Add support for indented link references on excerpt Excerpt link reference extraction is missing all the indented references at the bottom of the page. Markdown specify that those can be indented up to three spaces. --- lib/jekyll/excerpt.rb | 2 +- ...16-08-16-indented-link-references.markdown | 16 ++++++++++++ test/test_excerpt.rb | 26 +++++++++++++++++++ test/test_generated_site.rb | 2 +- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/source/_posts/2016-08-16-indented-link-references.markdown diff --git a/lib/jekyll/excerpt.rb b/lib/jekyll/excerpt.rb index c181cb68..34a2e65c 100644 --- a/lib/jekyll/excerpt.rb +++ b/lib/jekyll/excerpt.rb @@ -118,7 +118,7 @@ module Jekyll if tail.empty? head else - "" << head << "\n\n" << tail.scan(%r!^\[[^\]]+\]:.+$!).join("\n") + "" << head << "\n\n" << tail.scan(%r!^ {0,3}\[[^\]]+\]:.+$!).join("\n") end end end diff --git a/test/source/_posts/2016-08-16-indented-link-references.markdown b/test/source/_posts/2016-08-16-indented-link-references.markdown new file mode 100644 index 00000000..f5366162 --- /dev/null +++ b/test/source/_posts/2016-08-16-indented-link-references.markdown @@ -0,0 +1,16 @@ +--- +--- + +This is the first paragraph. It [has][link_0] [lots][link_1] [of][link_2] +[links][link_3]. + +This is the second paragraph. It has sample code that should not be extracted: + + [fakelink]: www.invalid.com + +And here are the real links: + +[link_0]: www.example.com/0 + [link_1]: www.example.com/1 + [link_2]: www.example.com/2 + [link_3]: www.example.com/3 diff --git a/test/test_excerpt.rb b/test/test_excerpt.rb index b8169794..671d55af 100644 --- a/test/test_excerpt.rb +++ b/test/test_excerpt.rb @@ -119,6 +119,32 @@ class TestExcerpt < JekyllUnitTest assert @extracted_excerpt.content.include?("http://www.jekyllrb.com/") end end + + context "with indented link references" do + setup do + @post = setup_post("2016-08-16-indented-link-references.markdown") + @excerpt = @post.excerpt + end + + should "contain all refs at the bottom of the page" do + (0..3).each do |i| + assert_match "[link_#{i}]: www.example.com/#{i}", @excerpt.content + end + end + + should "ignore indented code" do + refute_match "[fakelink]:", @excerpt.content + end + + should "render links properly" do + @rendered_post = @post.dup + do_render(@rendered_post) + output = @rendered_post.data["excerpt"].output + (0..3).each do |i| + assert_includes output, "" + end + end + end end end diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 8373f0fc..31784054 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -11,7 +11,7 @@ class TestGeneratedSite < JekyllUnitTest end should "ensure post count is as expected" do - assert_equal 49, @site.posts.size + assert_equal 50, @site.posts.size end should "insert site.posts into the index" do