Hexo: Colons in blog post titles break formatting

Created on 8 Sep 2014  路  6Comments  路  Source: hexojs/hexo

If I create a post like this:

title: Part One: The Things
author: Jonathan Daugherty
date: 2014-09-08 11:30:00

---
Stuff!

then the resulting HTML is broken, with the title and author fields actually appearing in the HTML and the date field being considered the heading of the blog post. If I remove the colon, the problem goes away.

question

Most helpful comment

Hexo uses directly js-yaml (after some tabulator escaping).

var yaml = require('js-yaml'),
  escape = require('../../util').escape.yaml;

module.exports = function(data){
  return yaml.load(escape(data.text));
};

In my eyes, you have two choices:

a) use quotation marks, as in title: "my title : with colon" to simply escape the title. There are some more to find in the YAML specs

b) extend the js-yaml library

You wrote "He tried escaping the colon within the title, but doing so had no effect."... hmm what exactly have you tried? For me option a) worked in a quick test. Following the specs "title: my title : with colon" should work, too, but I didn't test this one.

All 6 comments

In case it's not obvious, when Jonathan writes, "If I remove the colon, the problem goes away," he means removing the colon from the title stanza. So

title: Part One: The Things

will fail, while

title: Part One - The Things

will succeed. He tried escaping the colon within the title, but doing so had no effect.

As the colon character is used as a delimiter in most (all ?) static site generators for the front matter keys, then its not surprising that a colon in the name of a title causes an issue.

This same issue occurs if you push markdown to Github.

I just substitute the - character instead (as you show in your example)

A great solution would be to take the first colon as delimiter. This doesn't happen when the timestamp is parsed, so clearly some allowance for colons has already been made, but a general-purpose solution would be to parse up to the first colon and take the rest of the line as the field value.

Hexo uses directly js-yaml (after some tabulator escaping).

var yaml = require('js-yaml'),
  escape = require('../../util').escape.yaml;

module.exports = function(data){
  return yaml.load(escape(data.text));
};

In my eyes, you have two choices:

a) use quotation marks, as in title: "my title : with colon" to simply escape the title. There are some more to find in the YAML specs

b) extend the js-yaml library

You wrote "He tried escaping the colon within the title, but doing so had no effect."... hmm what exactly have you tried? For me option a) worked in a quick test. Following the specs "title: my title : with colon" should work, too, but I didn't test this one.

Use quotation marks. Take a look at this:

Great; we didn't know double quotes were the right way to do this. We tried backslashes, as one does. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fabien-h picture fabien-h  路  22Comments

SukkaW picture SukkaW  路  25Comments

201507 picture 201507  路  32Comments

pod4g picture pod4g  路  24Comments

noraj picture noraj  路  24Comments