mirror of
https://github.com/ericchiang/pup
synced 2024-11-28 02:48:16 +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 {
|
||||
case "*":
|
||||
case "*": // select all
|
||||
continue
|
||||
case "+":
|
||||
funcGenerator = SelectFromChildren
|
||||
case ">":
|
||||
funcGenerator = SelectNextSibling
|
||||
case ",": // nil will signify a comma
|
||||
selectorFuncs = append(selectorFuncs, nil)
|
||||
default:
|
||||
selector, err := ParseSelector(cmd)
|
||||
if err != nil {
|
||||
@ -70,9 +72,16 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
selectedNodes := []*html.Node{}
|
||||
currNodes := []*html.Node{root}
|
||||
for _, selectorFunc := range selectorFuncs {
|
||||
if selectorFunc == nil { // hit a comma
|
||||
selectedNodes = append(selectedNodes, currNodes...)
|
||||
currNodes = []*html.Node{root}
|
||||
} else {
|
||||
currNodes = selectorFunc(currNodes)
|
||||
}
|
||||
pupDisplayer.Display(currNodes)
|
||||
}
|
||||
selectedNodes = append(selectedNodes, currNodes...)
|
||||
pupDisplayer.Display(selectedNodes)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user