MCPcopy Create free account
hub / github.com/d0iasm/saba / insert_char

Method insert_char

core/src/renderer/html/parser.rs:116–153  ·  view source on GitHub ↗

https://html.spec.whatwg.org/multipage/parsing.html#insert-a-character

(&mut self, c: char)

Source from the content-addressed store, hash-verified

114
115 /// https://html.spec.whatwg.org/multipage/parsing.html#insert-a-character
116 fn insert_char(&mut self, c: char) {
117 let current = match self.stack_of_open_elements.last() {
118 Some(n) => n.clone(),
119 None => return,
120 };
121
122 // When the current node is Text, add a character to the current node.
123 // Do not access by current.borrow().kind(), otherwise, you can't add a next char to a
124 // correct node.
125 if let NodeKind::Text(ref mut s) = current.borrow_mut().kind {
126 s.push(c);
127 return;
128 }
129
130 // do not create a Text node if new char is '\n' or ' '
131 if c == '\n' || c == ' ' {
132 return;
133 }
134
135 let node = Rc::new(RefCell::new(self.create_char(c)));
136
137 if current.borrow().first_child().is_some() {
138 // TODO: Probably impossible to reach here. `first_child` of the current node is always None.
139 current
140 .borrow()
141 .first_child()
142 .unwrap()
143 .borrow_mut()
144 .set_next_sibling(Some(node.clone()));
145 } else {
146 current.borrow_mut().set_first_child(Some(node.clone()));
147 }
148
149 current.borrow_mut().set_last_child(Rc::downgrade(&node));
150 node.borrow_mut().set_parent(Rc::downgrade(&current));
151
152 self.stack_of_open_elements.push(node);
153 }
154
155 /// Returns true if the current node's kind is same as NodeKind::Element::<element_kind>.
156 fn pop_current_node(&mut self, element_kind: ElementKind) -> bool {

Callers 1

construct_treeMethod · 0.80

Calls 6

create_charMethod · 0.80
set_last_childMethod · 0.80
set_parentMethod · 0.80
first_childMethod · 0.45
set_next_siblingMethod · 0.45
set_first_childMethod · 0.45

Tested by

no test coverage detected