/[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.84 by wakaba, Thu Mar 6 15:23:17 2008 UTC revision 1.100 by wakaba, Sun Mar 9 04:08:41 2008 UTC
# Line 2743  sub _reset_insertion_mode ($) { Line 2743  sub _reset_insertion_mode ($) {
2743            
2744      ## Step 3      ## Step 3
2745      S3: {      S3: {
       ## ISSUE: Oops! "If node is the first node in the stack of open  
       ## elements, then set last to true. If the context element of the  
       ## HTML fragment parsing algorithm is neither a td element nor a  
       ## th element, then set node to the context element. (fragment case)":  
       ## The second "if" is in the scope of the first "if"!?  
2746        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
2747          $last = 1;          $last = 1;
2748          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
# Line 2908  sub _tree_construction_main ($) { Line 2903  sub _tree_construction_main ($) {
2903      !!!cp ('t39');      !!!cp ('t39');
2904    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2905    
2906    my $parse_rcdata = sub ($$) {    my $insert;
2907      my ($content_model_flag, $insert) = @_;  
2908      my $parse_rcdata = sub ($) {
2909        my ($content_model_flag) = @_;
2910    
2911      ## Step 1      ## Step 1
2912      my $start_tag_name = $token->{tag_name};      my $start_tag_name = $token->{tag_name};
# Line 2917  sub _tree_construction_main ($) { Line 2914  sub _tree_construction_main ($) {
2914      !!!create-element ($el, $start_tag_name, $token->{attributes});      !!!create-element ($el, $start_tag_name, $token->{attributes});
2915    
2916      ## Step 2      ## Step 2
2917      $insert->($el); # /context node/->append_child ($el)      $insert->($el);
2918    
2919      ## Step 3      ## Step 3
2920      $self->{content_model} = $content_model_flag; # CDATA or RCDATA      $self->{content_model} = $content_model_flag; # CDATA or RCDATA
# Line 2947  sub _tree_construction_main ($) { Line 2944  sub _tree_construction_main ($) {
2944          $token->{tag_name} eq $start_tag_name) {          $token->{tag_name} eq $start_tag_name) {
2945        !!!cp ('t42');        !!!cp ('t42');
2946        ## Ignore the token        ## Ignore the token
     } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {  
       !!!cp ('t43');  
       !!!parse-error (type => 'in CDATA:#'.$token->{type});  
     } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {  
       !!!cp ('t44');  
       !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
2947      } else {      } else {
2948        die "$0: $content_model_flag in parse_rcdata";        ## NOTE: An end-of-file token.
2949          if ($content_model_flag == CDATA_CONTENT_MODEL) {
2950            !!!cp ('t43');
2951            !!!parse-error (type => 'in CDATA:#'.$token->{type});
2952          } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2953            !!!cp ('t44');
2954            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2955          } else {
2956            die "$0: $content_model_flag in parse_rcdata";
2957          }
2958      }      }
2959      !!!next-token;      !!!next-token;
2960    }; # $parse_rcdata    }; # $parse_rcdata
2961    
2962    my $script_start_tag = sub ($) {    my $script_start_tag = sub () {
     my $insert = $_[0];  
2963      my $script_el;      my $script_el;
2964      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2965      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
# Line 3213  sub _tree_construction_main ($) { Line 3212  sub _tree_construction_main ($) {
3212      } # FET      } # FET
3213    }; # $formatting_end_tag    }; # $formatting_end_tag
3214    
3215    my $insert_to_current = sub {    ## NOTE: $open_tables->[-1]->[0] is the "current table".
3216      ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.
3217      my $open_tables = [[$self->{open_elements}->[0]->[0]]];
3218    
3219      $insert = my $insert_to_current = sub {
3220      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
3221    }; # $insert_to_current    }; # $insert_to_current
3222    
3223    my $insert_to_foster = sub {    my $insert_to_foster = sub {
3224                         my $child = shift;      my $child = shift;
3225                         if ({      if ({
3226                              table => 1, tbody => 1, tfoot => 1,           table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3227                              thead => 1, tr => 1,          }->{$self->{open_elements}->[-1]->[1]}) {
3228                             }->{$self->{open_elements}->[-1]->[1]}) {        # MUST
3229                           # MUST        my $foster_parent_element;
3230                           my $foster_parent_element;        my $next_sibling;
                          my $next_sibling;  
3231                           OE: for (reverse 0..$#{$self->{open_elements}}) {                           OE: for (reverse 0..$#{$self->{open_elements}}) {
3232                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3233                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
# Line 3245  sub _tree_construction_main ($) { Line 3247  sub _tree_construction_main ($) {
3247                             unless defined $foster_parent_element;                             unless defined $foster_parent_element;
3248                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3249                             ($child, $next_sibling);                             ($child, $next_sibling);
3250                         } else {        $open_tables->[-1]->[1] = 1; # tainted
3251                           !!!cp ('t72');      } else {
3252                           $self->{open_elements}->[-1]->[0]->append_child ($child);        !!!cp ('t72');
3253                         }        $self->{open_elements}->[-1]->[0]->append_child ($child);
3254        }
3255    }; # $insert_to_foster    }; # $insert_to_foster
3256    
   my $insert;  
   
3257    B: {    B: {
3258      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3259        !!!cp ('t73');        !!!cp ('t73');
# Line 3267  sub _tree_construction_main ($) { Line 3268  sub _tree_construction_main ($) {
3268          #          #
3269        } else {        } else {
3270          ## Generate implied end tags          ## Generate implied end tags
3271          if ({          while ({
3272               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,                  dd => 1, dt => 1, li => 1, p => 1,
3273               tbody => 1, tfoot=> 1, thead => 1,                 }->{$self->{open_elements}->[-1]->[1]}) {
             }->{$self->{open_elements}->[-1]->[1]}) {  
3274            !!!cp ('t75');            !!!cp ('t75');
3275            !!!back-token;            pop @{$self->{open_elements}};
           $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};  
           redo B;  
3276          }          }
3277                    
3278          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
# Line 3340  sub _tree_construction_main ($) { Line 3338  sub _tree_construction_main ($) {
3338      } elsif ($self->{insertion_mode} & HEAD_IMS) {      } elsif ($self->{insertion_mode} & HEAD_IMS) {
3339        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
3340          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3341            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3342                !!!cp ('t88.2');
3343                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3344              } else {
3345                !!!cp ('t88.1');
3346                ## Ignore the token.
3347                !!!next-token;
3348                redo B;
3349              }
3350            unless (length $token->{data}) {            unless (length $token->{data}) {
3351              !!!cp ('t88');              !!!cp ('t88');
3352              !!!next-token;              !!!next-token;
# Line 3441  sub _tree_construction_main ($) { Line 3447  sub _tree_construction_main ($) {
3447                }                }
3448                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3449                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3450                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3451                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3452                !!!next-token;                !!!next-token;
3453                redo B;                redo B;
# Line 3456  sub _tree_construction_main ($) { Line 3462  sub _tree_construction_main ($) {
3462                }                }
3463                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3464                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3465                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3466                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3467                !!!next-token;                !!!next-token;
3468                redo B;                redo B;
# Line 3517  sub _tree_construction_main ($) { Line 3523  sub _tree_construction_main ($) {
3523                  }                  }
3524                }                }
3525    
3526                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3527                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3528                !!!next-token;                !!!next-token;
3529                redo B;                redo B;
# Line 3541  sub _tree_construction_main ($) { Line 3547  sub _tree_construction_main ($) {
3547                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3548                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3549                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3550                $parse_rcdata->(RCDATA_CONTENT_MODEL,                $parse_rcdata->(RCDATA_CONTENT_MODEL);
3551                                sub { $parent->append_child ($_[0]) });                pop @{$self->{open_elements}} # <head>
               pop @{$self->{open_elements}}  
3552                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3553                redo B;                redo B;
3554              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style') {
# Line 3557  sub _tree_construction_main ($) { Line 3562  sub _tree_construction_main ($) {
3562                } else {                } else {
3563                  !!!cp ('t115');                  !!!cp ('t115');
3564                }                }
3565                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL);
3566                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3567                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3568                redo B;                redo B;
3569              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
# Line 3597  sub _tree_construction_main ($) { Line 3602  sub _tree_construction_main ($) {
3602                }                }
3603    
3604                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3605                $script_start_tag->($insert_to_current);                $script_start_tag->();
3606                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3607                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3608                redo B;                redo B;
3609              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
# Line 3886  sub _tree_construction_main ($) { Line 3891  sub _tree_construction_main ($) {
3891                    }                    }
3892                                    
3893                  ## generate implied end tags                  ## generate implied end tags
3894                  if ({                  while ({
3895                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3896                           }->{$self->{open_elements}->[-1]->[1]}) {
                      ## NOTE: Maybe the following elements never appear here.  
                      td => 1, th => 1, tr => 1,  
                      tbody => 1, tfoot => 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
3897                    !!!cp ('t158');                    !!!cp ('t158');
3898                    !!!back-token; # <?>                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN, tag_name => 'caption'};  
                   !!!back-token;  
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
3899                  }                  }
3900    
3901                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 3952  sub _tree_construction_main ($) { Line 3948  sub _tree_construction_main ($) {
3948                    }                    }
3949                                    
3950                  ## generate implied end tags                  ## generate implied end tags
3951                  if ({                  while ({
3952                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3953                       td => ($token->{tag_name} eq 'th'),                         }->{$self->{open_elements}->[-1]->[1]}) {
                      th => ($token->{tag_name} eq 'td'),  
   
                      ## NOTE: Maybe the following elements never appear here.  
                      tr => 1,  
                      tbody => 1, tfoot => 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
3954                    !!!cp ('t166');                    !!!cp ('t166');
3955                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
3956                  }                  }
3957                    
3958                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3959                    !!!cp ('t167');                    !!!cp ('t167');
3960                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
# Line 4019  sub _tree_construction_main ($) { Line 4006  sub _tree_construction_main ($) {
4006                    }                    }
4007                                    
4008                  ## generate implied end tags                  ## generate implied end tags
4009                  if ({                  while ({
4010                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4011                           }->{$self->{open_elements}->[-1]->[1]}) {
                      ## NOTE: The following elements never appear here, maybe.  
                      td => 1, th => 1, tr => 1,  
                      tbody => 1, tfoot => 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
4012                    !!!cp ('t174');                    !!!cp ('t174');
4013                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4014                  }                  }
4015                                    
4016                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4127  sub _tree_construction_main ($) { Line 4107  sub _tree_construction_main ($) {
4107                }                }
4108                                
4109                ## generate implied end tags                ## generate implied end tags
4110                if ({                while ({
4111                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4112                         }->{$self->{open_elements}->[-1]->[1]}) {
                    ## NOTE: The following elements never appear, maybe.  
                    td => 1, th => 1, tr => 1,  
                    tbody => 1, tfoot => 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4113                  !!!cp ('t187');                  !!!cp ('t187');
4114                  !!!back-token; # </table>                  pop @{$self->{open_elements}};
                 $token = {type => END_TAG_TOKEN, tag_name => 'caption'};  
                 !!!back-token;  
                 $token = {type => END_TAG_TOKEN,  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
4115                }                }
4116    
4117                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4193  sub _tree_construction_main ($) { Line 4164  sub _tree_construction_main ($) {
4164        #        #
4165      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
4166        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4167              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if (not $open_tables->[-1]->[1] and # tainted
4168                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4169              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4170                                
4171                unless (length $token->{data}) {            unless (length $token->{data}) {
4172                  !!!cp ('t194');              !!!cp ('t194');
4173                  !!!next-token;              !!!next-token;
4174                  redo B;              redo B;
4175                } else {            } else {
4176                  !!!cp ('t195');              !!!cp ('t195');
4177                }            }
4178              }          }
4179    
4180              !!!parse-error (type => 'in table:#character');              !!!parse-error (type => 'in table:#character');
4181    
# Line 4250  sub _tree_construction_main ($) { Line 4222  sub _tree_construction_main ($) {
4222                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4223                     $next_sibling);                     $next_sibling);
4224                }                }
4225              } else {            $open_tables->[-1]->[1] = 1; # tainted
4226                !!!cp ('t200');          } else {
4227                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});            !!!cp ('t200');
4228              }            $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4229            }
4230                            
4231              !!!next-token;          !!!next-token;
4232              redo B;          redo B;
4233        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4234              if ({              if ({
4235                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
# Line 4267  sub _tree_construction_main ($) { Line 4240  sub _tree_construction_main ($) {
4240                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4241                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4242                    !!!cp ('t201');                    !!!cp ('t201');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4243                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4244                  }                  }
4245                                    
# Line 4288  sub _tree_construction_main ($) { Line 4260  sub _tree_construction_main ($) {
4260                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4261                    !!!cp ('t203');                    !!!cp ('t203');
4262                    ## ISSUE: Can this case be reached?                    ## ISSUE: Can this case be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4263                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4264                  }                  }
4265                                    
# Line 4312  sub _tree_construction_main ($) { Line 4283  sub _tree_construction_main ($) {
4283                  tr => 1, html => 1,                  tr => 1, html => 1,
4284                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4285                  !!!cp ('t207');                  !!!cp ('t207');
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4286                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4287                }                }
4288                                
# Line 4363  sub _tree_construction_main ($) { Line 4333  sub _tree_construction_main ($) {
4333                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4334                    !!!cp ('t211');                    !!!cp ('t211');
4335                    ## ISSUE: Can this case be reached?                    ## ISSUE: Can this case be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4336                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4337                  }                  }
4338                                    
# Line 4412  sub _tree_construction_main ($) { Line 4381  sub _tree_construction_main ($) {
4381                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4382                    !!!cp ('t217');                    !!!cp ('t217');
4383                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4384                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4385                  }                  }
4386                                    
# Line 4436  sub _tree_construction_main ($) { Line 4404  sub _tree_construction_main ($) {
4404                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4405                    !!!cp ('t219');                    !!!cp ('t219');
4406                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4407                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4408                  }                  }
4409                                    
# Line 4454  sub _tree_construction_main ($) { Line 4421  sub _tree_construction_main ($) {
4421                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4422                    !!!cp ('t220');                    !!!cp ('t220');
4423                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4424                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4425                  }                  }
4426                                    
# Line 4504  sub _tree_construction_main ($) { Line 4470  sub _tree_construction_main ($) {
4470                }                }
4471                                
4472                ## generate implied end tags                ## generate implied end tags
4473                if ({                while ({
4474                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4475                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4476                  !!!cp ('t224');                  !!!cp ('t224');
4477                  !!!back-token; # <table>                  pop @{$self->{open_elements}};
                 $token = {type => END_TAG_TOKEN, tag_name => 'table'};  
                 !!!back-token;  
                 $token = {type => END_TAG_TOKEN,  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
4478                }                }
4479    
4480                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
# Line 4527  sub _tree_construction_main ($) { Line 4486  sub _tree_construction_main ($) {
4486                }                }
4487    
4488                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4489                  pop @{$open_tables};
4490    
4491                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4492    
4493                ## reprocess                ## reprocess
4494                redo B;                redo B;
4495            } elsif ($token->{tag_name} eq 'style') {
4496              if (not $open_tables->[-1]->[1]) { # tainted
4497                !!!cp ('t227.8');
4498                ## NOTE: This is a "as if in head" code clone.
4499                $parse_rcdata->(CDATA_CONTENT_MODEL);
4500                redo B;
4501              } else {
4502                !!!cp ('t227.7');
4503                #
4504              }
4505            } elsif ($token->{tag_name} eq 'script') {
4506              if (not $open_tables->[-1]->[1]) { # tainted
4507                !!!cp ('t227.6');
4508                ## NOTE: This is a "as if in head" code clone.
4509                $script_start_tag->();
4510                redo B;
4511              } else {
4512                !!!cp ('t227.5');
4513                #
4514              }
4515            } elsif ($token->{tag_name} eq 'input') {
4516              if (not $open_tables->[-1]->[1]) { # tainted
4517                if ($token->{attributes}->{type}) { ## TODO: case
4518                  my $type = lc $token->{attributes}->{type}->{value};
4519                  if ($type eq 'hidden') {
4520                    !!!cp ('t227.3');
4521                    !!!parse-error (type => 'in table:'.$token->{tag_name});
4522    
4523                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4524    
4525                    ## TODO: form element pointer
4526    
4527                    pop @{$self->{open_elements}};
4528    
4529                    !!!next-token;
4530                    redo B;
4531                  } else {
4532                    !!!cp ('t227.2');
4533                    #
4534                  }
4535                } else {
4536                  !!!cp ('t227.1');
4537                  #
4538                }
4539              } else {
4540                !!!cp ('t227.4');
4541                #
4542              }
4543          } else {          } else {
4544            !!!cp ('t227');            !!!cp ('t227');
           !!!parse-error (type => 'in table:'.$token->{tag_name});  
   
           $insert = $insert_to_foster;  
4545            #            #
4546          }          }
4547    
4548            !!!parse-error (type => 'in table:'.$token->{tag_name});
4549    
4550            $insert = $insert_to_foster;
4551            #
4552        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
4553              if ($token->{tag_name} eq 'tr' and              if ($token->{tag_name} eq 'tr' and
4554                  $self->{insertion_mode} == IN_ROW_IM) {                  $self->{insertion_mode} == IN_ROW_IM) {
# Line 4573  sub _tree_construction_main ($) { Line 4583  sub _tree_construction_main ($) {
4583                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4584                  !!!cp ('t231');                  !!!cp ('t231');
4585  ## ISSUE: Can this state be reached?  ## ISSUE: Can this state be reached?
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4586                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4587                }                }
4588    
# Line 4614  sub _tree_construction_main ($) { Line 4623  sub _tree_construction_main ($) {
4623                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4624                    !!!cp ('t236');                    !!!cp ('t236');
4625  ## ISSUE: Can this state be reached?  ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4626                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4627                  }                  }
4628                                    
# Line 4654  sub _tree_construction_main ($) { Line 4662  sub _tree_construction_main ($) {
4662                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4663                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4664                    !!!cp ('t240');                    !!!cp ('t240');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4665                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4666                  }                  }
4667                                    
# Line 4670  sub _tree_construction_main ($) { Line 4677  sub _tree_construction_main ($) {
4677                  ## reprocess in the "in table" insertion mode...                  ## reprocess in the "in table" insertion mode...
4678                }                }
4679    
4680                  ## NOTE: </table> in the "in table" insertion mode.
4681                  ## When you edit the code fragment below, please ensure that
4682                  ## the code for <table> in the "in table" insertion mode
4683                  ## is synced with it.
4684    
4685                ## have a table element in table scope                ## have a table element in table scope
4686                my $i;                my $i;
4687                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 4692  sub _tree_construction_main ($) { Line 4704  sub _tree_construction_main ($) {
4704                  !!!next-token;                  !!!next-token;
4705                  redo B;                  redo B;
4706                }                }
   
               ## 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]}) {  
                 !!!cp ('t244');  
 ## ISSUE: Can this case be reached?  
                 !!!back-token;  
                 $token = {type => END_TAG_TOKEN,  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
                 
               if ($self->{open_elements}->[-1]->[1] ne 'table') {  
                 !!!cp ('t245');  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               } else {  
                 !!!cp ('t246');  
               }  
4707                                    
4708                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4709                  pop @{$open_tables};
4710                                
4711                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4712                                
# Line 4778  sub _tree_construction_main ($) { Line 4770  sub _tree_construction_main ($) {
4770                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4771                    !!!cp ('t253');                    !!!cp ('t253');
4772  ## ISSUE: Can this case be reached?  ## ISSUE: Can this case be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4773                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4774                  }                  }
4775                                    
# Line 4816  sub _tree_construction_main ($) { Line 4807  sub _tree_construction_main ($) {
4807                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4808                  !!!cp ('t257');                  !!!cp ('t257');
4809  ## ISSUE: Can this case be reached?  ## ISSUE: Can this case be reached?
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4810                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4811                }                }
4812    
# Line 5273  sub _tree_construction_main ($) { Line 5263  sub _tree_construction_main ($) {
5263          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5264            !!!cp ('t320');            !!!cp ('t320');
5265            ## NOTE: As if in body.            ## NOTE: As if in body.
5266            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL);
5267            redo B;            redo B;
5268          } else {          } else {
5269            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
# Line 5352  sub _tree_construction_main ($) { Line 5342  sub _tree_construction_main ($) {
5342        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5343          !!!cp ('t332');          !!!cp ('t332');
5344          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5345          $script_start_tag->($insert);          $script_start_tag->();
5346          redo B;          redo B;
5347        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5348          !!!cp ('t333');          !!!cp ('t333');
5349          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5350          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5351          redo B;          redo B;
5352        } elsif ({        } elsif ({
5353                  base => 1, link => 1,                  base => 1, link => 1,
# Line 5420  sub _tree_construction_main ($) { Line 5410  sub _tree_construction_main ($) {
5410          redo B;          redo B;
5411        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5412          !!!cp ('t341');          !!!cp ('t341');
         !!!parse-error (type => 'in body:title');  
5413          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5414          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {          $parse_rcdata->(RCDATA_CONTENT_MODEL);
           if (defined $self->{head_element}) {  
             !!!cp ('t339');  
             $self->{head_element}->append_child ($_[0]);  
           } else {  
             !!!cp ('t340');  
             $insert->($_[0]);  
           }  
         });  
5415          redo B;          redo B;
5416        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
5417          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 5454  sub _tree_construction_main ($) { Line 5435  sub _tree_construction_main ($) {
5435          redo B;          redo B;
5436        } elsif ({        } elsif ({
5437                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5438                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1,
5439                    h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5440                  menu => 1, ol => 1, p => 1, ul => 1,                  menu => 1, ol => 1, p => 1, ul => 1,
5441                  pre => 1,                  pre => 1, listing => 1,
5442                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5443          ## has a p element in scope          ## has a p element in scope
5444          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
# Line 5475  sub _tree_construction_main ($) { Line 5457  sub _tree_construction_main ($) {
5457          } # INSCOPE          } # INSCOPE
5458                        
5459          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5460          if ($token->{tag_name} eq 'pre') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
5461            !!!next-token;            !!!next-token;
5462            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
5463              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
# Line 5657  sub _tree_construction_main ($) { Line 5639  sub _tree_construction_main ($) {
5639                        
5640          !!!next-token;          !!!next-token;
5641          redo B;          redo B;
       } elsif ({  
                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
                }->{$token->{tag_name}}) {  
         ## has a p element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'p') {  
             !!!cp ('t369');  
             !!!back-token;  
             $token = {type => END_TAG_TOKEN, tag_name => 'p'};  
             redo B;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             !!!cp ('t370');  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>  
         ## has an element in scope  
         #my $i;  
         #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
         #  my $node = $self->{open_elements}->[$_];  
         #  if ({  
         #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
         #      }->{$node->[1]}) {  
         #    $i = $_;  
         #    last INSCOPE;  
         #  } elsif ({  
         #            table => 1, caption => 1, td => 1, th => 1,  
         #            button => 1, marquee => 1, object => 1, html => 1,  
         #           }->{$node->[1]}) {  
         #    last INSCOPE;  
         #  }  
         #} # INSCOPE  
         #    
         #if (defined $i) {  
         #  !!! parse-error (type => 'in hn:hn');  
         #  splice @{$self->{open_elements}}, $i;  
         #}  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         !!!next-token;  
         redo B;  
5642        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
5643          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5644            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
# Line 5804  sub _tree_construction_main ($) { Line 5739  sub _tree_construction_main ($) {
5739          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5740                        
5741          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5742    
5743            ## TODO: associate with $self->{form_element} if defined
5744    
5745          push @$active_formatting_elements, ['#marker', ''];          push @$active_formatting_elements, ['#marker', ''];
5746    
5747          !!!next-token;          !!!next-token;
# Line 5821  sub _tree_construction_main ($) { Line 5759  sub _tree_construction_main ($) {
5759        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5760          !!!cp ('t381');          !!!cp ('t381');
5761          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5762          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5763          redo B;          redo B;
5764        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
5765          ## has a p element in scope          ## has a p element in scope
# Line 5841  sub _tree_construction_main ($) { Line 5779  sub _tree_construction_main ($) {
5779          } # INSCOPE          } # INSCOPE
5780                        
5781          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5782                      push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];
5783    
5784          $self->{insertion_mode} = IN_TABLE_IM;          $self->{insertion_mode} = IN_TABLE_IM;
5785                        
5786          !!!next-token;          !!!next-token;
# Line 5996  sub _tree_construction_main ($) { Line 5935  sub _tree_construction_main ($) {
5935                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5936          !!!cp ('t399');          !!!cp ('t399');
5937          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
5938          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5939          redo B;          redo B;
5940        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
5941          !!!cp ('t400');          !!!cp ('t400');
5942          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5943                    
5944          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5945    
5946            ## TODO: associate with $self->{form_element} if defined
5947                    
5948          $self->{insertion_mode} = IN_SELECT_IM;          $self->{insertion_mode} = IN_SELECT_IM;
5949          !!!next-token;          !!!next-token;
# Line 6079  sub _tree_construction_main ($) { Line 6020  sub _tree_construction_main ($) {
6020                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
6021                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
6022                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 p => 1,  
6023                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
6024                  button => 1, marquee => 1, object => 1,                  button => 1, marquee => 1, object => 1,
6025                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 6088  sub _tree_construction_main ($) { Line 6028  sub _tree_construction_main ($) {
6028          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6029            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6030            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
             ## generate implied end tags  
             if ({  
                  dd => ($token->{tag_name} ne 'dd'),  
                  dt => ($token->{tag_name} ne 'dt'),  
                  li => ($token->{tag_name} ne 'li'),  
                  p => ($token->{tag_name} ne 'p'),  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!cp ('t409');  
               !!!back-token;  
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
             }  
               
6031              !!!cp ('t410');              !!!cp ('t410');
6032              $i = $_;              $i = $_;
6033              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE;
6034            } elsif ({            } elsif ({
6035                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6036                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
# Line 6115  sub _tree_construction_main ($) { Line 6039  sub _tree_construction_main ($) {
6039              last INSCOPE;              last INSCOPE;
6040            }            }
6041          } # INSCOPE          } # INSCOPE
6042            
6043          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6044            if (defined $i) {            !!!cp ('t413');
6045              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6046            } else {
6047              ## Step 1. generate implied end tags
6048              while ({
6049                      dd => ($token->{tag_name} ne 'dd'),
6050                      dt => ($token->{tag_name} ne 'dt'),
6051                      li => ($token->{tag_name} ne 'li'),
6052                      p => 1,
6053                     }->{$self->{open_elements}->[-1]->[1]}) {
6054                !!!cp ('t409');
6055                pop @{$self->{open_elements}};
6056              }
6057    
6058              ## Step 2.
6059              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6060              !!!cp ('t412');              !!!cp ('t412');
6061              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6062            } else {            } else {
6063              !!!cp ('t413');              !!!cp ('t414');
             !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
6064            }            }
6065          }  
6066                      ## Step 3.
         if (defined $i) {  
           !!!cp ('t414');  
6067            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6068          } elsif ($token->{tag_name} eq 'p') {  
6069            !!!cp ('t415');            ## Step 4.
6070            ## As if <p>, then reprocess the current token            $clear_up_to_marker->()
6071            my $el;                if {
6072            !!!create-element ($el, 'p');                  button => 1, marquee => 1, object => 1,
6073            $insert->($el);                }->{$token->{tag_name}};
         } else {  
           !!!cp ('t416');  
6074          }          }
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
6075          !!!next-token;          !!!next-token;
6076          redo B;          redo B;
6077        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
6078            undef $self->{form_element};
6079    
6080          ## has an element in scope          ## has an element in scope
6081            my $i;
6082          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6083            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6084            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
             ## generate implied end tags  
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
   
                  ## NOTE: The following elements never appear here, maybe.  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!cp ('t417');  
               !!!back-token;  
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
             }  
               
6085              !!!cp ('t418');              !!!cp ('t418');
6086                $i = $_;
6087              last INSCOPE;              last INSCOPE;
6088            } elsif ({            } elsif ({
6089                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 6174  sub _tree_construction_main ($) { Line 6093  sub _tree_construction_main ($) {
6093              last INSCOPE;              last INSCOPE;
6094            }            }
6095          } # INSCOPE          } # INSCOPE
6096            
6097          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {          unless (defined $i) { # has an element in scope
           !!!cp ('t420');  
           pop @{$self->{open_elements}};  
         } else {  
6098            !!!cp ('t421');            !!!cp ('t421');
6099            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6100            } else {
6101              ## Step 1. generate implied end tags
6102              while ({
6103                      dd => 1, dt => 1, li => 1, p => 1,
6104                     }->{$self->{open_elements}->[-1]->[1]}) {
6105                !!!cp ('t417');
6106                pop @{$self->{open_elements}};
6107              }
6108              
6109              ## Step 2.
6110              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6111                !!!cp ('t417.1');
6112                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6113              } else {
6114                !!!cp ('t420');
6115              }  
6116              
6117              ## Step 3.
6118              splice @{$self->{open_elements}}, $i;
6119          }          }
6120    
         undef $self->{form_element};  
6121          !!!next-token;          !!!next-token;
6122          redo B;          redo B;
6123        } elsif ({        } elsif ({
# Line 6196  sub _tree_construction_main ($) { Line 6130  sub _tree_construction_main ($) {
6130            if ({            if ({
6131                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
6132                }->{$node->[1]}) {                }->{$node->[1]}) {
             ## generate implied end tags  
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!cp ('t422');  
               !!!back-token;  
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
             }  
   
6133              !!!cp ('t423');              !!!cp ('t423');
6134              $i = $_;              $i = $_;
6135              last INSCOPE;              last INSCOPE;
# Line 6220  sub _tree_construction_main ($) { Line 6141  sub _tree_construction_main ($) {
6141              last INSCOPE;              last INSCOPE;
6142            }            }
6143          } # INSCOPE          } # INSCOPE
6144            
6145          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6146            !!!cp ('t425');            !!!cp ('t425.1');
6147            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6148          } else {          } else {
6149            !!!cp ('t426');            ## Step 1. generate implied end tags
6150              while ({
6151                      dd => 1, dt => 1, li => 1, p => 1,
6152                     }->{$self->{open_elements}->[-1]->[1]}) {
6153                !!!cp ('t422');
6154                pop @{$self->{open_elements}};
6155              }
6156              
6157              ## Step 2.
6158              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6159                !!!cp ('t425');
6160                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6161              } else {
6162                !!!cp ('t426');
6163              }
6164    
6165              ## Step 3.
6166              splice @{$self->{open_elements}}, $i;
6167          }          }
6168                    
6169          splice @{$self->{open_elements}}, $i if defined $i;          !!!next-token;
6170            redo B;
6171          } elsif ($token->{tag_name} eq 'p') {
6172            ## has an element in scope
6173            my $i;
6174            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6175              my $node = $self->{open_elements}->[$_];
6176              if ($node->[1] eq $token->{tag_name}) {
6177                !!!cp ('t410.1');
6178                $i = $_;
6179                last INSCOPE;
6180              } elsif ({
6181                        table => 1, caption => 1, td => 1, th => 1,
6182                        button => 1, marquee => 1, object => 1, html => 1,
6183                       }->{$node->[1]}) {
6184                !!!cp ('t411.1');
6185                last INSCOPE;
6186              }
6187            } # INSCOPE
6188    
6189            if (defined $i) {
6190              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6191                !!!cp ('t412.1');
6192                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6193              } else {
6194                !!!cp ('t414.1');
6195              }
6196    
6197              splice @{$self->{open_elements}}, $i;
6198            } else {
6199              !!!cp ('t413.1');
6200              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6201    
6202              !!!cp ('t415.1');
6203              ## As if <p>, then reprocess the current token
6204              my $el;
6205              !!!create-element ($el, 'p');
6206              $insert->($el);
6207              ## NOTE: Not inserted into |$self->{open_elements}|.
6208            }
6209    
6210          !!!next-token;          !!!next-token;
6211          redo B;          redo B;
6212        } elsif ({        } elsif ({
# Line 6284  sub _tree_construction_main ($) { Line 6262  sub _tree_construction_main ($) {
6262            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6263              ## Step 1              ## Step 1
6264              ## generate implied end tags              ## generate implied end tags
6265              if ({              while ({
6266                   dd => 1, dt => 1, li => 1, p => 1,                      dd => 1, dt => 1, li => 1, p => 1,
6267                   td => 1, th => 1, tr => 1,                     }->{$self->{open_elements}->[-1]->[1]}) {
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
6268                !!!cp ('t430');                !!!cp ('t430');
6269                ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
6270                !!!back-token;                pop @{$self->{open_elements}};
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
6271              }              }
6272                    
6273              ## Step 2              ## Step 2

Legend:
Removed from v.1.84  
changed lines
  Added in v.1.100

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24