From 8bef3ef15b0474cd9509bbed731066dd28b72cf6 Mon Sep 17 00:00:00 2001 From: mdrokz <33598169+mdrokz@users.noreply.github.com> Date: Sat, 14 Aug 2021 14:34:43 +0530 Subject: [PATCH] added support for -n+A for :nth-child --- selector.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/selector.go b/selector.go index 6249f77..728981b 100644 --- a/selector.go +++ b/selector.go @@ -524,8 +524,18 @@ func parseNthPseudo(cmd string) (PseudoClass, error) { return n.Type == html.ElementNode && countNth(n)%cycle == offset }, 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 - r = regexp.MustCompile(`n[ ]?\+[ ]?([0-9])`) + 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])