summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-html/lib/dom.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-12-22 13:12:16 +0100
committerSamy Pessé <samypesse@gmail.com>2016-12-22 13:12:16 +0100
commit97f2c333a87b9d939b5a7dc2884590c971b53291 (patch)
treea22824b02d84a89e59c458c8af7d3494561d43f6 /packages/gitbook-html/lib/dom.js
parent627e6dd866f77ff497a21f0b706490b82e40ea0e (diff)
downloadgitbook-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/dom.js')
-rw-r--r--packages/gitbook-html/lib/dom.js50
1 files changed, 24 insertions, 26 deletions
diff --git a/packages/gitbook-html/lib/dom.js b/packages/gitbook-html/lib/dom.js
index 819ced0..96d370e 100644
--- a/packages/gitbook-html/lib/dom.js
+++ b/packages/gitbook-html/lib/dom.js
@@ -1,52 +1,49 @@
-var _ = require('lodash');
+'use strict';
+
var cheerio = require('cheerio');
/**
- Parse an HTML string and return its content
-
- @param {String}
- @return {cheerio.DOM}
-*/
+ * Parse an HTML string and return its content.
+ * @param {String}
+ * @return {cheerio.DOM}
+ */
function parse(html) {
var $ = cheerio.load(html);
var $el = $('html, body').first();
- return $el.length > 0? $el : $;
+ return $el.length > 0 ? $el : $;
}
/**
- Return main element for a DOM
-
- @param {cheerio.DOM}
- @return {cheerio.Node}
-*/
+ * Return main element for a DOM.
+ * @param {cheerio.DOM}
+ * @return {cheerio.Node}
+ */
function root($) {
var $el = $('html, body, > div').first();
- return $el.length > 0? $el : $.root();
+ return $el.length > 0 ? $el : $.root();
}
/**
- Return text node of an element
-
- @param {cheerio.Node}
- @return {String}
-*/
+ * Return text node of an element.
+ * @param {cheerio.Node}
+ * @return {String}
+ */
function textNode($el) {
- return _.reduce($el.children, function(text, e) {
+ return $el.children.reduce(function (text, e) {
if (e.type == 'text') text += e.data;
return text;
}, '');
}
/**
- Cleanup a DOM by removing all useless divs
-
- @param {cheerio.Node}
- @param {cheerio.DOM}
- @return {cheerio.Node}
-*/
+ * Cleanup a DOM by removing all useless divs.
+ * @param {cheerio.Node}
+ * @param {cheerio.DOM}
+ * @return {cheerio.Node}
+ */
function cleanup($el, $) {
- $el.find('div').each(function() {
+ $el.find('div').each(function () {
var $div = $(this);
cleanup($div, $);
@@ -62,3 +59,4 @@ module.exports = {
root: root,
cleanup: cleanup
};
+//# sourceMappingURL=dom.js.map \ No newline at end of file