jamietre / CsQuery

CsQuery is a complete CSS selector engine, HTML parser, and jQuery port for C# and .NET 4.
Other
1.16k stars 249 forks source link

Text() vs. InnerText vs. jQuery difference #193

Open keleshev opened 9 years ago

keleshev commented 9 years ago

I'm trying to get inner text of a node, however .InnerText property seems to misbehave:

> CQ.Create("<hai>foo &amp; bar &nbsp; baz<br>qux</hai>").["hai"].[0].InnerText;;
"foo &amp; bar &nbsp; bazqux"

Compare to jQuery:

> $("<hai>foo &amp; bar &nbsp; baz<br>qux</hai>")[0].innerText
"foo & bar   baz\nqux"

At the same time Text() seems to work closer to jQuery:

> CQ.Create("<hai>foo &amp; bar &nbsp; baz<br>qux</hai>").["hai"].Text();;    
"foo & bar   bazqux"

Do you have a suggestion on how can I want to achieve behaviour similar to jQuery?

asv7c2 commented 9 years ago

Write CsQuery.Config.OutputFormatter = OutputFormatters.HtmlEncodingNone; before any CQ use.

keleshev commented 9 years ago

@alexander1986 thanks, that makes output of .InnerText similar to .Text(). Although I wish I could get the exact behavior of jQuery.