/[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.85 by wakaba, Thu Mar 6 15:29:39 2008 UTC revision 1.104 by wakaba, Sun Mar 9 08:47:33 2008 UTC
# Line 74  my $special_category = { Line 74  my $special_category = {
74    textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1,    textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1,
75  };  };
76  my $scoping_category = {  my $scoping_category = {
77    button => 1, caption => 1, html => 1, marquee => 1, object => 1,    applet => 1, button => 1, caption => 1, html => 1, marquee => 1, object => 1,
78    table => 1, td => 1, th => 1,    table => 1, td => 1, th => 1,
79  };  };
80  my $formatting_category = {  my $formatting_category = {
# Line 303  sub TABLE_IMS ()      { 0b1000000 } Line 303  sub TABLE_IMS ()      { 0b1000000 }
303  sub ROW_IMS ()        { 0b10000000 }  sub ROW_IMS ()        { 0b10000000 }
304  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
305  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
306    sub SELECT_IMS ()     { 0b10000000000 }
307    
308  ## NOTE: "initial" and "before html" insertion modes have no constants.  ## NOTE: "initial" and "before html" insertion modes have no constants.
309    
# Line 325  sub IN_TABLE_IM () { TABLE_IMS } Line 326  sub IN_TABLE_IM () { TABLE_IMS }
326  sub AFTER_BODY_IM () { BODY_AFTER_IMS }  sub AFTER_BODY_IM () { BODY_AFTER_IMS }
327  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }
328  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }
329  sub IN_SELECT_IM () { 0b01 }  sub IN_SELECT_IM () { SELECT_IMS | 0b01 }
330    sub IN_SELECT_IN_TABLE_IM () { SELECT_IMS | 0b10 }
331  sub IN_COLUMN_GROUP_IM () { 0b10 }  sub IN_COLUMN_GROUP_IM () { 0b10 }
332    
333  ## Implementations MUST act as if state machine in the spec  ## Implementations MUST act as if state machine in the spec
# Line 2743  sub _reset_insertion_mode ($) { Line 2745  sub _reset_insertion_mode ($) {
2745            
2746      ## Step 3      ## Step 3
2747      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"!?  
2748        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
2749          $last = 1;          $last = 1;
2750          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
# Line 2908  sub _tree_construction_main ($) { Line 2905  sub _tree_construction_main ($) {
2905      !!!cp ('t39');      !!!cp ('t39');
2906    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2907    
2908    my $parse_rcdata = sub ($$) {    my $insert;
2909      my ($content_model_flag, $insert) = @_;  
2910      my $parse_rcdata = sub ($) {
2911        my ($content_model_flag) = @_;
2912    
2913      ## Step 1      ## Step 1
2914      my $start_tag_name = $token->{tag_name};      my $start_tag_name = $token->{tag_name};
# Line 2917  sub _tree_construction_main ($) { Line 2916  sub _tree_construction_main ($) {
2916      !!!create-element ($el, $start_tag_name, $token->{attributes});      !!!create-element ($el, $start_tag_name, $token->{attributes});
2917    
2918      ## Step 2      ## Step 2
2919      $insert->($el); # /context node/->append_child ($el)      $insert->($el);
2920    
2921      ## Step 3      ## Step 3
2922      $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 2946  sub _tree_construction_main ($) {
2946          $token->{tag_name} eq $start_tag_name) {          $token->{tag_name} eq $start_tag_name) {
2947        !!!cp ('t42');        !!!cp ('t42');
2948        ## 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});  
2949      } else {      } else {
2950        die "$0: $content_model_flag in parse_rcdata";        ## NOTE: An end-of-file token.
2951          if ($content_model_flag == CDATA_CONTENT_MODEL) {
2952            !!!cp ('t43');
2953            !!!parse-error (type => 'in CDATA:#'.$token->{type});
2954          } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2955            !!!cp ('t44');
2956            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2957          } else {
2958            die "$0: $content_model_flag in parse_rcdata";
2959          }
2960      }      }
2961      !!!next-token;      !!!next-token;
2962    }; # $parse_rcdata    }; # $parse_rcdata
2963    
2964    my $script_start_tag = sub ($) {    my $script_start_tag = sub () {
     my $insert = $_[0];  
2965      my $script_el;      my $script_el;
2966      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2967      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
# Line 3011  sub _tree_construction_main ($) { Line 3012  sub _tree_construction_main ($) {
3012      !!!next-token;      !!!next-token;
3013    }; # $script_start_tag    }; # $script_start_tag
3014    
3015      ## NOTE: $open_tables->[-1]->[0] is the "current table" element node.
3016      ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.
3017      my $open_tables = [[$self->{open_elements}->[0]->[0]]];
3018    
3019    my $formatting_end_tag = sub {    my $formatting_end_tag = sub {
3020      my $tag_name = shift;      my $tag_name = shift;
3021    
3022        ## NOTE: The adoption agency algorithm (AAA).
3023    
3024      FET: {      FET: {
3025        ## Step 1        ## Step 1
3026        my $formatting_element;        my $formatting_element;
# Line 3054  sub _tree_construction_main ($) { Line 3061  sub _tree_construction_main ($) {
3061              return;              return;
3062            }            }
3063          } elsif ({          } elsif ({
3064                    table => 1, caption => 1, td => 1, th => 1,                    applet => 1, table => 1, caption => 1, td => 1, th => 1,
3065                    button => 1, marquee => 1, object => 1, html => 1,                    button => 1, marquee => 1, object => 1, html => 1,
3066                   }->{$node->[1]}) {                   }->{$node->[1]}) {
3067            !!!cp ('t56');            !!!cp ('t56');
# Line 3081  sub _tree_construction_main ($) { Line 3088  sub _tree_construction_main ($) {
3088          if (not $formatting_category->{$node->[1]} and          if (not $formatting_category->{$node->[1]} and
3089              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3090              ($special_category->{$node->[1]} or              ($special_category->{$node->[1]} or
3091               $scoping_category->{$node->[1]})) {               $scoping_category->{$node->[1]})) { ## Scoping is redundant, maybe
3092            !!!cp ('t59');            !!!cp ('t59');
3093            $furthest_block = $node;            $furthest_block = $node;
3094            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
# Line 3167  sub _tree_construction_main ($) { Line 3174  sub _tree_construction_main ($) {
3174        } # S7          } # S7  
3175                
3176        ## Step 8        ## Step 8
3177        $common_ancestor_node->[0]->append_child ($last_node->[0]);        if ({
3178               table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3179              }->{$common_ancestor_node->[1]}) {
3180            my $foster_parent_element;
3181            my $next_sibling;
3182                             OE: for (reverse 0..$#{$self->{open_elements}}) {
3183                               if ($self->{open_elements}->[$_]->[1] eq 'table') {
3184                                 my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3185                                 if (defined $parent and $parent->node_type == 1) {
3186                                   !!!cp ('t65.1');
3187                                   $foster_parent_element = $parent;
3188                                   $next_sibling = $self->{open_elements}->[$_]->[0];
3189                                 } else {
3190                                   !!!cp ('t65.2');
3191                                   $foster_parent_element
3192                                     = $self->{open_elements}->[$_ - 1]->[0];
3193                                 }
3194                                 last OE;
3195                               }
3196                             } # OE
3197                             $foster_parent_element = $self->{open_elements}->[0]->[0]
3198                               unless defined $foster_parent_element;
3199            $foster_parent_element->insert_before ($last_node->[0], $next_sibling);
3200            $open_tables->[-1]->[1] = 1; # tainted
3201          } else {
3202            !!!cp ('t65.3');
3203            $common_ancestor_node->[0]->append_child ($last_node->[0]);
3204          }
3205                
3206        ## Step 9        ## Step 9
3207        my $clone = [$formatting_element->[0]->clone_node (0),        my $clone = [$formatting_element->[0]->clone_node (0),
# Line 3213  sub _tree_construction_main ($) { Line 3247  sub _tree_construction_main ($) {
3247      } # FET      } # FET
3248    }; # $formatting_end_tag    }; # $formatting_end_tag
3249    
3250    my $insert_to_current = sub {    $insert = my $insert_to_current = sub {
3251      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
3252    }; # $insert_to_current    }; # $insert_to_current
3253    
3254    my $insert_to_foster = sub {    my $insert_to_foster = sub {
3255                         my $child = shift;      my $child = shift;
3256                         if ({      if ({
3257                              table => 1, tbody => 1, tfoot => 1,           table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3258                              thead => 1, tr => 1,          }->{$self->{open_elements}->[-1]->[1]}) {
3259                             }->{$self->{open_elements}->[-1]->[1]}) {        # MUST
3260                           # MUST        my $foster_parent_element;
3261                           my $foster_parent_element;        my $next_sibling;
                          my $next_sibling;  
3262                           OE: for (reverse 0..$#{$self->{open_elements}}) {                           OE: for (reverse 0..$#{$self->{open_elements}}) {
3263                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3264                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
# Line 3245  sub _tree_construction_main ($) { Line 3278  sub _tree_construction_main ($) {
3278                             unless defined $foster_parent_element;                             unless defined $foster_parent_element;
3279                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3280                             ($child, $next_sibling);                             ($child, $next_sibling);
3281                         } else {        $open_tables->[-1]->[1] = 1; # tainted
3282                           !!!cp ('t72');      } else {
3283                           $self->{open_elements}->[-1]->[0]->append_child ($child);        !!!cp ('t72');
3284                         }        $self->{open_elements}->[-1]->[0]->append_child ($child);
3285        }
3286    }; # $insert_to_foster    }; # $insert_to_foster
3287    
   my $insert;  
   
3288    B: {    B: {
3289      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3290        !!!cp ('t73');        !!!cp ('t73');
# Line 3261  sub _tree_construction_main ($) { Line 3293  sub _tree_construction_main ($) {
3293        ## Stay in the phase        ## Stay in the phase
3294        !!!next-token;        !!!next-token;
3295        redo B;        redo B;
     } elsif ($token->{type} == END_OF_FILE_TOKEN) {  
       if ($self->{insertion_mode} & AFTER_HTML_IMS) {  
         !!!cp ('t74');  
         #  
       } else {  
         ## 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 ('t75');  
           !!!back-token;  
           $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};  
           redo B;  
         }  
           
         if (@{$self->{open_elements}} > 2 or  
             (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {  
           !!!cp ('t76');  
           !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
         } elsif (defined $self->{inner_html_node} and  
                  @{$self->{open_elements}} > 1 and  
                  $self->{open_elements}->[1]->[1] ne 'body') {  
 ## ISSUE: This case is never reached.  
           !!!cp ('t77');  
           !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
         } else {  
           !!!cp ('t78');  
         }  
   
         ## ISSUE: There is an issue in the spec.  
       }  
   
       ## Stop parsing  
       last B;  
3296      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3297               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3298        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
# Line 3340  sub _tree_construction_main ($) { Line 3337  sub _tree_construction_main ($) {
3337      } elsif ($self->{insertion_mode} & HEAD_IMS) {      } elsif ($self->{insertion_mode} & HEAD_IMS) {
3338        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
3339          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3340            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3341                !!!cp ('t88.2');
3342                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3343              } else {
3344                !!!cp ('t88.1');
3345                ## Ignore the token.
3346                !!!next-token;
3347                redo B;
3348              }
3349            unless (length $token->{data}) {            unless (length $token->{data}) {
3350              !!!cp ('t88');              !!!cp ('t88');
3351              !!!next-token;              !!!next-token;
# Line 3441  sub _tree_construction_main ($) { Line 3446  sub _tree_construction_main ($) {
3446                }                }
3447                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3448                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3449                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3450                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3451                !!!next-token;                !!!next-token;
3452                redo B;                redo B;
# Line 3456  sub _tree_construction_main ($) { Line 3461  sub _tree_construction_main ($) {
3461                }                }
3462                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3463                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3464                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3465                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3466                !!!next-token;                !!!next-token;
3467                redo B;                redo B;
# Line 3517  sub _tree_construction_main ($) { Line 3522  sub _tree_construction_main ($) {
3522                  }                  }
3523                }                }
3524    
3525                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3526                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3527                !!!next-token;                !!!next-token;
3528                redo B;                redo B;
# Line 3541  sub _tree_construction_main ($) { Line 3546  sub _tree_construction_main ($) {
3546                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3547                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3548                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3549                $parse_rcdata->(RCDATA_CONTENT_MODEL,                $parse_rcdata->(RCDATA_CONTENT_MODEL);
3550                                sub { $parent->append_child ($_[0]) });                pop @{$self->{open_elements}} # <head>
               pop @{$self->{open_elements}}  
3551                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3552                redo B;                redo B;
3553              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style') {
# Line 3557  sub _tree_construction_main ($) { Line 3561  sub _tree_construction_main ($) {
3561                } else {                } else {
3562                  !!!cp ('t115');                  !!!cp ('t115');
3563                }                }
3564                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL);
3565                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3566                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3567                redo B;                redo B;
3568              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
# Line 3597  sub _tree_construction_main ($) { Line 3601  sub _tree_construction_main ($) {
3601                }                }
3602    
3603                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3604                $script_start_tag->($insert_to_current);                $script_start_tag->();
3605                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3606                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3607                redo B;                redo B;
3608              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
# Line 3807  sub _tree_construction_main ($) { Line 3811  sub _tree_construction_main ($) {
3811              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
3812              ## reprocess              ## reprocess
3813              redo B;              redo B;
3814            } else {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3815              die "$0: $token->{type}: Unknown token type";          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3816            }            !!!cp ('t149.1');
3817    
3818              ## NOTE: As if <head>
3819              !!!create-element ($self->{head_element}, 'head');
3820              $self->{open_elements}->[-1]->[0]->append_child
3821                  ($self->{head_element});
3822              #push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3823              #$self->{insertion_mode} = IN_HEAD_IM;
3824              ## NOTE: Reprocess.
3825    
3826              ## NOTE: As if </head>
3827              #pop @{$self->{open_elements}};
3828              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3829              ## NOTE: Reprocess.
3830              
3831              #
3832            } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3833              !!!cp ('t149.2');
3834    
3835              ## NOTE: As if </head>
3836              pop @{$self->{open_elements}};
3837              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3838              ## NOTE: Reprocess.
3839    
3840              #
3841            } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3842              !!!cp ('t149.3');
3843    
3844              !!!parse-error (type => 'in noscript:#eof');
3845    
3846              ## As if </noscript>
3847              pop @{$self->{open_elements}};
3848              #$self->{insertion_mode} = IN_HEAD_IM;
3849              ## NOTE: Reprocess.
3850    
3851              ## NOTE: As if </head>
3852              pop @{$self->{open_elements}};
3853              #$self->{insertion_mode} = IN_AFTER_HEAD_IM;
3854              ## NOTE: Reprocess.
3855    
3856              #
3857            } else {
3858              !!!cp ('t149.4');
3859              #
3860            }
3861    
3862            ## NOTE: As if <body>
3863            !!!insert-element ('body');
3864            $self->{insertion_mode} = IN_BODY_IM;
3865            ## NOTE: Reprocess.
3866            redo B;
3867          } else {
3868            die "$0: $token->{type}: Unknown token type";
3869          }
3870    
3871            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3872      } elsif ($self->{insertion_mode} & BODY_IMS) {      } elsif ($self->{insertion_mode} & BODY_IMS) {
# Line 3886  sub _tree_construction_main ($) { Line 3943  sub _tree_construction_main ($) {
3943                    }                    }
3944                                    
3945                  ## generate implied end tags                  ## generate implied end tags
3946                  if ({                  while ({
3947                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3948                           }->{$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]}) {  
3949                    !!!cp ('t158');                    !!!cp ('t158');
3950                    !!!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;  
3951                  }                  }
3952    
3953                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 3952  sub _tree_construction_main ($) { Line 4000  sub _tree_construction_main ($) {
4000                    }                    }
4001                                    
4002                  ## generate implied end tags                  ## generate implied end tags
4003                  if ({                  while ({
4004                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4005                       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]}) {  
4006                    !!!cp ('t166');                    !!!cp ('t166');
4007                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4008                  }                  }
4009                    
4010                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
4011                    !!!cp ('t167');                    !!!cp ('t167');
4012                    !!!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 4058  sub _tree_construction_main ($) {
4058                    }                    }
4059                                    
4060                  ## generate implied end tags                  ## generate implied end tags
4061                  if ({                  while ({
4062                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4063                           }->{$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]}) {  
4064                    !!!cp ('t174');                    !!!cp ('t174');
4065                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4066                  }                  }
4067                                    
4068                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4127  sub _tree_construction_main ($) { Line 4159  sub _tree_construction_main ($) {
4159                }                }
4160                                
4161                ## generate implied end tags                ## generate implied end tags
4162                if ({                while ({
4163                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4164                         }->{$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]}) {  
4165                  !!!cp ('t187');                  !!!cp ('t187');
4166                  !!!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;  
4167                }                }
4168    
4169                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4185  sub _tree_construction_main ($) { Line 4208  sub _tree_construction_main ($) {
4208                !!!cp ('t193');                !!!cp ('t193');
4209                #                #
4210              }              }
4211          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4212            for my $entry (@{$self->{open_elements}}) {
4213              if (not {
4214                dd => 1, dt => 1, li => 1, p => 1, tbody => 1, td => 1, tfoot => 1,
4215                th => 1, thead => 1, tr => 1, body => 1, html => 1,
4216              }->{$entry->[1]}) {
4217                !!!cp ('t75');
4218                !!!parse-error (type => 'in body:#eof');
4219                last;
4220              }
4221            }
4222    
4223            ## Stop parsing.
4224            last B;
4225        } else {        } else {
4226          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4227        }        }
# Line 4193  sub _tree_construction_main ($) { Line 4230  sub _tree_construction_main ($) {
4230        #        #
4231      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
4232        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4233              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if (not $open_tables->[-1]->[1] and # tainted
4234                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4235              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4236                                
4237                unless (length $token->{data}) {            unless (length $token->{data}) {
4238                  !!!cp ('t194');              !!!cp ('t194');
4239                  !!!next-token;              !!!next-token;
4240                  redo B;              redo B;
4241                } else {            } else {
4242                  !!!cp ('t195');              !!!cp ('t195');
4243                }            }
4244              }          }
4245    
4246              !!!parse-error (type => 'in table:#character');              !!!parse-error (type => 'in table:#character');
4247    
# Line 4250  sub _tree_construction_main ($) { Line 4288  sub _tree_construction_main ($) {
4288                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4289                     $next_sibling);                     $next_sibling);
4290                }                }
4291              } else {            $open_tables->[-1]->[1] = 1; # tainted
4292                !!!cp ('t200');          } else {
4293                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});            !!!cp ('t200');
4294              }            $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4295            }
4296                            
4297              !!!next-token;          !!!next-token;
4298              redo B;          redo B;
4299        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4300              if ({              if ({
4301                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
# Line 4267  sub _tree_construction_main ($) { Line 4306  sub _tree_construction_main ($) {
4306                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4307                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4308                    !!!cp ('t201');                    !!!cp ('t201');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4309                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4310                  }                  }
4311                                    
# Line 4288  sub _tree_construction_main ($) { Line 4326  sub _tree_construction_main ($) {
4326                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4327                    !!!cp ('t203');                    !!!cp ('t203');
4328                    ## ISSUE: Can this case be reached?                    ## ISSUE: Can this case be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4329                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4330                  }                  }
4331                                    
# Line 4312  sub _tree_construction_main ($) { Line 4349  sub _tree_construction_main ($) {
4349                  tr => 1, html => 1,                  tr => 1, html => 1,
4350                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4351                  !!!cp ('t207');                  !!!cp ('t207');
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4352                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4353                }                }
4354                                
# Line 4363  sub _tree_construction_main ($) { Line 4399  sub _tree_construction_main ($) {
4399                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4400                    !!!cp ('t211');                    !!!cp ('t211');
4401                    ## ISSUE: Can this case be reached?                    ## ISSUE: Can this case be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4402                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4403                  }                  }
4404                                    
# Line 4412  sub _tree_construction_main ($) { Line 4447  sub _tree_construction_main ($) {
4447                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4448                    !!!cp ('t217');                    !!!cp ('t217');
4449                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4450                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4451                  }                  }
4452                                    
# Line 4436  sub _tree_construction_main ($) { Line 4470  sub _tree_construction_main ($) {
4470                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4471                    !!!cp ('t219');                    !!!cp ('t219');
4472                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4473                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4474                  }                  }
4475                                    
# Line 4454  sub _tree_construction_main ($) { Line 4487  sub _tree_construction_main ($) {
4487                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4488                    !!!cp ('t220');                    !!!cp ('t220');
4489                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4490                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4491                  }                  }
4492                                    
# Line 4504  sub _tree_construction_main ($) { Line 4536  sub _tree_construction_main ($) {
4536                }                }
4537                                
4538                ## generate implied end tags                ## generate implied end tags
4539                if ({                while ({
4540                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4541                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4542                  !!!cp ('t224');                  !!!cp ('t224');
4543                  !!!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;  
4544                }                }
4545    
4546                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
# Line 4527  sub _tree_construction_main ($) { Line 4552  sub _tree_construction_main ($) {
4552                }                }
4553    
4554                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4555                  pop @{$open_tables};
4556    
4557                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4558    
4559                ## reprocess                ## reprocess
4560                redo B;                redo B;
4561            } elsif ($token->{tag_name} eq 'style') {
4562              if (not $open_tables->[-1]->[1]) { # tainted
4563                !!!cp ('t227.8');
4564                ## NOTE: This is a "as if in head" code clone.
4565                $parse_rcdata->(CDATA_CONTENT_MODEL);
4566                redo B;
4567              } else {
4568                !!!cp ('t227.7');
4569                #
4570              }
4571            } elsif ($token->{tag_name} eq 'script') {
4572              if (not $open_tables->[-1]->[1]) { # tainted
4573                !!!cp ('t227.6');
4574                ## NOTE: This is a "as if in head" code clone.
4575                $script_start_tag->();
4576                redo B;
4577              } else {
4578                !!!cp ('t227.5');
4579                #
4580              }
4581            } elsif ($token->{tag_name} eq 'input') {
4582              if (not $open_tables->[-1]->[1]) { # tainted
4583                if ($token->{attributes}->{type}) { ## TODO: case
4584                  my $type = lc $token->{attributes}->{type}->{value};
4585                  if ($type eq 'hidden') {
4586                    !!!cp ('t227.3');
4587                    !!!parse-error (type => 'in table:'.$token->{tag_name});
4588    
4589                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4590    
4591                    ## TODO: form element pointer
4592    
4593                    pop @{$self->{open_elements}};
4594    
4595                    !!!next-token;
4596                    redo B;
4597                  } else {
4598                    !!!cp ('t227.2');
4599                    #
4600                  }
4601                } else {
4602                  !!!cp ('t227.1');
4603                  #
4604                }
4605              } else {
4606                !!!cp ('t227.4');
4607                #
4608              }
4609          } else {          } else {
4610            !!!cp ('t227');            !!!cp ('t227');
           !!!parse-error (type => 'in table:'.$token->{tag_name});  
   
           $insert = $insert_to_foster;  
4611            #            #
4612          }          }
4613    
4614            !!!parse-error (type => 'in table:'.$token->{tag_name});
4615    
4616            $insert = $insert_to_foster;
4617            #
4618        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
4619              if ($token->{tag_name} eq 'tr' and              if ($token->{tag_name} eq 'tr' and
4620                  $self->{insertion_mode} == IN_ROW_IM) {                  $self->{insertion_mode} == IN_ROW_IM) {
# Line 4573  sub _tree_construction_main ($) { Line 4649  sub _tree_construction_main ($) {
4649                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4650                  !!!cp ('t231');                  !!!cp ('t231');
4651  ## ISSUE: Can this state be reached?  ## ISSUE: Can this state be reached?
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4652                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4653                }                }
4654    
# Line 4614  sub _tree_construction_main ($) { Line 4689  sub _tree_construction_main ($) {
4689                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4690                    !!!cp ('t236');                    !!!cp ('t236');
4691  ## ISSUE: Can this state be reached?  ## ISSUE: Can this state be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4692                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4693                  }                  }
4694                                    
# Line 4654  sub _tree_construction_main ($) { Line 4728  sub _tree_construction_main ($) {
4728                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4729                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4730                    !!!cp ('t240');                    !!!cp ('t240');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4731                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4732                  }                  }
4733                                    
# Line 4670  sub _tree_construction_main ($) { Line 4743  sub _tree_construction_main ($) {
4743                  ## reprocess in the "in table" insertion mode...                  ## reprocess in the "in table" insertion mode...
4744                }                }
4745    
4746                  ## NOTE: </table> in the "in table" insertion mode.
4747                  ## When you edit the code fragment below, please ensure that
4748                  ## the code for <table> in the "in table" insertion mode
4749                  ## is synced with it.
4750    
4751                ## have a table element in table scope                ## have a table element in table scope
4752                my $i;                my $i;
4753                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 4692  sub _tree_construction_main ($) { Line 4770  sub _tree_construction_main ($) {
4770                  !!!next-token;                  !!!next-token;
4771                  redo B;                  redo B;
4772                }                }
   
               ## 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');  
               }  
4773                                    
4774                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4775                  pop @{$open_tables};
4776                                
4777                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4778                                
# Line 4778  sub _tree_construction_main ($) { Line 4836  sub _tree_construction_main ($) {
4836                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4837                    !!!cp ('t253');                    !!!cp ('t253');
4838  ## ISSUE: Can this case be reached?  ## ISSUE: Can this case be reached?
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4839                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4840                  }                  }
4841                                    
# Line 4816  sub _tree_construction_main ($) { Line 4873  sub _tree_construction_main ($) {
4873                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4874                  !!!cp ('t257');                  !!!cp ('t257');
4875  ## ISSUE: Can this case be reached?  ## ISSUE: Can this case be reached?
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4876                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4877                }                }
4878    
# Line 4842  sub _tree_construction_main ($) { Line 4898  sub _tree_construction_main ($) {
4898            $insert = $insert_to_foster;            $insert = $insert_to_foster;
4899            #            #
4900          }          }
4901          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4902            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
4903                    @{$self->{open_elements}} == 1) { # redundant, maybe
4904              !!!cp ('t259.1');
4905              !!!parse-error (type => 'in body:#eof');
4906            } else {
4907              !!!cp ('t259.2');
4908            }
4909    
4910            ## Stop parsing
4911            last B;
4912        } else {        } else {
4913          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4914        }        }
# Line 4894  sub _tree_construction_main ($) { Line 4961  sub _tree_construction_main ($) {
4961                !!!cp ('t267');                !!!cp ('t267');
4962                #                #
4963              }              }
4964            } else {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4965              die "$0: $token->{type}: Unknown token type";          if ($self->{open_elements}->[-1]->[1] eq 'html' or
4966            }              @{$self->{open_elements}} == 1) { # redundant, maybe
4967              !!!cp ('t270.2');
4968              ## Stop parsing.
4969              last B;
4970            } else {
4971              ## NOTE: As if </colgroup>.
4972              !!!cp ('t270.1');
4973              pop @{$self->{open_elements}}; # colgroup
4974              $self->{insertion_mode} = IN_TABLE_IM;
4975              ## Reprocess.
4976              redo B;
4977            }
4978          } else {
4979            die "$0: $token->{type}: Unknown token type";
4980          }
4981    
4982            ## As if </colgroup>            ## As if </colgroup>
4983            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] eq 'html') {
4984              !!!cp ('t269');              !!!cp ('t269');
4985    ## TODO: Wrong error type?
4986              !!!parse-error (type => 'unmatched end tag:colgroup');              !!!parse-error (type => 'unmatched end tag:colgroup');
4987              ## Ignore the token              ## Ignore the token
4988              !!!next-token;              !!!next-token;
# Line 4912  sub _tree_construction_main ($) { Line 4994  sub _tree_construction_main ($) {
4994              ## reprocess              ## reprocess
4995              redo B;              redo B;
4996            }            }
4997      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} & SELECT_IMS) {
4998        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4999          !!!cp ('t271');          !!!cp ('t271');
5000          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
# Line 4951  sub _tree_construction_main ($) { Line 5033  sub _tree_construction_main ($) {
5033                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
5034                !!!next-token;                !!!next-token;
5035                redo B;                redo B;
5036              } elsif ($token->{tag_name} eq 'select') {          } elsif ($token->{tag_name} eq 'select' or
5037  ## TODO: The type below is not good - <select> is replaced by </select>                   $token->{tag_name} eq 'input' or
5038                !!!parse-error (type => 'not closed:select');                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5039                ## As if </select> instead                    {
5040                       caption => 1, table => 1,
5041                       tbody => 1, tfoot => 1, thead => 1,
5042                       tr => 1, td => 1, th => 1,
5043                      }->{$token->{tag_name}})) {
5044              ## TODO: The type below is not good - <select> is replaced by </select>
5045              !!!parse-error (type => 'not closed:select');
5046              ## NOTE: As if the token were </select> (<select> case) or
5047              ## as if there were </select> (otherwise).
5048                ## have an element in table scope                ## have an element in table scope
5049                my $i;                my $i;
5050                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5051                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5052                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq 'select') {
5053                    !!!cp ('t278');                    !!!cp ('t278');
5054                    $i = $_;                    $i = $_;
5055                    last INSCOPE;                    last INSCOPE;
# Line 4983  sub _tree_construction_main ($) { Line 5073  sub _tree_construction_main ($) {
5073    
5074                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
5075    
5076                !!!next-token;            if ($token->{tag_name} eq 'select') {
5077                redo B;              !!!cp ('t281.2');
5078                !!!next-token;
5079                redo B;
5080              } else {
5081                !!!cp ('t281.1');
5082                ## Reprocess the token.
5083                redo B;
5084              }
5085          } else {          } else {
5086            !!!cp ('t282');            !!!cp ('t282');
5087            !!!parse-error (type => 'in select:'.$token->{tag_name});            !!!parse-error (type => 'in select:'.$token->{tag_name});
# Line 5051  sub _tree_construction_main ($) { Line 5148  sub _tree_construction_main ($) {
5148    
5149                !!!next-token;                !!!next-token;
5150                redo B;                redo B;
5151              } elsif ({          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5152                        caption => 1, table => 1, tbody => 1,                   {
5153                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    caption => 1, table => 1, tbody => 1,
5154                       }->{$token->{tag_name}}) {                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
5155                     }->{$token->{tag_name}}) {
5156  ## TODO: The following is wrong?  ## TODO: The following is wrong?
5157                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5158                                
# Line 5120  sub _tree_construction_main ($) { Line 5218  sub _tree_construction_main ($) {
5218            !!!next-token;            !!!next-token;
5219            redo B;            redo B;
5220          }          }
5221          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5222            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
5223                    @{$self->{open_elements}} == 1) { # redundant, maybe
5224              !!!cp ('t299.1');
5225              !!!parse-error (type => 'in body:#eof');
5226            } else {
5227              !!!cp ('t299.2');
5228            }
5229    
5230            ## Stop parsing.
5231            last B;
5232        } else {        } else {
5233          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5234        }        }
# Line 5203  sub _tree_construction_main ($) { Line 5312  sub _tree_construction_main ($) {
5312            ## reprocess            ## reprocess
5313            redo B;            redo B;
5314          }          }
5315          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5316            !!!cp ('t309.2');
5317            ## Stop parsing
5318            last B;
5319        } else {        } else {
5320          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5321        }        }
# Line 5273  sub _tree_construction_main ($) { Line 5386  sub _tree_construction_main ($) {
5386          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5387            !!!cp ('t320');            !!!cp ('t320');
5388            ## NOTE: As if in body.            ## NOTE: As if in body.
5389            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL);
5390            redo B;            redo B;
5391          } else {          } else {
5392            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
# Line 5338  sub _tree_construction_main ($) { Line 5451  sub _tree_construction_main ($) {
5451            !!!next-token;            !!!next-token;
5452            redo B;            redo B;
5453          }          }
5454          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5455            unless ($self->{open_elements}->[-1]->[1] eq 'html' and
5456                    @{$self->{open_elements}} == 1) { # redundant, maybe
5457              !!!cp ('t331.1');
5458              !!!parse-error (type => 'in body:#eof');
5459            } else {
5460              !!!cp ('t331.2');
5461            }
5462            
5463            ## Stop parsing
5464            last B;
5465        } else {        } else {
5466          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5467        }        }
# Line 5352  sub _tree_construction_main ($) { Line 5476  sub _tree_construction_main ($) {
5476        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5477          !!!cp ('t332');          !!!cp ('t332');
5478          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5479          $script_start_tag->($insert);          $script_start_tag->();
5480          redo B;          redo B;
5481        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5482          !!!cp ('t333');          !!!cp ('t333');
5483          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5484          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5485          redo B;          redo B;
5486        } elsif ({        } elsif ({
5487                  base => 1, link => 1,                  base => 1, link => 1,
# Line 5420  sub _tree_construction_main ($) { Line 5544  sub _tree_construction_main ($) {
5544          redo B;          redo B;
5545        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5546          !!!cp ('t341');          !!!cp ('t341');
         !!!parse-error (type => 'in body:title');  
5547          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5548          $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]);  
           }  
         });  
5549          redo B;          redo B;
5550        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
5551          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 5456  sub _tree_construction_main ($) { Line 5571  sub _tree_construction_main ($) {
5571                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5572                  div => 1, dl => 1, fieldset => 1,                  div => 1, dl => 1, fieldset => 1,
5573                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5574                  listing => 1, menu => 1, ol => 1, p => 1, ul => 1,                  menu => 1, ol => 1, p => 1, ul => 1,
5575                  pre => 1,                  pre => 1, listing => 1,
5576                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5577          ## has a p element in scope          ## has a p element in scope
5578          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
# Line 5467  sub _tree_construction_main ($) { Line 5582  sub _tree_construction_main ($) {
5582              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5583              redo B;              redo B;
5584            } elsif ({            } elsif ({
5585                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5586                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5587                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5588              !!!cp ('t345');              !!!cp ('t345');
# Line 5476  sub _tree_construction_main ($) { Line 5591  sub _tree_construction_main ($) {
5591          } # INSCOPE          } # INSCOPE
5592                        
5593          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5594          if ($token->{tag_name} eq 'pre') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
5595            !!!next-token;            !!!next-token;
5596            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
5597              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
# Line 5510  sub _tree_construction_main ($) { Line 5625  sub _tree_construction_main ($) {
5625                $token = {type => END_TAG_TOKEN, tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5626                redo B;                redo B;
5627              } elsif ({              } elsif ({
5628                        table => 1, caption => 1, td => 1, th => 1,                        applet => 1, table => 1, caption => 1, td => 1, th => 1,
5629                        button => 1, marquee => 1, object => 1, html => 1,                        button => 1, marquee => 1, object => 1, html => 1,
5630                       }->{$_->[1]}) {                       }->{$_->[1]}) {
5631                !!!cp ('t352');                !!!cp ('t352');
# Line 5532  sub _tree_construction_main ($) { Line 5647  sub _tree_construction_main ($) {
5647              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5648              redo B;              redo B;
5649            } elsif ({            } elsif ({
5650                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5651                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5652                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5653              !!!cp ('t354');              !!!cp ('t354');
# Line 5588  sub _tree_construction_main ($) { Line 5703  sub _tree_construction_main ($) {
5703              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5704              redo B;              redo B;
5705            } elsif ({            } elsif ({
5706                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5707                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5708                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5709              !!!cp ('t361');              !!!cp ('t361');
# Line 5644  sub _tree_construction_main ($) { Line 5759  sub _tree_construction_main ($) {
5759              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5760              redo B;              redo B;
5761            } elsif ({            } elsif ({
5762                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5763                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5764                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5765              !!!cp ('t368');              !!!cp ('t368');
# Line 5723  sub _tree_construction_main ($) { Line 5838  sub _tree_construction_main ($) {
5838              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
5839              redo B;              redo B;
5840            } elsif ({            } elsif ({
5841                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5842                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5843                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5844              !!!cp ('t377');              !!!cp ('t377');
# Line 5747  sub _tree_construction_main ($) { Line 5862  sub _tree_construction_main ($) {
5862              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
5863              redo B;              redo B;
5864            } elsif ({            } elsif ({
5865                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5866                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5867                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5868              !!!cp ('t379');              !!!cp ('t379');
# Line 5765  sub _tree_construction_main ($) { Line 5880  sub _tree_construction_main ($) {
5880    
5881          !!!next-token;          !!!next-token;
5882          redo B;          redo B;
5883        } elsif ($token->{tag_name} eq 'marquee' or        } elsif ({
5884                 $token->{tag_name} eq 'object') {                  applet => 1, marquee => 1, object => 1,
5885                   }->{$token->{tag_name}}) {
5886          !!!cp ('t380');          !!!cp ('t380');
5887          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5888                    
# Line 5778  sub _tree_construction_main ($) { Line 5894  sub _tree_construction_main ($) {
5894        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5895          !!!cp ('t381');          !!!cp ('t381');
5896          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5897          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5898          redo B;          redo B;
5899        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
5900          ## has a p element in scope          ## has a p element in scope
# Line 5789  sub _tree_construction_main ($) { Line 5905  sub _tree_construction_main ($) {
5905              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5906              redo B;              redo B;
5907            } elsif ({            } elsif ({
5908                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5909                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5910                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5911              !!!cp ('t383');              !!!cp ('t383');
# Line 5798  sub _tree_construction_main ($) { Line 5914  sub _tree_construction_main ($) {
5914          } # INSCOPE          } # INSCOPE
5915                        
5916          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5917                      push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];
5918    
5919          $self->{insertion_mode} = IN_TABLE_IM;          $self->{insertion_mode} = IN_TABLE_IM;
5920                        
5921          !!!next-token;          !!!next-token;
# Line 5833  sub _tree_construction_main ($) { Line 5950  sub _tree_construction_main ($) {
5950              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5951              redo B;              redo B;
5952            } elsif ({            } elsif ({
5953                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5954                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5955                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5956              !!!cp ('t387');              !!!cp ('t387');
# Line 5953  sub _tree_construction_main ($) { Line 6070  sub _tree_construction_main ($) {
6070                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6071          !!!cp ('t399');          !!!cp ('t399');
6072          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
6073          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
6074          redo B;          redo B;
6075        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
6076          !!!cp ('t400');          !!!cp ('t400');
# Line 5963  sub _tree_construction_main ($) { Line 6080  sub _tree_construction_main ($) {
6080    
6081          ## TODO: associate with $self->{form_element} if defined          ## TODO: associate with $self->{form_element} if defined
6082                    
6083          $self->{insertion_mode} = IN_SELECT_IM;          if ($self->{insertion_mode} & TABLE_IMS or
6084                $self->{insertion_mode} & BODY_TABLE_IMS or
6085                $self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
6086              !!!cp ('t400.1');
6087              $self->{insertion_mode} = IN_SELECT_IN_TABLE_IM;
6088            } else {
6089              !!!cp ('t400.2');
6090              $self->{insertion_mode} = IN_SELECT_IM;
6091            }
6092          !!!next-token;          !!!next-token;
6093          redo B;          redo B;
6094        } elsif ({        } elsif ({
# Line 6038  sub _tree_construction_main ($) { Line 6163  sub _tree_construction_main ($) {
6163                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
6164                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
6165                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 p => 1,  
6166                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
6167                  button => 1, marquee => 1, object => 1,                  applet => 1, button => 1, marquee => 1, object => 1,
6168                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6169          ## has an element in scope          ## has an element in scope
6170          my $i;          my $i;
6171          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6172            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6173            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;  
             }  
               
6174              !!!cp ('t410');              !!!cp ('t410');
6175              $i = $_;              $i = $_;
6176              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE;
6177            } elsif ({            } elsif ({
6178                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6179                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6180                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6181              !!!cp ('t411');              !!!cp ('t411');
6182              last INSCOPE;              last INSCOPE;
6183            }            }
6184          } # INSCOPE          } # INSCOPE
6185            
6186          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6187            if (defined $i) {            !!!cp ('t413');
6188              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6189            } else {
6190              ## Step 1. generate implied end tags
6191              while ({
6192                      dd => ($token->{tag_name} ne 'dd'),
6193                      dt => ($token->{tag_name} ne 'dt'),
6194                      li => ($token->{tag_name} ne 'li'),
6195                      p => 1,
6196                     }->{$self->{open_elements}->[-1]->[1]}) {
6197                !!!cp ('t409');
6198                pop @{$self->{open_elements}};
6199              }
6200    
6201              ## Step 2.
6202              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6203              !!!cp ('t412');              !!!cp ('t412');
6204              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6205            } else {            } else {
6206              !!!cp ('t413');              !!!cp ('t414');
             !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
6207            }            }
6208          }  
6209                      ## Step 3.
         if (defined $i) {  
           !!!cp ('t414');  
6210            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6211          } elsif ($token->{tag_name} eq 'p') {  
6212            !!!cp ('t415');            ## Step 4.
6213            ## As if <p>, then reprocess the current token            $clear_up_to_marker->()
6214            my $el;                if {
6215            !!!create-element ($el, 'p');                  applet => 1, button => 1, marquee => 1, object => 1,
6216            $insert->($el);                }->{$token->{tag_name}};
         } else {  
           !!!cp ('t416');  
6217          }          }
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
6218          !!!next-token;          !!!next-token;
6219          redo B;          redo B;
6220        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
6221            undef $self->{form_element};
6222    
6223          ## has an element in scope          ## has an element in scope
6224            my $i;
6225          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6226            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6227            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;  
             }  
               
6228              !!!cp ('t418');              !!!cp ('t418');
6229                $i = $_;
6230              last INSCOPE;              last INSCOPE;
6231            } elsif ({            } elsif ({
6232                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6233                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6234                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6235              !!!cp ('t419');              !!!cp ('t419');
6236              last INSCOPE;              last INSCOPE;
6237            }            }
6238          } # INSCOPE          } # INSCOPE
6239            
6240          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 {  
6241            !!!cp ('t421');            !!!cp ('t421');
6242            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6243            } else {
6244              ## Step 1. generate implied end tags
6245              while ({
6246                      dd => 1, dt => 1, li => 1, p => 1,
6247                     }->{$self->{open_elements}->[-1]->[1]}) {
6248                !!!cp ('t417');
6249                pop @{$self->{open_elements}};
6250              }
6251              
6252              ## Step 2.
6253              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6254                !!!cp ('t417.1');
6255                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6256              } else {
6257                !!!cp ('t420');
6258              }  
6259              
6260              ## Step 3.
6261              splice @{$self->{open_elements}}, $i;
6262          }          }
6263    
         undef $self->{form_element};  
6264          !!!next-token;          !!!next-token;
6265          redo B;          redo B;
6266        } elsif ({        } elsif ({
# Line 6155  sub _tree_construction_main ($) { Line 6273  sub _tree_construction_main ($) {
6273            if ({            if ({
6274                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
6275                }->{$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;  
             }  
   
6276              !!!cp ('t423');              !!!cp ('t423');
6277              $i = $_;              $i = $_;
6278              last INSCOPE;              last INSCOPE;
6279            } elsif ({            } elsif ({
6280                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6281                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6282                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6283              !!!cp ('t424');              !!!cp ('t424');
6284              last INSCOPE;              last INSCOPE;
6285            }            }
6286          } # INSCOPE          } # INSCOPE
6287            
6288          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6289            !!!cp ('t425');            !!!cp ('t425.1');
6290            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6291          } else {          } else {
6292            !!!cp ('t426');            ## Step 1. generate implied end tags
6293              while ({
6294                      dd => 1, dt => 1, li => 1, p => 1,
6295                     }->{$self->{open_elements}->[-1]->[1]}) {
6296                !!!cp ('t422');
6297                pop @{$self->{open_elements}};
6298              }
6299              
6300              ## Step 2.
6301              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6302                !!!cp ('t425');
6303                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6304              } else {
6305                !!!cp ('t426');
6306              }
6307    
6308              ## Step 3.
6309              splice @{$self->{open_elements}}, $i;
6310          }          }
6311                    
6312          splice @{$self->{open_elements}}, $i if defined $i;          !!!next-token;
6313            redo B;
6314          } elsif ($token->{tag_name} eq 'p') {
6315            ## has an element in scope
6316            my $i;
6317            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6318              my $node = $self->{open_elements}->[$_];
6319              if ($node->[1] eq $token->{tag_name}) {
6320                !!!cp ('t410.1');
6321                $i = $_;
6322                last INSCOPE;
6323              } elsif ({
6324                        applet => 1, table => 1, caption => 1, td => 1, th => 1,
6325                        button => 1, marquee => 1, object => 1, html => 1,
6326                       }->{$node->[1]}) {
6327                !!!cp ('t411.1');
6328                last INSCOPE;
6329              }
6330            } # INSCOPE
6331    
6332            if (defined $i) {
6333              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6334                !!!cp ('t412.1');
6335                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6336              } else {
6337                !!!cp ('t414.1');
6338              }
6339    
6340              splice @{$self->{open_elements}}, $i;
6341            } else {
6342              !!!cp ('t413.1');
6343              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6344    
6345              !!!cp ('t415.1');
6346              ## As if <p>, then reprocess the current token
6347              my $el;
6348              !!!create-element ($el, 'p');
6349              $insert->($el);
6350              ## NOTE: Not inserted into |$self->{open_elements}|.
6351            }
6352    
6353          !!!next-token;          !!!next-token;
6354          redo B;          redo B;
6355        } elsif ({        } elsif ({
# Line 6243  sub _tree_construction_main ($) { Line 6405  sub _tree_construction_main ($) {
6405            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6406              ## Step 1              ## Step 1
6407              ## generate implied end tags              ## generate implied end tags
6408              if ({              while ({
6409                   dd => 1, dt => 1, li => 1, p => 1,                      dd => 1, dt => 1, li => 1, p => 1,
6410                   td => 1, th => 1, tr => 1,                     }->{$self->{open_elements}->[-1]->[1]}) {
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
6411                !!!cp ('t430');                !!!cp ('t430');
6412                ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
6413                !!!back-token;                pop @{$self->{open_elements}};
               $token = {type => END_TAG_TOKEN,  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
6414              }              }
6415                    
6416              ## Step 2              ## Step 2

Legend:
Removed from v.1.85  
changed lines
  Added in v.1.104

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24