diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-19 16:23:44 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-19 16:23:44 +0100 |
commit | 7f01f4b048faf5ce5e1815c3676916ac7859279f (patch) | |
tree | 98a58abd2c18b3c46fea9987eb3316c1f2c80236 /lib/parsers.js | |
parent | 5ed584449007d9c6c816e765ce3e999e14abbf97 (diff) | |
download | gitbook-7f01f4b048faf5ce5e1815c3676916ac7859279f.zip gitbook-7f01f4b048faf5ce5e1815c3676916ac7859279f.tar.gz gitbook-7f01f4b048faf5ce5e1815c3676916ac7859279f.tar.bz2 |
Add plugin object
Diffstat (limited to 'lib/parsers.js')
-rw-r--r-- | lib/parsers.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/parsers.js b/lib/parsers.js new file mode 100644 index 0000000..da9732a --- /dev/null +++ b/lib/parsers.js @@ -0,0 +1,28 @@ +var _ = require("lodash"); +var path = require("path"); + +// This list is ordered by priority of parsers 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 +}; |