Support for YAML front matter
This commit is contained in:
parent
4c327ad586
commit
a9b9c3eb5e
@ -6,7 +6,7 @@ define([
|
||||
"classes/Extension",
|
||||
"settings",
|
||||
"text!html/settingsExtensionsAccordion.html",
|
||||
// "extensions/yamlFrontMatterParser",
|
||||
"extensions/yamlFrontMatterParser",
|
||||
"extensions/markdownSectionParser",
|
||||
"extensions/partialRendering",
|
||||
"extensions/buttonMarkdownSyntax",
|
||||
|
@ -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];
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
<p>Parses YAML front matter block at the begining of the document.</p>
|
||||
<blockquote><b>Interpreted variables:</b> <i>title, published, category/categories/tags</i></blockquote>
|
||||
<span class="help-block pull-right"><a target="_blank" href="http://jekyllrb.com/docs/frontmatter/">More info</a></span>
|
Loading…
Reference in New Issue
Block a user