andybalholm / cascadia

CSS selector library in Go
BSD 2-Clause "Simplified" License
703 stars 65 forks source link

Top level > in query #18

Closed anacrolix closed 7 years ago

anacrolix commented 8 years ago

I'm using goquery, and retrieved a selection. I want to do a further query on that selection, requiring direct descendents of the selected nodes, so I start my query with '>'. For example say I find a particular 'ul' element, then want to target direct child 'li' elements in a later query on the selection containing the 'ul', I'd pass '> li'. Perhaps I'm not doing this right, but it seems jQuery supports it, but cascadia will not. Thanks.

https://github.com/PuerkitoBio/goquery/issues/117

andybalholm commented 8 years ago

I don't think there is any way to do that in Cascadia without changing the API. Potentially there could be a CompileWithContext function, and you could pass it the current node along with the selector. But I think it would make more sense to handle this at the goquery level, where the selectors are being passed as strings.

anacrolix commented 8 years ago

That seems unfortunate. I think implementing this in cascadia level would be more performant and natural.

andybalholm commented 8 years ago

Actually, implementing it in goquery would have better performance, since it would not need to scan all the descendant nodes and check each one to see if it is an immediate child. It could just iterate over the child nodes and return the ones that match the remainder of the selector.

But I just realized that would only work if the remainder of the selector is all in reference to one node. If it's referring to descendants of that child node, things get really complicated.

andybalholm commented 7 years ago

I'm closing all requests for context-sensitive selectors as wontfix.