Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cheerio.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var Cheerio = module.exports = function(selector, context, root) {
if (!selector) return this;

if (root) {
if (typeof root === 'string') root = parse(root);
if (typeof root === 'string') root = parse(root, this.options);
this._root = this.make(root, this);
}

Expand All @@ -51,7 +51,7 @@ var Cheerio = module.exports = function(selector, context, root) {

// $(<html>)
if (typeof selector === 'string' && isHtml(selector)) {
return this.make(parse(selector).children);
return this.make(parse(selector, this.options).children);
}

// If we don't have a context, maybe we have a root, from loading
Expand Down
5 changes: 5 additions & 0 deletions lib/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ var load = exports.load = function(str, options) {
var Cheerio = require('./cheerio'),
root = parse(str, options);

// Overwrite default options if custom options are present
if (typeof options === 'object') {
Cheerio.prototype.options = options;
}

var initialize = function(selector, context, r) {
return new Cheerio(selector, context, r || root);
};
Expand Down
19 changes: 19 additions & 0 deletions test/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ var xml = function(str, options) {
return dom.xml();
};

var dom = function(str, options) {
$ = cheerio.load('', options);
return $(str).html();
}

describe('render', function() {

describe('(xml)', function() {
Expand All @@ -24,4 +29,18 @@ describe('render', function() {

});

describe('(dom)', function () {

it('should keep camelCase for new nodes', function() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant, "should force lowercase for new nodes".

But really, the functionality you've implemented forwards all parsing options. We should write the tests to verify this a little more generally. Mind adding another assertion to each of these tests for the ignoreWhiteSpace option? Then we'd want to name these something like, 'respects parsing options defined when the context was created'.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, and I agree.

var str = '<g><someElem someAttribute="something">hello</someElem></g>';
expect(dom(str, {xmlMode: false})).to.equal('<someelem someattribute="something">hello</someelem>');
});

it('should keep camelCase for new nodes', function() {
var str = '<g><someElem someAttribute="something">hello</someElem></g>';
expect(dom(str, {xmlMode: true})).to.equal('<someElem someAttribute="something">hello</someElem>');
});

});

});