-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
User definable custom selectors #92
Comments
This is actually really easy for us to implement, as this is how we add support for some of our internal selectors. The thing that gives me pause is the fact that there is no indication that this is the official direction that CSS will official take. Will they require |
Looking at the W3C draft spec vs the csswg draft, there is one difference. We could implement this and allow custom to start with One thing that seems odd in the proposal is that it allows arguments, but each argument is an |
So thinking about this more, I guess not being able to send in What I don't like is the @custom-selector $rest:--n-siblings($n, $sel) {...} Let's say we had 2 custom selectors, each that used
This kind of becomes a recursion problem. I could reasonably see implementing something like: @custom-selector :--n-siblings($n, $sel) But feel that allowing @custom-selector $rest:--n-siblings($n, $sel) I can see why this is still just a talking point, and not something official or fully implemented. I've only seen something like I'm thinking we probably wouldn't implement arguments right away either. We may not even reference the spec at all and simply say call it something like "CSS aliases" and simply define our own rules. Then we could say you don't have require |
Another question is do we require passing in aliases? Or do we allow the create of a custom parser: import soupsieve as sv
parser = sv.custom_parser()
parser.set_namespaces({"ns": "http:/ns.com"})
parser.set_aliases({':header': 'h1, h2, h3, h4, h5, h6'})
parser.select(':header.class', soup) There's nothing stopping us from allowing both though. import soupsieve as sv
ns = {"ns": "http:/ns.com"}
aliases = {':header': 'h1, h2, h3, h4, h5, h6'}
sv.select(':header.class1', soup, namespaces=ns, aliases=aliases) |
Experimental branch here: https://github.com/facelessuser/soupsieve/tree/custom-selectors. Implements custom aliases by creating an Aliases object and then using it to register aliases. The Alias object is then fed into There is no restriction requiring |
The idea of allowing user definable custom selectors is a cool idea that is currently in draft: https://drafts.csswg.org/css-extensions/#typedef-custom-selector.
The idea is essentially to allow create an custom pseudo-class as an alias for a more complex expression.
There seems to be some open issues for a lot more complexity than what is shown here, but I think it may be reasonable to to allow stuff like this, and then a user could construct aliases for whatever they would like. That way we don't ever actually need to support such things directly ourselves.
The text was updated successfully, but these errors were encountered: