From 52ac2b3850e25c783ec31c46eda948cffd861452 Mon Sep 17 00:00:00 2001 From: Lincoln Mullen Date: Mon, 3 Mar 2014 09:55:07 -0500 Subject: [PATCH] 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 --- lib/jekyll/convertible.rb | 2 +- test/source/_posts/2014-03-03-yaml-with-dots.md | 5 +++++ test/test_generated_site.rb | 2 +- test/test_post.rb | 12 ++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/source/_posts/2014-03-03-yaml-with-dots.md diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index bc87f336..4818328a 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -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 diff --git a/test/source/_posts/2014-03-03-yaml-with-dots.md b/test/source/_posts/2014-03-03-yaml-with-dots.md new file mode 100644 index 00000000..09639b23 --- /dev/null +++ b/test/source/_posts/2014-03-03-yaml-with-dots.md @@ -0,0 +1,5 @@ +--- +title: Test Post Where YAML Ends in Dots +... + +# Test diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 5059dd12..d960e743 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -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 diff --git a/test/test_post.rb b/test/test_post.rb index 7d4ab599..534e0297 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -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"