diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-19 16:12:43 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-12-22 12:32:14 +0100 |
commit | 4c44d677117d926b6dcc164f55fe34079c2ca3c7 (patch) | |
tree | 71d0fca56421f3a7b68d60a446f89d3735828f03 /packages/gitbook-html/lib/dom.js | |
parent | 9e99b5850fd866fc2f9196993a0ae7e342311558 (diff) | |
download | gitbook-4c44d677117d926b6dcc164f55fe34079c2ca3c7.zip gitbook-4c44d677117d926b6dcc164f55fe34079c2ca3c7.tar.gz gitbook-4c44d677117d926b6dcc164f55fe34079c2ca3c7.tar.bz2 |
Improve summary parser
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 }; |