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

Method construct_tree

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

https://html.spec.whatwg.org/multipage/parsing.html#tree-construction

(&mut self)

Source from the content-addressed store, hash-verified

200
201 /// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction
202 pub fn construct_tree(&mut self) -> Rc<RefCell<Window>> {
203 let mut token = self.t.next();
204
205 while token.is_some() {
206 match self.mode {
207 // https://html.spec.whatwg.org/multipage/parsing.html#the-initial-insertion-mode
208 InsertionMode::Initial => {
209 // Ignore <!doctype html>.
210 // <!doctype html> is generated as a Char token.
211 if let Some(HtmlToken::Char(_)) = token {
212 token = self.t.next();
213 continue;
214 }
215
216 self.mode = InsertionMode::BeforeHtml;
217 continue;
218 }
219
220 // https://html.spec.whatwg.org/multipage/parsing.html#the-before-html-insertion-mode
221 InsertionMode::BeforeHtml => {
222 match token {
223 Some(HtmlToken::Char(c)) => {
224 if c == ' ' || c == '\n' {
225 token = self.t.next();
226 continue;
227 }
228 }
229 Some(HtmlToken::StartTag {
230 ref tag,
231 self_closing: _,
232 ref attributes,
233 }) => {
234 // A start tag whose tag name is "html"
235 // Create an element for the token in the HTML namespace, with the Document
236 // as the intended parent. Append it to the Document object. Put this
237 // element in the stack of open elements.
238 if tag == "html" {
239 self.insert_element(tag, attributes.to_vec());
240 self.mode = InsertionMode::BeforeHead;
241 token = self.t.next();
242 continue;
243 }
244 }
245 Some(HtmlToken::EndTag { ref tag }) => {
246 // Any other end tag
247 // Parse error. Ignore the token.
248 if tag != "head" || tag != "body" || tag != "html" || tag != "br" {
249 // Ignore the token.
250 token = self.t.next();
251 continue;
252 }
253 }
254 Some(HtmlToken::Eof) | None => {
255 return self.window.clone();
256 }
257 }
258 self.insert_element("html", Vec::new());
259 self.mode = InsertionMode::BeforeHead;

Callers 7

create_frameMethod · 0.80
create_layout_viewFunction · 0.80
test_emptyFunction · 0.80
test_bodyFunction · 0.80
test_textFunction · 0.80
test_multiple_nodesFunction · 0.80
test_no_body_tagFunction · 0.80

Calls 8

console_warningFunction · 0.85
insert_elementMethod · 0.80
switch_contextMethod · 0.80
pop_untilMethod · 0.80
insert_charMethod · 0.80
contain_in_stackMethod · 0.80
pop_current_nodeMethod · 0.80
nextMethod · 0.45

Tested by 5

test_emptyFunction · 0.64
test_bodyFunction · 0.64
test_textFunction · 0.64
test_multiple_nodesFunction · 0.64
test_no_body_tagFunction · 0.64