diff --git a/res/eventMgr.js b/res/eventMgr.js index 3caf7cd5..a7313a6d 100644 --- a/res/eventMgr.js +++ b/res/eventMgr.js @@ -6,7 +6,7 @@ define([ "classes/Extension", "settings", "text!html/settingsExtensionsAccordion.html", -// "extensions/yamlFrontMatterParser", + "extensions/yamlFrontMatterParser", "extensions/markdownSectionParser", "extensions/partialRendering", "extensions/buttonMarkdownSyntax", diff --git a/res/extensions/yamlFrontMatterParser.js b/res/extensions/yamlFrontMatterParser.js index 536e24d1..15063723 100644 --- a/res/extensions/yamlFrontMatterParser.js +++ b/res/extensions/yamlFrontMatterParser.js @@ -1,33 +1,37 @@ define([ "classes/Extension", - "text!html/yamlFrontMatterParserSettingsBlock.html", "js-yaml", -], function(Extension, yamlFrontMatterParserSettingsBlock) { + ], function(Extension, yamlFrontMatterParserSettingsBlock) { - var yamlFrontMatterParser = new Extension("yamlFrontMatterParser", "YAML front matter", true); - yamlFrontMatterParser.settingsBlock = yamlFrontMatterParserSettingsBlock; + var yamlFrontMatterParser = new Extension("yamlFrontMatterParser", "YAML front matter"); var eventMgr = undefined; yamlFrontMatterParser.onEventMgrCreated = function(eventMgrParameter) { eventMgr = eventMgrParameter; }; + var fileDesc = undefined; + yamlFrontMatterParser.onFileSelected = function(fileDescParam) { + fileDesc = fileDescParam; + }; + + var regex = /^(\s*-{3}\s*\n([\w\W]+?)\n\s*-{3}\s*\n)?([\w\W]*)*/; yamlFrontMatterParser.onPagedownConfigure = function(editor) { var converter = editor.getConverter(); converter.hooks.chain("preConversion", function(text) { - try { - var re = /^(\s*-{3}\s*\n([\w\W]+?)\n\s*-{3}\s*\n)?([\w\W]*)*/, results = re.exec(text), conf = {}, yaml; + var results = regex.exec(text), + yaml; - if((yaml = results[2])) { - conf = jsyaml.load(yaml); - console.log(conf); + if ((yaml = results[2]) && (!fileDesc.frontMatter || fileDesc.frontMatter._yaml != yaml)) { + fileDesc.frontMatter = undefined; + try { + fileDesc.frontMatter = jsyaml.load(yaml); + fileDesc.frontMatter._yaml = yaml; } - eventMgr.onMarkdownTrim(results[1].length); - return results[3]; - } - catch(e) { - return text; + catch (e) {} } + eventMgr.onMarkdownTrim((results[1] || '').length); + return results[3]; }); }; diff --git a/res/html/yamlFrontMatterParserSettingsBlock.html b/res/html/yamlFrontMatterParserSettingsBlock.html deleted file mode 100644 index e4ffbf5b..00000000 --- a/res/html/yamlFrontMatterParserSettingsBlock.html +++ /dev/null @@ -1,3 +0,0 @@ -

Parses YAML front matter block at the begining of the document.

-
Interpreted variables: title, published, category/categories/tags
-More info \ No newline at end of file