Description
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:
- find all anchor elements - possible with
Floki.find
- 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.