HtmlAgilityPack.CssSelectors.NetCore icon indicating copy to clipboard operation
HtmlAgilityPack.CssSelectors.NetCore copied to clipboard

Added *-of-type pseudos

Open jpeirson opened this issue 4 years ago • 2 comments

Adds support for *-of-type pseudo-classes:

  • first-of-type
  • last-of-type
  • nth-of-type(n)
  • nth-last-of-type(n)
  • only-of-type

jpeirson avatar Aug 06 '20 13:08 jpeirson

Resolved conflicts since I first wrote this PR.

Also, fixed a bug in #14 where the nth index was off by one: the n is indexed starting from 1, not 0.

e.g., the behavior in Chrome is for the Test1.html doc in this repo:

document.querySelectorAll('div:nth-of-type(5)')
// NodeList [div#strict-starts-with-tests]
document.querySelectorAll('li:nth-of-type(2)')
// NodeList [li.lv1.active.hover]

See also MDN docs:

:nth-child() takes a single argument that describes a pattern for matching element indices in a list of siblings. Element indices are 1-based.

jpeirson avatar Aug 19 '21 21:08 jpeirson

Als note that NodeExtensionMethods.GetIndexOnParent() is indexed starting with 0, while the parameter returned to CheckNode() is indexed starting with 1.

jpeirson avatar Aug 19 '21 21:08 jpeirson