mirror of
https://github.com/ericchiang/pup
synced 2024-11-24 08:58:08 +00:00
comma separated selectors added
This commit is contained in:
parent
f72d543143
commit
31aa392d1a
13
pup.go
13
pup.go
@ -53,12 +53,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case "*":
|
case "*": // select all
|
||||||
continue
|
continue
|
||||||
case "+":
|
case "+":
|
||||||
funcGenerator = SelectFromChildren
|
funcGenerator = SelectFromChildren
|
||||||
case ">":
|
case ">":
|
||||||
funcGenerator = SelectNextSibling
|
funcGenerator = SelectNextSibling
|
||||||
|
case ",": // nil will signify a comma
|
||||||
|
selectorFuncs = append(selectorFuncs, nil)
|
||||||
default:
|
default:
|
||||||
selector, err := ParseSelector(cmd)
|
selector, err := ParseSelector(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -70,9 +72,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectedNodes := []*html.Node{}
|
||||||
currNodes := []*html.Node{root}
|
currNodes := []*html.Node{root}
|
||||||
for _, selectorFunc := range selectorFuncs {
|
for _, selectorFunc := range selectorFuncs {
|
||||||
|
if selectorFunc == nil { // hit a comma
|
||||||
|
selectedNodes = append(selectedNodes, currNodes...)
|
||||||
|
currNodes = []*html.Node{root}
|
||||||
|
} else {
|
||||||
currNodes = selectorFunc(currNodes)
|
currNodes = selectorFunc(currNodes)
|
||||||
}
|
}
|
||||||
pupDisplayer.Display(currNodes)
|
}
|
||||||
|
selectedNodes = append(selectedNodes, currNodes...)
|
||||||
|
pupDisplayer.Display(selectedNodes)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user