summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-markdown/src/toHTML.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-markdown/src/toHTML.js')
-rw-r--r--packages/gitbook-markdown/src/toHTML.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/gitbook-markdown/src/toHTML.js b/packages/gitbook-markdown/src/toHTML.js
new file mode 100644
index 0000000..e887e11
--- /dev/null
+++ b/packages/gitbook-markdown/src/toHTML.js
@@ -0,0 +1,35 @@
+const { State } = require('markup-it');
+const markdown = require('markup-it/lib/markdown');
+const html = require('markup-it/lib/html');
+
+/**
+ * Convert Markdown block to HTML
+ *
+ * @param {String} src (markdown)
+ * @return {String} (html)
+ */
+function convertMdToHTMLBlock(src) {
+ const fromMD = State.create(markdown);
+ const document = fromMD.deserializeToDocument(src);
+
+ const toHTML = State.create(html);
+ return toHTML.serializeDocument(document);
+}
+
+/**
+ * Convert Markdown inline to HTML
+ *
+ * @param {String} src (markdown)
+ * @return {String} (html)
+ */
+function convertMdToHTMLInline(src) {
+ const content = markdown.toInlineContent(src);
+ const textHtml = html.toInlineText(content);
+
+ return textHtml;
+}
+
+module.exports = {
+ block: convertMdToHTMLBlock,
+ inline: convertMdToHTMLInline
+};