@@ -2,6 +2,7 @@ package GoHtml
22
33import (
44 "strings"
5+
56 "golang.org/x/net/html"
67)
78
@@ -13,8 +14,8 @@ const (
1314 Tag
1415)
1516
16- //Selector struct represents a single css selector
17- //Ex: .my-class, #video, div
17+ // Selector struct represents a single css selector
18+ // Ex: .my-class, #video, div
1819type Selector struct {
1920 selector string
2021 selectorName string
@@ -42,8 +43,8 @@ func matchNode(node *Node, basicSelectorName string, basicSelectorType BasicSele
4243 return false
4344}
4445
45- //NewSelector takes a single css selector and returns a Selector struct.
46- //Selector string should be only of basic selector.
46+ // NewSelector takes a single css selector and returns a Selector struct.
47+ // Selector string should be only of basic selector.
4748func NewSelector (selector string ) Selector {
4849 selector = strings .TrimSpace (html .EscapeString (selector ))
4950 selectorStruct := Selector {}
@@ -60,7 +61,7 @@ func NewSelector(selector string) Selector {
6061 selectorStruct .selectorType = Tag
6162 }
6263
63- selectorStruct .selector = strings .ToLower (selector )
64+ // selectorStruct.selector = strings.ToLower(selector)
6465 if selectorStruct .selectorType != Tag {
6566 selectorStruct .selectorName = selector [1 :]
6667 } else {
@@ -80,26 +81,26 @@ const (
8081 NoneCombinator
8182)
8283
83- //CombinatorEl is used to represent selectors that are around a combinator.
84+ // CombinatorEl is used to represent selectors that are around a combinator.
8485type CombinatorEl struct {
8586 Type Combinator
8687 Selector1 Selector
8788 Selector2 Selector
8889}
8990
90- //This takes a selector or combinators and selectors and then returns a slice of CombinatorEl.
91+ // This takes a selector or combinators and selectors and then returns a slice of CombinatorEl.
9192func TokenizeSelectorsAndCombinators (selector string ) []CombinatorEl {
9293 iter := func (yield func (string ) bool ) {
9394 currentStr := ""
9495 for _ , char := range selector {
9596 switch char {
9697 case ' ' , '>' , '+' , '~' :
97- if ! yield (currentStr ) || ! yield (string (char )){
98+ if ! yield (currentStr ) || ! yield (string (char )) {
9899 return
99100 }
100101 currentStr = ""
101102 default :
102- currentStr += string (char )
103+ currentStr += string (char )
103104 }
104105 }
105106 yield (currentStr )
@@ -167,6 +168,7 @@ func (ce *CombinatorEl) getDescended(node *Node) *Node {
167168 if matchNode (parentNode , ce .Selector1 .selectorName , ce .Selector1 .selectorType ) {
168169 return parentNode
169170 }
171+
170172 parentNode = parentNode .GetParent ()
171173 }
172174 return nil
0 commit comments