New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for pseudo elements #40
Conversation
Somehow we need to make sure that a pseudo-element selector doesn't match anything at all unless the caller explicitly supports pseudo-elements. Would it be better to have a MatchPseudoElement(n *html.Node) (match bool, pseudo string)? It would return |
Why not, but I'm not sure to understand the need for this, since pseudo-elements can't change the node selected. They are only linked to a selector, and can be retrieved on matching, but don't have any influence on the matching (specificity aside). |
A selector like |
Ah, you're right ! |
If somebody enters a selector with a pseudo-element into a program that doesn't support pseudo-elements, they should either get an error, or it should do nothing. So we need to come up with an API that works this way for programs that don't specifically ask for pseudo-element support. |
In this case, we could add a boolean parameter |
I think you're on the right track. But I don't want to clutter up the common use case (no pseudo elements) with an extra parameter. I suppose that means we'd need to add a ParseWithPseudoElements method or something. I noticed you're working on porting a project from Python. Does it use a general-purpose selector library? If so, how does it handle this issue? |
They have built their own selector library cssselect2. |
So, as you suggested, I added a method |
Your doc comment mentions |
Added ParseWithPseudoElement alongside ParseGroupWithPseudoElements |
Hi again,
This PR adds support for pseudo elements.
The approach taken boils down to adding a method
PseudoElement
onSel
, even for simple selectors, where the implementation is "empty".