summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-markdown/lib/tomarkdown.js
blob: 5bee4e08029bb643508b245f34344b50f6547530 (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
34
35
36
37
38
39
40
41
42
43

// Return N time a string
function ns(s, n) {
    return Array(n + 1).join(s);
}

module.exports = {
    onTitleStart: function(level) {
        return ns('#', level) + ' ';
    },
    onTitleEnd: function(level) {
        return this.onBL();
    },

    onParagraphStart: function() {
        return this.onSection();
    },
    onParagraphEnd: function() {
        return this.onSection();
    },

    onLinkStart: function() {
        return '[';
    },
    onLinkEnd: function(href) {
        return '](' + href +')';
    },

    onListStart: function(level) {
        return '';
    },
    onListEnd: function() {
        return '';
    },

    onListItemStart: function(level) {
        return ns(' ', level * 4) + '* ';
    },
    onListItemEnd: function() {
        return '';
    },
};