causal-agent / scraper

HTML parsing and querying with CSS selectors
https://docs.rs/scraper
ISC License
1.79k stars 98 forks source link

Add convenience methods to iterate only over child and descendant elements instead of all nodes. #158

Closed adamreichold closed 8 months ago

adamreichold commented 8 months ago

Note that we cannot easily extend NodeRef as the types comes from ego-tree, not scaper.

(We could use an extension trait and such, but I think starting from an ElementRef is common enough, especially when using these iterators to stay within the elements.)

Closes #157

Caellian commented 8 months ago

Why not add the trait (e.g. TraverseElements) to extend NodeRef as well and then implement added functions for ElementRef through that?

I wouldn't say it closes #157 as it currently adresses only half of the suggestion.

adamreichold commented 8 months ago

Why not add the trait (e.g. TraverseElements) to extend NodeRef as well and then implement added functions for ElementRef through that?

I wouldn't say it closes #157 as it currently adresses only half of the suggestion.

As written above

(We could use an extension trait and such, but I think starting from an ElementRef is common enough, especially when using these iterators to stay within the elements.)

i.e. I don't think the additional complexity is warranted especially since one will most likely stay within the ElementRef-typed world using these traversal helpers.

cfvescovo commented 8 months ago

LGTM