} ; use crate :: tree_builder :: tag_sets :: * ; use crate :: tree_builder :: types :: * ; use std :: borrow :: ToOwned ; use crate :: tendril :: SliceExt ; fn any_not_whitespace (x : & StrTendril) -> bool {
} # [doc (hidden)] impl < Handle , Sink > TreeBuilder < Handle , Sink > where Handle : Clone , Sink : TreeSink < Handle = Handle > , {
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , _) => Done , CommentToken (text) => self . append_comment_to_doc (text) , last_arm_token => {
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , _) => Done , CommentToken (text) => self . append_comment_to_doc (text) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , _) => Done , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
self . head_elem = Some (self . insert_phantom (local_name ! ("head"))) ; Reprocess (InHead , token)
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , text) => self . append_text (text) , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
let elem = create_element (& mut self . sink , QualName :: new (None , ns ! (html) , local_name ! ("script")) , tag . attrs) ; if self . is_fragment () {
} self . insert_appropriately (AppendNode (elem . clone ()) , None) ; self . open_elems . push (elem) ; self . to_raw_text_mode (ScriptData)
self . insert_element_for (tag) ; self . active_formatting . push (Marker) ; self . frameset_ok = false ; self . mode = InTemplate ; self . template_modes . push (InTemplate) ; Done
self . generate_implied_end (thorough_implied_end) ; self . expect_to_close (local_name ! ("template")) ; self . clear_active_formatting_to_marker () ; self . template_modes . pop () ; self . mode = self . reset_insertion_mode () ;
}) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
} , CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , _) => self . step (InHead , token) , CommentToken (_) => self . step (InHead , token) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InHead , token) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , text) => self . append_text (text) , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
self . unexpected (& token) ; let head = self . head_elem . as_ref () . expect ("no head element") . clone () ; self . push (& head) ; let result = self . step (InHead , token) ; self . remove_from_stack (& head) ; result
}) => self . step (InHead , token) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
} , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
let top = html_elem (& self . open_elems) ; self . sink . add_attrs_if_missing (top , tag . attrs) ;
Some (ref node) if self . open_elems . len () != 1 && ! self . in_html_elem_named (local_name ! ("template")) => {
} let body = unwrap_or_return ! (self . body_elem () , Done) . clone () ; self . sink . remove_from_parent (& body) ; self . open_elems . truncate (1) ; self . insert_element_for (tag) ; self . mode = InFrameset ; Done
self . close_p_element_in_button_scope () ; self . insert_element_for (tag) ; self . ignore_lf = true ; self . frameset_ok = false ; Done
self . close_p_element_in_button_scope () ; let elem = self . insert_element_for (tag) ; if ! self . in_html_elem_named (local_name ! ("template")) {
declare_tag_set ! (close_list = "li") ; declare_tag_set ! (close_defn = "dd" "dt") ; declare_tag_set ! (extra_special = [special_tag] - "address" "div" "p") ; let list = match tag . name {
local_name ! ("li") => true , local_name ! ("dd") | local_name ! ("dt") => false , _ => unreachable ! () ,
} ; self . frameset_ok = false ; let mut to_close = None ; for node in self . open_elems . iter () . rev () {
self . sink . parse_error (Borrowed ("nested buttons")) ; self . generate_implied_end (cursory_implied_end) ; self . pop_until_named (local_name ! ("button")) ;
} self . reconstruct_formatting () ; self . insert_element_for (tag) ; self . frameset_ok = false ; Done
} self . generate_implied_end (cursory_implied_end) ; let current = self . current_node () . clone () ; self . remove_from_stack (& node) ; if ! self . sink . same_node (& current , & node) {
} self . generate_implied_end (cursory_implied_end) ; if ! self . current_node_named (local_name ! ("form")) {
self . sink . parse_error (Borrowed ("No <p> tag to close")) ; self . insert_phantom (local_name ! ("p")) ;
self . generate_implied_end_except (tag . name . clone ()) ; self . expect_to_close (tag . name) ;
self . generate_implied_end (cursory_implied_end) ; if ! self . current_node_named (tag . name) {
self . handle_misnested_a_tags (& tag) ; self . reconstruct_formatting () ; self . create_formatting_element_for (tag) ; Done
self . reconstruct_formatting () ; if self . in_scope_named (default_scope , local_name ! ("nobr")) {
self . sink . parse_error (Borrowed ("Nested <nobr>")) ; self . adoption_agency (local_name ! ("nobr")) ; self . reconstruct_formatting () ;
self . reconstruct_formatting () ; self . insert_element_for (tag) ; self . active_formatting . push (Marker) ; self . frameset_ok = false ; Done
self . generate_implied_end (cursory_implied_end) ; self . expect_to_close (tag . name) ; self . clear_active_formatting_to_marker () ;
} self . insert_element_for (tag) ; self . frameset_ok = false ; self . mode = InTable ; Done
} ; self . reconstruct_formatting () ; self . insert_and_pop_element_for (tag) ; if ! keep_frameset_ok {
self . close_p_element_in_button_scope () ; self . insert_and_pop_element_for (tag) ; self . frameset_ok = false ; DoneAckSelfClosing
self . close_p_element_in_button_scope () ; self . reconstruct_formatting () ; self . frameset_ok = false ; self . parse_raw_data (tag , Rawtext)
self . reconstruct_formatting () ; self . insert_element_for (tag) ; self . frameset_ok = false ; self . mode = match self . mode {
} if ! self . current_node_named (local_name ! ("rtc")) && ! self . current_node_named (local_name ! ("ruby")) {
}) => self . enter_foreign (tag , ns ! (mathml)) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
}) => self . enter_foreign (tag , ns ! (svg)) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
let current = current_node (& self . open_elems) ; self . sink . mark_script_already_started (current) ;
let node = self . pop () ; self . mode = self . orig_mode . take () . unwrap () ; if tag . name == local_name ! ("script") {
NullCharacterToken => self . process_chars_in_table (token) , CharacterTokens (..) => self . process_chars_in_table (token) , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
self . pop_until_current (table_scope) ; self . active_formatting . push (Marker) ; self . insert_element_for (tag) ; self . mode = InCaption ; Done
self . pop_until_current (table_scope) ; self . insert_element_for (tag) ; self . mode = InColumnGroup ; Done
self . pop_until_current (table_scope) ; self . insert_phantom (local_name ! ("colgroup")) ; Reprocess (InColumnGroup , token)
self . pop_until_current (table_scope) ; self . insert_element_for (tag) ; self . mode = InTableBody ; Done
self . pop_until_current (table_scope) ; self . insert_phantom (local_name ! ("tbody")) ; Reprocess (InTableBody , token)
self . pop_until_named (local_name ! ("table")) ; Reprocess (self . reset_insertion_mode () , token)
self . pop_until_named (local_name ! ("table")) ; self . mode = self . reset_insertion_mode () ;
}) => self . unexpected (& token) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InHead , token) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
self . unexpected (& tag) ; if ! self . in_html_elem_named (local_name ! ("template")) && self . form_elem . is_none () {
let pending = replace (& mut self . pending_table_text , vec ! ()) ; let contains_nonspace = pending . iter () . any (| & (split , ref text) | {
self . sink . parse_error (Borrowed ("Non-space table text")) ; for (split , text) in pending . into_iter () {
self . generate_implied_end (cursory_implied_end) ; self . expect_to_close (local_name ! ("caption")) ; self . clear_active_formatting_to_marker () ; match tag {
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , text) => self . append_text (text) , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
}) => self . unexpected (& token) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InHead , token) , EOFToken => self . step (InBody , token) , last_arm_token => {
self . pop_until_current (table_body_context) ; self . insert_element_for (tag) ; self . mode = InRow ; Done
self . unexpected (& token) ; self . pop_until_current (table_body_context) ; self . insert_phantom (local_name ! ("tr")) ; Reprocess (InRow , token)
declare_tag_set ! (table_outer = "table" "tbody" "tfoot") ; if self . in_scope (table_scope , | e | self . elem_in (& e , table_outer)) {
self . pop_until_current (table_row_context) ; self . insert_element_for (tag) ; self . mode = InCell ; self . active_formatting . push (Marker) ; Done
self . pop_until_current (table_row_context) ; let node = self . pop () ; self . assert_named (& node , local_name ! ("tr")) ; self . mode = InTableBody ;
self . pop_until_current (table_row_context) ; let node = self . pop () ; self . assert_named (& node , local_name ! ("tr")) ; Reprocess (InTableBody , token)
self . pop_until_current (table_row_context) ; let node = self . pop () ; self . assert_named (& node , local_name ! ("tr")) ; Reprocess (InTableBody , TagToken (tag))
self . generate_implied_end (cursory_implied_end) ; self . expect_to_close (tag . name) ; self . clear_active_formatting_to_marker () ; self . mode = InRow ;
}) => self . unexpected (& token) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
NullCharacterToken => self . unexpected (& token) , CharacterTokens (_ , text) => self . append_text (text) , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
if self . open_elems . len () >= 2 && self . current_node_named (local_name ! ("option")) && self . html_elem_named (& self . open_elems [self . open_elems . len () - 2] , local_name ! ("optgroup")) {
let in_scope = self . in_scope_named (select_scope , local_name ! ("select")) ; if ! in_scope || tag . kind == StartTag {
self . pop_until_named (local_name ! ("select")) ; self . mode = self . reset_insertion_mode () ;
self . unexpected (& token) ; if self . in_scope_named (select_scope , local_name ! ("select")) {
self . pop_until_named (local_name ! ("select")) ; Reprocess (self . reset_insertion_mode () , token)
}) => self . step (InHead , token) , EOFToken => self . step (InBody , token) , last_arm_token => {
self . unexpected (& token) ; self . pop_until_named (local_name ! ("select")) ; Reprocess (self . reset_insertion_mode () , token)
self . pop_until_named (local_name ! ("select")) ; Reprocess (self . reset_insertion_mode () , TagToken (tag))
CharacterTokens (_ , _) => self . step (InBody , token) , CommentToken (_) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
self . template_modes . pop () ; self . template_modes . push (InTable) ; Reprocess (InTable , token)
self . template_modes . pop () ; self . template_modes . push (InColumnGroup) ; Reprocess (InColumnGroup , token)
self . template_modes . pop () ; self . template_modes . push (InTableBody) ; Reprocess (InTableBody , token)
self . template_modes . pop () ; self . template_modes . push (InRow) ; Reprocess (InRow , token)
self . unexpected (& token) ; self . pop_until_named (local_name ! ("template")) ; self . clear_active_formatting_to_marker () ; self . template_modes . pop () ; self . mode = self . reset_insertion_mode () ; Reprocess (self . reset_insertion_mode () , token)
self . template_modes . pop () ; self . template_modes . push (InBody) ; Reprocess (InBody , TagToken (tag))
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , _) => self . step (InBody , token) , CommentToken (text) => self . append_comment_to_html (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , text) => self . append_text (text) , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
self . pop () ; if ! self . is_fragment () && ! self . current_node_named (local_name ! ("frameset")) {
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , text) => self . append_text (text) , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , _) => self . step (InBody , token) , CommentToken (text) => self . append_comment_to_doc (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , EOFToken => self . stop_parsing () , last_arm_token => {
CharacterTokens (NotSplit , text) => SplitWhitespace (text) , CharacterTokens (Whitespace , _) => self . step (InBody , token) , CommentToken (text) => self . append_comment_to_doc (text) , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
}) => self . step (InBody , token) , EOFToken => self . stop_parsing () , crate :: tree_builder :: types :: TagToken (crate :: tokenizer :: Tag {
} , CommentToken (text) => self . append_comment (text) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
}) => self . unexpected_start_tag_in_foreign_content (tag) , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
matches ! (attr . name . expanded () , expanded_name ! ("" , "color") | expanded_name ! ("" , "face") | expanded_name ! ("" , "size"))
})) => self . foreign_start_tag (tag) , (true , crate :: tree_builder :: types :: TagToken (tag @ crate :: tokenizer :: Tag {
let node_name = self . sink . elem_name (& self . open_elems [stack_idx]) ; html = * node_name . ns == ns ! (html) ; eq = node_name . local . eq_ignore_ascii_case (& tag . name) ;