@@ -607,40 +607,10 @@ where
607607 trace ! ( "html token={token:?}" ) ;
608608 match token {
609609 Token :: DoctypeToken ( _) => { }
610- Token :: TagToken ( tag) => {
611- match tag. kind {
612- TagKind :: StartTag => {
613- let is_closed = is_void_element ( & tag. name ) || tag. self_closing ;
614- is_raw = matches ! ( & * tag. name, "script" | "style" ) ;
615- let name = QualName :: new ( None , html5ever:: ns!( html) , tag. name ) ;
616- let attrs = tag
617- . attrs
618- . into_iter ( )
619- . map ( |attr| ( attr. name , attr. value ) )
620- . collect ( ) ;
621- let mut el = Element {
622- name,
623- attrs,
624- self_closing : tag. self_closing ,
625- was_raw : true ,
626- } ;
627- fix_html_link ( & mut el) ;
628- self . push ( Node :: Element ( el) ) ;
629- if is_closed {
630- // No end element.
631- self . pop ( ) ;
632- }
633- }
634- TagKind :: EndTag => {
635- is_raw = false ;
636- if self . is_html_tag_matching ( & tag. name ) {
637- self . pop ( ) ;
638- }
639- // else the stack is corrupt. I'm not really sure
640- // what to do here...
641- }
642- }
643- }
610+ Token :: TagToken ( tag) => match tag. kind {
611+ TagKind :: StartTag => self . start_html_tag ( tag, & mut is_raw) ,
612+ TagKind :: EndTag => self . end_html_tag ( tag, & mut is_raw) ,
613+ } ,
644614 Token :: CommentToken ( comment) => {
645615 self . append ( Node :: Comment ( comment) ) ;
646616 }
@@ -665,6 +635,40 @@ where
665635 }
666636 }
667637
638+ /// Adds an open HTML tag.
639+ fn start_html_tag ( & mut self , tag : html5ever:: tokenizer:: Tag , is_raw : & mut bool ) {
640+ let is_closed = is_void_element ( & tag. name ) || tag. self_closing ;
641+ * is_raw = matches ! ( & * tag. name, "script" | "style" ) ;
642+ let name = QualName :: new ( None , html5ever:: ns!( html) , tag. name ) ;
643+ let attrs = tag
644+ . attrs
645+ . into_iter ( )
646+ . map ( |attr| ( attr. name , attr. value ) )
647+ . collect ( ) ;
648+ let mut el = Element {
649+ name,
650+ attrs,
651+ self_closing : tag. self_closing ,
652+ was_raw : true ,
653+ } ;
654+ fix_html_link ( & mut el) ;
655+ self . push ( Node :: Element ( el) ) ;
656+ if is_closed {
657+ // No end element.
658+ self . pop ( ) ;
659+ }
660+ }
661+
662+ /// Closes the given HTML tag.
663+ fn end_html_tag ( & mut self , tag : html5ever:: tokenizer:: Tag , is_raw : & mut bool ) {
664+ * is_raw = false ;
665+ if self . is_html_tag_matching ( & tag. name ) {
666+ self . pop ( ) ;
667+ }
668+ // else the stack is corrupt. I'm not really sure
669+ // what to do here...
670+ }
671+
668672 /// This is used to verify HTML parsing keeps the stack of tags in sync.
669673 fn is_html_tag_matching ( & self , name : & str ) -> bool {
670674 let current = self . tree . get ( self . current_node ) . unwrap ( ) . value ( ) ;
0 commit comments