nipper icon indicating copy to clipboard operation
nipper copied to clipboard

Expose NodeData enum

Open xamgore opened this issue 1 year ago • 0 comments

Imagine you would like to iterate through Text nodes. It may be helpful when you have non-structured text intermixed with markup nodes.

<div class="cls">
  <strong>Title</strong>
  1 | 2 | 3
  Love you
  <span>18+</span>
  John Doe
</div>
node.select(".cls").nodes().iter().filter(|it| it.query(|n| match n.data {
    NodeData::Text{ .. } => true,
    _ => false,
})),

The other way around would look like this:

node
  .select(".cls")
  .nodes()
  .iter()
  .flat_map(|node| node.children())
  .filter(|node| node.is_text())
  .map(|node| node.text())
  .collect::<Vec<_>>();

But this approach won't work for HTML comments.

xamgore avatar Jun 07 '23 15:06 xamgore