atifaziz / Hazz

CSS Selectors (via Fizzler) for HtmlAgilityPack (HAP)
Other
63 stars 7 forks source link

nth-of-type #20

Open LukeTOBrien opened 4 years ago

LukeTOBrien commented 4 years ago

Hello there.

I am creating a WYSIWYG editor in Blazor and am using CSS nth-of-type to create a unique selector.
When I run my code I get the following error:

System.FormatException: Unknown functional pseudo 'nth-of-type'. Only nth-child and nth-last-child are supported.

For simple, non-nested elements, like SECTION H1:nth-of-type(1) I can use a work-around

HtmlNode element = null;
if (sel.Contains("nth-of-type"))
{
    var splitty = sel.Split(':');
    var elements = rootNode.QuerySelectorAll(splitty[0]);
    var n = int.Parse(Regex.Match(splitty[1], @"(\d)").Value);
    element = elements[n - 1];
}

But I hit a snag for more complex structures.
Any change of implementing nth-of-type?
You have nth-child, how much work would it be to have nth-of-type?

Thanks

atifaziz commented 4 years ago

This first needs support in Fizzler (atifaziz/Fizzler#28).