cheerio icon indicating copy to clipboard operation
cheerio copied to clipboard

Impact of options is hard to understand

Open tbaustin opened this issue 1 year ago • 2 comments

I am passing

const $ = cheerio.load("<div> > Hello world </div>", { decodeEntities: false }, false) // tried true and false for decodeEntities

return $.html()

We want it to return <div> > Hello world </div>, but it's returning <div> &gt; Hello world </div> instead.

tbaustin avatar Sep 07 '22 20:09 tbaustin

Not the maintainer, but decodeEntities controls the opposite - if &gt; in the input should become > in the output. I think you want xmlMode: true instead.

Properko avatar Sep 12 '22 13:09 Properko

That's almost the answer: The reason why decodeEntities doesn't work is that it is an option for htmlparser2, which isn't the default parser. Have a look at https://github.com/cheeriojs/cheerio#using-htmlparser2 for more details. The easiest way around this is probably by using the slim export.

Leaving this open to track the deeper issue.

fb55 avatar Sep 13 '22 21:09 fb55