/[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.41 by wakaba, Sat Jul 21 06:04:07 2007 UTC revision 1.49 by wakaba, Sat Jul 21 10:39:45 2007 UTC
# Line 2067  sub _reset_insertion_mode ($) { Line 2067  sub _reset_insertion_mode ($) {
2067                        th => 'in cell',                        th => 'in cell',
2068                        tr => 'in row',                        tr => 'in row',
2069                        tbody => 'in table body',                        tbody => 'in table body',
2070                        thead => 'in table head',                        thead => 'in table body',
2071                        tfoot => 'in table foot',                        tfoot => 'in table body',
2072                        caption => 'in caption',                        caption => 'in caption',
2073                        colgroup => 'in column group',                        colgroup => 'in column group',
2074                        table => 'in table',                        table => 'in table',
# Line 3046  sub _tree_construction_main ($) { Line 3046  sub _tree_construction_main ($) {
3046                  noframes => 1,                  noframes => 1,
3047                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
3048                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
3049            ## NOTE: There are two "as if in body" code clones.
3050          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
3051          return;          return;
3052        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
# Line 3432  sub _tree_construction_main ($) { Line 3433  sub _tree_construction_main ($) {
3433              $self->{insertion_mode} = 'in head';              $self->{insertion_mode} = 'in head';
3434              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3435                !!!next-token;                !!!next-token;
             #} elsif ({  
             #          base => 1, link => 1, meta => 1,  
             #          script => 1, style => 1, title => 1,  
             #         }->{$token->{tag_name}}) {  
             #  ## reprocess  
3436              } else {              } else {
3437                ## reprocess                ## reprocess
3438              }              }
# Line 3474  sub _tree_construction_main ($) { Line 3470  sub _tree_construction_main ($) {
3470                }                }
3471              }              }
3472                            
3473              #              if ($self->{insertion_mode} eq 'in head noscript') {
3474                  ## As if </noscript>
3475                  pop @{$self->{open_elements}};
3476                  !!!parse-error (type => 'in noscript:#character');
3477                  
3478                  ## Reprocess in the "in head" insertion mode...
3479                  ## As if </head>
3480                  pop @{$self->{open_elements}};
3481    
3482                  ## Reprocess in the "after head" insertion mode...
3483                } elsif ($self->{insertion_mode} eq 'in head') {
3484                  pop @{$self->{open_elements}};
3485    
3486                  ## Reprocess in the "after head" insertion mode...
3487                }
3488    
3489                ## 'after head' insertion mode
3490                ## As if <body>
3491                !!!insert-element ('body');
3492                $self->{insertion_mode} = 'in body';
3493                ## reprocess
3494                redo B;
3495            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3496              if ({base => ($self->{insertion_mode} eq 'in head' or              if ($token->{tag_name} eq 'base') {
3497                            $self->{insertion_mode} eq 'after head'),                if ($self->{insertion_mode} eq 'in head noscript') {
3498                   link => 1}->{$token->{tag_name}}) {                  ## As if </noscript>
3499                    pop @{$self->{open_elements}};
3500                    !!!parse-error (type => 'in noscript:base');
3501                  
3502                    $self->{insertion_mode} = 'in head';
3503                    ## Reprocess in the "in head" insertion mode...
3504                  }
3505    
3506                  ## NOTE: There is a "as if in head" code clone.
3507                  if ($self->{insertion_mode} eq 'after head') {
3508                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3509                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3510                  }
3511                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3512                  pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3513                  pop @{$self->{open_elements}}
3514                      if $self->{insertion_mode} eq 'after head';
3515                  !!!next-token;
3516                  redo B;
3517                } elsif ($token->{tag_name} eq 'link') {
3518                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3519                if ($self->{insertion_mode} eq 'after head') {                if ($self->{insertion_mode} eq 'after head') {
3520                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
# Line 3521  sub _tree_construction_main ($) { Line 3557  sub _tree_construction_main ($) {
3557                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
3558                !!!next-token;                !!!next-token;
3559                redo B;                redo B;
3560              } elsif ($token->{tag_name} eq 'title' and              } elsif ($token->{tag_name} eq 'title') {
3561                       $self->{insertion_mode} eq 'in head') {                if ($self->{insertion_mode} eq 'in head noscript') {
3562                ## NOTE: There is a "as if in head" code clone.                  ## As if </noscript>
3563                if ($self->{insertion_mode} eq 'after head') {                  pop @{$self->{open_elements}};
3564                    !!!parse-error (type => 'in noscript:title');
3565                  
3566                    $self->{insertion_mode} = 'in head';
3567                    ## Reprocess in the "in head" insertion mode...
3568                  } elsif ($self->{insertion_mode} eq 'after head') {
3569                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3570                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3571                }                }
3572    
3573                  ## NOTE: There is a "as if in head" code clone.
3574                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3575                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3576                $parse_rcdata->(RCDATA_CONTENT_MODEL,                $parse_rcdata->(RCDATA_CONTENT_MODEL,
# Line 3562  sub _tree_construction_main ($) { Line 3605  sub _tree_construction_main ($) {
3605                } else {                } else {
3606                  #                  #
3607                }                }
3608              } elsif ($token->{tag_name} eq 'head' and              } elsif ($token->{tag_name} eq 'head') {
3609                       $self->{insertion_mode} ne 'after head') {                if ($self->{insertion_mode} ne 'after head') {
3610                !!!parse-error (type => 'in head:head'); # or in head noscript                  !!!parse-error (type => 'in head:head'); # or in head noscript
3611                ## Ignore the token                  ## Ignore the token
3612                !!!next-token;                  !!!next-token;
3613                redo B;                  redo B;
3614              } elsif ($self->{insertion_mode} ne 'in head noscript' and                } else {
3615                       $token->{tag_name} eq 'script') {                  #
3616                if ($self->{insertion_mode} eq 'after head') {                }
3617                } elsif ($token->{tag_name} eq 'script') {
3618                  if ($self->{insertion_mode} eq 'in head noscript') {
3619                    ## As if </noscript>
3620                    pop @{$self->{open_elements}};
3621                    !!!parse-error (type => 'in noscript:script');
3622                  
3623                    $self->{insertion_mode} = 'in head';
3624                    ## Reprocess in the "in head" insertion mode...
3625                  } elsif ($self->{insertion_mode} eq 'after head') {
3626                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3627                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3628                }                }
3629    
3630                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3631                $script_start_tag->($insert_to_current);                $script_start_tag->($insert_to_current);
3632                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3633                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
3634                redo B;                redo B;
3635              } elsif ($self->{insertion_mode} eq 'after head' and              } elsif ($token->{tag_name} eq 'body' or
                      $token->{tag_name} eq 'body') {  
               !!!insert-element ('body', $token->{attributes});  
               $self->{insertion_mode} = 'in body';  
               !!!next-token;  
               redo B;  
             } elsif ($self->{insertion_mode} eq 'after head' and  
3636                       $token->{tag_name} eq 'frameset') {                       $token->{tag_name} eq 'frameset') {
3637                !!!insert-element ('frameset', $token->{attributes});                if ($self->{insertion_mode} eq 'in head noscript') {
3638                $self->{insertion_mode} = 'in frameset';                  ## As if </noscript>
3639                    pop @{$self->{open_elements}};
3640                    !!!parse-error (type => 'in noscript:'.$token->{tag_name});
3641                    
3642                    ## Reprocess in the "in head" insertion mode...
3643                    ## As if </head>
3644                    pop @{$self->{open_elements}};
3645                    
3646                    ## Reprocess in the "after head" insertion mode...
3647                  } elsif ($self->{insertion_mode} eq 'in head') {
3648                    pop @{$self->{open_elements}};
3649                    
3650                    ## Reprocess in the "after head" insertion mode...
3651                  }
3652    
3653                  ## "after head" insertion mode
3654                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3655                  $self->{insertion_mode} = 'in '.$token->{tag_name};
3656                !!!next-token;                !!!next-token;
3657                redo B;                redo B;
3658              } else {              } else {
3659                #                #
3660              }              }
3661            } elsif ($token->{type} eq 'end tag') {  
3662              if ($self->{insertion_mode} eq 'in head' and              if ($self->{insertion_mode} eq 'in head noscript') {
3663                  $token->{tag_name} eq 'head') {                ## As if </noscript>
3664                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3665                $self->{insertion_mode} = 'after head';                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
3666                !!!next-token;                
3667                redo B;                ## Reprocess in the "in head" insertion mode...
3668              } elsif ($self->{insertion_mode} eq 'in head noscript' and                ## As if </head>
                 $token->{tag_name} eq 'noscript') {  
3669                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3670                $self->{insertion_mode} = 'in head';  
3671                !!!next-token;                ## Reprocess in the "after head" insertion mode...
3672                redo B;              } elsif ($self->{insertion_mode} eq 'in head') {
3673              } elsif ($self->{insertion_mode} eq 'in head' and                ## As if </head>
3674                       {                pop @{$self->{open_elements}};
3675                        body => 1, html => 1,  
3676                        p => 1, br => 1,                ## Reprocess in the "after head" insertion mode...
                      }->{$token->{tag_name}}) {  
               #  
             } elsif ($self->{insertion_mode} eq 'in head noscript' and  
                      {  
                       p => 1, br => 1,  
                      }->{$token->{tag_name}}) {  
               #  
             } elsif ($self->{insertion_mode} ne 'after head') {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               redo B;  
             } else {  
               #  
3677              }              }
           } else {  
             #  
           }  
3678    
3679            ## As if </head> or </noscript> or <body>              ## "after head" insertion mode
3680            if ($self->{insertion_mode} eq 'in head') {              ## As if <body>
             pop @{$self->{open_elements}};  
             $self->{insertion_mode} = 'after head';  
           } elsif ($self->{insertion_mode} eq 'in head noscript') {  
             pop @{$self->{open_elements}};  
             !!!parse-error (type => 'in noscript:'.(defined $token->{tag_name} ? ($token->{type} eq 'end tag' ? '/' : '') . $token->{tag_name} : '#' . $token->{type}));  
             $self->{insertion_mode} = 'in head';  
           } else { # 'after head'  
3681              !!!insert-element ('body');              !!!insert-element ('body');
3682              $self->{insertion_mode} = 'in body';              $self->{insertion_mode} = 'in body';
3683            }              ## reprocess
           ## reprocess  
           redo B;  
   
           ## ISSUE: An issue in the spec.  
         } elsif ($self->{insertion_mode} eq 'in body') {  
           if ($token->{type} eq 'character') {  
             ## NOTE: There is a code clone of "character in body".  
             $reconstruct_active_formatting_elements->($insert_to_current);  
               
             $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});  
   
             !!!next-token;  
             redo B;  
           } else {  
             $in_body->($insert_to_current);  
3684              redo B;              redo B;
3685            }            } elsif ($token->{type} eq 'end tag') {
3686          } elsif ($self->{insertion_mode} eq 'in table') {              if ($token->{tag_name} eq 'head') {
3687            if ($token->{type} eq 'character') {                if ($self->{insertion_mode} eq 'in head noscript') {
3688              ## NOTE: There are "character in table" code clones.                  ## As if </noscript>
3689              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {                  pop @{$self->{open_elements}};
3690                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                  !!!parse-error (type => 'in noscript:script');
3691                    
3692                    $self->{insertion_mode} = 'in head';
3693                    ## Reprocess in the "in head" insertion mode...
3694                  }
3695                                
3696                unless (length $token->{data}) {                if ($self->{insertion_mode} eq 'in head') {
3697                    pop @{$self->{open_elements}};
3698                    $self->{insertion_mode} = 'after head';
3699                  !!!next-token;                  !!!next-token;
3700                  redo B;                  redo B;
               }  
             }  
   
             !!!parse-error (type => 'in table:#character');  
   
             ## As if in body, but insert into foster parent element  
             ## ISSUE: Spec says that "whenever a node would be inserted  
             ## into the current node" while characters might not be  
             ## result in a new Text node.  
             $reconstruct_active_formatting_elements->($insert_to_foster);  
               
             if ({  
                  table => 1, tbody => 1, tfoot => 1,  
                  thead => 1, tr => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               # MUST  
               my $foster_parent_element;  
               my $next_sibling;  
               my $prev_sibling;  
               OE: for (reverse 0..$#{$self->{open_elements}}) {  
                 if ($self->{open_elements}->[$_]->[1] eq 'table') {  
                   my $parent = $self->{open_elements}->[$_]->[0]->parent_node;  
                   if (defined $parent and $parent->node_type == 1) {  
                     $foster_parent_element = $parent;  
                     $next_sibling = $self->{open_elements}->[$_]->[0];  
                     $prev_sibling = $next_sibling->previous_sibling;  
                   } else {  
                     $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];  
                     $prev_sibling = $foster_parent_element->last_child;  
                   }  
                   last OE;  
                 }  
               } # OE  
               $foster_parent_element = $self->{open_elements}->[0]->[0] and  
               $prev_sibling = $foster_parent_element->last_child  
                 unless defined $foster_parent_element;  
               if (defined $prev_sibling and  
                   $prev_sibling->node_type == 3) {  
                 $prev_sibling->manakai_append_text ($token->{data});  
3701                } else {                } else {
3702                  $foster_parent_element->insert_before                  #
                   ($self->{document}->create_text_node ($token->{data}),  
                    $next_sibling);  
3703                }                }
3704              } else {              } elsif ($token->{tag_name} eq 'noscript') {
3705                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                if ($self->{insertion_mode} eq 'in head noscript') {
             }  
               
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ({  
                  caption => 1,  
                  colgroup => 1,  
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$token->{tag_name}}) {  
               ## Clear back to table context  
               while ($self->{open_elements}->[-1]->[1] ne 'table' and  
                      $self->{open_elements}->[-1]->[1] ne 'html') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
3706                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3707                    $self->{insertion_mode} = 'in head';
3708                    !!!next-token;
3709                    redo B;
3710                  } else {
3711                    #
3712                }                }
   
               push @$active_formatting_elements, ['#marker', '']  
                 if $token->{tag_name} eq 'caption';  
   
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               $self->{insertion_mode} = {  
                                  caption => 'in caption',  
                                  colgroup => 'in column group',  
                                  tbody => 'in table body',  
                                  tfoot => 'in table body',  
                                  thead => 'in table body',  
                                 }->{$token->{tag_name}};  
               !!!next-token;  
               redo B;  
3713              } elsif ({              } elsif ({
3714                        col => 1,                        body => 1, html => 1,
                       td => 1, th => 1, tr => 1,  
3715                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3716                ## Clear back to table context                if ($self->{insertion_mode} eq 'in head noscript') {
3717                while ($self->{open_elements}->[-1]->[1] ne 'table' and                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3718                       $self->{open_elements}->[-1]->[1] ne 'html') {                  ## Ignore the token
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
   
               !!!insert-element ($token->{tag_name} eq 'col' ? 'colgroup' : 'tbody');  
               $self->{insertion_mode} = $token->{tag_name} eq 'col'  
                 ? 'in column group' : 'in table body';  
               ## reprocess  
               redo B;  
             } elsif ($token->{tag_name} eq 'table') {  
               ## NOTE: There are code clones for this "table in table"  
               !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
   
               ## As if </table>  
               ## have a table element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'table') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:table');  
                 ## Ignore tokens </table><table>  
3719                  !!!next-token;                  !!!next-token;
3720                  redo B;                  redo B;
3721                  } else { # 'in head', 'after head'
3722                    #
3723                }                }
3724                              } elsif ({
3725                ## generate implied end tags                        p => 1, br => 1,
3726                if ({                       }->{$token->{tag_name}}) {
                    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; # <table>  
                 $token = {type => 'end tag', tag_name => 'table'};  
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne 'table') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $self->_reset_insertion_mode;  
   
               ## reprocess  
               redo B;  
             } else {  
3727                #                #
3728              }              } else {
3729            } elsif ($token->{type} eq 'end tag') {                if ($self->{insertion_mode} ne 'after head') {
             if ($token->{tag_name} eq 'table') {  
               ## have a table element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq $token->{tag_name}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
3730                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3731                  ## Ignore the token                  ## Ignore the token
3732                  !!!next-token;                  !!!next-token;
3733                  redo B;                  redo B;
3734                  } else {
3735                    #
3736                }                }
3737                              }
               ## 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  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne 'table') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
3738    
3739                splice @{$self->{open_elements}}, $i;              if ($self->{insertion_mode} eq 'in head noscript') {
3740                  ## As if </noscript>
3741                  pop @{$self->{open_elements}};
3742                  !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
3743                  
3744                  ## Reprocess in the "in head" insertion mode...
3745                  ## As if </head>
3746                  pop @{$self->{open_elements}};
3747    
3748                $self->_reset_insertion_mode;                ## Reprocess in the "after head" insertion mode...
3749                } elsif ($self->{insertion_mode} eq 'in head') {
3750                  ## As if </head>
3751                  pop @{$self->{open_elements}};
3752    
3753                !!!next-token;                ## Reprocess in the "after head" insertion mode...
               redo B;  
             } elsif ({  
                       body => 1, caption => 1, col => 1, colgroup => 1,  
                       html => 1, tbody => 1, td => 1, tfoot => 1, th => 1,  
                       thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               redo B;  
             } else {  
               #  
3754              }              }
3755    
3756                ## "after head" insertion mode
3757                ## As if <body>
3758                !!!insert-element ('body');
3759                $self->{insertion_mode} = 'in body';
3760                ## reprocess
3761                redo B;
3762            } else {            } else {
3763              #              die "$0: $token->{type}: Unknown token type";
3764            }            }
3765    
3766            !!!parse-error (type => 'in table:'.$token->{tag_name});            ## ISSUE: An issue in the spec.
3767            $in_body->($insert_to_foster);          } elsif ($self->{insertion_mode} eq 'in body' or
3768            redo B;                   $self->{insertion_mode} eq 'in cell' or
3769          } elsif ($self->{insertion_mode} eq 'in caption') {                   $self->{insertion_mode} eq 'in caption') {
3770            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3771              ## NOTE: This is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
3772              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
3773                            
3774              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
# Line 3889  sub _tree_construction_main ($) { Line 3780  sub _tree_construction_main ($) {
3780                   caption => 1, col => 1, colgroup => 1, tbody => 1,                   caption => 1, col => 1, colgroup => 1, tbody => 1,
3781                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,
3782                  }->{$token->{tag_name}}) {                  }->{$token->{tag_name}}) {
3783                !!!parse-error (type => 'not closed:caption');                if ($self->{insertion_mode} eq 'in cell') {
3784                    ## have an element in table scope
3785                ## As if </caption>                  my $tn;
3786                ## have a table element in table scope                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3787                my $i;                    my $node = $self->{open_elements}->[$_];
3788                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {
3789                  my $node = $self->{open_elements}->[$_];                      $tn = $node->[1];
3790                  if ($node->[1] eq 'caption') {                      last INSCOPE;
3791                    $i = $_;                    } elsif ({
3792                    last INSCOPE;                              table => 1, html => 1,
3793                  } elsif ({                             }->{$node->[1]}) {
3794                            table => 1, html => 1,                      last INSCOPE;
3795                           }->{$node->[1]}) {                    }
3796                    last INSCOPE;                  } # INSCOPE
3797                  }                    unless (defined $tn) {
3798                } # INSCOPE                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3799                unless (defined $i) {                      ## Ignore the token
3800                  !!!parse-error (type => 'unmatched end tag:caption');                      !!!next-token;
3801                  ## Ignore the token                      redo B;
3802                  !!!next-token;                    }
3803                  redo B;                  
3804                }                  ## Close the cell
                 
               ## 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]}) {  
3805                  !!!back-token; # <?>                  !!!back-token; # <?>
3806                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => 'end tag', tag_name => $tn};
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
3807                  redo B;                  redo B;
3808                  } elsif ($self->{insertion_mode} eq 'in caption') {
3809                    !!!parse-error (type => 'not closed:caption');
3810                    
3811                    ## As if </caption>
3812                    ## have a table element in table scope
3813                    my $i;
3814                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3815                      my $node = $self->{open_elements}->[$_];
3816                      if ($node->[1] eq 'caption') {
3817                        $i = $_;
3818                        last INSCOPE;
3819                      } elsif ({
3820                                table => 1, html => 1,
3821                               }->{$node->[1]}) {
3822                        last INSCOPE;
3823                      }
3824                    } # INSCOPE
3825                      unless (defined $i) {
3826                        !!!parse-error (type => 'unmatched end tag:caption');
3827                        ## Ignore the token
3828                        !!!next-token;
3829                        redo B;
3830                      }
3831                    
3832                    ## generate implied end tags
3833                    if ({
3834                         dd => 1, dt => 1, li => 1, p => 1,
3835                         td => 1, th => 1, tr => 1,
3836                         tbody => 1, tfoot=> 1, thead => 1,
3837                        }->{$self->{open_elements}->[-1]->[1]}) {
3838                      !!!back-token; # <?>
3839                      $token = {type => 'end tag', tag_name => 'caption'};
3840                      !!!back-token;
3841                      $token = {type => 'end tag',
3842                                tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3843                      redo B;
3844                    }
3845    
3846                    if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3847                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3848                    }
3849                    
3850                    splice @{$self->{open_elements}}, $i;
3851                    
3852                    $clear_up_to_marker->();
3853                    
3854                    $self->{insertion_mode} = 'in table';
3855                    
3856                    ## reprocess
3857                    redo B;
3858                  } else {
3859                    #
3860                }                }
   
               if ($self->{open_elements}->[-1]->[1] ne 'caption') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in table';  
   
               ## reprocess  
               redo B;  
3861              } else {              } else {
3862                #                #
3863              }              }
3864            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3865              if ($token->{tag_name} eq 'caption') {              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {
3866                ## have a table element in table scope                if ($self->{insertion_mode} eq 'in cell') {
3867                    ## have an element in table scope
3868                    my $i;
3869                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3870                      my $node = $self->{open_elements}->[$_];
3871                      if ($node->[1] eq $token->{tag_name}) {
3872                        $i = $_;
3873                        last INSCOPE;
3874                      } elsif ({
3875                                table => 1, html => 1,
3876                               }->{$node->[1]}) {
3877                        last INSCOPE;
3878                      }
3879                    } # INSCOPE
3880                      unless (defined $i) {
3881                        !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3882                        ## Ignore the token
3883                        !!!next-token;
3884                        redo B;
3885                      }
3886                    
3887                    ## generate implied end tags
3888                    if ({
3889                         dd => 1, dt => 1, li => 1, p => 1,
3890                         td => ($token->{tag_name} eq 'th'),
3891                         th => ($token->{tag_name} eq 'td'),
3892                         tr => 1,
3893                         tbody => 1, tfoot=> 1, thead => 1,
3894                        }->{$self->{open_elements}->[-1]->[1]}) {
3895                      !!!back-token;
3896                      $token = {type => 'end tag',
3897                                tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3898                      redo B;
3899                    }
3900                    
3901                    if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3902                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3903                    }
3904                    
3905                    splice @{$self->{open_elements}}, $i;
3906                    
3907                    $clear_up_to_marker->();
3908                    
3909                    $self->{insertion_mode} = 'in row';
3910                    
3911                    !!!next-token;
3912                    redo B;
3913                  } elsif ($self->{insertion_mode} eq 'in caption') {
3914                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3915                    ## Ignore the token
3916                    !!!next-token;
3917                    redo B;
3918                  } else {
3919                    #
3920                  }
3921                } elsif ($token->{tag_name} eq 'caption') {
3922                  if ($self->{insertion_mode} eq 'in caption') {
3923                    ## have a table element in table scope
3924                    my $i;
3925                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3926                      my $node = $self->{open_elements}->[$_];
3927                      if ($node->[1] eq $token->{tag_name}) {
3928                        $i = $_;
3929                        last INSCOPE;
3930                      } elsif ({
3931                                table => 1, html => 1,
3932                               }->{$node->[1]}) {
3933                        last INSCOPE;
3934                      }
3935                    } # INSCOPE
3936                      unless (defined $i) {
3937                        !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3938                        ## Ignore the token
3939                        !!!next-token;
3940                        redo B;
3941                      }
3942                    
3943                    ## generate implied end tags
3944                    if ({
3945                         dd => 1, dt => 1, li => 1, p => 1,
3946                         td => 1, th => 1, tr => 1,
3947                         tbody => 1, tfoot=> 1, thead => 1,
3948                        }->{$self->{open_elements}->[-1]->[1]}) {
3949                      !!!back-token;
3950                      $token = {type => 'end tag',
3951                                tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3952                      redo B;
3953                    }
3954                    
3955                    if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3956                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3957                    }
3958                    
3959                    splice @{$self->{open_elements}}, $i;
3960                    
3961                    $clear_up_to_marker->();
3962                    
3963                    $self->{insertion_mode} = 'in table';
3964                    
3965                    !!!next-token;
3966                    redo B;
3967                  } elsif ($self->{insertion_mode} eq 'in cell') {
3968                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3969                    ## Ignore the token
3970                    !!!next-token;
3971                    redo B;
3972                  } else {
3973                    #
3974                  }
3975                } elsif ({
3976                          table => 1, tbody => 1, tfoot => 1,
3977                          thead => 1, tr => 1,
3978                         }->{$token->{tag_name}} and
3979                         $self->{insertion_mode} eq 'in cell') {
3980                  ## have an element in table scope
3981                my $i;                my $i;
3982                  my $tn;
3983                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3984                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
3985                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
3986                    $i = $_;                    $i = $_;
3987                    last INSCOPE;                    last INSCOPE;
3988                    } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
3989                      $tn = $node->[1];
3990                      ## NOTE: There is exactly one |td| or |th| element
3991                      ## in scope in the stack of open elements by definition.
3992                  } elsif ({                  } elsif ({
3993                            table => 1, html => 1,                            table => 1, html => 1,
3994                           }->{$node->[1]}) {                           }->{$node->[1]}) {
# Line 3962  sub _tree_construction_main ($) { Line 4001  sub _tree_construction_main ($) {
4001                  !!!next-token;                  !!!next-token;
4002                  redo B;                  redo B;
4003                }                }
                 
               ## 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  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne 'caption') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
4004    
4005                $clear_up_to_marker->();                ## Close the cell
4006                  !!!back-token; # </?>
4007                $self->{insertion_mode} = 'in table';                $token = {type => 'end tag', tag_name => $tn};
   
               !!!next-token;  
4008                redo B;                redo B;
4009              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table' and
4010                         $self->{insertion_mode} eq 'in caption') {
4011                !!!parse-error (type => 'not closed:caption');                !!!parse-error (type => 'not closed:caption');
4012    
4013                ## As if </caption>                ## As if </caption>
# Line 4038  sub _tree_construction_main ($) { Line 4058  sub _tree_construction_main ($) {
4058                ## reprocess                ## reprocess
4059                redo B;                redo B;
4060              } elsif ({              } elsif ({
4061                        body => 1, col => 1, colgroup => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
                       html => 1, tbody => 1, td => 1, tfoot => 1,  
                       th => 1, thead => 1, tr => 1,  
4062                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4063                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                if ($self->{insertion_mode} eq 'in cell' or
4064                ## Ignore the token                    $self->{insertion_mode} eq 'in caption') {
4065                !!!next-token;                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
           }  
                 
           $in_body->($insert_to_current);  
           redo B;  
         } elsif ($self->{insertion_mode} eq 'in column group') {  
           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;  
               }  
             }  
               
             #  
           } elsif ($token->{type} eq 'start tag') {  
             if ($token->{tag_name} eq 'col') {  
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               pop @{$self->{open_elements}};  
               !!!next-token;  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'colgroup') {  
               if ($self->{open_elements}->[-1]->[1] eq 'html') {  
                 !!!parse-error (type => 'unmatched end tag:colgroup');  
4066                  ## Ignore the token                  ## Ignore the token
4067                  !!!next-token;                  !!!next-token;
4068                  redo B;                  redo B;
4069                } else {                } else {
4070                  pop @{$self->{open_elements}}; # colgroup                  #
                 $self->{insertion_mode} = 'in table';  
                 !!!next-token;  
                 redo B;              
4071                }                }
4072              } elsif ($token->{tag_name} eq 'col') {              } elsif ({
4073                !!!parse-error (type => 'unmatched end tag:col');                        tbody => 1, tfoot => 1,
4074                          thead => 1, tr => 1,
4075                         }->{$token->{tag_name}} and
4076                         $self->{insertion_mode} eq 'in caption') {
4077                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4078                ## Ignore the token                ## Ignore the token
4079                !!!next-token;                !!!next-token;
4080                redo B;                redo B;
4081              } else {              } else {
4082                #                #
4083              }              }
4084            } else {            } else {
4085              #              #
4086            }            }
4087              
4088            ## As if </colgroup>            $in_body->($insert_to_current);
4089            if ($self->{open_elements}->[-1]->[1] eq 'html') {            redo B;
4090              !!!parse-error (type => 'unmatched end tag:colgroup');          } elsif ($self->{insertion_mode} eq 'in row' or
4091              ## Ignore the token                   $self->{insertion_mode} eq 'in table body' or
4092              !!!next-token;                   $self->{insertion_mode} eq 'in table') {
             redo B;  
           } else {  
             pop @{$self->{open_elements}}; # colgroup  
             $self->{insertion_mode} = 'in table';  
             ## reprocess  
             redo B;  
           }  
         } elsif ($self->{insertion_mode} eq 'in table body') {  
4093            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
4094              ## NOTE: This is a "character in table" code clone.              ## NOTE: There are "character in table" code clones.
4095              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4096                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4097                                
# Line 4131  sub _tree_construction_main ($) { Line 4108  sub _tree_construction_main ($) {
4108              ## into the current node" while characters might not be              ## into the current node" while characters might not be
4109              ## result in a new Text node.              ## result in a new Text node.
4110              $reconstruct_active_formatting_elements->($insert_to_foster);              $reconstruct_active_formatting_elements->($insert_to_foster);
4111                
4112              if ({              if ({
4113                   table => 1, tbody => 1, tfoot => 1,                   table => 1, tbody => 1, tfoot => 1,
4114                   thead => 1, tr => 1,                   thead => 1, tr => 1,
# Line 4173  sub _tree_construction_main ($) { Line 4150  sub _tree_construction_main ($) {
4150              redo B;              redo B;
4151            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4152              if ({              if ({
4153                   tr => 1,                   tr => ($self->{insertion_mode} ne 'in row'),
4154                   th => 1, td => 1,                   th => 1, td => 1,
4155                  }->{$token->{tag_name}}) {                  }->{$token->{tag_name}}) {
4156                unless ($token->{tag_name} eq 'tr') {                if ($self->{insertion_mode} eq 'in table') {
4157                  !!!parse-error (type => 'missing start tag:tr');                  ## Clear back to table context
4158                    while ($self->{open_elements}->[-1]->[1] ne 'table' and
4159                           $self->{open_elements}->[-1]->[1] ne 'html') {
4160                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4161                      pop @{$self->{open_elements}};
4162                    }
4163                    
4164                    !!!insert-element ('tbody');
4165                    $self->{insertion_mode} = 'in table body';
4166                    ## reprocess in the "in table body" insertion mode...
4167                  }
4168    
4169                  if ($self->{insertion_mode} eq 'in table body') {
4170                    unless ($token->{tag_name} eq 'tr') {
4171                      !!!parse-error (type => 'missing start tag:tr');
4172                    }
4173                    
4174                    ## Clear back to table body context
4175                    while (not {
4176                      tbody => 1, tfoot => 1, thead => 1, html => 1,
4177                    }->{$self->{open_elements}->[-1]->[1]}) {
4178                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4179                      pop @{$self->{open_elements}};
4180                    }
4181                    
4182                    $self->{insertion_mode} = 'in row';
4183                    if ($token->{tag_name} eq 'tr') {
4184                      !!!insert-element ($token->{tag_name}, $token->{attributes});
4185                      !!!next-token;
4186                      redo B;
4187                    } else {
4188                      !!!insert-element ('tr');
4189                      ## reprocess in the "in row" insertion mode
4190                    }
4191                }                }
4192    
4193                ## Clear back to table body context                ## Clear back to table row context
4194                while (not {                while (not {
4195                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tr => 1, html => 1,
4196                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4197                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4198                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4199                }                }
4200                                
4201                $self->{insertion_mode} = 'in row';                !!!insert-element ($token->{tag_name}, $token->{attributes});
4202                if ($token->{tag_name} eq 'tr') {                $self->{insertion_mode} = 'in cell';
4203                  !!!insert-element ($token->{tag_name}, $token->{attributes});  
4204                  !!!next-token;                push @$active_formatting_elements, ['#marker', ''];
4205                } else {                
4206                  !!!insert-element ('tr');                !!!next-token;
                 ## reprocess  
               }  
4207                redo B;                redo B;
4208              } elsif ({              } elsif ({
4209                        caption => 1, col => 1, colgroup => 1,                        caption => 1, col => 1, colgroup => 1,
4210                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
4211                          tr => 1, # $self->{insertion_mode} eq 'in row'
4212                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4213                ## have an element in table scope                if ($self->{insertion_mode} eq 'in row') {
4214                my $i;                  ## As if </tr>
4215                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  ## have an element in table scope
4216                  my $node = $self->{open_elements}->[$_];                  my $i;
4217                  if ({                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4218                       tbody => 1, thead => 1, tfoot => 1,                    my $node = $self->{open_elements}->[$_];
4219                      }->{$node->[1]}) {                    if ($node->[1] eq 'tr') {
4220                    $i = $_;                      $i = $_;
4221                    last INSCOPE;                      last INSCOPE;
4222                  } elsif ({                    } elsif ({
4223                            table => 1, html => 1,                              table => 1, html => 1,
4224                           }->{$node->[1]}) {                             }->{$node->[1]}) {
4225                    last INSCOPE;                      last INSCOPE;
4226                      }
4227                    } # INSCOPE
4228                    unless (defined $i) {
4229                      !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4230                      ## Ignore the token
4231                      !!!next-token;
4232                      redo B;
4233                    }
4234                    
4235                    ## Clear back to table row context
4236                    while (not {
4237                      tr => 1, html => 1,
4238                    }->{$self->{open_elements}->[-1]->[1]}) {
4239                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4240                      pop @{$self->{open_elements}};
4241                    }
4242                    
4243                    pop @{$self->{open_elements}}; # tr
4244                    $self->{insertion_mode} = 'in table body';
4245                    if ($token->{tag_name} eq 'tr') {
4246                      ## reprocess
4247                      redo B;
4248                    } else {
4249                      ## reprocess in the "in table body" insertion mode...
4250                  }                  }
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
4251                }                }
4252    
4253                ## Clear back to table body context                if ($self->{insertion_mode} eq 'in table body') {
4254                while (not {                  ## have an element in table scope
4255                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  my $i;
4256                }->{$self->{open_elements}->[-1]->[1]}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4257                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    my $node = $self->{open_elements}->[$_];
4258                      if ({
4259                           tbody => 1, thead => 1, tfoot => 1,
4260                          }->{$node->[1]}) {
4261                        $i = $_;
4262                        last INSCOPE;
4263                      } elsif ({
4264                                table => 1, html => 1,
4265                               }->{$node->[1]}) {
4266                        last INSCOPE;
4267                      }
4268                    } # INSCOPE
4269                    unless (defined $i) {
4270                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4271                      ## Ignore the token
4272                      !!!next-token;
4273                      redo B;
4274                    }
4275    
4276                    ## Clear back to table body context
4277                    while (not {
4278                      tbody => 1, tfoot => 1, thead => 1, html => 1,
4279                    }->{$self->{open_elements}->[-1]->[1]}) {
4280                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4281                      pop @{$self->{open_elements}};
4282                    }
4283                    
4284                    ## As if <{current node}>
4285                    ## have an element in table scope
4286                    ## true by definition
4287                    
4288                    ## Clear back to table body context
4289                    ## nop by definition
4290                    
4291                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4292                    $self->{insertion_mode} = 'in table';
4293                    ## reprocess in "in table" insertion mode...
4294                }                }
4295    
4296                ## As if <{current node}>                if ($token->{tag_name} eq 'col') {
4297                ## have an element in table scope                  ## Clear back to table context
4298                ## true by definition                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4299                           $self->{open_elements}->[-1]->[1] ne 'html') {
4300                ## Clear back to table body context                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4301                ## nop by definition                    pop @{$self->{open_elements}};
4302                    }
4303                pop @{$self->{open_elements}};                  
4304                $self->{insertion_mode} = 'in table';                  !!!insert-element ('colgroup');
4305                ## reprocess                  $self->{insertion_mode} = 'in column group';
4306                redo B;                  ## reprocess
4307                    redo B;
4308                  } elsif ({
4309                            caption => 1,
4310                            colgroup => 1,
4311                            tbody => 1, tfoot => 1, thead => 1,
4312                           }->{$token->{tag_name}}) {
4313                    ## Clear back to table context
4314                    while ($self->{open_elements}->[-1]->[1] ne 'table' and
4315                           $self->{open_elements}->[-1]->[1] ne 'html') {
4316                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4317                      pop @{$self->{open_elements}};
4318                    }
4319                    
4320                    push @$active_formatting_elements, ['#marker', '']
4321                        if $token->{tag_name} eq 'caption';
4322                    
4323                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4324                    $self->{insertion_mode} = {
4325                                               caption => 'in caption',
4326                                               colgroup => 'in column group',
4327                                               tbody => 'in table body',
4328                                               tfoot => 'in table body',
4329                                               thead => 'in table body',
4330                                              }->{$token->{tag_name}};
4331                    !!!next-token;
4332                    redo B;
4333                  } else {
4334                    die "$0: in table: <>: $token->{tag_name}";
4335                  }
4336              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
4337                ## NOTE: This is a code clone of "table in table"                ## NOTE: There are code clones for this "table in table"
4338                !!!parse-error (type => 'not closed:table');                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4339    
4340                ## As if </table>                ## As if </table>
4341                ## have a table element in table scope                ## have a table element in table scope
# Line 4287  sub _tree_construction_main ($) { Line 4378  sub _tree_construction_main ($) {
4378    
4379                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4380    
4381                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4382    
4383                ## reprocess                ## reprocess
4384                redo B;                redo B;
# Line 4295  sub _tree_construction_main ($) { Line 4386  sub _tree_construction_main ($) {
4386                #                #
4387              }              }
4388            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
4389              if ({              if ($token->{tag_name} eq 'tr' and
4390                   tbody => 1, tfoot => 1, thead => 1,                  $self->{insertion_mode} eq 'in row') {
                 }->{$token->{tag_name}}) {  
4391                ## have an element in table scope                ## have an element in table scope
4392                my $i;                my $i;
4393                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 4318  sub _tree_construction_main ($) { Line 4408  sub _tree_construction_main ($) {
4408                  redo B;                  redo B;
4409                }                }
4410    
4411                ## Clear back to table body context                ## Clear back to table row context
4412                while (not {                while (not {
4413                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tr => 1, html => 1,
4414                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4415                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4416                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4417                }                }
4418    
4419                pop @{$self->{open_elements}};                pop @{$self->{open_elements}}; # tr
4420                $self->{insertion_mode} = 'in table';                $self->{insertion_mode} = 'in table body';
4421                !!!next-token;                !!!next-token;
4422                redo B;                redo B;
4423              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
4424                ## have an element in table scope                if ($self->{insertion_mode} eq 'in row') {
4425                my $i;                  ## As if </tr>
4426                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  ## have an element in table scope
4427                  my $node = $self->{open_elements}->[$_];                  my $i;
4428                  if ({                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4429                       tbody => 1, thead => 1, tfoot => 1,                    my $node = $self->{open_elements}->[$_];
4430                      }->{$node->[1]}) {                    if ($node->[1] eq 'tr') {
4431                    $i = $_;                      $i = $_;
4432                    last INSCOPE;                      last INSCOPE;
4433                  } elsif ({                    } elsif ({
4434                            table => 1, html => 1,                              table => 1, html => 1,
4435                           }->{$node->[1]}) {                             }->{$node->[1]}) {
4436                    last INSCOPE;                      last INSCOPE;
4437                  }                    }
4438                } # INSCOPE                  } # INSCOPE
4439                unless (defined $i) {                  unless (defined $i) {
4440                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4441                  ## Ignore the token                    ## Ignore the token
4442                  !!!next-token;                    !!!next-token;
4443                  redo B;                    redo B;
4444                }                  }
4445                    
4446                ## Clear back to table body context                  ## Clear back to table row context
4447                while (not {                  while (not {
4448                  tbody => 1, tfoot => 1, thead => 1, html => 1,                    tr => 1, html => 1,
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
   
               ## As if <{current node}>  
               ## have an element in table scope  
               ## true by definition  
   
               ## Clear back to table body context  
               ## nop by definition  
   
               pop @{$self->{open_elements}};  
               $self->{insertion_mode} = 'in table';  
               ## reprocess  
               redo B;  
             } elsif ({  
                       body => 1, caption => 1, col => 1, colgroup => 1,  
                       html => 1, td => 1, th => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
           }  
             
           ## As if in table  
           !!!parse-error (type => 'in table:'.$token->{tag_name});  
           $in_body->($insert_to_foster);  
           redo B;  
         } elsif ($self->{insertion_mode} eq 'in row') {  
           if ($token->{type} eq 'character') {  
             ## NOTE: This is a "character in table" code clone.  
             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;  
               }  
             }  
   
             !!!parse-error (type => 'in table:#character');  
   
             ## As if in body, but insert into foster parent element  
             ## ISSUE: Spec says that "whenever a node would be inserted  
             ## into the current node" while characters might not be  
             ## result in a new Text node.  
             $reconstruct_active_formatting_elements->($insert_to_foster);  
               
             if ({  
                  table => 1, tbody => 1, tfoot => 1,  
                  thead => 1, tr => 1,  
4449                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4450                # MUST                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4451                my $foster_parent_element;                    pop @{$self->{open_elements}};
4452                my $next_sibling;                  }
4453                my $prev_sibling;                  
4454                OE: for (reverse 0..$#{$self->{open_elements}}) {                  pop @{$self->{open_elements}}; # tr
4455                  if ($self->{open_elements}->[$_]->[1] eq 'table') {                  $self->{insertion_mode} = 'in table body';
4456                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                  ## reprocess in the "in table body" insertion mode...
4457                    if (defined $parent and $parent->node_type == 1) {                }
4458                      $foster_parent_element = $parent;  
4459                      $next_sibling = $self->{open_elements}->[$_]->[0];                if ($self->{insertion_mode} eq 'in table body') {
4460                      $prev_sibling = $next_sibling->previous_sibling;                  ## have an element in table scope
4461                    } else {                  my $i;
4462                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4463                      $prev_sibling = $foster_parent_element->last_child;                    my $node = $self->{open_elements}->[$_];
4464                      if ({
4465                           tbody => 1, thead => 1, tfoot => 1,
4466                          }->{$node->[1]}) {
4467                        $i = $_;
4468                        last INSCOPE;
4469                      } elsif ({
4470                                table => 1, html => 1,
4471                               }->{$node->[1]}) {
4472                        last INSCOPE;
4473                    }                    }
4474                    last OE;                  } # INSCOPE
4475                    unless (defined $i) {
4476                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4477                      ## Ignore the token
4478                      !!!next-token;
4479                      redo B;
4480                    }
4481                    
4482                    ## Clear back to table body context
4483                    while (not {
4484                      tbody => 1, tfoot => 1, thead => 1, html => 1,
4485                    }->{$self->{open_elements}->[-1]->[1]}) {
4486                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4487                      pop @{$self->{open_elements}};
4488                  }                  }
4489                } # OE                  
4490                $foster_parent_element = $self->{open_elements}->[0]->[0] and                  ## As if <{current node}>
4491                $prev_sibling = $foster_parent_element->last_child                  ## have an element in table scope
4492                  unless defined $foster_parent_element;                  ## true by definition
4493                if (defined $prev_sibling and                  
4494                    $prev_sibling->node_type == 3) {                  ## Clear back to table body context
4495                  $prev_sibling->manakai_append_text ($token->{data});                  ## nop by definition
4496                } else {                  
                 $foster_parent_element->insert_before  
                   ($self->{document}->create_text_node ($token->{data}),  
                    $next_sibling);  
               }  
             } else {  
               $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});  
             }  
               
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ($token->{tag_name} eq 'th' or  
                 $token->{tag_name} eq 'td') {  
               ## Clear back to table row context  
               while (not {  
                 tr => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4497                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4498                    $self->{insertion_mode} = 'in table';
4499                    ## reprocess in the "in table" insertion mode...
4500                }                }
                 
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               $self->{insertion_mode} = 'in cell';  
4501    
4502                push @$active_formatting_elements, ['#marker', ''];                ## have a table element in table scope
                 
               !!!next-token;  
               redo B;  
             } elsif ({  
                       caption => 1, col => 1, colgroup => 1,  
                       tbody => 1, tfoot => 1, thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               ## As if </tr>  
               ## have an element in table scope  
4503                my $i;                my $i;
4504                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4505                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4506                  if ($node->[1] eq 'tr') {                  if ($node->[1] eq $token->{tag_name}) {
4507                    $i = $_;                    $i = $_;
4508                    last INSCOPE;                    last INSCOPE;
4509                  } elsif ({                  } elsif ({
# Line 4487  sub _tree_construction_main ($) { Line 4513  sub _tree_construction_main ($) {
4513                  }                  }
4514                } # INSCOPE                } # INSCOPE
4515                unless (defined $i) {                unless (defined $i) {
4516                  !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4517                  ## Ignore the token                  ## Ignore the token
4518                  !!!next-token;                  !!!next-token;
4519                  redo B;                  redo B;
4520                }                }
4521    
               ## Clear back to table row context  
               while (not {  
                 tr => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
   
               pop @{$self->{open_elements}}; # tr  
               $self->{insertion_mode} = 'in table body';  
               ## reprocess  
               redo B;  
             } elsif ($token->{tag_name} eq 'table') {  
               ## NOTE: This is a code clone of "table in table"  
               !!!parse-error (type => 'not closed:table');  
   
               ## As if </table>  
               ## have a table element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'table') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:table');  
                 ## Ignore tokens </table><table>  
                 !!!next-token;  
                 redo B;  
               }  
                 
4522                ## generate implied end tags                ## generate implied end tags
4523                if ({                if ({
4524                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4525                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4526                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4527                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
                 !!!back-token; # <table>  
                 $token = {type => 'end tag', tag_name => 'table'};  
4528                  !!!back-token;                  !!!back-token;
4529                  $token = {type => 'end tag',                  $token = {type => 'end tag',
4530                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4531                  redo B;                  redo B;
4532                }                }
4533                  
4534                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4535                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4536                }                }
4537                    
4538                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4539                  
4540                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4541                  
               ## reprocess  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'tr') {  
               ## have an element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq $token->{tag_name}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
   
               ## Clear back to table row context  
               while (not {  
                 tr => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
   
               pop @{$self->{open_elements}}; # tr  
               $self->{insertion_mode} = 'in table body';  
4542                !!!next-token;                !!!next-token;
4543                redo B;                redo B;
             } elsif ($token->{tag_name} eq 'table') {  
               ## As if </tr>  
               ## have an element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'tr') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{type});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
   
               ## Clear back to table row context  
               while (not {  
                 tr => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
   
               pop @{$self->{open_elements}}; # tr  
               $self->{insertion_mode} = 'in table body';  
               ## reprocess  
               redo B;  
4544              } elsif ({              } elsif ({
4545                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
4546                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}} and
4547                ## have an element in table scope                       ($self->{insertion_mode} eq 'in row' or
4548                my $i;                        $self->{insertion_mode} eq 'in table body')) {
4549                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                if ($self->{insertion_mode} eq 'in row') {
4550                  my $node = $self->{open_elements}->[$_];                  ## have an element in table scope
4551                  if ($node->[1] eq $token->{tag_name}) {                  my $i;
4552                    $i = $_;                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4553                    last INSCOPE;                    my $node = $self->{open_elements}->[$_];
4554                  } elsif ({                    if ($node->[1] eq $token->{tag_name}) {
4555                            table => 1, html => 1,                      $i = $_;
4556                           }->{$node->[1]}) {                      last INSCOPE;
4557                    last INSCOPE;                    } elsif ({
4558                                table => 1, html => 1,
4559                               }->{$node->[1]}) {
4560                        last INSCOPE;
4561                      }
4562                    } # INSCOPE
4563                      unless (defined $i) {
4564                        !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4565                        ## Ignore the token
4566                        !!!next-token;
4567                        redo B;
4568                      }
4569                    
4570                    ## As if </tr>
4571                    ## have an element in table scope
4572                    my $i;
4573                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4574                      my $node = $self->{open_elements}->[$_];
4575                      if ($node->[1] eq 'tr') {
4576                        $i = $_;
4577                        last INSCOPE;
4578                      } elsif ({
4579                                table => 1, html => 1,
4580                               }->{$node->[1]}) {
4581                        last INSCOPE;
4582                      }
4583                    } # INSCOPE
4584                      unless (defined $i) {
4585                        !!!parse-error (type => 'unmatched end tag:tr');
4586                        ## Ignore the token
4587                        !!!next-token;
4588                        redo B;
4589                      }
4590                    
4591                    ## Clear back to table row context
4592                    while (not {
4593                      tr => 1, html => 1,
4594                    }->{$self->{open_elements}->[-1]->[1]}) {
4595                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4596                      pop @{$self->{open_elements}};
4597                  }                  }
4598                } # INSCOPE                  
4599                unless (defined $i) {                  pop @{$self->{open_elements}}; # tr
4600                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  $self->{insertion_mode} = 'in table body';
4601                  ## Ignore the token                  ## reprocess in the "in table body" insertion mode...
                 !!!next-token;  
                 redo B;  
4602                }                }
4603    
               ## As if </tr>  
4604                ## have an element in table scope                ## have an element in table scope
4605                my $i;                my $i;
4606                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4607                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4608                  if ($node->[1] eq 'tr') {                  if ($node->[1] eq $token->{tag_name}) {
4609                    $i = $_;                    $i = $_;
4610                    last INSCOPE;                    last INSCOPE;
4611                  } elsif ({                  } elsif ({
# Line 4663  sub _tree_construction_main ($) { Line 4615  sub _tree_construction_main ($) {
4615                  }                  }
4616                } # INSCOPE                } # INSCOPE
4617                unless (defined $i) {                unless (defined $i) {
4618                  !!!parse-error (type => 'unmatched end tag:tr');                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4619                  ## Ignore the token                  ## Ignore the token
4620                  !!!next-token;                  !!!next-token;
4621                  redo B;                  redo B;
4622                }                }
4623    
4624                ## Clear back to table row context                ## Clear back to table body context
4625                while (not {                while (not {
4626                  tr => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4627                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4628                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4629                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4630                }                }
4631    
4632                pop @{$self->{open_elements}}; # tr                pop @{$self->{open_elements}};
4633                $self->{insertion_mode} = 'in table body';                $self->{insertion_mode} = 'in table';
4634                ## reprocess                !!!next-token;
4635                redo B;                redo B;
4636              } elsif ({              } elsif ({
4637                        body => 1, caption => 1, col => 1,                        body => 1, caption => 1, col => 1, colgroup => 1,
4638                        colgroup => 1, html => 1, td => 1, th => 1,                        html => 1, td => 1, th => 1,
4639                          tr => 1, # $self->{insertion_mode} eq 'in row'
4640                          tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} eq 'in table'
4641                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4642                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4643                ## Ignore the token                ## Ignore the token
# Line 4693  sub _tree_construction_main ($) { Line 4647  sub _tree_construction_main ($) {
4647                #                #
4648              }              }
4649            } else {            } else {
4650              #              die "$0: $token->{type}: Unknown token type";
4651            }            }
4652    
           ## As if in table  
4653            !!!parse-error (type => 'in table:'.$token->{tag_name});            !!!parse-error (type => 'in table:'.$token->{tag_name});
4654            $in_body->($insert_to_foster);            $in_body->($insert_to_foster);
4655            redo B;            redo B;
4656          } elsif ($self->{insertion_mode} eq 'in cell') {          } elsif ($self->{insertion_mode} eq 'in column group') {
4657            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
4658              ## NOTE: This is a code clone of "character in body".              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4659              $reconstruct_active_formatting_elements->($insert_to_current);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4660                              unless (length $token->{data}) {
             $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});  
   
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ({  
                  caption => 1, col => 1, colgroup => 1,  
                  tbody => 1, td => 1, tfoot => 1, th => 1,  
                  thead => 1, tr => 1,  
                 }->{$token->{tag_name}}) {  
               ## have an element in table scope  
               my $tn;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'td' or $node->[1] eq 'th') {  
                   $tn = $node->[1];  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $tn) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
4661                  !!!next-token;                  !!!next-token;
4662                  redo B;                  redo B;
4663                }                }
4664                }
4665                ## Close the cell              
4666                !!!back-token; # <?>              #
4667                $token = {type => 'end tag', tag_name => $tn};            } elsif ($token->{type} eq 'start tag') {
4668                if ($token->{tag_name} eq 'col') {
4669                  !!!insert-element ($token->{tag_name}, $token->{attributes});
4670                  pop @{$self->{open_elements}};
4671                  !!!next-token;
4672                redo B;                redo B;
4673              } else {              } else {
4674                #                #
4675              }              }
4676            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
4677              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {              if ($token->{tag_name} eq 'colgroup') {
4678                ## have an element in table scope                if ($self->{open_elements}->[-1]->[1] eq 'html') {
4679                my $i;                  !!!parse-error (type => 'unmatched end tag:colgroup');
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq $token->{tag_name}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
4680                  ## Ignore the token                  ## Ignore the token
4681                  !!!next-token;                  !!!next-token;
4682                  redo B;                  redo B;
4683                  } else {
4684                    pop @{$self->{open_elements}}; # colgroup
4685                    $self->{insertion_mode} = 'in table';
4686                    !!!next-token;
4687                    redo B;            
4688                }                }
4689                              } elsif ($token->{tag_name} eq 'col') {
4690                ## generate implied end tags                !!!parse-error (type => 'unmatched end tag:col');
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => ($token->{tag_name} eq 'th'),  
                    th => ($token->{tag_name} eq 'td'),  
                    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  
                 redo B;  
               }  
   
               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;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in row';  
   
               !!!next-token;  
               redo B;  
             } elsif ({  
                       body => 1, caption => 1, col => 1,  
                       colgroup => 1, html => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
4691                ## Ignore the token                ## Ignore the token
4692                !!!next-token;                !!!next-token;
4693                redo B;                redo B;
             } elsif ({  
                       table => 1, tbody => 1, tfoot => 1,  
                       thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               ## have an element in table scope  
               my $i;  
               my $tn;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq $token->{tag_name}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {  
                   $tn = $node->[1];  
                   ## NOTE: There is exactly one |td| or |th| element  
                   ## in scope in the stack of open elements by definition.  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
   
               ## Close the cell  
               !!!back-token; # </?>  
               $token = {type => 'end tag', tag_name => $tn};  
               redo B;  
4694              } else {              } else {
4695                #                #
4696              }              }
4697            } else {            } else {
4698              #              #
4699            }            }
4700              
4701            $in_body->($insert_to_current);            ## As if </colgroup>
4702            redo B;            if ($self->{open_elements}->[-1]->[1] eq 'html') {
4703                !!!parse-error (type => 'unmatched end tag:colgroup');
4704                ## Ignore the token
4705                !!!next-token;
4706                redo B;
4707              } else {
4708                pop @{$self->{open_elements}}; # colgroup
4709                $self->{insertion_mode} = 'in table';
4710                ## reprocess
4711                redo B;
4712              }
4713          } elsif ($self->{insertion_mode} eq 'in select') {          } elsif ($self->{insertion_mode} eq 'in select') {
4714            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
4715              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
# Line 5083  sub _tree_construction_main ($) { Line 4953  sub _tree_construction_main ($) {
4953            !!!next-token;            !!!next-token;
4954            redo B;            redo B;
4955          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
4956            $in_body->($insert_to_current);            ## NOTE: As if in body.
4957              $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
4958            redo B;            redo B;
4959          } else {          } else {
4960            !!!parse-error (type => 'in frameset:'.$token->{tag_name});            !!!parse-error (type => 'in frameset:'.$token->{tag_name});
# Line 5143  sub _tree_construction_main ($) { Line 5014  sub _tree_construction_main ($) {
5014          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
5015        } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{type} eq 'start tag') {
5016          if ($token->{tag_name} eq 'noframes') {          if ($token->{tag_name} eq 'noframes') {
5017            $in_body->($insert_to_current);            ## NOTE: As if in body.
5018              $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
5019            redo B;            redo B;
5020          } else {          } else {
5021            !!!parse-error (type => 'after frameset:'.$token->{tag_name});            !!!parse-error (type => 'after frameset:'.$token->{tag_name});

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24