Append a new node or text to the document.
(&self, child: NodeOrText<NodeId>, previous: P, append: A)
| 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 | |
| 163 | impl TreeSink for Sink { |
no test coverage detected