From d09db32d10e206aa5c45843155602ead80bbcc92 Mon Sep 17 00:00:00 2001 From: ashmaroli Date: Thu, 12 Apr 2018 21:07:42 +0530 Subject: [PATCH] handle liquid tags in excerpts robustly (#6891) Merge pull request 6891 --- lib/jekyll/excerpt.rb | 8 ++++++-- .../2018-01-28-closed-liquid-block-excerpt.markdown | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/excerpt.rb b/lib/jekyll/excerpt.rb index 2dfbe958..c711a585 100644 --- a/lib/jekyll/excerpt.rb +++ b/lib/jekyll/excerpt.rb @@ -120,6 +120,10 @@ module Jekyll # Excerpts are rendered same time as content is rendered. # # Returns excerpt String + + LIQUID_TAG_REGEX = %r!{%\s*(\w+).+\s*%}!m + MKDWN_LINK_REF_REGEX = %r!^ {0,3}\[[^\]]+\]:.+$! + def extract_excerpt(doc_content) head, _, tail = doc_content.to_s.partition(doc.excerpt_separator) @@ -127,7 +131,7 @@ module Jekyll # partitioning resulted in leaving the closing tag somewhere in the "tail" # partition. if head.include?("{%") - head =~ %r!{%\s*(\w+).+\s*%}! + head =~ LIQUID_TAG_REGEX tag_name = Regexp.last_match(1) if liquid_block?(tag_name) && head.match(%r!{%\s*end#{tag_name}\s*%}!).nil? @@ -139,7 +143,7 @@ module Jekyll if tail.empty? head else - head.to_s.dup << "\n\n" << tail.scan(%r!^ {0,3}\[[^\]]+\]:.+$!).join("\n") + head.to_s.dup << "\n\n" << tail.scan(MKDWN_LINK_REF_REGEX).join("\n") end end diff --git a/test/source/_posts/2018-01-28-closed-liquid-block-excerpt.markdown b/test/source/_posts/2018-01-28-closed-liquid-block-excerpt.markdown index 599a0194..991ebf84 100644 --- a/test/source/_posts/2018-01-28-closed-liquid-block-excerpt.markdown +++ b/test/source/_posts/2018-01-28-closed-liquid-block-excerpt.markdown @@ -2,7 +2,8 @@ layout: post --- -{% if page.layout == "post" %} +{% if + page.layout == "post" %} You’ll find this post in your `_posts` directory. To add new posts, simply add a file in the `_posts` directory. {% endif %}