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

Method insert_element

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

Creates an element node for the token and insert it to the appropriate place for inserting a node. Put the new node in the stack of open elements. https://html.spec.whatwg.org/multipage/parsing.html#insert-a-foreign-element

(&mut self, tag: &str, attributes: Vec<Attribute>)

Source from the content-addressed store, hash-verified

71 /// a node. Put the new node in the stack of open elements.
72 /// https://html.spec.whatwg.org/multipage/parsing.html#insert-a-foreign-element
73 fn insert_element(&mut self, tag: &str, attributes: Vec<Attribute>) {
74 let window = self.window.borrow();
75 let current = match self.stack_of_open_elements.last() {
76 Some(n) => n.clone(),
77 None => window.document(),
78 };
79
80 let node = Rc::new(RefCell::new(self.create_element(tag, attributes)));
81
82 if current.borrow().first_child().is_some() {
83 let mut last_sibling = current.borrow().first_child();
84 loop {
85 last_sibling = match last_sibling {
86 Some(ref node) => {
87 if node.borrow().next_sibling().is_some() {
88 node.borrow().next_sibling()
89 } else {
90 break;
91 }
92 }
93 None => unimplemented!("last_sibling should be Some"),
94 };
95 }
96
97 last_sibling
98 .as_ref()
99 .unwrap()
100 .borrow_mut()
101 .set_next_sibling(Some(node.clone()));
102 node.borrow_mut().set_previous_sibling(Rc::downgrade(
103 &last_sibling.expect("last_sibling should be Some"),
104 ))
105 } else {
106 current.borrow_mut().set_first_child(Some(node.clone()));
107 }
108
109 current.borrow_mut().set_last_child(Rc::downgrade(&node));
110 node.borrow_mut().set_parent(Rc::downgrade(&current));
111
112 self.stack_of_open_elements.push(node);
113 }
114
115 /// https://html.spec.whatwg.org/multipage/parsing.html#insert-a-character
116 fn insert_char(&mut self, c: char) {

Callers 1

construct_treeMethod · 0.80

Calls 9

documentMethod · 0.80
create_elementMethod · 0.80
set_previous_siblingMethod · 0.80
set_last_childMethod · 0.80
set_parentMethod · 0.80
first_childMethod · 0.45
next_siblingMethod · 0.45
set_next_siblingMethod · 0.45
set_first_childMethod · 0.45

Tested by

no test coverage detected