From 6895f30ff33d5bac178ba3ad155b73716fe71ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20H=C3=B6ltje?= Date: Thu, 14 Aug 2014 22:15:17 -0400 Subject: [PATCH] Accept pandoc-style YAML frontmatter Pandoc (and some other tools) have decided to end their YAML frontmatter with `...` instead of `---`. In the name of flexibility, this patch allows either to mark the end of YAML frontmatter. Example: ``` --- title: No place like home ... ``` --- middleman-core/features/front-matter.feature | 11 +++++++++++ .../source/front-matter-pandoc.html.md.erb | 13 +++++++++++++ .../middleman-core/core_extensions/front_matter.rb | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 middleman-core/fixtures/frontmatter-app/source/front-matter-pandoc.html.md.erb diff --git a/middleman-core/features/front-matter.feature b/middleman-core/features/front-matter.feature index a0440f55..4625906f 100644 --- a/middleman-core/features/front-matter.feature +++ b/middleman-core/features/front-matter.feature @@ -21,6 +21,17 @@ Feature: YAML Front Matter Then I should see "This is a document" + Then I should see "

To be or not to be

" + Then I should see "The meaning of life is 42" + Then I should not see "..." + Then I should not see "layout: false" + Then I should not see "title: Pandoc likes trailing dots..." + + Scenario: YAML not on first line, no encoding Given the Server is running at "frontmatter-app" When I go to "/front-matter-line-2.html" diff --git a/middleman-core/fixtures/frontmatter-app/source/front-matter-pandoc.html.md.erb b/middleman-core/fixtures/frontmatter-app/source/front-matter-pandoc.html.md.erb new file mode 100644 index 00000000..b800a11b --- /dev/null +++ b/middleman-core/fixtures/frontmatter-app/source/front-matter-pandoc.html.md.erb @@ -0,0 +1,13 @@ +--- +layout: false +title: Pandoc likes trailing dots... +dotty_string: "..." +famous_quote: To be or not to be +popular_number: 42 +... + +# This is a document + +<%= current_page.data.famous_quote %> + +The meaning of life is <%= current_page.data.popular_number %>. diff --git a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb index b9f09647..ac683db7 100644 --- a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb +++ b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb @@ -119,7 +119,7 @@ module Middleman::CoreExtensions # @param [String] content # @return [Array] def parse_yaml_front_matter(content, full_path) - yaml_regex = /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m + yaml_regex = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m if content =~ yaml_regex content = content.sub(yaml_regex, '')