/[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.44 by wakaba, Sat Jul 21 07:34:32 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 3433  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 3475  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 3522  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 3563  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    
3676                  ## Reprocess in the "after head" insertion mode...
3677                }
3678    
3679                ## "after head" insertion mode
3680                ## As if <body>
3681                !!!insert-element ('body');
3682                $self->{insertion_mode} = 'in body';
3683                ## reprocess
3684                redo B;
3685              } elsif ($token->{type} eq 'end tag') {
3686                if ($token->{tag_name} eq 'head') {
3687                  if ($self->{insertion_mode} eq 'in head noscript') {
3688                    ## As if </noscript>
3689                    pop @{$self->{open_elements}};
3690                    !!!parse-error (type => 'in noscript:script');
3691                    
3692                    $self->{insertion_mode} = 'in head';
3693                    ## Reprocess in the "in head" insertion mode...
3694                  }
3695                  
3696                  if ($self->{insertion_mode} eq 'in head') {
3697                    pop @{$self->{open_elements}};
3698                    $self->{insertion_mode} = 'after head';
3699                    !!!next-token;
3700                    redo B;
3701                  } else {
3702                    #
3703                  }
3704                } elsif ($token->{tag_name} eq 'noscript') {
3705                  if ($self->{insertion_mode} eq 'in head noscript') {
3706                    pop @{$self->{open_elements}};
3707                    $self->{insertion_mode} = 'in head';
3708                    !!!next-token;
3709                    redo B;
3710                  } else {
3711                    #
3712                  }
3713                } elsif ({
3714                        body => 1, html => 1,                        body => 1, html => 1,
                       p => 1, br => 1,  
3715                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3716                #                if ($self->{insertion_mode} eq 'in head noscript') {
3717              } elsif ($self->{insertion_mode} eq 'in head noscript' and                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3718                       {                  ## Ignore the token
3719                    !!!next-token;
3720                    redo B;
3721                  } else { # 'in head', 'after head'
3722                    #
3723                  }
3724                } elsif ({
3725                        p => 1, br => 1,                        p => 1, br => 1,
3726                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3727                #                #
             } elsif ($self->{insertion_mode} ne 'after head') {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               redo B;  
3728              } else {              } else {
3729                #                if ($self->{insertion_mode} ne 'after head') {
3730                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3731                    ## Ignore the token
3732                    !!!next-token;
3733                    redo B;
3734                  } else {
3735                    #
3736                  }
3737              }              }
           } else {  
             #  
           }  
3738    
3739            ## As if </head> or </noscript> or <body>              if ($self->{insertion_mode} eq 'in head noscript') {
3740            if ($self->{insertion_mode} eq 'in head') {                ## As if </noscript>
3741              pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3742              $self->{insertion_mode} = 'after head';                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
3743            } elsif ($self->{insertion_mode} eq 'in head noscript') {                
3744              pop @{$self->{open_elements}};                ## Reprocess in the "in head" insertion mode...
3745              !!!parse-error (type => 'in noscript:'.(defined $token->{tag_name} ? ($token->{type} eq 'end tag' ? '/' : '') . $token->{tag_name} : '#' . $token->{type}));                ## As if </head>
3746              $self->{insertion_mode} = 'in head';                pop @{$self->{open_elements}};
3747            } else { # 'after head'  
3748                  ## 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                  ## Reprocess in the "after head" insertion mode...
3754                }
3755    
3756                ## "after head" insertion mode
3757                ## As if <body>
3758              !!!insert-element ('body');              !!!insert-element ('body');
3759              $self->{insertion_mode} = 'in body';              $self->{insertion_mode} = 'in body';
3760                ## reprocess
3761                redo B;
3762              } else {
3763                die "$0: $token->{type}: Unknown token type";
3764            }            }
           ## reprocess  
           redo B;  
3765    
3766            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3767          } elsif ($self->{insertion_mode} eq 'in body' or          } elsif ($self->{insertion_mode} eq 'in body' or
# Line 3970  sub _tree_construction_main ($) { Line 4087  sub _tree_construction_main ($) {
4087                        
4088            $in_body->($insert_to_current);            $in_body->($insert_to_current);
4089            redo B;            redo B;
4090          } elsif ($self->{insertion_mode} eq 'in table') {          } elsif ($self->{insertion_mode} eq 'in row' or
4091                     $self->{insertion_mode} eq 'in table body' or
4092                     $self->{insertion_mode} eq 'in table') {
4093            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
4094              ## NOTE: There are "character in table" code clones.              ## 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]+)//) {
# Line 4031  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                   caption => 1,                   tr => ($self->{insertion_mode} ne 'in row'),
4154                   colgroup => 1,                   th => 1, td => 1,
                  tbody => 1, tfoot => 1, thead => 1,  
4155                  }->{$token->{tag_name}}) {                  }->{$token->{tag_name}}) {
4156                ## Clear back to table context                if ($self->{insertion_mode} eq 'in table') {
4157                while ($self->{open_elements}->[-1]->[1] ne 'table' and                  ## Clear back to table context
4158                       $self->{open_elements}->[-1]->[1] ne 'html') {                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4159                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                         $self->{open_elements}->[-1]->[1] ne 'html') {
4160                  pop @{$self->{open_elements}};                    !!!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                push @$active_formatting_elements, ['#marker', '']                if ($self->{insertion_mode} eq 'in table body') {
4170                  if $token->{tag_name} eq 'caption';                  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 row context
4194                  while (not {
4195                    tr => 1, html => 1,
4196                  }->{$self->{open_elements}->[-1]->[1]}) {
4197                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4198                    pop @{$self->{open_elements}};
4199                  }
4200                  
4201                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4202                $self->{insertion_mode} = {                $self->{insertion_mode} = 'in cell';
4203                                   caption => 'in caption',  
4204                                   colgroup => 'in column group',                push @$active_formatting_elements, ['#marker', ''];
4205                                   tbody => 'in table body',                
                                  tfoot => 'in table body',  
                                  thead => 'in table body',  
                                 }->{$token->{tag_name}};  
4206                !!!next-token;                !!!next-token;
4207                redo B;                redo B;
4208              } elsif ({              } elsif ({
4209                        col => 1,                        caption => 1, col => 1, colgroup => 1,
4210                        td => 1, th => 1, tr => 1,                        tbody => 1, tfoot => 1, thead => 1,
4211                          tr => 1, # $self->{insertion_mode} eq 'in row'
4212                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4213                ## Clear back to table context                if ($self->{insertion_mode} eq 'in row') {
4214                while ($self->{open_elements}->[-1]->[1] ne 'table' and                  ## As if </tr>
4215                       $self->{open_elements}->[-1]->[1] ne 'html') {                  ## have an element in table scope
4216                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  my $i;
4217                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4218                      my $node = $self->{open_elements}->[$_];
4219                      if ($node->[1] eq 'tr') {
4220                        $i = $_;
4221                        last INSCOPE;
4222                      } elsif ({
4223                                table => 1, html => 1,
4224                               }->{$node->[1]}) {
4225                        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                    }
4251                  }
4252    
4253                  if ($self->{insertion_mode} eq 'in table body') {
4254                    ## have an element in table scope
4255                    my $i;
4256                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4257                      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                !!!insert-element ($token->{tag_name} eq 'col' ? 'colgroup' : 'tbody');                if ($token->{tag_name} eq 'col') {
4297                $self->{insertion_mode} = $token->{tag_name} eq 'col'                  ## Clear back to table context
4298                  ? 'in column group' : 'in table body';                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4299                ## reprocess                         $self->{open_elements}->[-1]->[1] ne 'html') {
4300                redo B;                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4301                      pop @{$self->{open_elements}};
4302                    }
4303                    
4304                    !!!insert-element ('colgroup');
4305                    $self->{insertion_mode} = 'in column group';
4306                    ## 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: There are code clones for this "table in table"                ## NOTE: There are code clones for this "table in table"
4338                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
# Line 4124  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 ($token->{tag_name} eq 'table') {              if ($token->{tag_name} eq 'tr' and
4390                ## have a table element in table scope                  $self->{insertion_mode} eq 'in row') {
4391                  ## 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}}) {
4394                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
# Line 4144  sub _tree_construction_main ($) { Line 4407  sub _tree_construction_main ($) {
4407                  !!!next-token;                  !!!next-token;
4408                  redo B;                  redo B;
4409                }                }
                 
               ## 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;  
               }  
4410    
4411                if ($self->{open_elements}->[-1]->[1] ne 'table') {                ## Clear back to table row context
4412                  while (not {
4413                    tr => 1, html => 1,
4414                  }->{$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}};
4417                }                }
4418    
4419                splice @{$self->{open_elements}}, $i;                pop @{$self->{open_elements}}; # tr
4420                  $self->{insertion_mode} = 'in table body';
               $self->_reset_insertion_mode;  
   
               !!!next-token;  
               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 {  
               #  
             }  
           } else {  
             #  
           }  
   
           !!!parse-error (type => 'in table:'.$token->{tag_name});  
           $in_body->($insert_to_foster);  
           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');  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               } else {  
                 pop @{$self->{open_elements}}; # colgroup  
                 $self->{insertion_mode} = 'in table';  
                 !!!next-token;  
                 redo B;              
               }  
             } elsif ($token->{tag_name} eq 'col') {  
               !!!parse-error (type => 'unmatched end tag:col');  
               ## Ignore the token  
4421                !!!next-token;                !!!next-token;
4422                redo B;                redo B;
4423              } else {              } elsif ($token->{tag_name} eq 'table') {
4424                #                if ($self->{insertion_mode} eq 'in row') {
4425              }                  ## As if </tr>
4426            } else {                  ## have an element in table scope
4427              #                  my $i;
4428            }                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4429                      my $node = $self->{open_elements}->[$_];
4430            ## As if </colgroup>                    if ($node->[1] eq 'tr') {
4431            if ($self->{open_elements}->[-1]->[1] eq 'html') {                      $i = $_;
4432              !!!parse-error (type => 'unmatched end tag:colgroup');                      last INSCOPE;
4433              ## Ignore the token                    } elsif ({
4434              !!!next-token;                              table => 1, html => 1,
4435              redo B;                             }->{$node->[1]}) {
4436            } else {                      last INSCOPE;
             pop @{$self->{open_elements}}; # colgroup  
             $self->{insertion_mode} = 'in table';  
             ## reprocess  
             redo B;  
           }  
         } elsif ($self->{insertion_mode} eq 'in table body') {  
           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,  
                 }->{$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;  
4437                    }                    }
4438                    last OE;                  } # INSCOPE
4439                    unless (defined $i) {
4440                      !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4441                      ## Ignore the token
4442                      !!!next-token;
4443                      redo B;
4444                  }                  }
4445                } # OE                  
4446                $foster_parent_element = $self->{open_elements}->[0]->[0] and                  ## Clear back to table row context
4447                $prev_sibling = $foster_parent_element->last_child                  while (not {
4448                  unless defined $foster_parent_element;                    tr => 1, html => 1,
4449                if (defined $prev_sibling and                  }->{$self->{open_elements}->[-1]->[1]}) {
4450                    $prev_sibling->node_type == 3) {                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4451                  $prev_sibling->manakai_append_text ($token->{data});                    pop @{$self->{open_elements}};
               } 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 ({  
                  tr => 1,  
                  th => 1, td => 1,  
                 }->{$token->{tag_name}}) {  
               unless ($token->{tag_name} eq 'tr') {  
                 !!!parse-error (type => 'missing start tag:tr');  
               }  
   
               ## Clear back to table body context  
               while (not {  
                 tbody => 1, tfoot => 1, thead => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
                 
               $self->{insertion_mode} = 'in row';  
               if ($token->{tag_name} eq 'tr') {  
                 !!!insert-element ($token->{tag_name}, $token->{attributes});  
                 !!!next-token;  
               } else {  
                 !!!insert-element ('tr');  
                 ## reprocess  
               }  
               redo B;  
             } elsif ({  
                       caption => 1, col => 1, colgroup => 1,  
                       tbody => 1, tfoot => 1, thead => 1,  
                      }->{$token->{tag_name}}) {  
               ## have an element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ({  
                      tbody => 1, thead => 1, tfoot => 1,  
                     }->{$node->[1]}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
4452                  }                  }
4453                } # INSCOPE                  
4454                unless (defined $i) {                  pop @{$self->{open_elements}}; # tr
4455                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  $self->{insertion_mode} = 'in table body';
4456                  ## Ignore the token                  ## reprocess in the "in table body" insertion mode...
                 !!!next-token;  
                 redo B;  
4457                }                }
4458    
4459                ## Clear back to table body context                if ($self->{insertion_mode} eq 'in table body') {
4460                while (not {                  ## have an element in table scope
4461                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  my $i;
4462                }->{$self->{open_elements}->[-1]->[1]}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4463                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    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                    } # 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                    
4490                    ## As if <{current node}>
4491                    ## have an element in table scope
4492                    ## true by definition
4493                    
4494                    ## Clear back to table body context
4495                    ## nop by definition
4496                    
4497                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4498                    $self->{insertion_mode} = 'in table';
4499                    ## reprocess in the "in table" insertion mode...
4500                }                }
4501    
               ## 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 ($token->{tag_name} eq 'table') {  
               ## NOTE: This is a code clone of "table in table"  
               !!!parse-error (type => 'not closed:table');  
   
               ## As if </table>  
4502                ## have a table element in table scope                ## have a table 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 'table') {                  if ($node->[1] eq $token->{tag_name}) {
4507                    $i = $_;                    $i = $_;
4508                    last INSCOPE;                    last INSCOPE;
4509                  } elsif ({                  } elsif ({
# Line 4392  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 => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4517                  ## Ignore tokens </table><table>                  ## Ignore the token
4518                  !!!next-token;                  !!!next-token;
4519                  redo B;                  redo B;
4520                }                }
4521                  
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                  
4542                ## reprocess                !!!next-token;
4543                redo B;                redo B;
4544              } else {              } elsif ({
4545                #                        tbody => 1, tfoot => 1, thead => 1,
4546              }                       }->{$token->{tag_name}} and
4547            } elsif ($token->{type} eq 'end tag') {                       ($self->{insertion_mode} eq 'in row' or
4548              if ({                        $self->{insertion_mode} eq 'in table body')) {
4549                   tbody => 1, tfoot => 1, thead => 1,                if ($self->{insertion_mode} eq 'in row') {
4550                  }->{$token->{tag_name}}) {                  ## have an element in table scope
4551                ## have an element in table scope                  my $i;
4552                my $i;                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4553                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                    my $node = $self->{open_elements}->[$_];
4554                  my $node = $self->{open_elements}->[$_];                    if ($node->[1] eq $token->{tag_name}) {
4555                  if ($node->[1] eq $token->{tag_name}) {                      $i = $_;
4556                    $i = $_;                      last INSCOPE;
4557                    last INSCOPE;                    } elsif ({
4558                  } elsif ({                              table => 1, html => 1,
4559                            table => 1, html => 1,                             }->{$node->[1]}) {
4560                           }->{$node->[1]}) {                      last INSCOPE;
4561                    last INSCOPE;                    }
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;  
               }  
   
               ## Clear back to table body context  
               while (not {  
                 tbody => 1, tfoot => 1, thead => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
4602                }                }
4603    
               pop @{$self->{open_elements}};  
               $self->{insertion_mode} = 'in table';  
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'table') {  
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 ({                  if ($node->[1] eq $token->{tag_name}) {
                      tbody => 1, thead => 1, tfoot => 1,  
                     }->{$node->[1]}) {  
4609                    $i = $_;                    $i = $_;
4610                    last INSCOPE;                    last INSCOPE;
4611                  } elsif ({                  } elsif ({
# Line 4492  sub _tree_construction_main ($) { Line 4629  sub _tree_construction_main ($) {
4629                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4630                }                }
4631    
               ## As if <{current node}>  
               ## have an element in table scope  
               ## true by definition  
   
               ## Clear back to table body context  
               ## nop by definition  
   
4632                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4633                $self->{insertion_mode} = 'in table';                $self->{insertion_mode} = 'in table';
4634                ## reprocess                !!!next-token;
4635                redo B;                redo B;
4636              } elsif ({              } elsif ({
4637                        body => 1, caption => 1, col => 1, colgroup => 1,                        body => 1, caption => 1, col => 1, colgroup => 1,
4638                        html => 1, td => 1, th => 1, tr => 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 4515  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 row') {          } elsif ($self->{insertion_mode} eq 'in column group') {
4657            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
             ## NOTE: This is a "character in table" code clone.  
4658              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4659                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
                 
4660                unless (length $token->{data}) {                unless (length $token->{data}) {
4661                  !!!next-token;                  !!!next-token;
4662                  redo B;                  redo B;
4663                }                }
4664              }              }
   
             !!!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);  
4665                            
4666              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});  
               } 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;  
4667            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4668              if ($token->{tag_name} eq 'th' or              if ($token->{tag_name} eq 'col') {
                 $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]);  
                 pop @{$self->{open_elements}};  
               }  
                 
4669                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4670                $self->{insertion_mode} = 'in cell';                pop @{$self->{open_elements}};
   
               push @$active_formatting_elements, ['#marker', ''];  
                 
4671                !!!next-token;                !!!next-token;
4672                redo B;                redo B;
4673              } elsif ({              } else {
                       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  
               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 => 'unmacthed 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';  
               ## 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;  
               }  
                 
               ## 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; # <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 {  
4674                #                #
4675              }              }
4676            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
4677              if ($token->{tag_name} eq 'tr') {              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});  
                 ## 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';  
               !!!next-token;  
               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;  
             } elsif ({  
                       tbody => 1, tfoot => 1, thead => 1,  
                      }->{$token->{tag_name}}) {  
               ## 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});  
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                ## As if </tr>                  $self->{insertion_mode} = 'in table';
               ## 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:tr');  
                 ## Ignore the token  
4686                  !!!next-token;                  !!!next-token;
4687                  redo B;                  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}};  
4688                }                }
4689                } elsif ($token->{tag_name} eq 'col') {
4690                pop @{$self->{open_elements}}; # tr                !!!parse-error (type => 'unmatched end tag:col');
               $self->{insertion_mode} = 'in table body';  
               ## reprocess  
               redo B;  
             } elsif ({  
                       body => 1, caption => 1, col => 1,  
                       colgroup => 1, html => 1, td => 1, th => 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;
4694              } else {              } else {
4695                #                #
4696              }              }
4697            } else {            } else {
4698              #              #
4699            }            }
4700    
4701            ## As if in table            ## As if </colgroup>
4702            !!!parse-error (type => 'in table:'.$token->{tag_name});            if ($self->{open_elements}->[-1]->[1] eq 'html') {
4703            $in_body->($insert_to_foster);              !!!parse-error (type => 'unmatched end tag:colgroup');
4704            redo B;              ## 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});

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24