diff --git a/selector/main.go b/selector/main.go
index ba3581d..06d1f89 100644
--- a/selector/main.go
+++ b/selector/main.go
@@ -34 +34 @@ func SplitSelector(s string) []string {
- var current strings.Builder
+ var current string
@@ -39,3 +39,3 @@ func SplitSelector(s string) []string {
- if current.Len() > 0 {
- if char == ']' {
- current.WriteRune(char)
+ if current != "" {
+ if string(char) == "]" {
+ current += string(char)
@@ -43,2 +43 @@ func SplitSelector(s string) []string {
- result = append(result, current.String())
- current.Reset()
+ result = append(result, current)
@@ -46,2 +45,3 @@ func SplitSelector(s string) []string {
- if char != ']' {
- current.WriteRune(char)
+ current = ""
+ if string(char) != "]" {
+ current += string(char)
@@ -50 +50 @@ func SplitSelector(s string) []string {
- current.WriteRune(char)
+ current += string(char)
@@ -54,2 +54,2 @@ func SplitSelector(s string) []string {
- if current.Len() > 0 {
- result = append(result, current.String())
+ if current != "" && current != "]" {
+ result = append(result, current)
package selector
import (
"slices"
"strings"
"golang.org/x/net/html"
)
// !ISSUE: Create :not and other selectors
func GetInitCSSSelectors(node *html.Node, selectors []string) []string {
if node.Type == html.ElementNode {
selectors = append(selectors, node.Data)
for _, attr := range node.Attr {
if attr.Key == "class" {
classes := strings.Split(attr.Val, " ")
for _, class := range classes {
selectors = append(selectors, "."+class)
}
} else if attr.Key == "id" {
selectors = append(selectors, "#"+attr.Val)
} else {
selectors = append(selectors, "["+attr.Key+"=\""+attr.Val+"\"]")
}
}
}
return selectors
}
func SplitSelector(s string) []string {
var result []string
var current strings.Builder
for _, char := range s {
switch char {
case '.', '#', '[', ']', ':':
if current.Len() > 0 {
if char == ']' {
current.WriteRune(char)
}
result = append(result, current.String())
current.Reset()
}
if char != ']' {
current.WriteRune(char)
}
default:
current.WriteRune(char)
}
}
if current.Len() > 0 {
result = append(result, current.String())
}
return result
}
func Contains(selector []string, node []string) bool {
has := true
for _, s := range selector {
if !slices.Contains(node, s) {
has = false
}
}
return has
}