/[suikacvs]/markup/html/whatpm/Whatpm/HTML.pm.src
Suika

Diff of /markup/html/whatpm/Whatpm/HTML.pm.src

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.49 by wakaba, Sat Jul 21 10:39:45 2007 UTC revision 1.52 by wakaba, Sat Jul 21 12:27:22 2007 UTC
# Line 2103  sub _reset_insertion_mode ($) { Line 2103  sub _reset_insertion_mode ($) {
2103  sub _tree_construction_main ($) {  sub _tree_construction_main ($) {
2104    my $self = shift;    my $self = shift;
2105    
   my $previous_insertion_mode;  
   
2106    my $active_formatting_elements = [];    my $active_formatting_elements = [];
2107    
2108    my $reconstruct_active_formatting_elements = sub { # MUST    my $reconstruct_active_formatting_elements = sub { # MUST
# Line 2496  sub _tree_construction_main ($) { Line 2494  sub _tree_construction_main ($) {
2494                         }                         }
2495    }; # $insert_to_foster    }; # $insert_to_foster
2496    
2497    my $in_body = sub {    my $insert;
     my $insert = shift;  
     if ($token->{type} eq 'start tag') {  
       if ($token->{tag_name} eq 'script') {  
         ## NOTE: This is an "as if in head" code clone  
         $script_start_tag->($insert);  
         return;  
       } elsif ($token->{tag_name} eq 'style') {  
         ## NOTE: This is an "as if in head" code clone  
         $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);  
         return;  
       } elsif ({  
                 base => 1, link => 1,  
                }->{$token->{tag_name}}) {  
         ## NOTE: This is an "as if in head" code clone, only "-t" differs  
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.  
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'meta') {  
         ## NOTE: This is an "as if in head" code clone, only "-t" differs  
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.  
   
         unless ($self->{confident}) {  
           my $charset;  
           if ($token->{attributes}->{charset}) { ## TODO: And if supported  
             $charset = $token->{attributes}->{charset}->{value};  
           }  
           if ($token->{attributes}->{'http-equiv'}) {  
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
             if ($token->{attributes}->{'http-equiv'}->{value}  
                 =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=  
                     [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|  
                     ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {  
               $charset = defined $1 ? $1 : defined $2 ? $2 : $3;  
             } ## TODO: And if supported  
           }  
           ## TODO: Change the encoding  
         }  
   
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'title') {  
         !!!parse-error (type => 'in body:title');  
         ## NOTE: This is an "as if in head" code clone  
         $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {  
           if (defined $self->{head_element}) {  
             $self->{head_element}->append_child ($_[0]);  
           } else {  
             $insert->($_[0]);  
           }  
         });  
         return;  
       } elsif ($token->{tag_name} eq 'body') {  
         !!!parse-error (type => 'in body:body');  
                 
         if (@{$self->{open_elements}} == 1 or  
             $self->{open_elements}->[1]->[1] ne 'body') {  
           ## Ignore the token  
         } else {  
           my $body_el = $self->{open_elements}->[1]->[0];  
           for my $attr_name (keys %{$token->{attributes}}) {  
             unless ($body_el->has_attribute_ns (undef, $attr_name)) {  
               $body_el->set_attribute_ns  
                 (undef, [undef, $attr_name],  
                  $token->{attributes}->{$attr_name}->{value});  
             }  
           }  
         }  
         !!!next-token;  
         return;  
       } elsif ({  
                 address => 1, blockquote => 1, center => 1, dir => 1,  
                 div => 1, dl => 1, fieldset => 1, listing => 1,  
                 menu => 1, ol => 1, p => 1, ul => 1,  
                 pre => 1,  
                }->{$token->{tag_name}}) {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         if ($token->{tag_name} eq 'pre') {  
           !!!next-token;  
           if ($token->{type} eq 'character') {  
             $token->{data} =~ s/^\x0A//;  
             unless (length $token->{data}) {  
               !!!next-token;  
             }  
           }  
         } else {  
           !!!next-token;  
         }  
         return;  
       } elsif ($token->{tag_name} eq 'form') {  
         if (defined $self->{form_element}) {  
           !!!parse-error (type => 'in form:form');  
           ## Ignore the token  
           !!!next-token;  
           return;  
         } else {  
           ## has a p element in scope  
           INSCOPE: for (reverse @{$self->{open_elements}}) {  
             if ($_->[1] eq 'p') {  
               !!!back-token;  
               $token = {type => 'end tag', tag_name => 'p'};  
               return;  
             } elsif ({  
                       table => 1, caption => 1, td => 1, th => 1,  
                       button => 1, marquee => 1, object => 1, html => 1,  
                      }->{$_->[1]}) {  
               last INSCOPE;  
             }  
           } # INSCOPE  
               
           !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           $self->{form_element} = $self->{open_elements}->[-1]->[0];  
           !!!next-token;  
           return;  
         }  
       } elsif ($token->{tag_name} eq 'li') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## Step 1  
         my $i = -1;  
         my $node = $self->{open_elements}->[$i];  
         LI: {  
           ## Step 2  
           if ($node->[1] eq 'li') {  
             if ($i != -1) {  
               !!!parse-error (type => 'end tag missing:'.  
                               $self->{open_elements}->[-1]->[1]);  
             }  
             splice @{$self->{open_elements}}, $i;  
             last LI;  
           }  
             
           ## Step 3  
           if (not $formatting_category->{$node->[1]} and  
               #not $phrasing_category->{$node->[1]} and  
               ($special_category->{$node->[1]} or  
                $scoping_category->{$node->[1]}) and  
               $node->[1] ne 'address' and $node->[1] ne 'div') {  
             last LI;  
           }  
             
           ## Step 4  
           $i--;  
           $node = $self->{open_elements}->[$i];  
           redo LI;  
         } # LI  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'dd' or $token->{tag_name} eq 'dt') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## Step 1  
         my $i = -1;  
         my $node = $self->{open_elements}->[$i];  
         LI: {  
           ## Step 2  
           if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {  
             if ($i != -1) {  
               !!!parse-error (type => 'end tag missing:'.  
                               $self->{open_elements}->[-1]->[1]);  
             }  
             splice @{$self->{open_elements}}, $i;  
             last LI;  
           }  
             
           ## Step 3  
           if (not $formatting_category->{$node->[1]} and  
               #not $phrasing_category->{$node->[1]} and  
               ($special_category->{$node->[1]} or  
                $scoping_category->{$node->[1]}) and  
               $node->[1] ne 'address' and $node->[1] ne 'div') {  
             last LI;  
           }  
             
           ## Step 4  
           $i--;  
           $node = $self->{open_elements}->[$i];  
           redo LI;  
         } # LI  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'plaintext') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         $self->{content_model} = PLAINTEXT_CONTENT_MODEL;  
             
         !!!next-token;  
         return;  
       } elsif ({  
                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
                }->{$token->{tag_name}}) {  
         ## has a p element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>  
         ## has an element in scope  
         #my $i;  
         #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
         #  my $node = $self->{open_elements}->[$_];  
         #  if ({  
         #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
         #      }->{$node->[1]}) {  
         #    $i = $_;  
         #    last INSCOPE;  
         #  } elsif ({  
         #            table => 1, caption => 1, td => 1, th => 1,  
         #            button => 1, marquee => 1, object => 1, html => 1,  
         #           }->{$node->[1]}) {  
         #    last INSCOPE;  
         #  }  
         #} # INSCOPE  
         #    
         #if (defined $i) {  
         #  !!! parse-error (type => 'in hn:hn');  
         #  splice @{$self->{open_elements}}, $i;  
         #}  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'a') {  
         AFE: for my $i (reverse 0..$#$active_formatting_elements) {  
           my $node = $active_formatting_elements->[$i];  
           if ($node->[1] eq 'a') {  
             !!!parse-error (type => 'in a:a');  
               
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'a'};  
             $formatting_end_tag->($token->{tag_name});  
               
             AFE2: for (reverse 0..$#$active_formatting_elements) {  
               if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {  
                 splice @$active_formatting_elements, $_, 1;  
                 last AFE2;  
               }  
             } # AFE2  
             OE: for (reverse 0..$#{$self->{open_elements}}) {  
               if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {  
                 splice @{$self->{open_elements}}, $_, 1;  
                 last OE;  
               }  
             } # OE  
             last AFE;  
           } elsif ($node->[0] eq '#marker') {  
             last AFE;  
           }  
         } # AFE  
             
         $reconstruct_active_formatting_elements->($insert_to_current);  
   
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, $self->{open_elements}->[-1];  
   
         !!!next-token;  
         return;  
       } elsif ({  
                 b => 1, big => 1, em => 1, font => 1, i => 1,  
                 s => 1, small => 1, strile => 1,  
                 strong => 1, tt => 1, u => 1,  
                }->{$token->{tag_name}}) {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, $self->{open_elements}->[-1];  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'nobr') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
   
         ## has a |nobr| element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'nobr') {  
             !!!parse-error (type => 'not closed:nobr');  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'nobr'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, $self->{open_elements}->[-1];  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'button') {  
         ## has a button element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'button') {  
             !!!parse-error (type => 'in button:button');  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'button'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         $reconstruct_active_formatting_elements->($insert_to_current);  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, ['#marker', ''];  
   
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'marquee' or  
                $token->{tag_name} eq 'object') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, ['#marker', ''];  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'xmp') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
         $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);  
         return;  
       } elsif ($token->{tag_name} eq 'table') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         $self->{insertion_mode} = 'in table';  
             
         !!!next-token;  
         return;  
       } elsif ({  
                 area => 1, basefont => 1, bgsound => 1, br => 1,  
                 embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,  
                 image => 1,  
                }->{$token->{tag_name}}) {  
         if ($token->{tag_name} eq 'image') {  
           !!!parse-error (type => 'image');  
           $token->{tag_name} = 'img';  
         }  
   
         ## NOTE: There is an "as if <br>" code clone.  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}};  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'hr') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}};  
             
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'input') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         ## TODO: associate with $self->{form_element} if defined  
         pop @{$self->{open_elements}};  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'isindex') {  
         !!!parse-error (type => 'isindex');  
           
         if (defined $self->{form_element}) {  
           ## Ignore the token  
           !!!next-token;  
           return;  
         } else {  
           my $at = $token->{attributes};  
           my $form_attrs;  
           $form_attrs->{action} = $at->{action} if $at->{action};  
           my $prompt_attr = $at->{prompt};  
           $at->{name} = {name => 'name', value => 'isindex'};  
           delete $at->{action};  
           delete $at->{prompt};  
           my @tokens = (  
                         {type => 'start tag', tag_name => 'form',  
                          attributes => $form_attrs},  
                         {type => 'start tag', tag_name => 'hr'},  
                         {type => 'start tag', tag_name => 'p'},  
                         {type => 'start tag', tag_name => 'label'},  
                        );  
           if ($prompt_attr) {  
             push @tokens, {type => 'character', data => $prompt_attr->{value}};  
           } else {  
             push @tokens, {type => 'character',  
                            data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD  
             ## TODO: make this configurable  
           }  
           push @tokens,  
                         {type => 'start tag', tag_name => 'input', attributes => $at},  
                         #{type => 'character', data => ''}, # SHOULD  
                         {type => 'end tag', tag_name => 'label'},  
                         {type => 'end tag', tag_name => 'p'},  
                         {type => 'start tag', tag_name => 'hr'},  
                         {type => 'end tag', tag_name => 'form'};  
           $token = shift @tokens;  
           !!!back-token (@tokens);  
           return;  
         }  
       } elsif ($token->{tag_name} eq 'textarea') {  
         my $tag_name = $token->{tag_name};  
         my $el;  
         !!!create-element ($el, $token->{tag_name}, $token->{attributes});  
           
         ## TODO: $self->{form_element} if defined  
         $self->{content_model} = RCDATA_CONTENT_MODEL;  
         delete $self->{escape}; # MUST  
           
         $insert->($el);  
           
         my $text = '';  
         !!!next-token;  
         if ($token->{type} eq 'character') {  
           $token->{data} =~ s/^\x0A//;  
           unless (length $token->{data}) {  
             !!!next-token;  
           }  
         }  
         while ($token->{type} eq 'character') {  
           $text .= $token->{data};  
           !!!next-token;  
         }  
         if (length $text) {  
           $el->manakai_append_text ($text);  
         }  
           
         $self->{content_model} = PCDATA_CONTENT_MODEL;  
           
         if ($token->{type} eq 'end tag' and  
             $token->{tag_name} eq $tag_name) {  
           ## Ignore the token  
         } else {  
           !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
         }  
         !!!next-token;  
         return;  
       } elsif ({  
                 iframe => 1,  
                 noembed => 1,  
                 noframes => 1,  
                 noscript => 0, ## TODO: 1 if scripting is enabled  
                }->{$token->{tag_name}}) {  
         ## NOTE: There are two "as if in body" code clones.  
         $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);  
         return;  
       } elsif ($token->{tag_name} eq 'select') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           
         $self->{insertion_mode} = 'in select';  
         !!!next-token;  
         return;  
       } elsif ({  
                 caption => 1, col => 1, colgroup => 1, frame => 1,  
                 frameset => 1, head => 1, option => 1, optgroup => 1,  
                 tbody => 1, td => 1, tfoot => 1, th => 1,  
                 thead => 1, tr => 1,  
                }->{$token->{tag_name}}) {  
         !!!parse-error (type => 'in body:'.$token->{tag_name});  
         ## Ignore the token  
         !!!next-token;  
         return;  
           
         ## ISSUE: An issue on HTML5 new elements in the spec.  
       } else {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           
         !!!next-token;  
         return;  
       }  
     } elsif ($token->{type} eq 'end tag') {  
       if ($token->{tag_name} eq 'body') {  
         if (@{$self->{open_elements}} > 1 and  
             $self->{open_elements}->[1]->[1] eq 'body') {  
           for (@{$self->{open_elements}}) {  
             unless ({  
                        dd => 1, dt => 1, li => 1, p => 1, td => 1,  
                        th => 1, tr => 1, body => 1, html => 1,  
                      tbody => 1, tfoot => 1, thead => 1,  
                     }->{$_->[1]}) {  
               !!!parse-error (type => 'not closed:'.$_->[1]);  
             }  
           }  
   
           $self->{insertion_mode} = 'after body';  
           !!!next-token;  
           return;  
         } else {  
           !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
           ## Ignore the token  
           !!!next-token;  
           return;  
         }  
       } elsif ($token->{tag_name} eq 'html') {  
         if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {  
           ## ISSUE: There is an issue in the spec.  
           if ($self->{open_elements}->[-1]->[1] ne 'body') {  
             !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);  
           }  
           $self->{insertion_mode} = 'after body';  
           ## reprocess  
           return;  
         } else {  
           !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
           ## Ignore the token  
           !!!next-token;  
           return;  
         }  
       } elsif ({  
                 address => 1, blockquote => 1, center => 1, dir => 1,  
                 div => 1, dl => 1, fieldset => 1, listing => 1,  
                 menu => 1, ol => 1, pre => 1, ul => 1,  
                 p => 1,  
                 dd => 1, dt => 1, li => 1,  
                 button => 1, marquee => 1, object => 1,  
                }->{$token->{tag_name}}) {  
         ## has an element in scope  
         my $i;  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq $token->{tag_name}) {  
             ## generate implied end tags  
             if ({  
                  dd => ($token->{tag_name} ne 'dd'),  
                  dt => ($token->{tag_name} ne 'dt'),  
                  li => ($token->{tag_name} ne 'li'),  
                  p => ($token->{tag_name} ne 'p'),  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => 'end tag',  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               return;  
             }  
             $i = $_;  
             last INSCOPE unless $token->{tag_name} eq 'p';  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
           
         if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {  
           if (defined $i) {  
             !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
           } else {  
             !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
           }  
         }  
           
         if (defined $i) {  
           splice @{$self->{open_elements}}, $i;  
         } elsif ($token->{tag_name} eq 'p') {  
           ## As if <p>, then reprocess the current token  
           my $el;  
           !!!create-element ($el, 'p');  
           $insert->($el);  
         }  
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'form') {  
         ## has an element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq $token->{tag_name}) {  
             ## generate implied end tags  
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => 'end tag',  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               return;  
             }  
             last INSCOPE;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
           
         if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {  
           pop @{$self->{open_elements}};  
         } else {  
           !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
         }  
   
         undef $self->{form_element};  
         !!!next-token;  
         return;  
       } elsif ({  
                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
                }->{$token->{tag_name}}) {  
         ## has an element in scope  
         my $i;  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ({  
                h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
               }->{$node->[1]}) {  
             ## generate implied end tags  
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => 'end tag',  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               return;  
             }  
             $i = $_;  
             last INSCOPE;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
           
         if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {  
           !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
         }  
           
         splice @{$self->{open_elements}}, $i if defined $i;  
         !!!next-token;  
         return;  
       } elsif ({  
                 a => 1,  
                 b => 1, big => 1, em => 1, font => 1, i => 1,  
                 nobr => 1, s => 1, small => 1, strile => 1,  
                 strong => 1, tt => 1, u => 1,  
                }->{$token->{tag_name}}) {  
         $formatting_end_tag->($token->{tag_name});  
         return;  
       } elsif ($token->{tag_name} eq 'br') {  
         !!!parse-error (type => 'unmatched end tag:br');  
   
         ## As if <br>  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         my $el;  
         !!!create-element ($el, 'br');  
         $insert->($el);  
           
         ## Ignore the token.  
         !!!next-token;  
         return;  
       } elsif ({  
                 caption => 1, col => 1, colgroup => 1, frame => 1,  
                 frameset => 1, head => 1, option => 1, optgroup => 1,  
                 tbody => 1, td => 1, tfoot => 1, th => 1,  
                 thead => 1, tr => 1,  
                 area => 1, basefont => 1, bgsound => 1,  
                 embed => 1, hr => 1, iframe => 1, image => 1,  
                 img => 1, input => 1, isindex => 1, noembed => 1,  
                 noframes => 1, param => 1, select => 1, spacer => 1,  
                 table => 1, textarea => 1, wbr => 1,  
                 noscript => 0, ## TODO: if scripting is enabled  
                }->{$token->{tag_name}}) {  
         !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
         ## Ignore the token  
         !!!next-token;  
         return;  
           
         ## ISSUE: Issue on HTML5 new elements in spec  
           
       } else {  
         ## Step 1  
         my $node_i = -1;  
         my $node = $self->{open_elements}->[$node_i];  
   
         ## Step 2  
         S2: {  
           if ($node->[1] eq $token->{tag_name}) {  
             ## Step 1  
             ## generate implied end tags  
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => 'end tag',  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               return;  
             }  
           
             ## Step 2  
             if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {  
               !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
             }  
               
             ## Step 3  
             splice @{$self->{open_elements}}, $node_i;  
   
             !!!next-token;  
             last S2;  
           } else {  
             ## Step 3  
             if (not $formatting_category->{$node->[1]} and  
                 #not $phrasing_category->{$node->[1]} and  
                 ($special_category->{$node->[1]} or  
                  $scoping_category->{$node->[1]})) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               last S2;  
             }  
           }  
             
           ## Step 4  
           $node_i--;  
           $node = $self->{open_elements}->[$node_i];  
             
           ## Step 5;  
           redo S2;  
         } # S2  
         return;  
       }  
     }  
   }; # $in_body  
2498    
2499    B: {    B: {
2500      if ($token->{type} eq 'DOCTYPE') {      if ($token->{type} eq 'DOCTYPE') {
# Line 3350  sub _tree_construction_main ($) { Line 2504  sub _tree_construction_main ($) {
2504        !!!next-token;        !!!next-token;
2505        redo B;        redo B;
2506      } elsif ($token->{type} eq 'end-of-file') {      } elsif ($token->{type} eq 'end-of-file') {
2507        if ($token->{insertion_mode} ne 'trailing end') {        if ($self->{insertion_mode} eq 'after html body' or
2508              $self->{insertion_mode} eq 'after html frameset') {
2509            #
2510          } else {
2511          ## Generate implied end tags          ## Generate implied end tags
2512          if ({          if ({
2513               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,
# Line 3377  sub _tree_construction_main ($) { Line 2534  sub _tree_construction_main ($) {
2534        last B;        last B;
2535      } elsif ($token->{type} eq 'start tag' and      } elsif ($token->{type} eq 'start tag' and
2536               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
2537        if ($self->{insertion_mode} eq 'trailing end') {        if ($self->{insertion_mode} eq 'after html body') {
2538            ## Turn into the main phase
2539            !!!parse-error (type => 'after html:html');
2540            $self->{insertion_mode} = 'after body';
2541          } elsif ($self->{insertion_mode} eq 'after html frameset') {
2542          ## Turn into the main phase          ## Turn into the main phase
2543          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
2544          $self->{insertion_mode} = $previous_insertion_mode;          $self->{insertion_mode} = 'after frameset';
2545        }        }
2546    
2547  ## ISSUE: "aa<html>" is not a parse error.  ## ISSUE: "aa<html>" is not a parse error.
# Line 3400  sub _tree_construction_main ($) { Line 2561  sub _tree_construction_main ($) {
2561        redo B;        redo B;
2562      } elsif ($token->{type} eq 'comment') {      } elsif ($token->{type} eq 'comment') {
2563        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2564        if ($self->{insertion_mode} eq 'trailing end') {        if ($self->{insertion_mode} eq 'after html body' or
2565              $self->{insertion_mode} eq 'after html frameset') {
2566          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2567        } elsif ($self->{insertion_mode} eq 'after body') {        } elsif ($self->{insertion_mode} eq 'after body') {
2568          $self->{open_elements}->[0]->[0]->append_child ($comment);          $self->{open_elements}->[0]->[0]->append_child ($comment);
# Line 3409  sub _tree_construction_main ($) { Line 2571  sub _tree_construction_main ($) {
2571        }        }
2572        !!!next-token;        !!!next-token;
2573        redo B;        redo B;
2574      } elsif ($self->{insertion_mode} eq 'before head') {      } elsif ($self->{insertion_mode} eq 'in head' or
2575            if ($token->{type} eq 'character') {               $self->{insertion_mode} eq 'in head noscript' or
2576              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {               $self->{insertion_mode} eq 'after head' or
2577                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);               $self->{insertion_mode} eq 'before head') {
2578                unless (length $token->{data}) {        if ($token->{type} eq 'character') {
2579                  !!!next-token;          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
2580                  redo B;            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
2581                }            unless (length $token->{data}) {
2582              }              !!!next-token;
2583              ## As if <head>              redo B;
2584              !!!create-element ($self->{head_element}, 'head');            }
2585              $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});          }
2586              push @{$self->{open_elements}}, [$self->{head_element}, 'head'];  
2587              $self->{insertion_mode} = 'in head';          if ($self->{insertion_mode} eq 'before head') {
2588              ## As if <head>
2589              !!!create-element ($self->{head_element}, 'head');
2590              $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2591              push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2592    
2593              ## Reprocess in the "in head" insertion mode...
2594              pop @{$self->{open_elements}};
2595    
2596              ## Reprocess in the "after head" insertion mode...
2597            } elsif ($self->{insertion_mode} eq 'in head noscript') {
2598              ## As if </noscript>
2599              pop @{$self->{open_elements}};
2600              !!!parse-error (type => 'in noscript:#character');
2601              
2602              ## Reprocess in the "in head" insertion mode...
2603              ## As if </head>
2604              pop @{$self->{open_elements}};
2605    
2606              ## Reprocess in the "after head" insertion mode...
2607            } elsif ($self->{insertion_mode} eq 'in head') {
2608              pop @{$self->{open_elements}};
2609    
2610              ## Reprocess in the "after head" insertion mode...
2611            }
2612    
2613                ## "after head" insertion mode
2614                ## As if <body>
2615                !!!insert-element ('body');
2616                $self->{insertion_mode} = 'in body';
2617              ## reprocess              ## reprocess
2618              redo B;              redo B;
2619            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
             my $attr = $token->{tag_name} eq 'head' ? $token->{attributes} : {};  
             !!!create-element ($self->{head_element}, 'head', $attr);  
             $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});  
             push @{$self->{open_elements}}, [$self->{head_element}, 'head'];  
             $self->{insertion_mode} = 'in head';  
2620              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
2621                !!!next-token;                if ($self->{insertion_mode} eq 'before head') {
2622              } else {                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});
2623                ## reprocess                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2624              }                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];
2625              redo B;                  $self->{insertion_mode} = 'in head';
2626            } elsif ($token->{type} eq 'end tag') {                  !!!next-token;
2627              if ({                  redo B;
2628                   head => 1, body => 1, html => 1,                } elsif ($self->{insertion_mode} ne 'after head') {
2629                   p => 1, br => 1,                  !!!parse-error (type => 'in head:head'); # or in head noscript
2630                  }->{$token->{tag_name}}) {                  ## Ignore the token
2631                    !!!next-token;
2632                    redo B;
2633                  } else {
2634                    #
2635                  }
2636                } elsif ($self->{insertion_mode} eq 'before head') {
2637                ## As if <head>                ## As if <head>
2638                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
2639                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2640                push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2641    
2642                $self->{insertion_mode} = 'in head';                $self->{insertion_mode} = 'in head';
               ## reprocess  
               redo B;  
             } else {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token ## ISSUE: An issue in the spec.  
               !!!next-token;  
               redo B;  
             }  
           } else {  
             die "$0: $token->{type}: Unknown type";  
           }  
         } elsif ($self->{insertion_mode} eq 'in head' or  
                  $self->{insertion_mode} eq 'in head noscript' or  
                  $self->{insertion_mode} eq 'after head') {  
           if ($token->{type} eq 'character') {  
             if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {  
               $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);  
               unless (length $token->{data}) {  
                 !!!next-token;  
                 redo B;  
               }  
             }  
               
             if ($self->{insertion_mode} eq 'in head noscript') {  
               ## As if </noscript>  
               pop @{$self->{open_elements}};  
               !!!parse-error (type => 'in noscript:#character');  
                 
2643                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
               ## As if </head>  
               pop @{$self->{open_elements}};  
   
               ## Reprocess in the "after head" insertion mode...  
             } elsif ($self->{insertion_mode} eq 'in head') {  
               pop @{$self->{open_elements}};  
   
               ## Reprocess in the "after head" insertion mode...  
2644              }              }
2645    
             ## 'after head' insertion mode  
             ## As if <body>  
             !!!insert-element ('body');  
             $self->{insertion_mode} = 'in body';  
             ## reprocess  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
2646              if ($token->{tag_name} eq 'base') {              if ($token->{tag_name} eq 'base') {
2647                if ($self->{insertion_mode} eq 'in head noscript') {                if ($self->{insertion_mode} eq 'in head noscript') {
2648                  ## As if </noscript>                  ## As if </noscript>
# Line 3605  sub _tree_construction_main ($) { Line 2755  sub _tree_construction_main ($) {
2755                } else {                } else {
2756                  #                  #
2757                }                }
             } elsif ($token->{tag_name} eq 'head') {  
               if ($self->{insertion_mode} ne 'after head') {  
                 !!!parse-error (type => 'in head:head'); # or in head noscript  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               } else {  
                 #  
               }  
2758              } elsif ($token->{tag_name} eq 'script') {              } elsif ($token->{tag_name} eq 'script') {
2759                if ($self->{insertion_mode} eq 'in head noscript') {                if ($self->{insertion_mode} eq 'in head noscript') {
2760                  ## As if </noscript>                  ## As if </noscript>
# Line 3684  sub _tree_construction_main ($) { Line 2825  sub _tree_construction_main ($) {
2825              redo B;              redo B;
2826            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
2827              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
2828                if ($self->{insertion_mode} eq 'in head noscript') {                if ($self->{insertion_mode} eq 'before head') {
2829                    ## As if <head>
2830                    !!!create-element ($self->{head_element}, 'head');
2831                    $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2832                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2833    
2834                    ## Reprocess in the "in head" insertion mode...
2835                    pop @{$self->{open_elements}};
2836                    $self->{insertion_mode} = 'after head';
2837                    !!!next-token;
2838                    redo B;
2839                  } elsif ($self->{insertion_mode} eq 'in head noscript') {
2840                  ## As if </noscript>                  ## As if </noscript>
2841                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
2842                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:script');
2843                                    
                 $self->{insertion_mode} = 'in head';  
2844                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
2845                }                  pop @{$self->{open_elements}};
2846                                  $self->{insertion_mode} = 'after head';
2847                if ($self->{insertion_mode} eq 'in head') {                  !!!next-token;
2848                    redo B;
2849                  } elsif ($self->{insertion_mode} eq 'in head') {
2850                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
2851                  $self->{insertion_mode} = 'after head';                  $self->{insertion_mode} = 'after head';
2852                  !!!next-token;                  !!!next-token;
# Line 3707  sub _tree_construction_main ($) { Line 2860  sub _tree_construction_main ($) {
2860                  $self->{insertion_mode} = 'in head';                  $self->{insertion_mode} = 'in head';
2861                  !!!next-token;                  !!!next-token;
2862                  redo B;                  redo B;
2863                  } elsif ($self->{insertion_mode} eq 'before head') {
2864                    !!!parse-error (type => 'unmatched end tag:noscript');
2865                    ## Ignore the token ## ISSUE: An issue in the spec.
2866                    !!!next-token;
2867                    redo B;
2868                } else {                } else {
2869                  #                  #
2870                }                }
2871              } elsif ({              } elsif ({
2872                        body => 1, html => 1,                        body => 1, html => 1,
2873                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
2874                if ($self->{insertion_mode} eq 'in head noscript') {                if ($self->{insertion_mode} eq 'before head') {
2875                    ## As if <head>
2876                    !!!create-element ($self->{head_element}, 'head');
2877                    $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2878                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2879    
2880                    $self->{insertion_mode} = 'in head';
2881                    ## Reprocess in the "in head" insertion mode...
2882                  } elsif ($self->{insertion_mode} eq 'in head noscript') {
2883                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
2884                  ## Ignore the token                  ## Ignore the token
2885                  !!!next-token;                  !!!next-token;
2886                  redo B;                  redo B;
               } else { # 'in head', 'after head'  
                 #  
2887                }                }
2888                  
2889                  #
2890              } elsif ({              } elsif ({
2891                        p => 1, br => 1,                        p => 1, br => 1,
2892                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
2893                  if ($self->{insertion_mode} eq 'before head') {
2894                    ## As if <head>
2895                    !!!create-element ($self->{head_element}, 'head');
2896                    $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2897                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2898    
2899                    $self->{insertion_mode} = 'in head';
2900                    ## Reprocess in the "in head" insertion mode...
2901                  }
2902    
2903                #                #
2904              } else {              } else {
2905                if ($self->{insertion_mode} ne 'after head') {                if ($self->{insertion_mode} ne 'after head') {
# Line 3751  sub _tree_construction_main ($) { Line 2927  sub _tree_construction_main ($) {
2927                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
2928    
2929                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
2930                } elsif ($self->{insertion_mode} eq 'before head') {
2931                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
2932                  ## Ignore the token ## ISSUE: An issue in the spec.
2933                  !!!next-token;
2934                  redo B;
2935              }              }
2936    
2937              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3764  sub _tree_construction_main ($) { Line 2945  sub _tree_construction_main ($) {
2945            }            }
2946    
2947            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
2948          } elsif ($self->{insertion_mode} eq 'in body' or      } elsif ($self->{insertion_mode} eq 'in body' or
2949                   $self->{insertion_mode} eq 'in cell' or               $self->{insertion_mode} eq 'in cell' or
2950                   $self->{insertion_mode} eq 'in caption') {               $self->{insertion_mode} eq 'in caption') {
2951            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
2952              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
2953              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
# Line 4081  sub _tree_construction_main ($) { Line 3262  sub _tree_construction_main ($) {
3262              } else {              } else {
3263                #                #
3264              }              }
3265            } else {        } else {
3266              #          die "$0: $token->{type}: Unknown token type";
3267            }        }
3268              
3269            $in_body->($insert_to_current);        $insert = $insert_to_current;
3270            redo B;        #
3271          } elsif ($self->{insertion_mode} eq 'in row' or      } elsif ($self->{insertion_mode} eq 'in row' or
3272                   $self->{insertion_mode} eq 'in table body' or               $self->{insertion_mode} eq 'in table body' or
3273                   $self->{insertion_mode} eq 'in table') {               $self->{insertion_mode} eq 'in table') {
3274            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3275              ## NOTE: There are "character in table" code clones.              ## NOTE: There are "character in table" code clones.
3276              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
# Line 4650  sub _tree_construction_main ($) { Line 3831  sub _tree_construction_main ($) {
3831              die "$0: $token->{type}: Unknown token type";              die "$0: $token->{type}: Unknown token type";
3832            }            }
3833    
3834            !!!parse-error (type => 'in table:'.$token->{tag_name});        !!!parse-error (type => 'in table:'.$token->{tag_name});
3835            $in_body->($insert_to_foster);  
3836            redo B;        $insert = $insert_to_foster;
3837          } elsif ($self->{insertion_mode} eq 'in column group') {        #
3838        } elsif ($self->{insertion_mode} eq 'in column group') {
3839            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3840              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3841                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
# Line 4710  sub _tree_construction_main ($) { Line 3892  sub _tree_construction_main ($) {
3892              ## reprocess              ## reprocess
3893              redo B;              redo B;
3894            }            }
3895          } elsif ($self->{insertion_mode} eq 'in select') {      } elsif ($self->{insertion_mode} eq 'in select') {
3896            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3897              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
3898              !!!next-token;              !!!next-token;
# Line 4884  sub _tree_construction_main ($) { Line 4066  sub _tree_construction_main ($) {
4066            ## Ignore the token            ## Ignore the token
4067            !!!next-token;            !!!next-token;
4068            redo B;            redo B;
4069          } elsif ($self->{insertion_mode} eq 'after body') {      } elsif ($self->{insertion_mode} eq 'after body' or
4070            if ($token->{type} eq 'character') {               $self->{insertion_mode} eq 'after html body') {
4071              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {        if ($token->{type} eq 'character') {
4072                my $data = $1;          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4073                ## As if in body            my $data = $1;
4074                $reconstruct_active_formatting_elements->($insert_to_current);            ## As if in body
4075              $reconstruct_active_formatting_elements->($insert_to_current);
4076                                
4077                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4078              
4079              unless (length $token->{data}) {
4080                !!!next-token;
4081                redo B;
4082              }
4083            }
4084            
4085            if ($self->{insertion_mode} eq 'after html body') {
4086              !!!parse-error (type => 'after html:#character');
4087    
4088                unless (length $token->{data}) {            ## Reprocess in the "main" phase, "after body" insertion mode...
4089                  !!!next-token;          }
4090                  redo B;          
4091                }          ## "after body" insertion mode
4092              }          !!!parse-error (type => 'after body:#character');
4093                
4094              #          $self->{insertion_mode} = 'in body';
4095              !!!parse-error (type => 'after body:#character');          ## reprocess
4096            } elsif ($token->{type} eq 'start tag') {          redo B;
4097              !!!parse-error (type => 'after body:'.$token->{tag_name});        } elsif ($token->{type} eq 'start tag') {
4098              #          if ($self->{insertion_mode} eq 'after html body') {
4099            } elsif ($token->{type} eq 'end tag') {            !!!parse-error (type => 'after html:'.$token->{tag_name});
4100              if ($token->{tag_name} eq 'html') {            
4101                if (defined $self->{inner_html_node}) {            ## Reprocess in the "main" phase, "after body" insertion mode...
4102                  !!!parse-error (type => 'unmatched end tag:html');          }
4103                  ## Ignore the token  
4104                  !!!next-token;          ## "after body" insertion mode
4105                  redo B;          !!!parse-error (type => 'after body:'.$token->{tag_name});
4106                } else {  
4107                  $previous_insertion_mode = $self->{insertion_mode};          $self->{insertion_mode} = 'in body';
4108                  $self->{insertion_mode} = 'trailing end';          ## reprocess
4109                  !!!next-token;          redo B;
4110                  redo B;        } elsif ($token->{type} eq 'end tag') {
4111                }          if ($self->{insertion_mode} eq 'after html body') {
4112              } else {            !!!parse-error (type => 'after html:/'.$token->{tag_name});
4113                !!!parse-error (type => 'after body:/'.$token->{tag_name});            
4114              }            $self->{insertion_mode} = 'after body';
4115              ## Reprocess in the "main" phase, "after body" insertion mode...
4116            }
4117    
4118            ## "after body" insertion mode
4119            if ($token->{tag_name} eq 'html') {
4120              if (defined $self->{inner_html_node}) {
4121                !!!parse-error (type => 'unmatched end tag:html');
4122                ## Ignore the token
4123                !!!next-token;
4124                redo B;
4125            } else {            } else {
4126              die "$0: $token->{type}: Unknown token type";              $self->{insertion_mode} = 'after html body';
4127                !!!next-token;
4128                redo B;
4129            }            }
4130            } else {
4131              !!!parse-error (type => 'after body:/'.$token->{tag_name});
4132    
4133            $self->{insertion_mode} = 'in body';            $self->{insertion_mode} = 'in body';
4134            ## reprocess            ## reprocess
4135            redo B;            redo B;
4136      } elsif ($self->{insertion_mode} eq 'in frameset') {          }
4137          } else {
4138            die "$0: $token->{type}: Unknown token type";
4139          }
4140        } elsif ($self->{insertion_mode} eq 'in frameset' or
4141                 $self->{insertion_mode} eq 'after frameset' or
4142                 $self->{insertion_mode} eq 'after html frameset') {
4143        if ($token->{type} eq 'character') {        if ($token->{type} eq 'character') {
4144          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4145            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4146              
4147            unless (length $token->{data}) {            unless (length $token->{data}) {
4148              !!!next-token;              !!!next-token;
4149              redo B;              redo B;
4150            }            }
4151          }          }
4152            
4153            if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
4154              if ($self->{insertion_mode} eq 'in frameset') {
4155                !!!parse-error (type => 'in frameset:#character');
4156              } elsif ($self->{insertion_mode} eq 'after frameset') {
4157                !!!parse-error (type => 'after frameset:#character');
4158              } else { # "after html frameset"
4159                !!!parse-error (type => 'after html:#character');
4160    
4161          !!!parse-error (type => 'in frameset:#character');              $self->{insertion_mode} = 'after frameset';
4162          ## Ignore the token              ## Reprocess in the "main" phase, "after frameset"...
4163          !!!next-token;              !!!parse-error (type => 'after frameset:#character');
4164          redo B;            }
4165              
4166              ## Ignore the token.
4167              if (length $token->{data}) {
4168                ## reprocess the rest of characters
4169              } else {
4170                !!!next-token;
4171              }
4172              redo B;
4173            }
4174            
4175            die qq[$0: Character "$token->{data}"];
4176        } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{type} eq 'start tag') {
4177          if ($token->{tag_name} eq 'frameset') {          if ($self->{insertion_mode} eq 'after html frameset') {
4178              !!!parse-error (type => 'after html:'.$token->{tag_name});
4179    
4180              $self->{insertion_mode} = 'after frameset';
4181              ## Process in the "main" phase, "after frameset" insertion mode...
4182            }
4183    
4184            if ($token->{tag_name} eq 'frameset' and
4185                $self->{insertion_mode} eq 'in frameset') {
4186            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
4187            !!!next-token;            !!!next-token;
4188            redo B;            redo B;
4189          } elsif ($token->{tag_name} eq 'frame') {          } elsif ($token->{tag_name} eq 'frame' and
4190                     $self->{insertion_mode} eq 'in frameset') {
4191            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
4192            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4193            !!!next-token;            !!!next-token;
# Line 4957  sub _tree_construction_main ($) { Line 4197  sub _tree_construction_main ($) {
4197            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
4198            redo B;            redo B;
4199          } else {          } else {
4200            !!!parse-error (type => 'in frameset:'.$token->{tag_name});            if ($self->{insertion_mode} eq 'in frameset') {
4201                !!!parse-error (type => 'in frameset:'.$token->{tag_name});
4202              } else {
4203                !!!parse-error (type => 'after frameset:'.$token->{tag_name});
4204              }
4205            ## Ignore the token            ## Ignore the token
4206            !!!next-token;            !!!next-token;
4207            redo B;            redo B;
4208          }          }
4209        } elsif ($token->{type} eq 'end tag') {        } elsif ($token->{type} eq 'end tag') {
4210          if ($token->{tag_name} eq 'frameset') {          if ($self->{insertion_mode} eq 'after html frameset') {
4211              !!!parse-error (type => 'after html:/'.$token->{tag_name});
4212    
4213              $self->{insertion_mode} = 'after frameset';
4214              ## Process in the "main" phase, "after frameset" insertion mode...
4215            }
4216    
4217            if ($token->{tag_name} eq 'frameset' and
4218                $self->{insertion_mode} eq 'in frameset') {
4219            if ($self->{open_elements}->[-1]->[1] eq 'html' and            if ($self->{open_elements}->[-1]->[1] eq 'html' and
4220                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
4221              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
# Line 4979  sub _tree_construction_main ($) { Line 4231  sub _tree_construction_main ($) {
4231              $self->{insertion_mode} = 'after frameset';              $self->{insertion_mode} = 'after frameset';
4232            }            }
4233            redo B;            redo B;
4234            } elsif ($token->{tag_name} eq 'html' and
4235                     $self->{insertion_mode} eq 'after frameset') {
4236              $self->{insertion_mode} = 'after html frameset';
4237              !!!next-token;
4238              redo B;
4239          } else {          } else {
4240            !!!parse-error (type => 'in frameset:/'.$token->{tag_name});            if ($self->{insertion_mode} eq 'in frameset') {
4241                !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
4242              } else {
4243                !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
4244              }
4245            ## Ignore the token            ## Ignore the token
4246            !!!next-token;            !!!next-token;
4247            redo B;            redo B;
# Line 4988  sub _tree_construction_main ($) { Line 4249  sub _tree_construction_main ($) {
4249        } else {        } else {
4250          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4251        }        }
     } elsif ($self->{insertion_mode} eq 'after frameset') {  
       if ($token->{type} eq 'character') {  
             if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {  
               $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);  
4252    
4253                unless (length $token->{data}) {        ## ISSUE: An issue in spec here
4254                  !!!next-token;      } else {
4255                  redo B;        die "$0: $self->{insertion_mode}: Unknown insertion mode";
4256                }      }
             }  
4257    
4258              if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {      ## "in body" insertion mode
4259                !!!parse-error (type => 'after frameset:#character');    my $in_body = sub {
4260        if ($token->{type} eq 'start tag') {
4261          if ($token->{tag_name} eq 'script') {
4262            ## NOTE: This is an "as if in head" code clone
4263            $script_start_tag->($insert);
4264            return;
4265          } elsif ($token->{tag_name} eq 'style') {
4266            ## NOTE: This is an "as if in head" code clone
4267            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
4268            return;
4269          } elsif ({
4270                    base => 1, link => 1,
4271                   }->{$token->{tag_name}}) {
4272            ## NOTE: This is an "as if in head" code clone, only "-t" differs
4273            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4274            pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4275            !!!next-token;
4276            return;
4277          } elsif ($token->{tag_name} eq 'meta') {
4278            ## NOTE: This is an "as if in head" code clone, only "-t" differs
4279            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4280            pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4281    
4282                ## Ignore the token.          unless ($self->{confident}) {
4283                if (length $token->{data}) {            my $charset;
4284                  ## reprocess the rest of characters            if ($token->{attributes}->{charset}) { ## TODO: And if supported
4285                } else {              $charset = $token->{attributes}->{charset}->{value};
4286                  !!!next-token;            }
4287                }            if ($token->{attributes}->{'http-equiv'}) {
4288                redo B;              ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.
4289              }              if ($token->{attributes}->{'http-equiv'}->{value}
4290                    =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
4291                        [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4292                        ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
4293                  $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
4294                } ## TODO: And if supported
4295              }
4296              ## TODO: Change the encoding
4297            }
4298    
4299          die qq[$0: Character "$token->{data}"];          !!!next-token;
4300        } elsif ($token->{type} eq 'start tag') {          return;
4301          if ($token->{tag_name} eq 'noframes') {        } elsif ($token->{tag_name} eq 'title') {
4302            ## NOTE: As if in body.          !!!parse-error (type => 'in body:title');
4303            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);          ## NOTE: This is an "as if in head" code clone
4304            redo B;          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {
4305          } else {            if (defined $self->{head_element}) {
4306            !!!parse-error (type => 'after frameset:'.$token->{tag_name});              $self->{head_element}->append_child ($_[0]);
4307              } else {
4308                $insert->($_[0]);
4309              }
4310            });
4311            return;
4312          } elsif ($token->{tag_name} eq 'body') {
4313            !!!parse-error (type => 'in body:body');
4314                  
4315            if (@{$self->{open_elements}} == 1 or
4316                $self->{open_elements}->[1]->[1] ne 'body') {
4317            ## Ignore the token            ## Ignore the token
4318            !!!next-token;          } else {
4319            redo B;            my $body_el = $self->{open_elements}->[1]->[0];
4320              for my $attr_name (keys %{$token->{attributes}}) {
4321                unless ($body_el->has_attribute_ns (undef, $attr_name)) {
4322                  $body_el->set_attribute_ns
4323                    (undef, [undef, $attr_name],
4324                     $token->{attributes}->{$attr_name}->{value});
4325                }
4326              }
4327          }          }
4328        } elsif ($token->{type} eq 'end tag') {          !!!next-token;
4329          if ($token->{tag_name} eq 'html') {          return;
4330            $previous_insertion_mode = $self->{insertion_mode};        } elsif ({
4331            $self->{insertion_mode} = 'trailing end';                  address => 1, blockquote => 1, center => 1, dir => 1,
4332                    div => 1, dl => 1, fieldset => 1, listing => 1,
4333                    menu => 1, ol => 1, p => 1, ul => 1,
4334                    pre => 1,
4335                   }->{$token->{tag_name}}) {
4336            ## has a p element in scope
4337            INSCOPE: for (reverse @{$self->{open_elements}}) {
4338              if ($_->[1] eq 'p') {
4339                !!!back-token;
4340                $token = {type => 'end tag', tag_name => 'p'};
4341                return;
4342              } elsif ({
4343                        table => 1, caption => 1, td => 1, th => 1,
4344                        button => 1, marquee => 1, object => 1, html => 1,
4345                       }->{$_->[1]}) {
4346                last INSCOPE;
4347              }
4348            } # INSCOPE
4349              
4350            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4351            if ($token->{tag_name} eq 'pre') {
4352            !!!next-token;            !!!next-token;
4353            redo B;            if ($token->{type} eq 'character') {
4354                $token->{data} =~ s/^\x0A//;
4355                unless (length $token->{data}) {
4356                  !!!next-token;
4357                }
4358              }
4359          } else {          } else {
4360            !!!parse-error (type => 'after frameset:/'.$token->{tag_name});            !!!next-token;
4361            }
4362            return;
4363          } elsif ($token->{tag_name} eq 'form') {
4364            if (defined $self->{form_element}) {
4365              !!!parse-error (type => 'in form:form');
4366            ## Ignore the token            ## Ignore the token
4367            !!!next-token;            !!!next-token;
4368            redo B;            return;
4369            } else {
4370              ## has a p element in scope
4371              INSCOPE: for (reverse @{$self->{open_elements}}) {
4372                if ($_->[1] eq 'p') {
4373                  !!!back-token;
4374                  $token = {type => 'end tag', tag_name => 'p'};
4375                  return;
4376                } elsif ({
4377                          table => 1, caption => 1, td => 1, th => 1,
4378                          button => 1, marquee => 1, object => 1, html => 1,
4379                         }->{$_->[1]}) {
4380                  last INSCOPE;
4381                }
4382              } # INSCOPE
4383                
4384              !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4385              $self->{form_element} = $self->{open_elements}->[-1]->[0];
4386              !!!next-token;
4387              return;
4388          }          }
4389        } else {        } elsif ($token->{tag_name} eq 'li') {
4390          die "$0: $token->{type}: Unknown token type";          ## has a p element in scope
4391        }          INSCOPE: for (reverse @{$self->{open_elements}}) {
4392              if ($_->[1] eq 'p') {
4393                !!!back-token;
4394                $token = {type => 'end tag', tag_name => 'p'};
4395                return;
4396              } elsif ({
4397                        table => 1, caption => 1, td => 1, th => 1,
4398                        button => 1, marquee => 1, object => 1, html => 1,
4399                       }->{$_->[1]}) {
4400                last INSCOPE;
4401              }
4402            } # INSCOPE
4403              
4404            ## Step 1
4405            my $i = -1;
4406            my $node = $self->{open_elements}->[$i];
4407            LI: {
4408              ## Step 2
4409              if ($node->[1] eq 'li') {
4410                if ($i != -1) {
4411                  !!!parse-error (type => 'end tag missing:'.
4412                                  $self->{open_elements}->[-1]->[1]);
4413                }
4414                splice @{$self->{open_elements}}, $i;
4415                last LI;
4416              }
4417              
4418              ## Step 3
4419              if (not $formatting_category->{$node->[1]} and
4420                  #not $phrasing_category->{$node->[1]} and
4421                  ($special_category->{$node->[1]} or
4422                   $scoping_category->{$node->[1]}) and
4423                  $node->[1] ne 'address' and $node->[1] ne 'div') {
4424                last LI;
4425              }
4426              
4427              ## Step 4
4428              $i--;
4429              $node = $self->{open_elements}->[$i];
4430              redo LI;
4431            } # LI
4432              
4433            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4434            !!!next-token;
4435            return;
4436          } elsif ($token->{tag_name} eq 'dd' or $token->{tag_name} eq 'dt') {
4437            ## has a p element in scope
4438            INSCOPE: for (reverse @{$self->{open_elements}}) {
4439              if ($_->[1] eq 'p') {
4440                !!!back-token;
4441                $token = {type => 'end tag', tag_name => 'p'};
4442                return;
4443              } elsif ({
4444                        table => 1, caption => 1, td => 1, th => 1,
4445                        button => 1, marquee => 1, object => 1, html => 1,
4446                       }->{$_->[1]}) {
4447                last INSCOPE;
4448              }
4449            } # INSCOPE
4450              
4451            ## Step 1
4452            my $i = -1;
4453            my $node = $self->{open_elements}->[$i];
4454            LI: {
4455              ## Step 2
4456              if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {
4457                if ($i != -1) {
4458                  !!!parse-error (type => 'end tag missing:'.
4459                                  $self->{open_elements}->[-1]->[1]);
4460                }
4461                splice @{$self->{open_elements}}, $i;
4462                last LI;
4463              }
4464              
4465              ## Step 3
4466              if (not $formatting_category->{$node->[1]} and
4467                  #not $phrasing_category->{$node->[1]} and
4468                  ($special_category->{$node->[1]} or
4469                   $scoping_category->{$node->[1]}) and
4470                  $node->[1] ne 'address' and $node->[1] ne 'div') {
4471                last LI;
4472              }
4473              
4474              ## Step 4
4475              $i--;
4476              $node = $self->{open_elements}->[$i];
4477              redo LI;
4478            } # LI
4479              
4480            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4481            !!!next-token;
4482            return;
4483          } elsif ($token->{tag_name} eq 'plaintext') {
4484            ## has a p element in scope
4485            INSCOPE: for (reverse @{$self->{open_elements}}) {
4486              if ($_->[1] eq 'p') {
4487                !!!back-token;
4488                $token = {type => 'end tag', tag_name => 'p'};
4489                return;
4490              } elsif ({
4491                        table => 1, caption => 1, td => 1, th => 1,
4492                        button => 1, marquee => 1, object => 1, html => 1,
4493                       }->{$_->[1]}) {
4494                last INSCOPE;
4495              }
4496            } # INSCOPE
4497              
4498            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4499              
4500            $self->{content_model} = PLAINTEXT_CONTENT_MODEL;
4501              
4502            !!!next-token;
4503            return;
4504          } elsif ({
4505                    h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
4506                   }->{$token->{tag_name}}) {
4507            ## has a p element in scope
4508            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4509              my $node = $self->{open_elements}->[$_];
4510              if ($node->[1] eq 'p') {
4511                !!!back-token;
4512                $token = {type => 'end tag', tag_name => 'p'};
4513                return;
4514              } elsif ({
4515                        table => 1, caption => 1, td => 1, th => 1,
4516                        button => 1, marquee => 1, object => 1, html => 1,
4517                       }->{$node->[1]}) {
4518                last INSCOPE;
4519              }
4520            } # INSCOPE
4521              
4522            ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>
4523            ## has an element in scope
4524            #my $i;
4525            #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4526            #  my $node = $self->{open_elements}->[$_];
4527            #  if ({
4528            #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
4529            #      }->{$node->[1]}) {
4530            #    $i = $_;
4531            #    last INSCOPE;
4532            #  } elsif ({
4533            #            table => 1, caption => 1, td => 1, th => 1,
4534            #            button => 1, marquee => 1, object => 1, html => 1,
4535            #           }->{$node->[1]}) {
4536            #    last INSCOPE;
4537            #  }
4538            #} # INSCOPE
4539            #  
4540            #if (defined $i) {
4541            #  !!! parse-error (type => 'in hn:hn');
4542            #  splice @{$self->{open_elements}}, $i;
4543            #}
4544              
4545            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4546              
4547            !!!next-token;
4548            return;
4549          } elsif ($token->{tag_name} eq 'a') {
4550            AFE: for my $i (reverse 0..$#$active_formatting_elements) {
4551              my $node = $active_formatting_elements->[$i];
4552              if ($node->[1] eq 'a') {
4553                !!!parse-error (type => 'in a:a');
4554                
4555                !!!back-token;
4556                $token = {type => 'end tag', tag_name => 'a'};
4557                $formatting_end_tag->($token->{tag_name});
4558                
4559                AFE2: for (reverse 0..$#$active_formatting_elements) {
4560                  if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
4561                    splice @$active_formatting_elements, $_, 1;
4562                    last AFE2;
4563                  }
4564                } # AFE2
4565                OE: for (reverse 0..$#{$self->{open_elements}}) {
4566                  if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {
4567                    splice @{$self->{open_elements}}, $_, 1;
4568                    last OE;
4569                  }
4570                } # OE
4571                last AFE;
4572              } elsif ($node->[0] eq '#marker') {
4573                last AFE;
4574              }
4575            } # AFE
4576              
4577            $reconstruct_active_formatting_elements->($insert_to_current);
4578    
4579        ## ISSUE: An issue in spec here          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4580      } elsif ($self->{insertion_mode} eq 'trailing end') {          push @$active_formatting_elements, $self->{open_elements}->[-1];
4581        ## states in the main stage is preserved yet # MUST  
4582                  !!!next-token;
4583        if ($token->{type} eq 'character') {          return;
4584          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {        } elsif ({
4585            my $data = $1;                  b => 1, big => 1, em => 1, font => 1, i => 1,
4586            ## As if in the main phase.                  s => 1, small => 1, strile => 1,
4587            ## NOTE: The insertion mode in the main phase                  strong => 1, tt => 1, u => 1,
4588            ## just before the phase has been changed to the trailing                 }->{$token->{tag_name}}) {
4589            ## end phase is either "after body" or "after frameset".          $reconstruct_active_formatting_elements->($insert_to_current);
4590            $reconstruct_active_formatting_elements->($insert_to_current);          
4591            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4592            push @$active_formatting_elements, $self->{open_elements}->[-1];
4593            
4594            !!!next-token;
4595            return;
4596          } elsif ($token->{tag_name} eq 'nobr') {
4597            $reconstruct_active_formatting_elements->($insert_to_current);
4598    
4599            ## has a |nobr| element in scope
4600            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4601              my $node = $self->{open_elements}->[$_];
4602              if ($node->[1] eq 'nobr') {
4603                !!!parse-error (type => 'not closed:nobr');
4604                !!!back-token;
4605                $token = {type => 'end tag', tag_name => 'nobr'};
4606                return;
4607              } elsif ({
4608                        table => 1, caption => 1, td => 1, th => 1,
4609                        button => 1, marquee => 1, object => 1, html => 1,
4610                       }->{$node->[1]}) {
4611                last INSCOPE;
4612              }
4613            } # INSCOPE
4614            
4615            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4616            push @$active_formatting_elements, $self->{open_elements}->[-1];
4617            
4618            !!!next-token;
4619            return;
4620          } elsif ($token->{tag_name} eq 'button') {
4621            ## has a button element in scope
4622            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4623              my $node = $self->{open_elements}->[$_];
4624              if ($node->[1] eq 'button') {
4625                !!!parse-error (type => 'in button:button');
4626                !!!back-token;
4627                $token = {type => 'end tag', tag_name => 'button'};
4628                return;
4629              } elsif ({
4630                        table => 1, caption => 1, td => 1, th => 1,
4631                        button => 1, marquee => 1, object => 1, html => 1,
4632                       }->{$node->[1]}) {
4633                last INSCOPE;
4634              }
4635            } # INSCOPE
4636              
4637            $reconstruct_active_formatting_elements->($insert_to_current);
4638              
4639            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4640            push @$active_formatting_elements, ['#marker', ''];
4641    
4642            !!!next-token;
4643            return;
4644          } elsif ($token->{tag_name} eq 'marquee' or
4645                   $token->{tag_name} eq 'object') {
4646            $reconstruct_active_formatting_elements->($insert_to_current);
4647            
4648            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4649            push @$active_formatting_elements, ['#marker', ''];
4650            
4651            !!!next-token;
4652            return;
4653          } elsif ($token->{tag_name} eq 'xmp') {
4654            $reconstruct_active_formatting_elements->($insert_to_current);
4655            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
4656            return;
4657          } elsif ($token->{tag_name} eq 'table') {
4658            ## has a p element in scope
4659            INSCOPE: for (reverse @{$self->{open_elements}}) {
4660              if ($_->[1] eq 'p') {
4661                !!!back-token;
4662                $token = {type => 'end tag', tag_name => 'p'};
4663                return;
4664              } elsif ({
4665                        table => 1, caption => 1, td => 1, th => 1,
4666                        button => 1, marquee => 1, object => 1, html => 1,
4667                       }->{$_->[1]}) {
4668                last INSCOPE;
4669              }
4670            } # INSCOPE
4671              
4672            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4673                        
4674            $self->{open_elements}->[-1]->[0]->manakai_append_text ($data);          $self->{insertion_mode} = 'in table';
4675                        
4676            !!!next-token;
4677            return;
4678          } elsif ({
4679                    area => 1, basefont => 1, bgsound => 1, br => 1,
4680                    embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,
4681                    image => 1,
4682                   }->{$token->{tag_name}}) {
4683            if ($token->{tag_name} eq 'image') {
4684              !!!parse-error (type => 'image');
4685              $token->{tag_name} = 'img';
4686            }
4687    
4688            ## NOTE: There is an "as if <br>" code clone.
4689            $reconstruct_active_formatting_elements->($insert_to_current);
4690            
4691            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4692            pop @{$self->{open_elements}};
4693            
4694            !!!next-token;
4695            return;
4696          } elsif ($token->{tag_name} eq 'hr') {
4697            ## has a p element in scope
4698            INSCOPE: for (reverse @{$self->{open_elements}}) {
4699              if ($_->[1] eq 'p') {
4700                !!!back-token;
4701                $token = {type => 'end tag', tag_name => 'p'};
4702                return;
4703              } elsif ({
4704                        table => 1, caption => 1, td => 1, th => 1,
4705                        button => 1, marquee => 1, object => 1, html => 1,
4706                       }->{$_->[1]}) {
4707                last INSCOPE;
4708              }
4709            } # INSCOPE
4710              
4711            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4712            pop @{$self->{open_elements}};
4713              
4714            !!!next-token;
4715            return;
4716          } elsif ($token->{tag_name} eq 'input') {
4717            $reconstruct_active_formatting_elements->($insert_to_current);
4718            
4719            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4720            ## TODO: associate with $self->{form_element} if defined
4721            pop @{$self->{open_elements}};
4722            
4723            !!!next-token;
4724            return;
4725          } elsif ($token->{tag_name} eq 'isindex') {
4726            !!!parse-error (type => 'isindex');
4727            
4728            if (defined $self->{form_element}) {
4729              ## Ignore the token
4730              !!!next-token;
4731              return;
4732            } else {
4733              my $at = $token->{attributes};
4734              my $form_attrs;
4735              $form_attrs->{action} = $at->{action} if $at->{action};
4736              my $prompt_attr = $at->{prompt};
4737              $at->{name} = {name => 'name', value => 'isindex'};
4738              delete $at->{action};
4739              delete $at->{prompt};
4740              my @tokens = (
4741                            {type => 'start tag', tag_name => 'form',
4742                             attributes => $form_attrs},
4743                            {type => 'start tag', tag_name => 'hr'},
4744                            {type => 'start tag', tag_name => 'p'},
4745                            {type => 'start tag', tag_name => 'label'},
4746                           );
4747              if ($prompt_attr) {
4748                push @tokens, {type => 'character', data => $prompt_attr->{value}};
4749              } else {
4750                push @tokens, {type => 'character',
4751                               data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
4752                ## TODO: make this configurable
4753              }
4754              push @tokens,
4755                            {type => 'start tag', tag_name => 'input', attributes => $at},
4756                            #{type => 'character', data => ''}, # SHOULD
4757                            {type => 'end tag', tag_name => 'label'},
4758                            {type => 'end tag', tag_name => 'p'},
4759                            {type => 'start tag', tag_name => 'hr'},
4760                            {type => 'end tag', tag_name => 'form'};
4761              $token = shift @tokens;
4762              !!!back-token (@tokens);
4763              return;
4764            }
4765          } elsif ($token->{tag_name} eq 'textarea') {
4766            my $tag_name = $token->{tag_name};
4767            my $el;
4768            !!!create-element ($el, $token->{tag_name}, $token->{attributes});
4769            
4770            ## TODO: $self->{form_element} if defined
4771            $self->{content_model} = RCDATA_CONTENT_MODEL;
4772            delete $self->{escape}; # MUST
4773            
4774            $insert->($el);
4775            
4776            my $text = '';
4777            !!!next-token;
4778            if ($token->{type} eq 'character') {
4779              $token->{data} =~ s/^\x0A//;
4780            unless (length $token->{data}) {            unless (length $token->{data}) {
4781              !!!next-token;              !!!next-token;
             redo B;  
4782            }            }
4783          }          }
4784            while ($token->{type} eq 'character') {
4785              $text .= $token->{data};
4786              !!!next-token;
4787            }
4788            if (length $text) {
4789              $el->manakai_append_text ($text);
4790            }
4791            
4792            $self->{content_model} = PCDATA_CONTENT_MODEL;
4793            
4794            if ($token->{type} eq 'end tag' and
4795                $token->{tag_name} eq $tag_name) {
4796              ## Ignore the token
4797            } else {
4798              !!!parse-error (type => 'in RCDATA:#'.$token->{type});
4799            }
4800            !!!next-token;
4801            return;
4802          } elsif ({
4803                    iframe => 1,
4804                    noembed => 1,
4805                    noframes => 1,
4806                    noscript => 0, ## TODO: 1 if scripting is enabled
4807                   }->{$token->{tag_name}}) {
4808            ## NOTE: There are two "as if in body" code clones.
4809            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
4810            return;
4811          } elsif ($token->{tag_name} eq 'select') {
4812            $reconstruct_active_formatting_elements->($insert_to_current);
4813            
4814            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4815            
4816            $self->{insertion_mode} = 'in select';
4817            !!!next-token;
4818            return;
4819          } elsif ({
4820                    caption => 1, col => 1, colgroup => 1, frame => 1,
4821                    frameset => 1, head => 1, option => 1, optgroup => 1,
4822                    tbody => 1, td => 1, tfoot => 1, th => 1,
4823                    thead => 1, tr => 1,
4824                   }->{$token->{tag_name}}) {
4825            !!!parse-error (type => 'in body:'.$token->{tag_name});
4826            ## Ignore the token
4827            !!!next-token;
4828            return;
4829            
4830            ## ISSUE: An issue on HTML5 new elements in the spec.
4831          } else {
4832            $reconstruct_active_formatting_elements->($insert_to_current);
4833            
4834            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4835            
4836            !!!next-token;
4837            return;
4838          }
4839        } elsif ($token->{type} eq 'end tag') {
4840          if ($token->{tag_name} eq 'body') {
4841            if (@{$self->{open_elements}} > 1 and
4842                $self->{open_elements}->[1]->[1] eq 'body') {
4843              for (@{$self->{open_elements}}) {
4844                unless ({
4845                           dd => 1, dt => 1, li => 1, p => 1, td => 1,
4846                           th => 1, tr => 1, body => 1, html => 1,
4847                         tbody => 1, tfoot => 1, thead => 1,
4848                        }->{$_->[1]}) {
4849                  !!!parse-error (type => 'not closed:'.$_->[1]);
4850                }
4851              }
4852    
4853          !!!parse-error (type => 'after html:#character');            $self->{insertion_mode} = 'after body';
4854          $self->{insertion_mode} = $previous_insertion_mode;            !!!next-token;
4855          ## reprocess            return;
4856          redo B;          } else {
4857        } elsif ($token->{type} eq 'start tag') {            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4858          !!!parse-error (type => 'after html:'.$token->{tag_name});            ## Ignore the token
4859          $self->{insertion_mode} = $previous_insertion_mode;            !!!next-token;
4860          ## reprocess            return;
4861          redo B;          }
4862        } elsif ($token->{type} eq 'end tag') {        } elsif ($token->{tag_name} eq 'html') {
4863          !!!parse-error (type => 'after html:/'.$token->{tag_name});          if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {
4864          $self->{insertion_mode} = $previous_insertion_mode;            ## ISSUE: There is an issue in the spec.
4865          ## reprocess            if ($self->{open_elements}->[-1]->[1] ne 'body') {
4866          redo B;              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);
4867              }
4868              $self->{insertion_mode} = 'after body';
4869              ## reprocess
4870              return;
4871            } else {
4872              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4873              ## Ignore the token
4874              !!!next-token;
4875              return;
4876            }
4877          } elsif ({
4878                    address => 1, blockquote => 1, center => 1, dir => 1,
4879                    div => 1, dl => 1, fieldset => 1, listing => 1,
4880                    menu => 1, ol => 1, pre => 1, ul => 1,
4881                    p => 1,
4882                    dd => 1, dt => 1, li => 1,
4883                    button => 1, marquee => 1, object => 1,
4884                   }->{$token->{tag_name}}) {
4885            ## has an element in scope
4886            my $i;
4887            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4888              my $node = $self->{open_elements}->[$_];
4889              if ($node->[1] eq $token->{tag_name}) {
4890                ## generate implied end tags
4891                if ({
4892                     dd => ($token->{tag_name} ne 'dd'),
4893                     dt => ($token->{tag_name} ne 'dt'),
4894                     li => ($token->{tag_name} ne 'li'),
4895                     p => ($token->{tag_name} ne 'p'),
4896                     td => 1, th => 1, tr => 1,
4897                     tbody => 1, tfoot=> 1, thead => 1,
4898                    }->{$self->{open_elements}->[-1]->[1]}) {
4899                  !!!back-token;
4900                  $token = {type => 'end tag',
4901                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4902                  return;
4903                }
4904                $i = $_;
4905                last INSCOPE unless $token->{tag_name} eq 'p';
4906              } elsif ({
4907                        table => 1, caption => 1, td => 1, th => 1,
4908                        button => 1, marquee => 1, object => 1, html => 1,
4909                       }->{$node->[1]}) {
4910                last INSCOPE;
4911              }
4912            } # INSCOPE
4913            
4914            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
4915              if (defined $i) {
4916                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4917              } else {
4918                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4919              }
4920            }
4921            
4922            if (defined $i) {
4923              splice @{$self->{open_elements}}, $i;
4924            } elsif ($token->{tag_name} eq 'p') {
4925              ## As if <p>, then reprocess the current token
4926              my $el;
4927              !!!create-element ($el, 'p');
4928              $insert->($el);
4929            }
4930            $clear_up_to_marker->()
4931              if {
4932                button => 1, marquee => 1, object => 1,
4933              }->{$token->{tag_name}};
4934            !!!next-token;
4935            return;
4936          } elsif ($token->{tag_name} eq 'form') {
4937            ## has an element in scope
4938            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4939              my $node = $self->{open_elements}->[$_];
4940              if ($node->[1] eq $token->{tag_name}) {
4941                ## generate implied end tags
4942                if ({
4943                     dd => 1, dt => 1, li => 1, p => 1,
4944                     td => 1, th => 1, tr => 1,
4945                     tbody => 1, tfoot=> 1, thead => 1,
4946                    }->{$self->{open_elements}->[-1]->[1]}) {
4947                  !!!back-token;
4948                  $token = {type => 'end tag',
4949                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4950                  return;
4951                }
4952                last INSCOPE;
4953              } elsif ({
4954                        table => 1, caption => 1, td => 1, th => 1,
4955                        button => 1, marquee => 1, object => 1, html => 1,
4956                       }->{$node->[1]}) {
4957                last INSCOPE;
4958              }
4959            } # INSCOPE
4960            
4961            if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {
4962              pop @{$self->{open_elements}};
4963            } else {
4964              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4965            }
4966    
4967            undef $self->{form_element};
4968            !!!next-token;
4969            return;
4970          } elsif ({
4971                    h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
4972                   }->{$token->{tag_name}}) {
4973            ## has an element in scope
4974            my $i;
4975            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4976              my $node = $self->{open_elements}->[$_];
4977              if ({
4978                   h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
4979                  }->{$node->[1]}) {
4980                ## generate implied end tags
4981                if ({
4982                     dd => 1, dt => 1, li => 1, p => 1,
4983                     td => 1, th => 1, tr => 1,
4984                     tbody => 1, tfoot=> 1, thead => 1,
4985                    }->{$self->{open_elements}->[-1]->[1]}) {
4986                  !!!back-token;
4987                  $token = {type => 'end tag',
4988                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4989                  return;
4990                }
4991                $i = $_;
4992                last INSCOPE;
4993              } elsif ({
4994                        table => 1, caption => 1, td => 1, th => 1,
4995                        button => 1, marquee => 1, object => 1, html => 1,
4996                       }->{$node->[1]}) {
4997                last INSCOPE;
4998              }
4999            } # INSCOPE
5000            
5001            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
5002              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
5003            }
5004            
5005            splice @{$self->{open_elements}}, $i if defined $i;
5006            !!!next-token;
5007            return;
5008          } elsif ({
5009                    a => 1,
5010                    b => 1, big => 1, em => 1, font => 1, i => 1,
5011                    nobr => 1, s => 1, small => 1, strile => 1,
5012                    strong => 1, tt => 1, u => 1,
5013                   }->{$token->{tag_name}}) {
5014            $formatting_end_tag->($token->{tag_name});
5015            return;
5016          } elsif ($token->{tag_name} eq 'br') {
5017            !!!parse-error (type => 'unmatched end tag:br');
5018    
5019            ## As if <br>
5020            $reconstruct_active_formatting_elements->($insert_to_current);
5021            
5022            my $el;
5023            !!!create-element ($el, 'br');
5024            $insert->($el);
5025            
5026            ## Ignore the token.
5027            !!!next-token;
5028            return;
5029          } elsif ({
5030                    caption => 1, col => 1, colgroup => 1, frame => 1,
5031                    frameset => 1, head => 1, option => 1, optgroup => 1,
5032                    tbody => 1, td => 1, tfoot => 1, th => 1,
5033                    thead => 1, tr => 1,
5034                    area => 1, basefont => 1, bgsound => 1,
5035                    embed => 1, hr => 1, iframe => 1, image => 1,
5036                    img => 1, input => 1, isindex => 1, noembed => 1,
5037                    noframes => 1, param => 1, select => 1, spacer => 1,
5038                    table => 1, textarea => 1, wbr => 1,
5039                    noscript => 0, ## TODO: if scripting is enabled
5040                   }->{$token->{tag_name}}) {
5041            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5042            ## Ignore the token
5043            !!!next-token;
5044            return;
5045            
5046            ## ISSUE: Issue on HTML5 new elements in spec
5047            
5048        } else {        } else {
5049          die "$0: $token->{type}: Unknown token";          ## Step 1
5050            my $node_i = -1;
5051            my $node = $self->{open_elements}->[$node_i];
5052    
5053            ## Step 2
5054            S2: {
5055              if ($node->[1] eq $token->{tag_name}) {
5056                ## Step 1
5057                ## generate implied end tags
5058                if ({
5059                     dd => 1, dt => 1, li => 1, p => 1,
5060                     td => 1, th => 1, tr => 1,
5061                     tbody => 1, tfoot=> 1, thead => 1,
5062                    }->{$self->{open_elements}->[-1]->[1]}) {
5063                  !!!back-token;
5064                  $token = {type => 'end tag',
5065                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
5066                  return;
5067                }
5068            
5069                ## Step 2
5070                if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {
5071                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
5072                }
5073                
5074                ## Step 3
5075                splice @{$self->{open_elements}}, $node_i;
5076    
5077                !!!next-token;
5078                last S2;
5079              } else {
5080                ## Step 3
5081                if (not $formatting_category->{$node->[1]} and
5082                    #not $phrasing_category->{$node->[1]} and
5083                    ($special_category->{$node->[1]} or
5084                     $scoping_category->{$node->[1]})) {
5085                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5086                  ## Ignore the token
5087                  !!!next-token;
5088                  last S2;
5089                }
5090              }
5091              
5092              ## Step 4
5093              $node_i--;
5094              $node = $self->{open_elements}->[$node_i];
5095              
5096              ## Step 5;
5097              redo S2;
5098            } # S2
5099            return;
5100        }        }
     } else {  
       die "$0: $self->{insertion_mode}: Unknown insertion mode";  
5101      }      }
5102      }; # $in_body
5103        $in_body->($insert_to_current);
5104        redo B;
5105    } # B    } # B
5106    
5107      ## NOTE: The "trailing end" phase in HTML5 is split into
5108      ## two insertion modes: "after html body" and "after html frameset".
5109      ## NOTE: States in the main stage is preserved while
5110      ## the parser stays in the trailing end phase. # MUST
5111    
5112    ## Stop parsing # MUST    ## Stop parsing # MUST
5113        
5114    ## TODO: script stuffs    ## TODO: script stuffs

Legend:
Removed from v.1.49  
changed lines
  Added in v.1.52

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24