diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-12-22 13:12:16 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-12-22 13:12:16 +0100 |
commit | 97f2c333a87b9d939b5a7dc2884590c971b53291 (patch) | |
tree | a22824b02d84a89e59c458c8af7d3494561d43f6 /packages/gitbook-html/lib/index.js | |
parent | 627e6dd866f77ff497a21f0b706490b82e40ea0e (diff) | |
download | gitbook-97f2c333a87b9d939b5a7dc2884590c971b53291.zip gitbook-97f2c333a87b9d939b5a7dc2884590c971b53291.tar.gz gitbook-97f2c333a87b9d939b5a7dc2884590c971b53291.tar.bz2 |
Import and adapt gitbook-html
Refactor to remove lodash and q as dependencies
Diffstat (limited to 'packages/gitbook-html/lib/index.js')
-rwxr-xr-x | packages/gitbook-html/lib/index.js | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/packages/gitbook-html/lib/index.js b/packages/gitbook-html/lib/index.js index 2658914..b6fa18c 100755 --- a/packages/gitbook-html/lib/index.js +++ b/packages/gitbook-html/lib/index.js @@ -1,4 +1,5 @@ -var _ = require('lodash'); +'use strict'; + var ToText = require('./totext'); var htmlParser = { @@ -11,22 +12,26 @@ var htmlParser = { // Compose a function with a transform function for the first argument only function compose(toHTML, fn) { - return function() { - var args = _.toArray(arguments); - args[0] = toHTML(args[0]); + return function () { + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } - return fn.apply(null, args); - } + args[0] = toHTML(args[0]); + return fn.apply(undefined, args); + }; } -// Create a GitBook parser from an HTML converter -function createParser(toHTML, toText) { - if (_.isFunction(toHTML)) { - toHTML = { - inline: toHTML, - block: toHTML - }; - } +/** + * Create a GitBook parser from an HTML converter. + * @param {Object} toHTML + * {Function} [toHTML.inline] + * {Function} [toHTML.block] + * @param {Object} toText + * @return {[type]} [description] + */ +function createParser(toHTML) { + var toText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var parser = { summary: compose(toHTML.block, htmlParser.summary), @@ -38,12 +43,27 @@ function createParser(toHTML, toText) { }; var _toText = new ToText(toText); - parser.summary.toText =_toText.summary; - parser.langs.toText =_toText.langs; - parser.glossary.toText =_toText.glossary; + + parser.summary.toText = function (summary) { + return _toText.summary(summary); + }; + parser.langs.toText = function (langs) { + return _toText.langs(langs); + }; + parser.glossary.toText = function (glossary) { + return _toText.glossary(glossary); + }; return parser; } -module.exports = createParser(_.identity); +module.exports = createParser({ + block: function block(html) { + return html; + }, + inline: function inline(html) { + return html; + } +}); module.exports.createParser = createParser; +//# sourceMappingURL=index.js.map
\ No newline at end of file |