diff --git a/lib/cheerio.js b/lib/cheerio.js index 943571d83a..f378fa431e 100644 --- a/lib/cheerio.js +++ b/lib/cheerio.js @@ -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); } @@ -51,7 +51,7 @@ var Cheerio = module.exports = function(selector, context, root) { // $() 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 diff --git a/lib/static.js b/lib/static.js index 10eabf5a2d..53423113d4 100644 --- a/lib/static.js +++ b/lib/static.js @@ -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); }; diff --git a/test/xml.js b/test/xml.js index d3a0bea6fb..0bf50d5eda 100644 --- a/test/xml.js +++ b/test/xml.js @@ -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() { @@ -24,4 +29,18 @@ describe('render', function() { }); + describe('(dom)', function () { + + it('should keep camelCase for new nodes', function() { + var str = 'hello'; + expect(dom(str, {xmlMode: false})).to.equal('hello'); + }); + + it('should keep camelCase for new nodes', function() { + var str = 'hello'; + expect(dom(str, {xmlMode: true})).to.equal('hello'); + }); + + }); + });