summaryrefslogtreecommitdiffstats
path: root/lib/parser.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parser.js')
-rw-r--r--lib/parser.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/parser.js b/lib/parser.js
new file mode 100644
index 0000000..b4243e0
--- /dev/null
+++ b/lib/parser.js
@@ -0,0 +1,28 @@
+var _ = require("lodash");
+var path = require("path");
+
+// This list is ordered by priority of parser to use
+var PARSER = [
+ {
+ extensions: [".md", ".markdown"],
+ parser: require("gitbook-markdown")
+ }
+];
+
+// Return a specific parser according to an extension
+function getParser(ext) {
+ return _.find(PARSER, function(input) {
+ return _.contains(input.extensions, ext);
+ });
+}
+
+// Return parser for a file
+function getParserForFile(filename) {
+ return getParser(path.extname(filename));
+};
+
+module.exports = {
+ extensions: _.flatten(_.pluck(PARSER, "extensions")),
+ get: getParser,
+ getForFile: getParserForFile
+};