CSS Class Names being Output in Lowercase when using AddClass #12

Closed
CJCannon opened this Issue Jun 21, 2012 · 7 comments

Comments

Projects
None yet
2 participants
@CJCannon

Love CsQuery so far :) hey I tested your new DLL v1.1.1.22414 and the nth-child selector now works, but I got a tiny little problem - when using AddClass my css class names are being output in lowercase - although lowercase class names are the norm - being a .NET guy I like to use camel case e.g. MyCssClass please fix. Apart from that I gotta say "GOOD JOOOB!!!" on a really easy to use and fast program!

@jamietre

This comment has been minimized.

Show comment
Hide comment
@jamietre

jamietre Jun 21, 2012

Owner

Do you mean it's actually converting class names to lower case, even though you've coded them as camelcase?

Owner

jamietre commented Jun 21, 2012

Do you mean it's actually converting class names to lower case, even though you've coded them as camelcase?

@CJCannon

This comment has been minimized.

Show comment
Hide comment
@CJCannon

CJCannon Jun 21, 2012

Yes for example doc("div#Foo > p:nth-child(3)").AddClass("Bar") will output as

(<)div id="Foo" class="main"(>)

(<)h2(>)
    Welcome to ASP.NET!
(<)/h2(>)
(<)p(>)
    To learn more about ASP.NET visit (<)a href="http://www.asp.net" title="ASP.NET Website"(>)www.asp.net(<)/a(>).
(<)/p(>)
(<)p class="bar"(>)
    You can also find (<)a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409" title="MSDN ASP.NET Docs"(>)documentation on ASP.NET at MSDN(<)/a(>).
(<)/p(>)

    (<)/div(>)
    (<)div class="clear"(>)
    (<)/div(>)
(<)/div(>)

Without the parentheses of course :)

Yes for example doc("div#Foo > p:nth-child(3)").AddClass("Bar") will output as

(<)div id="Foo" class="main"(>)

(<)h2(>)
    Welcome to ASP.NET!
(<)/h2(>)
(<)p(>)
    To learn more about ASP.NET visit (<)a href="http://www.asp.net" title="ASP.NET Website"(>)www.asp.net(<)/a(>).
(<)/p(>)
(<)p class="bar"(>)
    You can also find (<)a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409" title="MSDN ASP.NET Docs"(>)documentation on ASP.NET at MSDN(<)/a(>).
(<)/p(>)

    (<)/div(>)
    (<)div class="clear"(>)
    (<)/div(>)
(<)/div(>)

Without the parentheses of course :)

@jamietre

This comment has been minimized.

Show comment
Hide comment
@jamietre

jamietre Jun 21, 2012

Owner

Ugh, nasty. Took two seconds to fix, can't believe I've never noticed that before. Am testing now, will have an update pushed out shortly.

Owner

jamietre commented Jun 21, 2012

Ugh, nasty. Took two seconds to fix, can't believe I've never noticed that before. Am testing now, will have an update pushed out shortly.

@CJCannon

This comment has been minimized.

Show comment
Hide comment
@CJCannon

CJCannon Jun 21, 2012

High five! BTW can I ask about my selectors e.g. "div#Foo > p:nth-child(3)" would you say that it is the best way of doing it i.e. selecting a child which is not the first or last? Just for peace of mind. Thanks.

High five! BTW can I ask about my selectors e.g. "div#Foo > p:nth-child(3)" would you say that it is the best way of doing it i.e. selecting a child which is not the first or last? Just for peace of mind. Thanks.

@jamietre

This comment has been minimized.

Show comment
Hide comment
@jamietre

jamietre Jun 21, 2012

Owner

div#Foo is redundant - all you need is #Foo. IDs are unique, so there should only be one "Foo" and #Foo will get it in the fastest possible way.

Are you trying to select all children except the first and last? You could do this with the ":not" pseudoselector (i think it's a jquery extension), e.g.

#Foo > :not(:first-child,:last-child) 

You could do it with jQuery/csQuey, e.g.

var allButFirstAndLast = dom["#Foo"].Children().Not(":first-child,:last-child");

It may be faster to use C# to extract everything but the first & last children, e.g. using an example I just created as a test from the "TestHtml" document in the CsQuery.Tests project:

        // a reference to be sure we get the same result
        var res = Dom["#hlinks-user > :not(:first-child,:last-child)"];

        var hlinks = Dom["#hlinks-user"][0];

        // we need to know when we've hit the end to stop enumerating
        // you want to cache a reference to LastElementChild rather than 
        // just looking it up in the loop because
        // it may be expensive each time it has to figure out the last child

       var lastEl = hlinks.LastElementChild;

       // use linq to skip the first one & take until you've hit the last one

       res2 = hlinks.ChildElements.Skip(1).TakeWhile(item => item != lastEl);

      // make sure we got the same results both ways
       CollectionAssert.AreEqual(res, res2);
Owner

jamietre commented Jun 21, 2012

div#Foo is redundant - all you need is #Foo. IDs are unique, so there should only be one "Foo" and #Foo will get it in the fastest possible way.

Are you trying to select all children except the first and last? You could do this with the ":not" pseudoselector (i think it's a jquery extension), e.g.

#Foo > :not(:first-child,:last-child) 

You could do it with jQuery/csQuey, e.g.

var allButFirstAndLast = dom["#Foo"].Children().Not(":first-child,:last-child");

It may be faster to use C# to extract everything but the first & last children, e.g. using an example I just created as a test from the "TestHtml" document in the CsQuery.Tests project:

        // a reference to be sure we get the same result
        var res = Dom["#hlinks-user > :not(:first-child,:last-child)"];

        var hlinks = Dom["#hlinks-user"][0];

        // we need to know when we've hit the end to stop enumerating
        // you want to cache a reference to LastElementChild rather than 
        // just looking it up in the loop because
        // it may be expensive each time it has to figure out the last child

       var lastEl = hlinks.LastElementChild;

       // use linq to skip the first one & take until you've hit the last one

       res2 = hlinks.ChildElements.Skip(1).TakeWhile(item => item != lastEl);

      // make sure we got the same results both ways
       CollectionAssert.AreEqual(res, res2);

jamietre added a commit that referenced this issue Jun 21, 2012

@jamietre

This comment has been minimized.

Show comment
Hide comment
@jamietre

jamietre Jun 21, 2012

Owner

Fixed in current push. You can download the compiled dll under "distribution" folder before I update nuget. I may not update for a couple days because there are a ton of changes to the HTML parser that I want to kick around a bit more before making this official, but it's passing all the tests and everything looks good

Owner

jamietre commented Jun 21, 2012

Fixed in current push. You can download the compiled dll under "distribution" folder before I update nuget. I may not update for a couple days because there are a ton of changes to the HTML parser that I want to kick around a bit more before making this official, but it's passing all the tests and everything looks good

@jamietre jamietre closed this Jun 21, 2012

@CJCannon

This comment has been minimized.

Show comment
Hide comment
@CJCannon

CJCannon Jun 21, 2012

Thanks jamietre. P.S. I understood MOST of the post re. CSS selectors so I will keep that in mind if I need to do anything exotic. I didn't know about :not so that will be useful!!! Many thanks again.

Thanks jamietre. P.S. I understood MOST of the post re. CSS selectors so I will keep that in mind if I need to do anything exotic. I didn't know about :not so that will be useful!!! Many thanks again.

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