[lib] Add markdown parsing.
diff --git a/lib/doclet/index.js b/lib/doclet/index.js
index 06125a5..498f75a 100644
--- a/lib/doclet/index.js
+++ b/lib/doclet/index.js
@@ -2,7 +2,11 @@
* Module dependencies.
*/
-var dir = require('node-dir');
+var async = require('async'),
+ dir = require('node-dir'),
+ fs = require('fs'),
+ marked = require('marked'),
+ path = require('path');
/**
* Doclet compiler.
@@ -16,9 +20,35 @@
// default to current working directory
path = path || process.cwd();
- // each file
+ // configure markdown parser
+ marked.setOptions({
+ gfm: true,
+ tables: true,
+ breaks: false,
+ pedantic: false,
+ sanitize: false,
+ smartLists: true
+ });
+
+ // find all files
dir.paths(path, function(e, paths) {
- // parse markdown
- // render html
+ // iterate each file
+ async.each(paths.files, function(filepath, callback) {
+ // render markdown
+ if (isMarkdown(filepath)) {
+ console.log(module.exports.markdown(filepath));
+ }
+ else {
+ console.log('cp asset');
+ }
+ });
});
};
+
+module.exports.markdown = function(filepath) {
+ return marked(fs.readFileSync(filepath, 'utf8'));
+};
+
+function isMarkdown(filepath) {
+ return (['.md'].indexOf(path.extname(filepath)) >= 0);
+}
diff --git a/package.json b/package.json
index 838799d..3f61469 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,8 @@
"node": ">=0.10.0"
},
"dependencies": {
+ "async": "0.2.9",
+ "marked": "0.2.10",
"node-dir": "0.1.5",
"optimist": "0.6.0",
"shelljs": "0.2.6"
diff --git a/spec/doclet/index.spec.js b/spec/doclet/index.spec.js
index 5704657..6982215 100644
--- a/spec/doclet/index.spec.js
+++ b/spec/doclet/index.spec.js
@@ -4,6 +4,7 @@
var dir = require('node-dir'),
doclet = require('../../lib/doclet'),
+ fs = require('fs'),
options;
/*!
@@ -37,4 +38,23 @@
);
});
});
+
+ describe('markdown parser', function() {
+ beforeEach(function() {
+ dir.paths.andCallFake(function(path, callback) {
+ callback(null, { files: [
+ '/some/path/file-1.md',
+ '/some/path/file-2.md',
+ '/some/path/file-3.md'
+ ]});
+ });
+ spyOn(fs, 'readFileSync').andReturn('# Markdown');
+ spyOn(doclet, 'markdown');
+ });
+
+ it('should be called for each file', function() {
+ doclet.compile(options);
+ expect(doclet.markdown.calls.length).toEqual(3);
+ });
+ });
});