support CSS pseudo-element selectors #2361
Replies: 6 comments
-
@mattparlane Thanks for opening a ticket about this. Can you help me understand a bit more about what you're trying to do? Nokogiri's CSS parser is intended only to transform CSS queries into XPath queries; it's not intended to be a complete implementation of CSS syntax. Another way to phrase the above question: can you give me a complete code snippet that demonstrates what you're trying to do when you provide a property/value pair like you did above ( Further, I'm interested in hearing your thoughts on which of the pseudo-element selectors you think are important for Nokogiri to implement? |
Beta Was this translation helpful? Give feedback.
-
Hey @flavorjones, thanks for getting back to me. I'm actually using Nokogiri indirectly, via an old unmaintained gem called inline_style. I understand now that this is probably not the intended use, but I didn't realise that previously. The gem takes an HTML file which may include CSS rules inside a Up to you as to what you want to do about it... Thanks for your time. |
Beta Was this translation helpful? Give feedback.
-
@mattparlane Oh, I see - so you have a style sheet that uses If so, I think it's a reasonable feature request for Nokogiri's parser to not error out when it sees pseudo-elements -- I can fix that relatively easily. But I would like to understand which pseudo-elements you care about, so that I can prioritize which ones we try to implement properly. Can you share more about your usage to help us prioritize? |
Beta Was this translation helpful? Give feedback.
-
Sorry about the delay. I guess my naive thinking is that all pseudo-elements should be supported... but I'm not au fait with the reason why each needs to be implemented separately or how much work it would be. My use case is for custom CSS which is entered by users, so the universe of options is basically all CSS. Before you ask (because I also asked), pseudo-elements are indeed supported in some email clients: https://www.emailonacid.com/blog/article/email-development/using-pseudo-elements-to-progressively-enhance-your-emails/ Sorry if that's too vague... and totally understand if it's not realistic. Thanks! |
Beta Was this translation helpful? Give feedback.
-
@mattparlane It's helpful to know your use case is, essentially, "make inline_style not throw up on these selectors". There are some very real challenges to implementing most of these pseudo-elements correctly, though, which is why I asked the question. What should be returned on a query for But what should be returned on a query for All of which is to say, there are deeper issues around return values for a pseudo-element query that we'd need to figure out before starting to implement anything. In the meantime, maybe we could make a minor improvement to Nokogiri to raise a new exception type like |
Beta Was this translation helpful? Give feedback.
-
Hey @flavorjones, thanks for getting back to me. And thanks for explaining, I now understand the challenges involved. Yes, I believe that new exception would work, as long as it's raised in a way that's not terminal. Thanks again, this will help a lot! |
Beta Was this translation helpful? Give feedback.
-
Hi!
Apologies if this has been submitted already. It looks like Nokogiri's CSS parser can't handle pseudo-elements (as opposed to pseudo-classes). As far as I can tell it's valid CSS3.
To reproduce:
Result:
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions