Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • nipper nipper
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 4
    • Issues 4
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • importcjj
  • nippernipper
  • Merge requests
  • !28

Open
Created Jun 07, 2023 by importcjj@importcjjMaintainer
  • Report abuse
Report abuse

Expose NodeData enum

  • Overview 0
  • Commits 1
  • Changes 1

Created by: xamgore

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.

Assignee
Assign to
Reviewer
Request review from
None
Milestone
None
Assign milestone
Time tracking
Source branch: github/fork/xamgore/patch-1