[selectors] Proposal: filtered sibling combinator


One problem I am interested in solving is the inability to format documents that do not have a strong hierarchical structure.

For example, let's take:
    <h1>Title 1</h1>
    <h1>Title 2</h1>
A common use case is styling the first paragraph after a title (for example, using ::first-letter). We can try:
but that is too strong, it does not patch Paragraph1. We can try:
but that is too weak, every paragraph matches.

My current idea to solve those cases is to extend the ~ combinator to take a selector filtering the traversal. Something of the form:
    a ~(b) c

Traversal to find "c" would
1) Evaluate "c" on a sibling.
2) If [1] fails, evaluate b on the sibling.
3) If [2] succeed, go to the next sibling.
4) If [2] fails, fail to match.

The use case above can be written has:
    h1 ~(:not(h1, p)) p
Which is traverse from <h1> to a <p> but never skip over a <h1> or <p>.

The same principle could be used for descendant selector for generality.
For example, an image not in a link:
    img:not(:any-link *)
can be rewritten as
    * >>(:not(:any-link)) img
which is cleaner in my opinion.

Any interest?


Received on Saturday, 11 October 2014 06:32:08 UTC