Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front matter documents as valid YAML streams #5

Open
trans opened this issue Nov 3, 2016 · 1 comment
Open

Front matter documents as valid YAML streams #5

trans opened this issue Nov 3, 2016 · 1 comment

Comments

@trans
Copy link
Member

trans commented Nov 3, 2016

YAML front matter has become a common design pattern for static site generation tools. An example of which looks like:

---
title: Some Title
date: 2016-11-02

---
# Some Subtitle
This is a *blog* post ...

And it goes on ...

Notice that this isn't a valid YAML stream, but it is very close. The problem is two fold. First the block scalar string, holding the text of the post and written in Markdown, is not indented. Secondly the string will be folded so the blank line in the post text will be lost, even though it is significant to the Markdown.

I tend to think its a good idea to follow usage to see how a spec might adapt, and here we have a very good case where YAML might be able to do that. Would it be possible for the next generation of YAML to see the above as a valid stream?

I've suggested that plain scalars be treated as literals before. I still think that is a better approach, b/c an application can always remove lines, but it can't get them back if they've already been stripped out.

Allowing block strings flush to left without indention is a little tricker. Maybe it is not possible to do for all nodes, e.g. block sequence

-
this
-
that

But if the content of a document is just one big string, then it seems that at least should be doable.

@jackmcdade
Copy link

Supporting a Front Matter doc as valid YAML is very interesting. We build Statamic, a flat file CMS (not static site generator) that uses this format. Usually it's in a .md file, so we pre-process them by extracting everything between the first two --- delineators and parse as YAML, leaving the rest of the doc as Markdown.

The biggest downside to this is we lose the ability to have multiple docs in a stream. We could open up some interesting options if there was native support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants