diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-12-22 12:31:22 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-12-22 12:31:22 +0100 |
commit | eb0bf31baa6cb903ba4242ae5a3866ff67aeb97c (patch) | |
tree | e2347c9e8c58dd3c2681a6028b5f8d69c40d4e04 /packages/gitbook-asciidoc/src | |
parent | 1c1e58b8641cac34b5f3d7c05951f507557fcb1a (diff) | |
download | gitbook-eb0bf31baa6cb903ba4242ae5a3866ff67aeb97c.zip gitbook-eb0bf31baa6cb903ba4242ae5a3866ff67aeb97c.tar.gz gitbook-eb0bf31baa6cb903ba4242ae5a3866ff67aeb97c.tar.bz2 |
Import gitbook-asciidoc
Diffstat (limited to 'packages/gitbook-asciidoc/src')
-rwxr-xr-x | packages/gitbook-asciidoc/src/index.js | 5 | ||||
-rw-r--r-- | packages/gitbook-asciidoc/src/toAsciidoc.js | 46 | ||||
-rw-r--r-- | packages/gitbook-asciidoc/src/toHTML.js | 24 |
3 files changed, 75 insertions, 0 deletions
diff --git a/packages/gitbook-asciidoc/src/index.js b/packages/gitbook-asciidoc/src/index.js new file mode 100755 index 0000000..9ba30e7 --- /dev/null +++ b/packages/gitbook-asciidoc/src/index.js @@ -0,0 +1,5 @@ +const HTMLParser = require('gitbook-html'); +const toHTML = require('./toHTML'); +const toAsciidoc = require('./toAsciidoc'); + +module.exports = HTMLParser.createParser(toHTML, toAsciidoc); diff --git a/packages/gitbook-asciidoc/src/toAsciidoc.js b/packages/gitbook-asciidoc/src/toAsciidoc.js new file mode 100644 index 0000000..77759d8 --- /dev/null +++ b/packages/gitbook-asciidoc/src/toAsciidoc.js @@ -0,0 +1,46 @@ + +// Return N time a string +function ns(s, n) { + return Array(n + 1).join(s); +} + +module.exports = { + onTitleStart(level) { + return ns('=', level) + ' '; + }, + onTitleEnd(level) { + return this.onBL(); + }, + + onParagraphStart() { + return this.onSection(); + }, + onParagraphEnd() { + return this.onSection(); + }, + + onLinkStart(href) { + return 'link:' + href + '['; + }, + onLinkEnd() { + return ']'; + }, + + onListStart(level) { + return ''; + }, + onListEnd() { + return ''; + }, + + onListItemStart(level) { + return ns('.', level + 1) + ' '; + }, + onListItemEnd() { + return ''; + }, + + onHR() { + return '\'\'\''; + } +}; diff --git a/packages/gitbook-asciidoc/src/toHTML.js b/packages/gitbook-asciidoc/src/toHTML.js new file mode 100644 index 0000000..0fc8f5f --- /dev/null +++ b/packages/gitbook-asciidoc/src/toHTML.js @@ -0,0 +1,24 @@ +const asciidoctor = require('asciidoctor.js')(); + +/** + * Render Asciidoc to HTML (block) + * @param {String} content + * @return {String} html + */ +function asciidocToHTML(content) { + return asciidoctor.convert(content, {'attributes': 'showtitle'}); +} + +/** + * Render Asciidoc to HTML (inline) + * @param {String} content + * @return {String} html + */ +function asciidocToHTMLInline(content) { + return asciidoctor.convert(content, {doctype: 'inline', attributes: 'showtitle'}); +} + +module.exports = { + block: asciidocToHTML, + inline: asciidocToHTMLInline +}; |