pub struct TreeNodeOps {}Implementations§
Source§impl TreeNodeOps
impl TreeNodeOps
Sourcepub fn text_of(nodes: Ref<'_, Vec<TreeNode>>, id: NodeId) -> StrTendril
pub fn text_of(nodes: Ref<'_, Vec<TreeNode>>, id: NodeId) -> StrTendril
Collects all text content of a node and its descendants.
§Arguments
nodes: a reference to a vector ofTreeNodes.id:NodeIdof the element to get the text content from.
This function will traverse the tree and collect all text content
from the node and its descendants. It will ignore any nodes that
are not Elements or Texts.
The function returns a StrTendril containing all collected text content.
Sourcepub fn normalized_char_count(nodes: Ref<'_, Vec<TreeNode>>, id: NodeId) -> usize
pub fn normalized_char_count(nodes: Ref<'_, Vec<TreeNode>>, id: NodeId) -> usize
Traverses the tree and counts all text content of a node and its descendants, but only counting each sequence of whitespace as a single character.
§Arguments
nodes: a reference to a vector ofTreeNodes.id:NodeIdof the element to get the text content from.
This function will traverse the tree and count all text content from the node and its descendants.
It has an advantage over node.text().split_whitespace().count()
because it doesn’t need to collect and consume the text content.
§Returns
The number of characters that would be in the text content if it were normalized, where normalization means treating any sequence of whitespace characters as a single space.
Sourcepub fn immediate_text_of(
nodes: Ref<'_, Vec<TreeNode>>,
id: NodeId,
) -> StrTendril
pub fn immediate_text_of( nodes: Ref<'_, Vec<TreeNode>>, id: NodeId, ) -> StrTendril
Returns the text of the node without its descendants.
Sourcepub fn last_sibling_of(nodes: &[TreeNode], id: &NodeId) -> Option<NodeId>
pub fn last_sibling_of(nodes: &[TreeNode], id: &NodeId) -> Option<NodeId>
Gets the last sibling node of a node by id.
This function walks through sibling nodes from the given node until there are no more sibling nodes. It returns the last sibling node id it found.
Sourcepub fn next_element_sibling_of(
nodes: &[TreeNode],
id: &NodeId,
) -> Option<NodeId>
pub fn next_element_sibling_of( nodes: &[TreeNode], id: &NodeId, ) -> Option<NodeId>
Returns the next sibling id, that is an NodeData::Element of the selected node.
Sourcepub fn prev_element_sibling_of(
nodes: &[TreeNode],
id: &NodeId,
) -> Option<NodeId>
pub fn prev_element_sibling_of( nodes: &[TreeNode], id: &NodeId, ) -> Option<NodeId>
Returns the previous sibling id, that is an NodeData::Element of the selected node.
Sourcepub fn first_element_child_of(nodes: &[TreeNode], id: &NodeId) -> Option<NodeId>
pub fn first_element_child_of(nodes: &[TreeNode], id: &NodeId) -> Option<NodeId>
Returns the first child id, that is an NodeData::Element of the selected node.
Sourcepub fn is_valid_node_id(nodes: &[TreeNode], id: &NodeId) -> bool
pub fn is_valid_node_id(nodes: &[TreeNode], id: &NodeId) -> bool
Checks if the given node id is valid in the tree.
Source§impl TreeNodeOps
impl TreeNodeOps
Sourcepub fn create_node(nodes: &mut Vec<TreeNode>, data: NodeData) -> NodeId
pub fn create_node(nodes: &mut Vec<TreeNode>, data: NodeData) -> NodeId
Creates a new node with the given data.
Sourcepub fn append_child_data_of(
nodes: &mut Vec<TreeNode>,
id: &NodeId,
data: NodeData,
)
pub fn append_child_data_of( nodes: &mut Vec<TreeNode>, id: &NodeId, data: NodeData, )
Creates a new element from data and appends it to a node by id
Sourcepub fn append_child_of(
nodes: &mut [TreeNode],
id: &NodeId,
new_child_id: &NodeId,
)
pub fn append_child_of( nodes: &mut [TreeNode], id: &NodeId, new_child_id: &NodeId, )
Appends a child node by new_child_id to a node by id. new_child_id must exist in the tree.
Sourcepub fn prepend_child_of(
nodes: &mut [TreeNode],
id: &NodeId,
new_child_id: &NodeId,
)
pub fn prepend_child_of( nodes: &mut [TreeNode], id: &NodeId, new_child_id: &NodeId, )
Prepend a child node by new_child_id to a node by id. new_child_id must exist in the tree.
Sourcepub fn insert_before_of(
nodes: &mut [TreeNode],
id: &NodeId,
new_sibling_id: &NodeId,
)
pub fn insert_before_of( nodes: &mut [TreeNode], id: &NodeId, new_sibling_id: &NodeId, )
Append a sibling node in the tree before the given node.
Sourcepub fn insert_after_of(
nodes: &mut [TreeNode],
id: &NodeId,
new_sibling_id: &NodeId,
)
pub fn insert_after_of( nodes: &mut [TreeNode], id: &NodeId, new_sibling_id: &NodeId, )
Append a sibling node in the tree after the given node.
Sourcepub fn insert_siblings_before(
nodes: &mut [TreeNode],
id: &NodeId,
new_node_id: &NodeId,
)
pub fn insert_siblings_before( nodes: &mut [TreeNode], id: &NodeId, new_node_id: &NodeId, )
Inserts a node and it’s siblings by id before the selected node.
Sourcepub fn insert_siblings_after(
nodes: &mut [TreeNode],
id: &NodeId,
new_node_id: &NodeId,
)
pub fn insert_siblings_after( nodes: &mut [TreeNode], id: &NodeId, new_node_id: &NodeId, )
Inserts a node and it’s siblings by id after the selected node.
Sourcepub fn append_children_of(
nodes: &mut [TreeNode],
id: &NodeId,
new_child_id: &NodeId,
)
pub fn append_children_of( nodes: &mut [TreeNode], id: &NodeId, new_child_id: &NodeId, )
Appends another node and it’s siblings to the selected node.
Sourcepub fn prepend_children_of(
nodes: &mut [TreeNode],
id: &NodeId,
new_child_id: &NodeId,
)
pub fn prepend_children_of( nodes: &mut [TreeNode], id: &NodeId, new_child_id: &NodeId, )
Prepend another node and it’s siblings to the selected node.
Sourcepub fn remove_from_parent(nodes: &mut [TreeNode], id: &NodeId)
pub fn remove_from_parent(nodes: &mut [TreeNode], id: &NodeId)
Remove a node from the its parent by id. The node remains in the tree. It is possible to assign it to another node in the tree after this operation.
Sourcepub fn reparent_children_of(
nodes: &mut [TreeNode],
id: &NodeId,
new_parent_id: Option<NodeId>,
)
pub fn reparent_children_of( nodes: &mut [TreeNode], id: &NodeId, new_parent_id: Option<NodeId>, )
Changes the parent of children nodes of a node.