Skip to content

(Preview) Selectors can match against Nodes #2324

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

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft

(Preview) Selectors can match against Nodes #2324

wants to merge 14 commits into from

Conversation

jhy
Copy link
Owner

@jhy jhy commented May 15, 2025

This extends the QueryParser and Evaluators to support matching nodes (including specific node types, and their nodeValue contents)

Allows finding e.g. Elements following a particular comment or text node.

E.g.: ::comment:contains(prices) + p will find p Elements directly after a <!-- prices: --> comment.

Or: div:has(>::comment) will find div Elements that directly have comment children.

Available operators so far:

  • ::node (matches any leaf node)
  • ::text (matches a text node)
  • ::comment (matches a comment node)
  • ::data (matches a data node)
  • :contains(text) when in a node context will match the text against the normalized node value

This is the first pass; next pass will be to implement various NodeList selectNodes(css) methods to allow nodes to be selected directly (not just Elements).

Extends the QueryParser and Evaluators to support matching nodes (including specific node types, and their nodeValue contents)

Allows finding e.g. Elements following a particular comment or text node.
@jhy jhy marked this pull request as draft May 15, 2025 00:59
First draft of the ability to select nodes, into Nodes<T extends Node>.
... and remove unused root param
@821938089
Copy link
Contributor

Does the Nodes class have a DOM update feature like the Elements class?
If so, please provide aliases for all original array methods.

@jhy
Copy link
Owner Author

jhy commented May 22, 2025

Does the Nodes class have a DOM update feature like the Elements class? If so, please provide aliases for all original array methods.

@821938089 yup, same as Elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants