diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-12-22 17:13:30 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-12-22 17:13:30 +0100 |
commit | f9fccfd271a2cdf316d334e94951114a9c5fcedb (patch) | |
tree | 2c9beea5934c250942503a0c4e068f3e0550910a /packages/gitbook-markdown/src/toHTML.js | |
parent | c4e512477e3cbe1344caaa2f1cc56e4bb402ad79 (diff) | |
download | gitbook-f9fccfd271a2cdf316d334e94951114a9c5fcedb.zip gitbook-f9fccfd271a2cdf316d334e94951114a9c5fcedb.tar.gz gitbook-f9fccfd271a2cdf316d334e94951114a9c5fcedb.tar.bz2 |
Start adapting markdown parser for markup-it@3
Diffstat (limited to 'packages/gitbook-markdown/src/toHTML.js')
-rw-r--r-- | packages/gitbook-markdown/src/toHTML.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/packages/gitbook-markdown/src/toHTML.js b/packages/gitbook-markdown/src/toHTML.js index e887e11..e115b71 100644 --- a/packages/gitbook-markdown/src/toHTML.js +++ b/packages/gitbook-markdown/src/toHTML.js @@ -1,4 +1,5 @@ -const { State } = require('markup-it'); +const { State, Block, BLOCKS } = require('markup-it'); +const { Document } = require('slate'); const markdown = require('markup-it/lib/markdown'); const html = require('markup-it/lib/html'); @@ -23,10 +24,21 @@ function convertMdToHTMLBlock(src) { * @return {String} (html) */ function convertMdToHTMLInline(src) { - const content = markdown.toInlineContent(src); - const textHtml = html.toInlineText(content); + const fromMD = State.create(markdown); + const document = fromMD.deserializeToDocument(src); - return textHtml; + // Create a document with a single unstyled node + const newDocument = Document.create({ + nodes: [ + Block.create({ + type: BLOCKS.TEXT, + nodes: document.nodes.get(0).nodes + }) + ] + }); + + const toHTML = State.create(html); + return toHTML.serializeDocument(newDocument); } module.exports = { |