diff options
Diffstat (limited to 'packages/gitbook-html/lib/dom.js')
-rw-r--r-- | packages/gitbook-html/lib/dom.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/packages/gitbook-html/lib/dom.js b/packages/gitbook-html/lib/dom.js index 2c2eaf7..df4de90 100644 --- a/packages/gitbook-html/lib/dom.js +++ b/packages/gitbook-html/lib/dom.js @@ -3,12 +3,18 @@ var cheerio = require('cheerio'); // Parse an HTML string and return its content function parse(html) { - var $ = cheerio.load('<div>'+html+'</div>'); + var $ = cheerio.load(html); var $el = $('html, body').first(); return $el.length > 0? $el : $; } +// Return main element +function root($) { + var $el = $('html, body, > div').first(); + return $el.length > 0? $el : $.root(); +} + // Return text node of an element function textNode($el) { return _.reduce($el.children, function(text, e) { @@ -19,5 +25,6 @@ function textNode($el) { module.exports = { parse: parse, - textNode: textNode + textNode: textNode, + root: root }; |