Skip to content
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

Whitespace not being rendered #55

Closed
drewwilson opened this issue Apr 26, 2012 · 10 comments
Closed

Whitespace not being rendered #55

drewwilson opened this issue Apr 26, 2012 · 10 comments

Comments

@drewwilson
Copy link

Any whitespace between tags is NOT being rendered with .html()

For example: Link HyperLink

The output of that when rendered with .html() is: LinkHyperLink

It removes the space in-between the 2 tags. This only happens when 2 tags are one after the other. To get around it i have to do the following to the html string: .replace('> <','>&nbsp;<');

@matthewmueller
Copy link
Member

Hmm... try passing the ignoreWhitespace : false option into cheerio.load.

Example: var $ = cheerio.load('<ul id = "fruits">...</ul>', { ignoreWhitespace: false });

@drewwilson
Copy link
Author

we tried that, but it doesnt work.

Drew Wilson

www.drewwilson.com

On Apr 26, 2012, at 1:15 PM, Matt Mueller wrote:

Hmm... try passing the ignoreWhitespace : false option into cheerio.load.

Example: var $ = cheerio.load('<ul id = "fruits">...</ul>', { ignoreWhitespace: false });


Reply to this email directly or view it on GitHub:
#55 (comment)

@matthewmueller
Copy link
Member

Okay hmm... yah that's a problem. I'll take a look at this over the weekend.

@drewwilson
Copy link
Author

by the way, i'm using cheerio for my newly launched app: http://dialog.gs :D Much faster than JSDOM.
Drew Wilson

www.drewwilson.com

On Apr 26, 2012, at 1:56 PM, Matt Mueller wrote:

Okay hmm... yah that's a problem. I'll take a look at this over the weekend.


Reply to this email directly or view it on GitHub:
#55 (comment)

@matthewmueller
Copy link
Member

Oh the app seems pretty cool! Could I get an invite? ;-)

@matthewmueller
Copy link
Member

Okay, I've had a chance to look at this. I've upgraded cheerio to use the latest version of htmlparser2, and that seemed to fix it:

var html = '<a href = "./haha.html">hi</a> <a href = "./blah.html">blah</a>';
$ = cheerio.load(html, { ignoreWhitespace : false });
console.log($.html()) // => <a href="./haha.html">hi</a> <a href="./blah.html">blah</a>

@matthewmueller
Copy link
Member

Could you please pull down master and verify it on your end? I'll bump the version once I can confirm this has been resolved.

@drewwilson
Copy link
Author

Hey! Got the new changes, thanks. However it doesn't work for me still.

var $ = cheerio.load(html,{ ignoreWhitespace : false });

Doing the above works, but the options are not actually set. So 'ignoreWhitespace' is still set to 'true' when i do:
console.log($);

For now i have to do this, and it all works as it should:

var $ = cheerio.load(html);
$.fn.options.ignoreWhitespace = false;

@matthewmueller
Copy link
Member

weird. maybe I forgot to commit something.. let me check.

@matthewmueller
Copy link
Member

This should work as expected in version 0.8.0. { ignoreWhitespace : false } is now the default again, so you should be able to remove that option altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants