MCPcopy Create free account
hub / github.com/Stranger6667/css-inline / append_impl

Method append_impl

css-inline/src/html/parser.rs:132–160  ·  view source on GitHub ↗

Append a new node or text to the document.

(&self, child: NodeOrText<NodeId>, previous: P, append: A)

Source from the content-addressed store, hash-verified

130
131 /// Append a new node or text to the document.
132 fn append_impl<P, A>(&self, child: NodeOrText<NodeId>, previous: P, append: A)
133 where
134 P: FnOnce(&mut Document) -> Option<NodeId>,
135 A: FnOnce(&mut Document, NodeId),
136 {
137 let new_node = match child {
138 NodeOrText::AppendText(text) => {
139 // If the previous node is a text node, append to it.
140 // Otherwise create a new text node.
141 let Some(id) = previous(&mut self.document.borrow_mut()) else {
142 let new_node = self.push_text(text);
143 append(&mut self.document.borrow_mut(), new_node);
144 return;
145 };
146 if let Node {
147 data: NodeData::Text { text: existing },
148 ..
149 } = &mut self.document.borrow_mut()[id]
150 {
151 existing.push_tendril(&text);
152 return;
153 }
154 self.push_text(text)
155 }
156 NodeOrText::AppendNode(node) => node,
157 };
158
159 append(&mut self.document.borrow_mut(), new_node);
160 }
161}
162
163impl TreeSink for Sink {

Callers 2

appendMethod · 0.80
append_before_siblingMethod · 0.80

Calls 1

push_textMethod · 0.80

Tested by

no test coverage detected