tylerbutler / engineer

A static website generator written in Python.
http://engineer.readthedocs.org/
MIT License
25 stars 3 forks source link

YAML parsing error: fields cannot have ':' in the body #60

Closed pridkett closed 11 years ago

pridkett commented 11 years ago

The YAML processor chokes if a field has a colon in it's body. This means that it is currently impossible to have a blog post title with a colon in it. For example, if I have a blog post with the following title field:

title: Great News: I cured cancer!

Running engineer build will produce the following error:

SKIPPING '2013-04-17-i-cured-cancer.markdown': metadata is invalid. YAML error parsing metadata.

Changing the YAML to:

title: Great News: I cured cancer!

Seems to work, but is a rather janky workaround.

tylerbutler commented 11 years ago

This unfortunately isn't valid YAML, and I'm not sure this is something I can easily fix in Engineer since it's the YAML parser that is complaining. I could catch the exception and try to be smart about it, but I am more inclined to require that the YAML be 'well formed.' The easiest way to work around this is to enclose your title in either single or double quotes.

title: "Great News: I cured cancer!"

There are some details of the options for representing strings in YAML at http://pyyaml.org/wiki/PyYAMLDocumentation#Scalars:

Each style has its own quirks. A plain scalar does not use indicators to denote its start and end, therefore it's the most restricted style. Its natural applications are names of attributes and parameters.

Using single-quoted scalars, you may express any value that does not contain special characters. No escaping occurs for single quoted scalars except that a pair of adjacent quotes '' is replaced with a lone single quote '.

Double-quoted is the most powerful style and the only style that can express any scalar value. Double-quoted scalars allow escaping. Using escaping sequences \x** and \u****, you may express any ASCII or Unicode character.