NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io
crates.io, #2056 most downloaded on crates.io
HTML querying and manipulation with CSS selectors
Latest stable
0.29.0
Last release 1 months ago
23 Oct 2026
Release timing varies
gaps range from 8 days to 5 months
Nearly every release is documented
notes for 47 of 49 stable releases
1 version withdrawn
withdrawn after publishing
3 years old
50 releases · first in 2023
Drag across the ruler to compare, or tap a release to open it.
Added the checked-node-mutations feature for additional protection against invalid ancestor moves in NodeRef mutation methods.
checked-node-mutations feature for additional protection against invalid ancestor moves in NodeRef mutation methods.NodeIdProver::tree to identify the tree that owns a node ID.Tree::len to report the total number of nodes, including detached nodes.StrTendril to String, with no public API changes.NodeId as a NonZeroU32, halving the size of TreeNode and reducing NodeData size -- thanks to @emschwartz.AncestorNodes, NodeRef::formatted_text, and selector matching for better performance (@emschwartz).checked-node-mutations, ancestor moves that could corrupt the tree.Tree::validate to detect inconsistent parent-child relationships.NodeRef::normalize and NodeRef::strip_elements to handle deeply nested documents without stack overflow; also improved their performance.Special thanks to @emschwartz for the enthusiasm and substantial contributions to this release, particularly the significant improvements to Markdown serialization and the reduced memory footprint of the dom_query tree.
Full Changelog: 0.28.0...0.29.0
Your coding agent can read these notes before it upgrades. Set up the MCP server →
checked-node-mutations feature (disabled by default): NodeRef mutation methods also ignore ancestor moves, including ancestors anywhere in the moved sibling run. Self moves are always ignored.NodeIdProver::tree, which reports the tree that owns the node id; it returns None by default, and &NodeRef returns its tree.Tree::len, a method that returns the total number of nodes in the Tree, including detached nodes.NodeRef mutation methods now ignore a node from another document instead of using its id in the wrong arena and corrupting the tree. The check compares tree identity by pointer and is always enabled; raw &NodeId providers carry no tree and cannot be checked.NodeRef mutation methods now ignore self moves in all builds; with checked-node-mutations, they also ignore ancestor moves instead of detaching nodes and corrupting the tree.append_selection, replace_with_selection and NodeRef::to_fragment no longer drop the contents of a <template> when the template itself is the copied node.Tree::validate now catches nodes that name a parent but are missing from that parent's child list.NodeRef::wrap_html no longer leaves unused fragment nodes pointing at an unrelated live node as their parent when the fragment is not a single element.Tree::reparent_children_of now appends the moved children after the new parent's existing children instead of replacing them, and leaves the tree untouched when the target node does not exist.NodeRef::append_children and NodeRef::prepend_children no longer loop forever when the moved node is already a child of the target node; the run is collected before any node is moved.append_html, set_html, before_html, after_html and replace_with_html no longer lose the content that the parser foster-parents out of a <table> (text or elements written directly inside it), on both NodeRef and Selection.replace_with_html on table elements (td, th, tr, etc.) now parses the replacement in the parent's table context, so a <td> or <tr> in the new HTML is no longer stripped to plain text, on both NodeRef and Selection.NodeRef::unwrap_node no longer drops the parent's children that precede the unwrapped node; every child of the parent is kept.NodeRef::normalize and NodeRef::strip_elements no longer recurse per DOM level, so deeply nested documents no longer overflow the stack; both now do a single pass under one borrow instead of per-node NodeRef calls, which is also faster. normalize now keeps the first text node of a merged run, as the DOM Standard does, instead of the last. ) in md link destinations to align with html5ever behavior.# marker inside a list item, and keep text that follows a block in a list item inside the item; the text was written at column zero, which ended the list and ran into the next item's marker.<div>, <section> or <article> inside the item; they were written at column zero, which left the item empty and ended the list.<p>).<th> in its own row instead of moving it into the table's header row.<br> and drop a trailing <br> from a cell.<p>).# in a heading, which was dropped as the ATX closing sequence, and a line of only =, which turned the line above it into a setext heading.<blockquote> inside its list item by indenting every line to the item's content column; previously the quote's > markers were dropped and its text ended the list.<pre> code blocks inside their list item by indenting every line to the item's content column; previously the fence started at column zero and ended the list.<hr> inside its list item as an indented --- on its own line; the rule was dropped.[ ](url).<code> and whitespace-only <code>, padding the span so parsers don't strip them; whitespace around a line break at an edge is still trimmed as source indentation. ) instead of collapsing them like ASCII whitespace.ol start and li value; ordered list markers now increment instead of every item being 1. .<span>1</span>. text). ).<code> content containing backticks in a longer delimiter run instead of backslash-escaping the backticks (backslash escapes are not interpreted inside code spans).[...] broke the link.<, or unbalanced parens; escape [/] in alt text and " in titles.srcset URL, then data-src, for images without src.<a><img></a>) as [](href) instead of dropping them.! right before a link, so Wow!<a> no longer becomes image syntax.<strong>text </strong> no longer serializes as **text ** (which renderers display as literal asterisks).., ,, !, (, ), {, } is no longer backslash-escaped.~ in text; a ~~~ line opened a code fence and ~~x~~ rendered as strikethrough.<th> are recognized by renderers.link, image, table, list, code, emphasis, quote) with element-specific helpers next to them; shared text utilities stay in text_utils. No public API or output changes.AncestorNodes by tracking the remaining depth in a single u32, reducing its size and per-step work. No public API changes.NodeRef::formatted_text performance by using String buffer instead of StrTendril. No public API changes.Selection::select visits each node once when the selection's nodes are nested in one another; a subtree shared by nested roots was traversed again for each root.NodeId as a NonZeroU32 (index + 1), so Option<NodeId> takes 4 bytes instead of 16. This halves TreeNode (160 to 80 bytes) and shrinks NodeData (72 to 56 bytes), cutting parsed document memory by about 30%. A tree can now hold at most u32::MAX - 1 nodes. No public API changes.String instead of StrTendril. No public API changes.Matcher matches a list of bare type selectors (p, ul,ol) by comparing local names instead of running the full selector matcher on every element; a single-root select with such a list reads each node once through its iterator's borrow. No public API changes.html5ever: 0.39.0 -> 0.40.1selectors: 0.38.0 -> 0.41.0cssparser: 0.37.0 -> 0.38.0hashbrown: 0.16.1 -> 0.17.1bit-set: 0.8.0 -> 0.11.1Refactored internal Selection tree access logic to improve maintainability. No public API changes.
html5ever: 0.38.0 -> 0.39.0selectors: 0.36.0 -> 0.38.0cssparser: 0.36.0 -> 0.37.0hashbrown: 0.16.0 -> 0.16.1Selection tree access logic to improve maintainability. No public API changes.pedantic and nursery) suggestions to improve overall code quality.NodeRef::md and Document::md implementations into a dedicated serializing/md submodule for better internal organization. No public API changes.Full Changelog: 0.27.0...0.28.0
html5ever: 0.38.0 -> 0.39.0selectors: 0.36.0 -> 0.38.0cssparser: 0.36.0 -> 0.37.0hashbrown: 0.16.0 -> 0.16.1Selection tree access logic. No public API changes.NodeRef::md and Document::md implementations to a dedicated serializing/md
submodule to improve code organization. No public API changes.Introduced Tree::new_element_qualname , allowing creation of elements with a specific html5ever::QualName .
Tree::new_element_qualname, allowing creation of elements with a specific html5ever::QualName.Element::add_class for both empty and existing class attributes.Element::remove_class using a Vec-based approach, preserving the original class order while improving performance.Tree::new_element. Previously, manually created void elements could serialize with closing tags due to the wrong namespace. Elements created during HTML parsing were not affected.Full Changelog: 0.26.0...0.27.0
Tree::new_element_qualname, which allows to create a new element with specific html5ever::QualName.Element::add_class for both empty and pre-existing class attributes.Element::remove_class now uses a Vec-based approach to remove classes, preserving the original order and improving performance.Tree::new_element that caused manually created void elements
to serialize with closing tags (elements created during parsing were not affected).Refactored internal TreeNodeOps methods; no functional or API changes.
html5ever: 0.36.1 → 0.38.0tendril: 0.4.3 → 0.5.0selectors: 0.35.0 → 0.36.0TreeNodeOps methods; no functional or API changes.NodeRef::immediate_text now returns text for text nodes, not only the immediate text of child elements.Full Changelog:
0.25.1...0.26.0
Update dependencies:
html5ever: 0.36.1 -> 0.38.0tendril: 0.4.3 -> 0.5.0selectors: 0.35.0 -> 0.36.0Refactor internal TreeNodeOps methods. No functional changes.
NodeRef::immediate_text now returns text for text nodes, not just immediate text of elements.Rolled back dependencies due to an upstream issue (details in #168):
Rolled back dependencies due to an upstream issue (details in #168):
html5ever: 0.37.1 → 0.36.1tendril: 0.5.0 → 0.4.3Reverted code changes introduced to maintain compatibility with newer versions of html5ever and tendril.
Full Changelog: https://github.com/niklak/dom_query/compare/0.25.0...0.25.1
html5ever: 0.37.1 -> 0.36.1tendril: 0.5.0 -> 0.4.3html5ever and tendril compatibility.Refactored internal code to stay compatible with the latest html5ever and tendril APIs.
Updated dependencies:
selectors: 0.33.0 → 0.35.0html5ever: 0.36.1 → 0.37.1tendril: 0.4.3 → 0.5.0Refactored internal code to stay compatible with the latest html5ever and tendril APIs.
Reworked the internal structure of the markdown feature; no public API changes.
ul, ol), resulting in more correct and predictable Markdown output.Full Changelog: https://github.com/niklak/dom_query/compare/0.24.0...0.25.0
Update dependencies:
selectors: 0.33.0 -> 0.35.0html5ever: 0.36.1 -> 0.37.1tendril: 0.4.3 -> 0.5.0Refactored code to be compatible with the latest changes in html5ever and tendril.
Change internal code structure for markdown feature.
Updated internal implementation of NodeRef::find for cleaner logic and improved maintainability.
Updated internal implementation of NodeRef::find for cleaner logic and improved maintainability.
Exposed TreeNode to the public API.
Dependency updates:
selectors: 0.31.1 -> 0.33.0cssparser: 0.35.0 -> 0.36.0html5ever: 0.35.0 -> 0.36.1Selection.NodeRef::normalized_char_count.Document::from.Document::html.Examples Changelog Full Changelog: https://github.com/niklak/dom_query/compare/0.23.1...0.24.0
Selection.NodeRef::normalized_char_count.Document::from.Document::html.NodeRef::find method.TreeNode.selectors: 0.31.1 -> 0.33.0cssparser: 0.35.0 -> 0.36.0html5ever: 0.35.0 -> 0.36.1Markdown: MDSerializer::find_code_language now uses MDSerializer::find_code_language_css_class as a fallback when it fails to detect the code language
MDSerializer::find_code_language now uses MDSerializer::find_code_language_css_class as a fallback when it fails to detect the code language from ancestor elements. (by @justahero)title attributes of <a> elements. (by @justahero)Full Changelog: https://github.com/niklak/dom_query/compare/0.23.0...0.23.1
MDSerializer::find_code_language now uses MDSerializer::find_code_language_css_class as a fallback when it fails to detect the code language from the ancestors (by @justahero).title attributes of <a> elements (by @justahero).markdown is a default crate feature.Implemented Element::attr_ref method, which returns an &str reference to the attribute value by html5ever::LocalName.
Element::attr_ref method, which returns an &str reference to the attribute value by html5ever::LocalName.html5ever::LocalName and html5ever::local_name for easier access.<pre>-block parsing by checking data-lang and data-language attributes. (by @justahero)<code> blocks are now parsed as <pre> blocks. (by @justahero)NodeRef::find_descendants (requires mini_selector feature). This method now supports the Adjacent (+) and Sibling (~) combinators.Full Changelog: https://github.com/niklak/dom_query/compare/0.22.0...0.23.0
Element::attr_ref method which returns an &str reference to the attribute value by html5ever::LocalName.html5ever::LocalName and html5ever::local_name.<pre>-block parsing by checking its associated data-lang and data-language attributes (by @justahero)<code> blocks are now parsed as <pre> blocks (by @justahero).NodeRef::find_descendants (requires mini_selector feature). This method now supports Adjacent (+) and Sibling (~) combinators.Added Tree::is_mathml_annotation_xml_integration_point method to check whether a node is a MathML annotation XML integration point.
Tree::is_mathml_annotation_xml_integration_point method to check whether a node is a MathML annotation XML integration point.Updated dependencies:
foldhash: 0.1.5 → 0.2.0hashbrown: 0.15.3 → 0.16.0Refactored dom_tree::helpers::normalized_char_count for cleaner implementation.
Set MSRV (Minimum Supported Rust Version) to 1.75.
Full Changelog: https://github.com/niklak/dom_query/compare/0.21.0...0.22.0
Tree::is_mathml_annotation_xml_integration_point method, which checks whether a node is a MathML annotation XML integration point.foldhash: 0.1.5 -> 0.2.0hashbrown: 0.15.3 -> 0.16.0 (features unchanged)dom_tree::helpers::normalized_char_count.Introduced Tree::head and Tree::body methods, which return None if the corresponding element is absent (e.g., fragments typically lack / ). Added equi
Tree::head and Tree::body methods, which return None if the corresponding element is absent (e.g., fragments typically lack <head>/<body>). Added equivalent Document::head and Document::body methods.TreeNode::adjust method; no functional or API changes.Document::create_element. Now the template element precedes its Fragment, allowing HTML trees with templates to be merged more predictably.Document::default()).Full Changelog: https://github.com/niklak/dom_query/compare/0.20.0...0.21.0
Fixed TreeNode::adjust behavior, now considering that another tree may contain template elements.
TreeNode::adjust behavior, now considering that another tree may contain template elements.Refactored TreeNodeOps::normalized_char_count, TreeNodeOps::text_of and NodeRef::has_text methods to use iterator-based traversal.
TreeNodeOps::normalized_char_count, TreeNodeOps::text_of and NodeRef::has_text methods to use iterator-based traversal.NodeRef::is_nonempty_text.Introduced Selection::select_matcher_iter, a method that returns an iterator over all nodes matching a given matcher, without collecting them into a r
Selection::select_matcher_iter, a method that returns an iterator over all nodes matching a given matcher, without collecting them into a result vector. This approach is more efficient for read-only use cases where a full collection isn't needed.NodeRef now implements the Copy trait, simplifying usage in performance-critical scenarios.examples/manipulate_html.rs: added an assertion that doc.select(".remove-it").exists() is false. (by @aaronsturm in #110)Full Changelog: https://github.com/niklak/dom_query/compare/0.19.0...0.20.0
Selection::select_matcher_iter method, which returns an iterator over all nodes matching the given matcher, without collecting them into a result vector. Useful for read-only operations.NodeRef implements Copy trait.selectors from 0.27.0 to 0.30.0
selectors from 0.27.0 to 0.30.0html5ever from 0.31.0 to 0.35.0Fixed the behavior of NodeRef::to_fragment when the node is an element or the root itself.
NodeRef::to_fragment when the node is an <html> element or the root itself.Removed deprecated methods for better maintainability and clarity:
Tree::html_root and Document::html_root methods to conveniently retrieve the <html> root element of a document.NodeRef::to_fragment, which allows creating a deep copy of a node's contents as a standalone document fragment.Removed deprecated methods for better maintainability and clarity:
Tree::append_prev_sibling_ofNodeRef::append_prev_siblingNodeRef::append_prev_siblingsSelection::nextFull Changelog: https://github.com/niklak/dom_query/compare/0.18.0...0.19.0
Tree::html_root and Document::html_root methods to get the root element (<html>) node of a document.NodeRef::to_fragment method to create a full copy of a node's contents as a Document fragment.Tree::append_prev_sibling_of, NodeRef::append_prev_sibling, NodeRef::append_prev_siblings, Selection::next.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
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)Tree::validate, a method to perform comprehensive integrity checks on node relationships, links, and cycles within the DOM tree. (by @phayes)selectors updated to 0.27.0.cssparser updated to 0.35.0.html5ever updated to 0.31.0.mini_selector::Attribute: attribute values can now be enclosed in double quotes, single quotes, or left unquoted.entities::Attr visibility to pub, making it publicly accessible.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.template element serialization in the NodeRef::html and NodeRef::inner_html methods.Full Changelog: https://github.com/niklak/dom_query/compare/0.17.0...0.18.0
NodeRef::wrap_node, NodeRef::wrap_html, and NodeRef::unwrap_node methods, allowing a node to be wrapped with another node or HTML fragment, and unwrapped (by @phayes).Tree::validate, a method for performing comprehensive integrity checks on node relationships, links, and cycles within the DOM tree (by @phayes).selectors dependency to version 0.27.0.cssparser dependency to version 0.35.0.html5ever dependency to version 0.31.0.mini_selector::Attribute: attribute values can now be enclosed in either double or single quotes, or left unquoted.entities::Attr visibility to pub.TreeNodeOps::append_child_of and TreeNodeOps::prepend_child_of now internally call TreeNodeOps::remove_from_parent on the new child to ensure it is safely detached from the tree before being reattached. This guarantees that the node has no lingering references (parent or siblings).template serialization in NodeRef::html and NodeRef::inner_html methods.Introduced the NodeRef::strip_elements(&[&str]) method, which removes matched elements while retaining their children in the document tree.
NodeRef::strip_elements(&[&str]) method, which removes matched elements while retaining their children in the document tree.Selection::strip_elements(&[&str]) method, which performs the same operation as NodeRef::strip_elements(&[&str]) but for every node in the Selection.NodeRef::retain_attrs(&[&str]) method, which allows retaining only the specified attributes of a node.Selection::retain_attrs(&[&str]) method, which performs the same operation as NodeRef::retain_attrs but for every node in the Selection.Full Changelog: https://github.com/niklak/dom_query/compare/0.16.0...0.17.0
Added NodeRef::element_ref, which returns a reference to the underlying Element if the node is an element node.
NodeRef::element_ref, which returns a reference to the underlying Element if the node is an element node.NodeRef::qual_name_ref, which returns a reference to the qualified name of the node.NodeRef::has_name, which checks if the node is an element with the given local name.NodeRef::is_nonempty_text, which checks if the node is a non-empty text node.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.<NodeRef as selectors::Element>::is_link to always return false as its impact on element matching was unclear and added unnecessary overhead.Full Changelog: https://github.com/niklak/dom_query/compare/0.15.2...0.16.0
NodeRef::element_ref method, which returns a reference to the underlying Element if the node is an element node.NodeRef::qual_name_ref method, which returns a reference to the qualified name of the node.NodeRef::has_name method, which checks if the node is an element with the given local name.NodeRef::is_nonempty_text method, which checks if the node is a non-empty text node.DescendantMatches (based on DescendantNodes) will be used as the internal iterator, which provides a faster approach and doesn't require an additional check for result duplicates. In the other case, Matches will be used, which, as previously, performs a check for duplicates.<NodeRef as selectors::Element>::is_link, which now always returns false since its effect on matching elements is unclear and it adds some overhead.Fixed another issue where DescendantNodes could traverse beyond the initial node when iterating over descendants, affecting NodeRef::descendants and N
DescendantNodes could traverse beyond the initial node when iterating over descendants, affecting NodeRef::descendants and NodeRef::descendants_it, e.g., when the tree had been modified.Improved markdown serialization for NodeRef:
markdown serialization for NodeRef:
\n\n\ after elements that require a newline at the end if \n\n is already present.code elements, except for the ` character.Implemented the markdown feature, which allows serializing a Document or NodeRef into Markdown text using the md() method.
markdown feature, which allows serializing a Document or NodeRef into Markdown text using the md() method.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.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.Full Changelog: https://github.com/niklak/dom_query/compare/0.14.0...0.15.0
Implemented the Node::id_attr and Node::class methods, which return the id and class attributes of the node, respectively. The Selection::id and Selec
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.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.NodeRef::formatted_text implementation: moved related code to a separate module, extended the formatting logic, and added more test cases.DescendantNodes could traverse beyond the initial node when iterating over descendants, affecting NodeRef::descendants and NodeRef::descendants_it.Full Changelog: https://github.com/niklak/dom_query/compare/0.13.3...0.14.0
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 do the same for the first node in the selection.bit_set::BitSet instead of foldhash::HashSet for the Matches::next method. Since it is necessary to ensure there are no duplicates in the Matches result, and this check needs to be as cheap as possible, bit-set was chosen.NodeRef::formatted_text implementation: moved related code to a separate module, extended the formatting logic, and added more test cases.DescendantNodes could traverse beyond the initial node when iterating over descendants. This affected NodeRef::descendants and NodeRef::descendants_it.Nothing published for this version
Updated html5ever dependency to version 0.29.1.
html5ever dependency to version 0.29.1.NodeRef::find to correctly collect nodes when there is only one item in the path slice.Corrected NodeRef::normalized_char_count behavior for various cases.
NodeRef::normalized_char_count behavior for various cases.Added NodeRef::normalized_char_count method to estimate character count in descendant nodes' text after normalization.
NodeRef::normalized_char_count method to estimate character count in descendant nodes' text after normalization.Document::formatted_text for document-level text formattingSelection::formatted_text for handling formatted text in selectionsNodeRef::formatted_text for node-specific formatted text extractionChangelog Full Changelog: https://github.com/niklak/dom_query/compare/0.12.0...0.13.0
NodeRef::normalized_char_count which estimates the number of characters in the text of descendant nodes as if the total string were normalized.Document::formatted_text, Selection::formatted_text, and NodeRef::formatted_text, which return formatted text of the document, selection, or node respectively.Added NodeRef::is_match and NodeRef::is methods for checking if a node matches a given matcher (&Matcher) or selector (&str) without creating a Select
NodeRef Enhancements:
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.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:
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.RefCell::borrow and RefCell::borrow_mut to simplify internal code.Full Changelog: https://github.com/niklak/dom_query/compare/0.11.0...0.12.0
NodeRef::is_match and NodeRef::is methods, which allow checking if a node matches
a given matcher (&Matcher) or selector (&str) without creating a Selection object.Tree::base_uri, a quick method that returns the base URI of the document based on the href attribute of the <base> element. Document::base_uri and NodeRef::base_uri provide the same functionality. Inspired by Node: baseURI property.NodeRef::find an experimental method to find all descendant elements of a node that match a given path. It is much faster than Selection::select method.Selection's internal code changes aimed at reducing calls to RefCell::borrow and RefCell::borrow_mut.Matches aimed at increasing selection performance.Atomic Feature: Added the `atomic` feature, which replaces NodeData's use of StrTendril with Tendril . This enables NodeData and related structures, i
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:
NodeRef::insert_siblings_after, enabling the insertion of a node along with its siblings after a selected node.NodeRef::before_html and NodeRef::after_html for inserting HTML content before or after a specific node.Selection Enhancements:
Selection::set_text to set the content of each node in the selection to specified content.Selection::before_html and Selection::after_html to insert HTML content before or after each node in a selection.Selection::prepend_selection, allowing nodes from one selection to be prepended to the current selection.RefCell::borrow and RefCell::borrow_mut.Full Changelog: https://github.com/niklak/dom_query/compare/0.10.0...0.11.0
atomic feature which switches NodeData from using StrTendril to Tendril<tendril::fmt::UTF8, tendril::Atomic>.
This allows NodeData and all ascending structures, including Document, to implement the Send trait.Selection::set_text method, which sets the content of each node in the selection to specified content.NodeRef::insert_siblings_after method, which allows inserting a node and its siblings after the selected node.NodeRef::before_html method, which allows inserting contents of an HTML fragment before the selected node.
Selection::before_html does the same thing for the every node inside selection.NodeRef::after_html method, which allows inserting contents of an HTML fragment after the selected node.
Selection::after_html does the same thing for the every node inside selection.Selection::prepend_selection method, which prepends nodes from another selection to the nodes in the current selection.RefCell::borrow and RefCell::borrow_mut.Several methods have been deprecated in favor of more consistently named alternatives:
NodeRef::insert_after: Insert a node after the selected nodeNodeRef::descendants_it: Iterate over all descendants of a nodeNodeRef::descendants: Get a vector containing all descendants of a nodeNodeRef::normalize: Merges adjacent text nodes and removes empty text nodes at node levelDocument::normalize: Performs normalization across the entire documentSeveral methods have been deprecated in favor of more consistently named alternatives:
NodeRef::append_prev_sibling → NodeRef::insert_beforeNodeRef::append_prev_siblings → NodeRef::insert_siblings_beforeTree::append_prev_sibling_of → Tree::insert_before_ofDocument::from and Document::fragment to disable scripting in HTML parser, enabling proper querying of noscript elementsDocument::text method now returns the text content, whereas previously it returned an empty stringOrd trait for NodeIdUsers 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.
Full Changelog: https://github.com/niklak/dom_query/compare/0.9.1...0.10.0
NodeRef::append_prev_sibling is deprecated, please use NodeRef::insert_before instead.NodeRef::append_prev_siblings is deprecated, please use NodeRef::insert_siblings_before instead.Tree::append_prev_sibling_of is deprecated, please use Tree::insert_before_of instead.Document::from and Document::fragment now call html5ever::parse_document with the tree_builder option scripting_enabled set to false.
This allows querying into the noscript element.Ord trait for NodeIdNodeRef::insert_after method, which allows to insert a node after the selected node.NodeRef::descendants_it method, which allows iterating over all descendants of a node.NodeRef::descendants method, which returns a vector of all descendants of a node.NodeRef::normalize method, which merges adjacent text nodes and removes empty text nodes.
Document::normalize does the same thing, but across all the document.Document::text method now returns the text content, whereas previously it returned an empty string.Hide visibility of Tree::nodes, which was accidentally exposed in the previous version.
Tree::nodes, which was accidentally exposed in the previous version.This release includes significant improvements to node selection and manipulation methods, new functionality for content prepending, and a critical bu
This release includes significant improvements to node selection and manipulation methods, new functionality for content prepending, and a critical bug fix
Tree::child_ids_of_it and NodeRef::children_it (use rev: true for reverse order)Selection::append_selection and Selection::replace_with_selection)NodeRef::prepend_child: Insert a single child at the startNodeRef::prepend_children: Insert multiple children at the startNodeRef::prepend_html: Parse and insert HTML content at the startSelection::prepend_html: Parse and insert HTML at the start of all matched nodesSelection::ancestors: Get ancestors of matched elementsSelection::add_selection: Add another selection to current selectionSelection::add_matcherSelection::addSelection::try_addSelection::append_selectionSelection::replace_with_selectionNode::append_childNode::append_childrenNode::prepend_childNode::prepend_childrenFixed 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.
:has() behavior could have been affectedPlease review any code that depends on NodeRef::first_element_child after upgrading to ensure compatibility with the corrected behavior.
Full Changelog: https://github.com/niklak/dom_query/compare/0.8.0...0.9.0
Tree::merge_with_fn instead of Tree::merge to reduce code duplication.Tree::child_ids_of_it now require rev argument. Set true to iterate children in reverse order.NodeRef::children_it now require rev argument. Set true to iterate children in reverse order.Selection::append_selection and Selection::replace_with_selection.NodeRef::prepend_child method, that inserts a child at the beginning of node content.NodeRef::prepend_children method, that inserts a child and its siblings at the beginning of the node content.NodeRef::prepend_html method, that parses html string and inserts its parsed nodes at the beginning of the node content.Selection::prepend_html method, which parses an HTML string and inserts its parsed nodes at the beginning of the content of all matched nodes.Selection::add_selection, Selection:add_matcher, Selection::add and Selection::try_add to extend current selection with other selections.Selection::append_selection to work with selections with multiple nodes and selections from another tree.Selection::replace_with_selection to work with selections with multiple nodes and selections from another tree.Node::append_child, Node::append_children, Node::prepend_child, and Node::prepend_children: these methods now internally remove the child/children from their previous parent node before attachment.NodeRef::first_element_child: Previously, due to a logic error, the method checked the node itself instead of its child nodes. This could have caused:
The following deprecated methods have been removed:
This release brings significant internal refactoring, new filtering capabilities, and improvements to node manipulation methods.
NodeData typeNode to NodeRef (Node is now an alias for NodeRef)replace_with_html, set_html, append_html) using Tree::mergeSelection::filterSelection::filter_matcherSelection::try_filterSelection::filter_selectionNodeRef::replace_with - replace a node with another oneNodeRef::replace_with_html - replace a node with HTML contentNodeRef::set_text - set node's text contentNodeRef::append_prev_siblings - prepend nodes before selected node:only-text pseudo-class for selecting nodes with single text childNodeIdProver trait for NodeRef and Node to simplify API usageNode::has_text functionality<NodeRef<'a> as selectors::Element>::is_empty to handle line breaks and whitespace properly.The following deprecated methods have been removed:
Tree::append_children_from_another_treeTree::append_prev_siblings_from_another_treeNode::append_children_from_another_treeNode::append_prev_siblings_from_another_treeFull Changelog: https://github.com/niklak/dom_query/compare/0.7.0...0.8.0
Node::has_text.NodeData, simplifying code and improving readability without affecting the public API.Node with implementations for NodeRef. Node is just an alias for NodeRef.Selection::replace_with_html, Selection::set_html,
Selection::append_html, Node::set_html, Node::append_html, and Node::replace_with_html by using Tree::merge.Selection::filter , Selection::filter_matcher and Selection::try_filter methods that filter a current selection.Selection::filter_selection method that filters a current selection with another selection.NodeRef::replace_with method that allows to replace a node with another one.NodeRef::replace_with_html method that allows to replace a node with a new node created from the given HTML.NodeIdProver trait and implementations for NodeRef and Node. Which allows to call some node functions with a &NodeRef and &NodeId.
Previously these functions required NodeId as a parameter.:only-text that allows selecting a node with no child elements except a single text child node.NodeRef::set_text method, which sets the text content of a node, replacing any existing content.NodeRef::append_prev_siblings method, which allows to prepend other nodes and their siblings before the selected node.<NodeRef<'a> as selectors::Element>::is_empty to correctly handle line breaks, whitespace, and ensure only elements pass the check.Tree::append_children_from_another_tree method.Tree::append_prev_siblings_from_another_tree method.Node::append_children_from_another_tree method.Node::append_prev_siblings_from_another_tree method.Added Node::ancestors method to get all or limited number of node ancestors
Node::ancestors method to get all or limited number of node ancestorsNode::element_children: returns child nodes of NodeData::Element typeNode::children_it: provides an iterator over child nodesNode::ancestors_it: provides an iterator over ancestor nodesNode::immediate_text method to get node's text without descendants
Selection::immediate_text does the same for every node in selectionTree:child_ids_of and Tree:child_ids_of_it: get child node IDs as vec and as iterator respectivelyTree:ancestor_ids_of and Tree:ancestor_ids_of_it: get ancestor node IDs as vec and as iterator respectively:is() and :where() pseudo-classes:has support from the selectors crateFrom<Vec<Node>> implementation for SelectionDocument::fromSelection::selectrustc-hash to foldhashMatcher::match_element for use outside the crateselectors::Element implementation for Node<'a>::opaque&mut requirement from Selection methodsselectors v0.26.0Full Changelog: https://github.com/niklak/dom_query/compare/0.6.0...0.7.0
Matcher::match_element since it can be useful outside the crate.impl<'a> selectors::Element for Node<'a>::opaque to work with :has pseudo-element from selectors crate.:has implementation from selectors crate.selectors v0.26.0 switch.Selection methods that required &mut now doesn't require &mut, finally.Document::from, Selection::select and others.rustc-hash to foldhash.Node::ancestors method, that allows to get all or limited number of ancestors of a node.From<Vec<NodeRef<'a, NodeData>>> for Selection<'a>:is() and :where() pseudo-classes.Node::element_children method that returns children nodes, that are node_data::Elements.Node::children_it method that returns an iterator over children nodes.Node::ancestors_it method that returns an iterator over ancestors nodes.Tree:child_ids_of and Tree:child_ids_of_it methods that returns ids of the child nodes as vec and as iterator respectively.Tree:ancestor_ids_of and Tree:ancestor_ids_of_it methods that returns ids of the ancestor nodes as vec and as iterator respectively.Node::immediate_text method returns text of the node without it's descendants.
Selection::immediate_text does the same thing for the every node inside selection.Selection methods that required &mut now doesn't require &mut.
Document::tree.Selection methods that required &mut now doesn't require &mut.struct implementations.Node::append_html and Node::set_html methods for creating children nodes of a single selected node.Tree<NodeData>::new_element, an easy way to create an empty element with a given name.NodeRef::last_child.Node::has_attr method, which returns true if an attribute exists on the node element.
Selection::has_attr does the same thing for the first node inside selection.Node::remove_all_attrs method for removing all attributes of a node.
Selection::remove_all_attrs does the same thing for the every node inside selection.Node::remove_attrs method, a convenient way to remove multiple attributes from the node element.
Selection::remove_attrs does the same thing for the every node inside selection.Node::rename method, which allows to change node's name.
Selection::rename does the same thing for the every node inside selection.Full Changelog: https://github.com/niklak/dom_query/compare/0.5.0...0.6.0
*A small breaking change*: From implementation for Document, now it is based on Into and because of that, previous From<&String> implementation will n…
select_single_matcher and select_single methods for Document and Selection.Document::fragment which allows to create a document fragment.From implementation for Document, now it is based on Into<StrTendril> and because of that, previous From<&String> implementation will not work anymore (they are in config). If your code consumes &String, you should use String::as_str() instead.NodeData::Element).Removed a readability examples and related dev-dependencies.
readability examples and related dev-dependencies.Selection::inner_html, Selection::try_html, and Selection::try_inner methods.Fixed Iterator::next for Matches
Iterator::next for MatchesRefactor code due to major changes in html5ever 0.29.0
### Changed - Update dependencies.
### Changed - Update dependencies.
Add support for :has-text and :contains pseudo-classes, which allow to search elements by their text contents. Some example are here.
:has-text and :contains pseudo-classes, which allow to search elements by their text contents. Some example are here.Fix :has selector name comparison. Previously :has behavior worked, even if pseudo-class just started from :has.
:has selector name comparison. Previously :has behavior worked, even if pseudo-class just started from :has.revise matcher::Matcher usage, now selection::Selection's underlying select methods uses matcher::Matcher reference if it possible.
InnerNode<NodeData>.is_comment.dom_tree::NodeData.matcher::Matcher usage, now selection::Selection's underlying select methods uses matcher::Matcher reference if it possible.css::CssString now wraps String instead of StrTendril. Because StrTendril can't be shared between multiple threads without mutex.### Changed - Minor refactoring. ### Fixed - Fix spelling.
Refactor dom_tree.rs -- remove internal macro, revise some functions for better performance.
hashbrown -- which replace standard HashSet and HashMap with it's own implementation.CssString now wraps a StrTendril instead of a String.
CssString now wraps a StrTendril instead of a String.rustc_hash::FxHashSet instead of std::collections::HashSet.rustc_hash::FxHashMap instead of std::collections::HashMap.Replace unsafe code with safe code.
Nothing published for this version
One column per month.