From ca05d89a1075c3b4af8cc7716518dc65386c7a68 Mon Sep 17 00:00:00 2001 From: benweet Date: Fri, 14 Mar 2014 14:57:22 +0000 Subject: [PATCH] Fixed parsing of non YAML front matter. Fixes #350 --- public/res/extensions/yamlFrontMatterParser.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/public/res/extensions/yamlFrontMatterParser.js b/public/res/extensions/yamlFrontMatterParser.js index 0366b428..7eca45fd 100644 --- a/public/res/extensions/yamlFrontMatterParser.js +++ b/public/res/extensions/yamlFrontMatterParser.js @@ -1,7 +1,8 @@ define([ + "underscore", "classes/Extension", "yaml-js", -], function(Extension, YAML) { +], function(_, Extension, YAML) { var yamlFrontMatterParser = new Extension("yamlFrontMatterParser", "YAML front matter"); @@ -26,10 +27,16 @@ define([ fileDesc.frontMatter = undefined; try { fileDesc.frontMatter = YAML.parse(yaml); + if(!_.isObject(fileDesc.frontMatter)) { + fileDesc.frontMatter = undefined; + } fileDesc.frontMatter._yaml = yaml; fileDesc.frontMatter._frontMatter = results[1]; } - catch (e) {} + catch (e) { + eventMgr.onMarkdownTrim(0); + return text; + } } eventMgr.onMarkdownTrim((results[1] || '').length); return results[3];