summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-html/lib/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-html/lib/index.js')
-rwxr-xr-xpackages/gitbook-html/lib/index.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/packages/gitbook-html/lib/index.js b/packages/gitbook-html/lib/index.js
index a7c478c..0e67c94 100755
--- a/packages/gitbook-html/lib/index.js
+++ b/packages/gitbook-html/lib/index.js
@@ -1,8 +1,33 @@
+var _ = require('lodash');
-module.exports = {
+var htmlParser = {
summary: require("./summary"),
glossary: require("./glossary"),
langs: require("./langs"),
readme: require("./readme"),
page: require("./page")
};
+
+// Compose a function with a transform function for the first args
+function compose(toHTML, fn) {
+ return function() {
+ var args = _.toArray(arguments);
+ args[0] = toHTML(args[0]);
+
+ return fn.apply(null, args);
+ }
+}
+
+// Create a GitBook parser
+function createParser(toHTML) {
+ return {
+ summary: compose(toHTML, htmlParser.summary),
+ glossary: compose(toHTML, htmlParser.glossary),
+ langs: compose(toHTML, htmlParser.langs),
+ readme: compose(toHTML, htmlParser.readme),
+ page: compose(toHTML, htmlParser.page)
+ }
+}
+
+module.exports = htmlParser;
+module.exports.createParser = createParser;