Skip to content

Commit

Permalink
chore: upgrade dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
a60814billy committed Feb 4, 2018
1 parent 6313095 commit 8b0cf4c
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.js]
indent_style = space
indent_size = 2
44 changes: 23 additions & 21 deletions lib/meta-marked.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
/* © 2013-2014 j201
* https://github.com/j201/meta-marked */

var marked = require('marked');
var yaml = require('js-yaml');
const marked = require("marked");
const yaml = require("js-yaml");

// Splits the given string into a meta section and a markdown section if a meta section is present, else returns null
function splitInput(str) {
if (str.slice(0, 3) !== '---') return;
if (str.slice(0, 3) !== "---") return;

var matcher = /\n(\.{3}|-{3})/g;
var metaEnd = matcher.exec(str);
const matcher = /\n(\.{3}|-{3})/g;
const metaEnd = matcher.exec(str);

return metaEnd && [str.slice(0, metaEnd.index), str.slice(matcher.lastIndex)];
return metaEnd && [str.slice(0, metaEnd.index), str.slice(matcher.lastIndex)];
}

var metaMarked = function(src, opt, callback) {
if (Object.prototype.toString.call(src) !== '[object String]')
throw new TypeError('First parameter must be a string.');

var mySplitInput = splitInput(src);

return mySplitInput ? {
meta : yaml.safeLoad(mySplitInput[0]),
html : marked(mySplitInput[1], opt, callback),
markdown: mySplitInput[1]
} : {
meta : null,
html : marked(src, opt, callback),
markdown: src
};
const metaMarked = function(src, opt, callback) {
if (Object.prototype.toString.call(src) !== "[object String]")
throw new TypeError("First parameter must be a string.");

const mySplitInput = splitInput(src);

return mySplitInput
? {
meta: yaml.safeLoad(mySplitInput[0]),
html: marked(mySplitInput[1], opt, callback),
markdown: mySplitInput[1]
}
: {
meta: null,
html: marked(src, opt, callback),
markdown: src
};
};

metaMarked.__proto__ = marked; // Yeah, it's non-standard, but it's better than copying everything over
Expand Down
50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"name": "meta-marked",
"version": "0.4.2",
"description": "The 'marked' markdown processor with a simple metadata system.",
"main": "./lib/meta-marked.js",
"keywords": [
"markdown",
"metadata",
"html"
],
"author": "j201 <j201.alex@gmail.com> (http://j201.github.io/)",
"license": "MIT",
"repository" : {
"type" : "git",
"url" : "git://github.com/j201/meta-marked.git"
},
"dependencies" : {
"marked" : "~0.3.6",
"js-yaml" : "~3.5.5"
},
"devDependencies" : {
"tape" : "~4.2.0"
},
"scripts" : {
"test" : "node ./test/test"
}
"name": "meta-marked",
"version": "0.4.3",
"description": "The 'marked' markdown processor with a simple metadata system.",
"main": "./lib/meta-marked.js",
"keywords": [
"markdown",
"metadata",
"html"
],
"author": "j201 <j201.alex@gmail.com> (http://j201.github.io/)",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/hackmdio/meta-marked"
},
"dependencies": {
"marked": "~0.3.12",
"js-yaml": "~3.10.0"
},
"devDependencies": {
"tape": "~4.8.0"
},
"scripts": {
"test": "node ./test/test"
}
}
67 changes: 43 additions & 24 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
var metaMarked = require('../lib/meta-marked.js');
var marked = require('marked');
var tape = require('tape');
const metaMarked = require("../lib/meta-marked.js");
const marked = require("marked");
const tape = require("tape");

tape("meta-marked", function(t) {
var basicTestText = "---\nTitle: My awesome markdown file\nAuthor: Me\nScripts:\n - js/doStuff.js\n - js/doMoreStuff.js\n...\n\n##Header\nRegular text and stuff goes here. \n\n...\n\n---\n";
var basicTestMD = "\n\n##Header\nRegular text and stuff goes here. \n\n...\n\n---\n";
var basicResult = metaMarked(basicTestText);
var basicTestText =
"---\nTitle: My awesome markdown file\nAuthor: Me\nScripts:\n - js/doStuff.js\n - js/doMoreStuff.js\n...\n\n##Header\nRegular text and stuff goes here. \n\n...\n\n---\n";
var basicTestMD =
"\n\n##Header\nRegular text and stuff goes here. \n\n...\n\n---\n";
var basicResult = metaMarked(basicTestText);

t.ok(basicResult.meta, "result.meta exists");
t.ok(basicResult.html, "result.html exists");
t.ok(basicResult.markdown, "result.markdown exists");
t.ok(basicResult.meta, "result.meta exists");
t.ok(basicResult.html, "result.html exists");
t.ok(basicResult.markdown, "result.markdown exists");

t.equal(basicResult.html, marked(basicTestMD), "result.html matches the marked output");
t.deepEqual(basicResult.meta, {
"Title": "My awesome markdown file",
"Author": "Me",
"Scripts": [
"js/doStuff.js",
"js/doMoreStuff.js"
]
}, "result.meta matches the yml output");
t.equal(basicResult.markdown, basicTestMD, "result.markdown matches the markdown input");
t.equal(
basicResult.html,
marked(basicTestMD),
"result.html matches the marked output"
);
t.deepEqual(
basicResult.meta,
{
Title: "My awesome markdown file",
Author: "Me",
Scripts: ["js/doStuff.js", "js/doMoreStuff.js"]
},
"result.meta matches the yml output"
);
t.equal(
basicResult.markdown,
basicTestMD,
"result.markdown matches the markdown input"
);

t.equal(metaMarked.noMeta(basicTestMD), marked(basicTestMD), ".noMeta produces the same output as marked");
t.equal(
metaMarked.noMeta(basicTestMD),
marked(basicTestMD),
".noMeta produces the same output as marked"
);

t.equal(metaMarked.lexer, marked.lexer, "inherits from marked");
t.equal(metaMarked.lexer, marked.lexer, "inherits from marked");

var dashTestText = basicTestText.replace('...', '---');
t.deepEqual(basicResult, metaMarked(dashTestText), "works with dashes as yaml terminators too");
var dashTestText = basicTestText.replace("...", "---");
t.deepEqual(
basicResult,
metaMarked(dashTestText),
"works with dashes as yaml terminators too"
);

t.end();
t.end();
});
Loading

0 comments on commit 8b0cf4c

Please sign in to comment.