-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed encoding mishaps. Adjusted tests. #499
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ var load = exports.load = function(content, options) { | |
|
||
// Add in the root | ||
initialize._root = root; | ||
// store options | ||
initialize._options = options; | ||
|
||
return initialize; | ||
}; | ||
|
@@ -37,11 +39,16 @@ var load = exports.load = function(content, options) { | |
*/ | ||
|
||
var html = exports.html = function(dom) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous |
||
var Cheerio = require('./cheerio'); | ||
// sometimes $.html() used without preloading html | ||
// so fallback non existing options to the default ones | ||
var options = _.defaults(this._options || {}, Cheerio.prototype.options); | ||
|
||
if (dom) { | ||
dom = (typeof dom === 'string') ? select(dom, this._root, this.options) : dom; | ||
return render(dom, this.options); | ||
dom = (typeof dom === 'string') ? select(dom, this._root, options) : dom; | ||
return render(dom, options); | ||
} else if (this._root && this._root.children) { | ||
return render(this._root.children, this.options); | ||
return render(this._root.children, options); | ||
} else { | ||
return ''; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,10 +245,11 @@ describe('cheerio', function() { | |
|
||
it('should render xml in html() when options.xmlMode = true', function() { | ||
var str = '<MixedCaseTag UPPERCASEATTRIBUTE=""></MixedCaseTag>', | ||
expected = '<MixedCaseTag UPPERCASEATTRIBUTE=""/>', | ||
dom = $.load(str, {xmlMode: true}); | ||
|
||
expect(dom('MixedCaseTag').get(0).name).to.equal('MixedCaseTag'); | ||
expect(dom.html()).to.be(str); | ||
expect(dom.html()).to.be(expected); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of scope of this PR, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I follow you on this one, does it mean you don't want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In contrary: Currently, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does inherit options set on load: (from
It was part of this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this test proves it. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm referring to return $.html(this[0].children);
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, when there was no But it this case we called // Yeah, it took me some time to figure out the right context with all that sticking "static" methods around. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not in the scope of this PR. I only wanted to point it out, to ensure it won't be missed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, it would require more thinking, since not all the options would make effect, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be awesome; I already created #501 as a reference, but a patch would be very appreciated. |
||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows to pass
options
object to.html
method.