summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-markdown/lib/toHTML.js
blob: 9140624964202c4ea011f863780eafabeb197ba3 (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
var MarkupIt = require('markup-it');
var markdownSyntax = require('markup-it/syntaxes/markdown');
var htmlSyntax = require('markup-it/syntaxes/html');

var markdown = new MarkupIt(markdownSyntax);
var html     = new MarkupIt(htmlSyntax);

/**
 * Convert Markdown block to HTML
 *
 * @param {String} src (markdown)
 * @return {String} (html)
 */
function convertMdToHTMLBlock(src) {
    var content  = markdown.toContent(src);
    var textHtml = html.toText(content);

    return textHtml;
}

/**
 * Convert Markdown inline to HTML
 *
 * @param {String} src (markdown)
 * @return {String} (html)
 */
function convertMdToHTMLInline(src) {
    var content  = markdown.toInlineContent(src);
    var textHtml = html.toInlineText(content);

    return textHtml;
}

module.exports = {
    block: convertMdToHTMLBlock,
    inline: convertMdToHTMLInline
};