Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Commit

Permalink
front matter support when parsing (not tested) #49
Browse files Browse the repository at this point in the history
  • Loading branch information
demiurgosoft committed Sep 25, 2016
1 parent ba413c6 commit 5484fb0
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The aim of this package is to provide an easy-to-use toolbox for markdown-relate
* **GitHub:** <https://github.com/angrykoala/yamp>
* **Npm:** <https://www.npmjs.com/package/yamp>

{{toc}}

## Features
* HTML conversion
Expand Down
9 changes: 9 additions & 0 deletions app/parsers/front_matter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

const frontMatter = require('front-matter');

module.exports = function(content, done) {
let data = frontMatter(content);

done(null, data.body, data.attributes);
};
37 changes: 23 additions & 14 deletions app/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const path = require('path');
const titleParser = require('./parsers/title_parser');
const xejsParser = require('./parsers/xejs_parser');
const tocParser = require('./parsers/toc_parser');
const frontMatterParser = require('./parsers/front_matter');

const resourcesPath = __dirname + "/../resources";

Expand All @@ -15,7 +16,8 @@ const defaultOptions = {
style: true,
minify: false,
tags: true,
koala: false
koala: false,
frontMatter: true
};

function removeFileExtension(filename) {
Expand Down Expand Up @@ -92,20 +94,27 @@ module.exports = class Renderer {
this.beforeLoad(file);
this.fileLoader(file, (err, rawContent) => {
if (err) return done(err);
tocParser(rawContent, (err,res) => {
if (err) console.log("Warning:" + err);
rawContent=res;
this.contentParse(rawContent, (err, content) => {
if (err) return done(err);
let title = this.getTitle(content);
let templateData = this.setTemplateOptions();
templateData.content = content;
templateData.title = title;
this.beforeRender(templateData);
this.templateRender(templateData, (err, res) => {
frontMatterParser(rawContent, (err, res, attr) => {
if (err) console.log("Warning:" + err);
if (this.options.frontMatter) {
rawContent = res;
Object.assign(this.options, attr);
}
tocParser(rawContent, (err, res) => {
if (err) console.log("Warning:" + err);
rawContent = res;
this.contentParse(rawContent, (err, content) => {
if (err) return done(err);
this.afterRender(res);
this.fileOutput(res, done);
let title = this.getTitle(content);
let templateData = this.setTemplateOptions();
templateData.content = content;
templateData.title = title;
this.beforeRender(templateData);
this.templateRender(templateData, (err, res) => {
if (err) return done(err);
this.afterRender(res);
this.fileOutput(res, done);
});
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions bin/yamp_cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ commander.version(version)
.option("--minify", "minifies html output")
.option("--no-highlight", "disable code highlight")
.option("--no-tags", "disable markdown yamp tags")
.option("--no-front-matter", "disable initial yaml options parsing")
.option("-k, --koala", "your output will be koalafied")
.parse(process.argv);
if (!inputFile) {
Expand All @@ -43,6 +44,7 @@ let rendererOptions = {
minify: commander.minify || false,
title: commander.title,
tags: commander.tags,
frontMatter: commander.frontMatter,
koala: commander.koala
};

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"commander": "^2.9.0",
"ejs": "^2.5.2",
"front-matter": "^2.1.0",
"highlight.js": "^9.6.0",
"html-minifier": "^3.0.3",
"html-pdf": "^2.1.0",
Expand Down
12 changes: 12 additions & 0 deletions test/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,16 @@ describe("Parsers", function() {

});
});
describe("Front Matter parser",function(done){
it.skip("Default Parser",function(){

});
it.skip("Parsing file",function(){

});
it.skip("Parsing file disabled",function(){


});
});
});
4 changes: 4 additions & 0 deletions test/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ describe("Renderers", function() {
it.skip("Koala", function() {


});
it.skip("Fron Matter",function(){


});
});
it.skip("Extending class", function() {
Expand Down

0 comments on commit 5484fb0

Please sign in to comment.