1
0
mirror of https://github.com/ericchiang/pup synced 2025-01-30 17:41:39 +00:00

added support for -n+A for :nth-child

This commit is contained in:
mdrokz 2021-08-14 14:34:43 +05:30
parent 681d7bb639
commit 8bef3ef15b

View File

@ -524,8 +524,18 @@ func parseNthPseudo(cmd string) (PseudoClass, error) {
return n.Type == html.ElementNode && countNth(n)%cycle == offset return n.Type == html.ElementNode && countNth(n)%cycle == offset
}, nil }, nil
} }
r = regexp.MustCompile(`^-n[ ]?\+[ ]?([0-9])`)
subMatch = r.FindAllStringSubmatch(number, -1)
if len(subMatch) == 1 && len(subMatch[0]) == 2 {
offset, _ := strconv.Atoi(subMatch[0][1])
return func(n *html.Node) bool {
return n.Type == html.ElementNode && countNth(n) <= offset
}, nil
}
// check against 'n+2' pattern // check against 'n+2' pattern
r = regexp.MustCompile(`n[ ]?\+[ ]?([0-9])`) r = regexp.MustCompile(`^n[ ]?\+[ ]?([0-9])`)
subMatch = r.FindAllStringSubmatch(number, -1) subMatch = r.FindAllStringSubmatch(number, -1)
if len(subMatch) == 1 && len(subMatch[0]) == 2 { if len(subMatch) == 1 && len(subMatch[0]) == 2 {
offset, _ := strconv.Atoi(subMatch[0][1]) offset, _ := strconv.Atoi(subMatch[0][1])