From 88d63c930390d088bbb2889d5357a5a353b745ab Mon Sep 17 00:00:00 2001 From: Kyle Barbour Date: Fri, 4 Jan 2019 04:30:29 -0500 Subject: [PATCH] Excerpt handling of custom and intermediate tags (#7382) Merge pull request 7382 --- lib/jekyll/excerpt.rb | 2 +- test/source/_plugins/custom_block.rb | 14 +++++++++ .../_posts/2018-11-15-excerpt-liquid-block.md | 29 +++++++++++++++++++ test/test_excerpt.rb | 25 ++++++++++++++++ test/test_generated_site.rb | 2 +- 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 test/source/_plugins/custom_block.rb create mode 100644 test/source/_posts/2018-11-15-excerpt-liquid-block.md diff --git a/lib/jekyll/excerpt.rb b/lib/jekyll/excerpt.rb index 4a915152..91fea1c5 100644 --- a/lib/jekyll/excerpt.rb +++ b/lib/jekyll/excerpt.rb @@ -167,7 +167,7 @@ module Jekyll def liquid_block?(tag_name) return false unless tag_name.is_a?(String) - return false if tag_name.start_with?("end") + return false unless Liquid::Template.tags[tag_name] Liquid::Template.tags[tag_name].ancestors.include?(Liquid::Block) rescue NoMethodError diff --git a/test/source/_plugins/custom_block.rb b/test/source/_plugins/custom_block.rb new file mode 100644 index 00000000..eee0fbaa --- /dev/null +++ b/test/source/_plugins/custom_block.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# For testing excerpt handling of custom tags + +module Jekyll + class DoNothingBlock < Liquid::Block + end + + class DoNothingOther < Liquid::Tag + end +end + +Liquid::Template.register_tag("do_nothing", Jekyll::DoNothingBlock) +Liquid::Template.register_tag("do_nothing_other", Jekyll::DoNothingOther) diff --git a/test/source/_posts/2018-11-15-excerpt-liquid-block.md b/test/source/_posts/2018-11-15-excerpt-liquid-block.md new file mode 100644 index 00000000..7995d9db --- /dev/null +++ b/test/source/_posts/2018-11-15-excerpt-liquid-block.md @@ -0,0 +1,29 @@ +--- +title: liquid_block excerpt test with open tags in excerpt +layout: post +--- + +{% assign company = "Yoyodyne" %} +{% do_nothing_other %} +{% do_nothing %} + {% unless false %} + {% for i in (1..10) %} + {% if true %} + {% raw %} + EVIL! PURE AND SIMPLE FROM THE EIGHTH DIMENSION! + {% endraw %} + {% elsif false %} + No matter where you go, there you are. + {% break %} + {% else %} + {% case company %} + {% when "Yoyodyne" %} + Buckaroo Banzai + {% else %} + {% continue %} + + {% endcase %} + {% endif %} + {% endfor %} + {% endunless %} +{% enddo_nothing %} diff --git a/test/test_excerpt.rb b/test/test_excerpt.rb index d97dbe1b..dd0acdf7 100644 --- a/test/test_excerpt.rb +++ b/test/test_excerpt.rb @@ -274,4 +274,29 @@ class TestExcerpt < JekyllUnitTest assert_equal true, @excerpt.is_a?(Jekyll::Excerpt) end end + + context "An excerpt with Liquid tags" do + setup do + clear_dest + @site = fixture_site + @post = setup_post("2018-11-15-excerpt-liquid-block.md") + @excerpt = @post.data["excerpt"] + + assert_includes @post.content.split("\n\n")[0].strip, "{% continue %}" + assert_equal true, Jekyll::DoNothingBlock.ancestors.include?(Liquid::Block) + assert_equal false, Jekyll::DoNothingOther.ancestors.include?(Liquid::Block) + assert_match "Jekyll::DoNothingBlock", Liquid::Template.tags["do_nothing"].name + assert_match "Jekyll::DoNothingOther", Liquid::Template.tags["do_nothing_other"].name + end + + should "close open block tags, including custom tags, and ignore others" do + assert_includes @excerpt.content, "{% endcase %}" + assert_includes @excerpt.content, "{% endif %}" + assert_includes @excerpt.content, "{% endfor %}" + assert_includes @excerpt.content, "{% endunless %}" + assert_includes @excerpt.content, "{% enddo_nothing %}" + refute_includes @excerpt.content, "{% enddo_nothing_other %}" + assert_equal true, @excerpt.is_a?(Jekyll::Excerpt) + end + end end diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 56c2bf4e..c9b3595c 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -16,7 +16,7 @@ class TestGeneratedSite < JekyllUnitTest end should "ensure post count is as expected" do - assert_equal 57, @site.posts.size + assert_equal 58, @site.posts.size end should "insert site.posts into the index" do