handle liquid tags in excerpts robustly (#6891)
Merge pull request 6891
This commit is contained in:
parent
d1aa1cfd5b
commit
d09db32d10
|
@ -120,6 +120,10 @@ module Jekyll
|
||||||
# Excerpts are rendered same time as content is rendered.
|
# Excerpts are rendered same time as content is rendered.
|
||||||
#
|
#
|
||||||
# Returns excerpt String
|
# Returns excerpt String
|
||||||
|
|
||||||
|
LIQUID_TAG_REGEX = %r!{%\s*(\w+).+\s*%}!m
|
||||||
|
MKDWN_LINK_REF_REGEX = %r!^ {0,3}\[[^\]]+\]:.+$!
|
||||||
|
|
||||||
def extract_excerpt(doc_content)
|
def extract_excerpt(doc_content)
|
||||||
head, _, tail = doc_content.to_s.partition(doc.excerpt_separator)
|
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"
|
# partitioning resulted in leaving the closing tag somewhere in the "tail"
|
||||||
# partition.
|
# partition.
|
||||||
if head.include?("{%")
|
if head.include?("{%")
|
||||||
head =~ %r!{%\s*(\w+).+\s*%}!
|
head =~ LIQUID_TAG_REGEX
|
||||||
tag_name = Regexp.last_match(1)
|
tag_name = Regexp.last_match(1)
|
||||||
|
|
||||||
if liquid_block?(tag_name) && head.match(%r!{%\s*end#{tag_name}\s*%}!).nil?
|
if liquid_block?(tag_name) && head.match(%r!{%\s*end#{tag_name}\s*%}!).nil?
|
||||||
|
@ -139,7 +143,7 @@ module Jekyll
|
||||||
if tail.empty?
|
if tail.empty?
|
||||||
head
|
head
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
layout: post
|
layout: post
|
||||||
---
|
---
|
||||||
|
|
||||||
{% if page.layout == "post" %}
|
{% if
|
||||||
|
page.layout == "post" %}
|
||||||
You’ll find this post in your `_posts` directory.
|
You’ll find this post in your `_posts` directory.
|
||||||
To add new posts, simply add a file in the `_posts` directory.
|
To add new posts, simply add a file in the `_posts` directory.
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in New Issue