1
0
mirror of https://github.com/ericchiang/pup synced 2025-01-28 08:31:26 +00:00

modified regex to allow numbers over 9 :nth-child

This commit is contained in:
mdrokz 2021-08-15 08:39:59 +05:30
parent 0a20559174
commit 7ffc0578de

View File

@ -510,12 +510,13 @@ func parseNthPseudo(cmd string) (PseudoClass, error) {
oddOrEven = 0
}
if oddOrEven > -1 {
fmt.Println("bruh it stopped")
return func(n *html.Node) bool {
return n.Type == html.ElementNode && countNth(n)%2 == oddOrEven
}, nil
}
// Check against '3n+4' pattern
r := regexp.MustCompile(`([0-9]+)n[ ]?\+[ ]?([0-9])`)
r := regexp.MustCompile(`([0-9]+)n[ ]?\+[ ]?([1-9][0-9]{0,2}|1000)$`)
subMatch := r.FindAllStringSubmatch(number, -1)
if len(subMatch) == 1 && len(subMatch[0]) == 3 {
cycle, _ := strconv.Atoi(subMatch[0][1])
@ -526,7 +527,7 @@ func parseNthPseudo(cmd string) (PseudoClass, error) {
}
// check against '-n+2' pattern
r = regexp.MustCompile(`^-n[ ]?\+[ ]?([0-9])`)
r = regexp.MustCompile(`^-n[ ]?\+[ ]?([1-9][0-9]{0,2}|1000)$`)
subMatch = r.FindAllStringSubmatch(number, -1)
if len(subMatch) == 1 && len(subMatch[0]) == 2 {
offset, _ := strconv.Atoi(subMatch[0][1])
@ -536,7 +537,7 @@ func parseNthPseudo(cmd string) (PseudoClass, error) {
}
// check against 'n+2' pattern
r = regexp.MustCompile(`^n[ ]?\+[ ]?([0-9])`)
r = regexp.MustCompile(`^n[ ]?\+[ ]?([1-9][0-9]{0,2}|1000)$`)
subMatch = r.FindAllStringSubmatch(number, -1)
if len(subMatch) == 1 && len(subMatch[0]) == 2 {
offset, _ := strconv.Atoi(subMatch[0][1])