modified regex to allow numbers over 9 :nth-child

pull/158/head
mdrokz 3 years ago
parent 0a20559174
commit 7ffc0578de

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

Loading…
Cancel
Save