Permit YAML blocks to end with three dots

The YAML spec permits blocks to end with three dots (...) in addition to
three dashes (---): http://www.yaml.org/spec/1.2/spec.html#id2760395. Some
programs that work with Jekyll (e.g., Pandoc) prefer the dots to dashes. This
commit permits the YAML metadata block to end with either dots or dashes. It
includes tests.

Signed-off-by: Parker Moore <parkrmoore@gmail.com>
This commit is contained in:
Lincoln Mullen 2014-03-03 09:55:07 -05:00 committed by Parker Moore
parent 21ea105a82
commit 52ac2b3850
4 changed files with 19 additions and 2 deletions

View File

@ -43,7 +43,7 @@ module Jekyll
begin
self.content = File.read(File.join(base, name),
merged_file_read_opts(opts))
if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
self.content = $POSTMATCH
self.data = SafeYAML.load($1)
end

View File

@ -0,0 +1,5 @@
---
title: Test Post Where YAML Ends in Dots
...
# Test

View File

@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
end
should "ensure post count is as expected" do
assert_equal 39, @site.posts.size
assert_equal 40, @site.posts.size
end
should "insert site.posts into the index" do

View File

@ -127,6 +127,18 @@ class TestPost < Test::Unit::TestCase
end
end
context "with three dots ending YAML header" do
setup do
@real_file = "2014-03-03-yaml-with-dots.md"
end
should "should read the YAML header" do
@post.read_yaml(@source, @real_file)
assert_equal({"title" => "Test Post Where YAML Ends in Dots"},
@post.data)
end
end
context "with embedded triple dash" do
setup do
@real_file = "2010-01-08-triple-dash.markdown"