Skip to content

Releases: niklak/dom_query

0.18.0

26 Apr 10:20
Compare
Choose a tag to compare

Release Notes for 0.18.0 (2025-04-26) 🚀

✨ New Features

  • Added NodeRef::wrap_node, NodeRef::wrap_html, and NodeRef::unwrap_node methods. These allow wrapping a node with another node or an HTML fragment, and unwrapping it back. (by @phayes)
  • Introduced Tree::validate, a method to perform comprehensive integrity checks on node relationships, links, and cycles within the DOM tree. (by @phayes)

🔧 Changes

  • Updated dependencies:
    • selectors updated to 0.27.0.
    • cssparser updated to 0.35.0.
    • html5ever updated to 0.31.0.
  • Improved mini_selector::Attribute: attribute values can now be enclosed in double quotes, single quotes, or left unquoted.
  • Changed entities::Attr visibility to pub, making it publicly accessible.
  • Enhanced TreeNodeOps::append_child_of and TreeNodeOps::prepend_child_of to internally call TreeNodeOps::remove_from_parent on the new child node. This ensures the node is properly detached from its previous parent and siblings before reattachment, preventing dangling references.

🐛 Bug Fixes

  • Fixed template element serialization in the NodeRef::html and NodeRef::inner_html methods.

Examples

Changelog

Full Changelog: 0.17.0...0.18.0

0.17.0

31 Mar 08:49
Compare
Choose a tag to compare

Release Notes for 0.17.0 (2025-03-31) 🚀

✨ New Features

  • Introduced the NodeRef::strip_elements(&[&str]) method, which removes matched elements while retaining their children in the document tree.
  • Introduced the Selection::strip_elements(&[&str]) method, which performs the same operation as NodeRef::strip_elements(&[&str]) but for every node in the Selection.
  • Introduced the NodeRef::retain_attrs(&[&str]) method, which allows retaining only the specified attributes of a node.
  • Introduced the Selection::retain_attrs(&[&str]) method, which performs the same operation as NodeRef::retain_attrs but for every node in the Selection.

Changelog

Full Changelog: 0.16.0...0.17.0

0.16.0

09 Mar 10:53
Compare
Choose a tag to compare

Release Notes for 0.16.0 (2025-03-09) 🚀

✨ New Features

  • Added NodeRef::element_ref, which returns a reference to the underlying Element if the node is an element node.
  • Added NodeRef::qual_name_ref, which returns a reference to the qualified name of the node.
  • Added NodeRef::has_name, which checks if the node is an element with the given local name.
  • Added NodeRef::is_nonempty_text, which checks if the node is a non-empty text node.

🔧 Changes

  • Optimized element matching: when a single root node is present, DescendantMatches (using DescendantNodes) is now utilized as the internal iterator, improving performance by eliminating the need for duplicate checks. When multiple root nodes exist, Matches remains in use, ensuring proper duplicate handling.
  • Updated <NodeRef as selectors::Element>::is_link to always return false as its impact on element matching was unclear and added unnecessary overhead.

Changelog

Full Changelog: 0.15.2...0.16.0

0.15.0

01 Mar 18:33
Compare
Choose a tag to compare

Release Notes for 0.15.0 (2025-03-01) 🚀

📚 Check out examples

✨ New Features

  • Implemented the markdown feature, which allows serializing a Document or NodeRef into Markdown text using the md() method.
  • Implemented the mini_selector feature, providing a lightweight and faster alternative for element matching with limited CSS selector support. This includes additional NodeRef methods: find_descendants, try_find_descendants, mini_is, and mini_match.

🐛 Bug Fixes

  • Selection::select now returns nodes in ascending order if there were multiple underlying root nodes. If there was only one root node, it still returns nodes in ascending order, just as before.

Changelog

Full Changelog: 0.14.0...0.15.0

0.14.0

16 Feb 08:38
Compare
Choose a tag to compare

Release Notes for 0.14.0 (2025-02-16) 🚀

✨ New Features

  • Implemented the Node::id_attr and Node::class methods, which return the id and class attributes of the node, respectively. The Selection::id and Selection::class methods provide the same functionality for the first node in the selection.

🔧 Changes

  • Replaced foldhash::HashSet with bit-set::BitSet in the Matches::next method. This ensures efficient duplicate detection while iterating over matches, as bit-set offers better performance for this use case.
  • Revised the NodeRef::formatted_text implementation: moved related code to a separate module, extended the formatting logic, and added more test cases.

🐛 Bug Fixes

  • Fixed an issue where DescendantNodes could traverse beyond the initial node when iterating over descendants, affecting NodeRef::descendants and NodeRef::descendants_it.

Changelog

Full Changelog: 0.13.3...0.14.0

0.13.0

02 Feb 11:59
Compare
Choose a tag to compare

Release Notes for v0.13.0 (2025-02-02) 🚀

📚 Check out examples

✨ New Features

  • Text Processing Enhancements:
    • Added NodeRef::normalized_char_count method to estimate character count in descendant nodes' text after normalization.
    • Introduced new formatted text retrieval methods across different levels:
      • Document::formatted_text for document-level text formatting
      • Selection::formatted_text for handling formatted text in selections
      • NodeRef::formatted_text for node-specific formatted text extraction

Changelog
Full Changelog: 0.12.0...0.13.0

0.12.0

16 Jan 14:31
Compare
Choose a tag to compare

Release Notes for v0.12.0 (2025-01-16) 🚀

📚 Check out examples

✨ New Features

  • NodeRef Enhancements:

    • Added NodeRef::is_match and NodeRef::is methods for checking if a node matches a given matcher (&Matcher) or selector (&str) without creating a Selection object.
    • Introduced NodeRef::find, an experimental method for finding all descendant elements matching a given path. It is significantly faster than Selection::select.
  • Tree and Document Enhancements:

    • Added Document::base_uri and NodeRef::base_uri for retrieving the base URI of a document using the href attribute of the <base> element. Inspired by Node: baseURI property.

🔨 Improvements

  • Selection:
    • Reduced usage of RefCell::borrow and RefCell::borrow_mut to simplify internal code.
  • Matches:
    • Optimized internal code to improve selection performance.

Changelog

Full Changelog: 0.11.0...0.12.0

0.11.0

11 Dec 09:32
Compare
Choose a tag to compare

Release Notes for v0.11.0 (2024-12-10) 🚀

📚 Check out examples

✨ New Features

  • Atomic Feature:
    Added the atomic feature, which replaces NodeData's use of StrTendril with Tendril<tendril::fmt::UTF8, tendril::Atomic>.
    This enables NodeData and related structures, including Document, to implement the Send trait.

  • NodeRef Enhancements:

    • Introduced NodeRef::insert_siblings_after, enabling the insertion of a node along with its siblings after a selected node.
    • Introduced NodeRef::before_html and NodeRef::after_html for inserting HTML content before or after a specific node.
  • Selection Enhancements:

    • Introduced Selection::set_text to set the content of each node in the selection to specified content.
    • Introduced Selection::before_html and Selection::after_html to insert HTML content before or after each node in a selection.
    • Introduced Selection::prepend_selection, allowing nodes from one selection to be prepended to the current selection.

🔨 Improvements

  • Internal code changes reduce calls to RefCell::borrow and RefCell::borrow_mut.

Changelog

Full Changelog: 0.10.0...0.11.0

0.10.0

25 Nov 10:08
Compare
Choose a tag to compare

Release Notes v0.10.0 (November 25, 2024) 🚀

📚 Check out examples

✨ New Features

  • Introduced new node manipulation methods:
    • NodeRef::insert_after: Insert a node after the selected node
    • NodeRef::descendants_it: Iterate over all descendants of a node
    • NodeRef::descendants: Get a vector containing all descendants of a node
  • Added normalization functionality:
    • NodeRef::normalize: Merges adjacent text nodes and removes empty text nodes at node level
    • Document::normalize: Performs normalization across the entire document

⚠️ Deprecations

Several methods have been deprecated in favor of more consistently named alternatives:

  • NodeRef::append_prev_siblingNodeRef::insert_before
  • NodeRef::append_prev_siblingsNodeRef::insert_siblings_before
  • Tree::append_prev_sibling_ofTree::insert_before_of

🔨 Improvements

  • Modified Document::from and Document::fragment to disable scripting in HTML parser, enabling proper querying of noscript elements

🐛 Fixed

  • Document::text method now returns the text content, whereas previously it returned an empty string

🔧 Minor Changes

  • Added support for ordered comparison of node IDs through implementation of Ord trait for NodeId

🔄 Migration Guide

Users are encouraged to update their code to use the new method names for better maintainability. The deprecated methods will be removed in a future release.

Changelog

Full Changelog: 0.9.1...0.10.0

0.9.0

09 Nov 18:01
Compare
Choose a tag to compare

Release Notes v0.9.0 (November 9, 2024)

This release includes significant improvements to node selection and manipulation methods, new functionality for content prepending, and a critical bug fix

🔄 Changes

  • Added reverse iteration support in Tree::child_ids_of_it and NodeRef::children_it (use rev: true for reverse order)
  • Improved internal logic for selection operations (Selection::append_selection and Selection::replace_with_selection)

✨ New Features

  • Added new node prepending methods:
    • NodeRef::prepend_child: Insert a single child at the start
    • NodeRef::prepend_children: Insert multiple children at the start
    • NodeRef::prepend_html: Parse and insert HTML content at the start
    • Selection::prepend_html: Parse and insert HTML at the start of all matched nodes
  • Introduced new selection extension methods:
    • Selection::ancestors: Get ancestors of matched elements
    • Selection::add_selection: Add another selection to current selection
    • Selection::add_matcher
    • Selection::add
    • Selection::try_add

🐛 Bug Fixes

  • Enhanced selection operations to properly handle multiple nodes and cross-tree selections:
    • Fixed Selection::append_selection
    • Fixed Selection::replace_with_selection
  • Improved node attachment methods to automatically handle node detachment from previous parent:
    • Node::append_child
    • Node::append_children
    • Node::prepend_child
    • Node::prepend_children

⚠️ Critical Fix

Fixed a significant issue in NodeRef::first_element_child where the method incorrectly checked the node itself instead of its children. This fix may affect existing code that relies on this method.

Impact:

  • CSS selector :has() behavior could have been affected
  • First element child detection logic
  • Code depending on this method's behavior

Action Required:

Please review any code that depends on NodeRef::first_element_child after upgrading to ensure compatibility with the corrected behavior.

Changelog

Full Changelog: 0.8.0...0.9.0