1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

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
...
```
This commit is contained in:
Christian Höltje 2014-08-14 22:15:17 -04:00
parent fae0e00f42
commit 6895f30ff3
3 changed files with 25 additions and 1 deletions

View file

@ -21,6 +21,17 @@ Feature: YAML Front Matter
Then I should see "<?php"
Then I should not see "---"
Scenario: Rendering markdown (template-less) (yaml)
Given the Server is running at "frontmatter-app"
When I go to "/front-matter-pandoc.html"
Then I should see ">This is a document</h1>"
Then I should see "<p>To be or not to be</p>"
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"

View file

@ -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 %>.

View file

@ -119,7 +119,7 @@ module Middleman::CoreExtensions
# @param [String] content
# @return [Array<Hash, String>]
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, '')