Skip to content
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

Get node selector #378

Open
benpony opened this issue Dec 21, 2021 · 0 comments
Open

Get node selector #378

benpony opened this issue Dec 21, 2021 · 0 comments
Labels

Comments

@benpony
Copy link

benpony commented Dec 21, 2021

Feature goal

When one wishes server-side to return processed elements selectors that the browser can use.

Example: find and replace text mechanism: at first it makes sense to only highlight the elements one wishes to replace on a certain page - this functionally requires a selector: client-side probably expects an array of elements selectors in order to highlight them:

flow example

Requirement: highlight all links pointing to google.com
Suggested Solution:

  1. find all anchor elements - possible with Floki.find
  2. return elements selectors to client-side so it can perform the wanted ui actions on them - Currently not possible

Also it can be extremely nice to combine this functionality with current text search:
"Give me all the nodes that contains a 'hello'" -> Floki.text returning a collection of nodes with their selector is extremely useful here!

# the new api
@spec node_selector(html_tree(), html_node()) :: css_selector()
{:ok, selector} = Floki.node_selector(html_tree, html_node)

Dependencies

Should be achievable without new dependencies by a recursive logic that gets the html_tree() and the html_node():
While it searches for a given node in the html tree, it assembles a valid css/xpath selector based on node properties such as tag name and class name.

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

No branches or pull requests

1 participant