keeganstreet / element-finder

Find in Files with CSS selectors
http://keegan.st/2012/06/03/find-in-files-with-css-selectors/
118 stars 8 forks source link

Does not correctly parse self-closing tags #8

Open instanceofme opened 7 years ago

instanceofme commented 7 years ago

E.g. .a .b will incorrectly find 2 results in the following case:

<div class="a">
    <div class="b">Should match</div>
    <div class="autoclosed" />
</div>
<div class="b">Should not match</div>
instanceofme commented 7 years ago

Hmm maybe this is actually more of a domtosource issue? Or even further down the dependency tree…

instanceofme commented 7 years ago

Indeed: domtosource -> cheerio -> htmlparser2.

Trying this in htmlparser2's live demo yields the incorrect DOM tree.

instanceofme commented 7 years ago

But actually it seems that there is a recognizeSelfClosing option for this in the parser. ~Not sure if it's exposed by cheerio though.~

Yes it is! The load function accepts htmlparser2 options.

These parsing options are taken directly from htmlparser2, therefore any options that can be used in htmlparser2 are valid in cheerio as well.

Would it be possible to use this option? or to expose it?