Cheerio: Cheerio .html() should not encode cyrillic symbols

Created on 19 May 2015  路  6Comments  路  Source: cheeriojs/cheerio

var cheerio = require('cheerio');
var $ = cheerio.load('<div>泻懈褉懈谢谢懈褑邪</div>');
console.log($.html()); // => <div>&#x43A;&#x438;&#x440;&#x438;&#x43B;&#x43B;&#x438;&#x446;&#x430;</div>

when expected output is <div>泻懈褉懈谢谢懈褑邪</div>

Most helpful comment

decodeEntities is not an option for .html, but for .load (or the constructor).

All 6 comments

$('div').text() returns normal, not encoded value

Found a solution in #466 with $.html({decodeEntities: false}), which works fine. Anybody knows what could be the downsides of using this option?

And here's the downside - $('div').html({decodeEntities: false}) returns an object, instead of a string with actual HTML.

Could be solve with nasty hack:

var div = cheerio.load($('div').html());
div.html({decodeEntities: false});

decodeEntities is not an option for .html, but for .load (or the constructor).

Thanks, that helped!

decodeEntities is not an option for .html, but for .load (or the constructor).

thanks, this helped me!

Was this page helpful?
0 / 5 - 0 ratings