summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-html/lib/dom.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-html/lib/dom.js')
-rw-r--r--packages/gitbook-html/lib/dom.js30
1 files changed, 25 insertions, 5 deletions
diff --git a/packages/gitbook-html/lib/dom.js b/packages/gitbook-html/lib/dom.js
index d8f7c84..819ced0 100644
--- a/packages/gitbook-html/lib/dom.js
+++ b/packages/gitbook-html/lib/dom.js
@@ -1,7 +1,12 @@
var _ = require('lodash');
var cheerio = require('cheerio');
-// Parse an HTML string and return its content
+/**
+ 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();
@@ -9,13 +14,23 @@ function parse(html) {
return $el.length > 0? $el : $;
}
-// Return main element
+/**
+ 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 text node of an element
+/**
+ Return text node of an element
+
+ @param {cheerio.Node}
+ @return {String}
+*/
function textNode($el) {
return _.reduce($el.children, function(text, e) {
if (e.type == 'text') text += e.data;
@@ -23,8 +38,13 @@ function textNode($el) {
}, '');
}
-// Cleanup a dom
-// Remove all divs
+/**
+ 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() {
var $div = $(this);