Skip to content

Commit 0855be6

Browse files
authored
fix(load): Support passing a single element (#1580)
Fixes #1577
1 parent f7cae99 commit 0855be6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/parse.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ exports = module.exports = function parse(content, options, isDocument) {
3535
} else {
3636
// Generic root element
3737
var root = new domhandler.Document(content);
38-
content.forEach(function (node) {
39-
node.parent = root;
40-
});
38+
39+
// Update the DOM using the root
40+
exports.update(content, root);
4141

4242
dom = root;
4343
}

test/cheerio.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ describe('cheerio', function () {
262262
expect($('ul')).to.have.length(3);
263263
});
264264

265+
it('should allow loading a single element', function () {
266+
var el = htmlparser2.parseDOM(food)[0];
267+
var $ = cheerio.load(el);
268+
269+
expect($('ul')).to.have.length(3);
270+
});
271+
265272
it('should render xml in html() when options.xml = true', function () {
266273
var str = '<MixedCaseTag UPPERCASEATTRIBUTE=""></MixedCaseTag>';
267274
var expected = '<MixedCaseTag UPPERCASEATTRIBUTE=""/>';

0 commit comments

Comments
 (0)