summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-html/lib/index.js
blob: 0e67c94d895ded43ccc85400430435866b4ec123 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var _ = require('lodash');

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;