summaryrefslogtreecommitdiffstats
path: root/lib/parser.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-19 10:59:43 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-19 10:59:43 +0100
commit39b2aaf4898921fc845ffa165d038fa58404548d (patch)
tree251e5344791e60c0a17fadf193af4a5b9e5b84ce /lib/parser.js
parent58b04da60fd819ad851a0ccc826b45bbbafaa0b5 (diff)
downloadgitbook-39b2aaf4898921fc845ffa165d038fa58404548d.zip
gitbook-39b2aaf4898921fc845ffa165d038fa58404548d.tar.gz
gitbook-39b2aaf4898921fc845ffa165d038fa58404548d.tar.bz2
Add parsing of summary and associated tests
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
+};