/[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.81 by wakaba, Tue Mar 4 14:51:54 2008 UTC revision 1.95 by wakaba, Sat Mar 8 05:09:25 2008 UTC
# Line 304  sub ROW_IMS ()        { 0b10000000 } Line 304  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    
307    ## NOTE: "initial" and "before html" insertion modes have no constants.
308    
309    ## NOTE: "after after body" insertion mode.
310  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }
311    
312    ## NOTE: "after after frameset" insertion mode.
313  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }
314    
315  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }
316  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }
317  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }
# Line 2420  sub _construct_tree ($) { Line 2426  sub _construct_tree ($) {
2426        
2427    !!!next-token;    !!!next-token;
2428    
   $self->{insertion_mode} = BEFORE_HEAD_IM;  
2429    undef $self->{form_element};    undef $self->{form_element};
2430    undef $self->{head_element};    undef $self->{head_element};
2431    $self->{open_elements} = [];    $self->{open_elements} = [];
2432    undef $self->{inner_html_node};    undef $self->{inner_html_node};
2433    
2434      ## NOTE: The "initial" insertion mode.
2435    $self->_tree_construction_initial; # MUST    $self->_tree_construction_initial; # MUST
2436    
2437      ## NOTE: The "before html" insertion mode.
2438    $self->_tree_construction_root_element;    $self->_tree_construction_root_element;
2439      $self->{insertion_mode} = BEFORE_HEAD_IM;
2440    
2441      ## NOTE: The "before head" insertion mode and so on.
2442    $self->_tree_construction_main;    $self->_tree_construction_main;
2443  } # _construct_tree  } # _construct_tree
2444    
2445  sub _tree_construction_initial ($) {  sub _tree_construction_initial ($) {
2446    my $self = shift;    my $self = shift;
2447    
2448      ## NOTE: "initial" insertion mode
2449    
2450    INITIAL: {    INITIAL: {
2451      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
2452        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"
# Line 2579  sub _tree_construction_initial ($) { Line 2593  sub _tree_construction_initial ($) {
2593          !!!cp ('t13');          !!!cp ('t13');
2594        }        }
2595                
2596        ## Go to the root element phase.        ## Go to the "before html" insertion mode.
2597        !!!next-token;        !!!next-token;
2598        return;        return;
2599      } elsif ({      } elsif ({
# Line 2590  sub _tree_construction_initial ($) { Line 2604  sub _tree_construction_initial ($) {
2604        !!!cp ('t14');        !!!cp ('t14');
2605        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2606        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2607        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2608        ## reprocess        ## reprocess
2609        return;        return;
2610      } elsif ($token->{type} == CHARACTER_TOKEN) {      } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2599  sub _tree_construction_initial ($) { Line 2613  sub _tree_construction_initial ($) {
2613    
2614          unless (length $token->{data}) {          unless (length $token->{data}) {
2615            !!!cp ('t15');            !!!cp ('t15');
2616            ## Stay in the phase            ## Stay in the insertion mode.
2617            !!!next-token;            !!!next-token;
2618            redo INITIAL;            redo INITIAL;
2619          } else {          } else {
# Line 2611  sub _tree_construction_initial ($) { Line 2625  sub _tree_construction_initial ($) {
2625    
2626        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2627        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2628        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2629        ## reprocess        ## reprocess
2630        return;        return;
2631      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
# Line 2619  sub _tree_construction_initial ($) { Line 2633  sub _tree_construction_initial ($) {
2633        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2634        $self->{document}->append_child ($comment);        $self->{document}->append_child ($comment);
2635                
2636        ## Stay in the phase.        ## Stay in the insertion mode.
2637        !!!next-token;        !!!next-token;
2638        redo INITIAL;        redo INITIAL;
2639      } else {      } else {
# Line 2632  sub _tree_construction_initial ($) { Line 2646  sub _tree_construction_initial ($) {
2646    
2647  sub _tree_construction_root_element ($) {  sub _tree_construction_root_element ($) {
2648    my $self = shift;    my $self = shift;
2649    
2650      ## NOTE: "before html" insertion mode.
2651        
2652    B: {    B: {
2653        if ($token->{type} == DOCTYPE_TOKEN) {        if ($token->{type} == DOCTYPE_TOKEN) {
2654          !!!cp ('t19');          !!!cp ('t19');
2655          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
2656          ## Ignore the token          ## Ignore the token
2657          ## Stay in the phase          ## Stay in the insertion mode.
2658          !!!next-token;          !!!next-token;
2659          redo B;          redo B;
2660        } elsif ($token->{type} == COMMENT_TOKEN) {        } elsif ($token->{type} == COMMENT_TOKEN) {
2661          !!!cp ('t20');          !!!cp ('t20');
2662          my $comment = $self->{document}->create_comment ($token->{data});          my $comment = $self->{document}->create_comment ($token->{data});
2663          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2664          ## Stay in the phase          ## Stay in the insertion mode.
2665          !!!next-token;          !!!next-token;
2666          redo B;          redo B;
2667        } elsif ($token->{type} == CHARACTER_TOKEN) {        } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2654  sub _tree_construction_root_element ($) Line 2670  sub _tree_construction_root_element ($)
2670    
2671            unless (length $token->{data}) {            unless (length $token->{data}) {
2672              !!!cp ('t21');              !!!cp ('t21');
2673              ## Stay in the phase              ## Stay in the insertion mode.
2674              !!!next-token;              !!!next-token;
2675              redo B;              redo B;
2676            } else {            } else {
# Line 2668  sub _tree_construction_root_element ($) Line 2684  sub _tree_construction_root_element ($)
2684    
2685          #          #
2686        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
2687          if ($token->{tag_name} eq 'html' and          if ($token->{tag_name} eq 'html') {
2688              $token->{attributes}->{manifest}) {            my $root_element;
2689            !!!cp ('t24');            !!!create-element ($root_element, $token->{tag_name}, $token->{attributes});
2690            $self->{application_cache_selection}            $self->{document}->append_child ($root_element);
2691                 ->($token->{attributes}->{manifest}->{value});            push @{$self->{open_elements}}, [$root_element, 'html'];
2692            ## ISSUE: No relative reference resolution?  
2693              if ($token->{attributes}->{manifest}) {
2694                !!!cp ('t24');
2695                $self->{application_cache_selection}
2696                    ->($token->{attributes}->{manifest}->{value});
2697                ## ISSUE: No relative reference resolution?
2698              } else {
2699                !!!cp ('t25');
2700                $self->{application_cache_selection}->(undef);
2701              }
2702    
2703              !!!next-token;
2704              return; ## Go to the "before head" insertion mode.
2705          } else {          } else {
2706            !!!cp ('t25');            !!!cp ('t25.1');
2707            $self->{application_cache_selection}->(undef);            #
2708          }          }
   
         ## ISSUE: There is an issue in the spec  
         #  
2709        } elsif ({        } elsif ({
2710                  END_TAG_TOKEN, 1,                  END_TAG_TOKEN, 1,
2711                  END_OF_FILE_TOKEN, 1,                  END_OF_FILE_TOKEN, 1,
2712                 }->{$token->{type}}) {                 }->{$token->{type}}) {
2713          !!!cp ('t26');          !!!cp ('t26');
         $self->{application_cache_selection}->(undef);  
   
         ## ISSUE: There is an issue in the spec  
2714          #          #
2715        } else {        } else {
2716          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
2717        }        }
2718    
2719        my $root_element; !!!create-element ($root_element, 'html');      my $root_element; !!!create-element ($root_element, 'html');
2720        $self->{document}->append_child ($root_element);      $self->{document}->append_child ($root_element);
2721        push @{$self->{open_elements}}, [$root_element, 'html'];      push @{$self->{open_elements}}, [$root_element, 'html'];
2722        ## reprocess  
2723        #redo B;      $self->{application_cache_selection}->(undef);
2724        return; ## Go to the main phase.  
2725        ## NOTE: Reprocess the token.
2726        return; ## Go to the "before head" insertion mode.
2727    
2728        ## ISSUE: There is an issue in the spec
2729    } # B    } # B
2730    
2731    die "$0: _tree_construction_root_element: This should never be reached";    die "$0: _tree_construction_root_element: This should never be reached";
# Line 2717  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 2739  sub _reset_insertion_mode ($) { Line 2760  sub _reset_insertion_mode ($) {
2760        ## Step 4..13        ## Step 4..13
2761        my $new_mode = {        my $new_mode = {
2762                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
2763                          ## NOTE: |option| and |optgroup| do not set
2764                          ## insertion mode to "in select" by themselves.
2765                        td => IN_CELL_IM,                        td => IN_CELL_IM,
2766                        th => IN_CELL_IM,                        th => IN_CELL_IM,
2767                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
# Line 3185  sub _tree_construction_main ($) { Line 3208  sub _tree_construction_main ($) {
3208      } # FET      } # FET
3209    }; # $formatting_end_tag    }; # $formatting_end_tag
3210    
3211      ## NOTE: $open_tables->[-1]->[0] is the "current table".
3212      ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.
3213      my $open_tables = [[$self->{open_elements}->[0]->[0]]];
3214    
3215    my $insert_to_current = sub {    my $insert_to_current = sub {
3216      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
3217    }; # $insert_to_current    }; # $insert_to_current
3218    
3219    my $insert_to_foster = sub {    my $insert_to_foster = sub {
3220                         my $child = shift;      my $child = shift;
3221                         if ({      if ({
3222                              table => 1, tbody => 1, tfoot => 1,           table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3223                              thead => 1, tr => 1,          }->{$self->{open_elements}->[-1]->[1]}) {
3224                             }->{$self->{open_elements}->[-1]->[1]}) {        # MUST
3225                           # MUST        my $foster_parent_element;
3226                           my $foster_parent_element;        my $next_sibling;
                          my $next_sibling;  
3227                           OE: for (reverse 0..$#{$self->{open_elements}}) {                           OE: for (reverse 0..$#{$self->{open_elements}}) {
3228                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3229                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
# Line 3217  sub _tree_construction_main ($) { Line 3243  sub _tree_construction_main ($) {
3243                             unless defined $foster_parent_element;                             unless defined $foster_parent_element;
3244                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3245                             ($child, $next_sibling);                             ($child, $next_sibling);
3246                         } else {        $open_tables->[-1]->[1] = 1; # tainted
3247                           !!!cp ('t72');      } else {
3248                           $self->{open_elements}->[-1]->[0]->append_child ($child);        !!!cp ('t72');
3249                         }        $self->{open_elements}->[-1]->[0]->append_child ($child);
3250        }
3251    }; # $insert_to_foster    }; # $insert_to_foster
3252    
3253    my $insert;    my $insert;
# Line 3239  sub _tree_construction_main ($) { Line 3266  sub _tree_construction_main ($) {
3266          #          #
3267        } else {        } else {
3268          ## Generate implied end tags          ## Generate implied end tags
3269          if ({          while ({
3270               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,                  dd => 1, dt => 1, li => 1, p => 1,
3271               tbody => 1, tfoot=> 1, thead => 1,                 }->{$self->{open_elements}->[-1]->[1]}) {
             }->{$self->{open_elements}->[-1]->[1]}) {  
3272            !!!cp ('t75');            !!!cp ('t75');
3273            !!!back-token;            pop @{$self->{open_elements}};
           $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};  
           redo B;  
3274          }          }
3275                    
3276          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
# Line 3272  sub _tree_construction_main ($) { Line 3296  sub _tree_construction_main ($) {
3296               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3297        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
3298          !!!cp ('t79');          !!!cp ('t79');
         ## Turn into the main phase  
3299          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3300          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3301        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3302          !!!cp ('t80');          !!!cp ('t80');
         ## Turn into the main phase  
3303          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3304          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3305        } else {        } else {
3306          !!!cp ('t81');          !!!cp ('t81');
3307        }        }
3308    
3309  ## ISSUE: "aa<html>" is not a parse error.        !!!cp ('t82');
3310  ## ISSUE: "<html>" in fragment is not a parse error.        !!!parse-error (type => 'not first start tag');
       unless ($token->{first_start_tag}) {  
         !!!cp ('t82');  
         !!!parse-error (type => 'not first start tag');  
       } else {  
         !!!cp ('t83');  
       }  
3311        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3312        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3313          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
# Line 3666  sub _tree_construction_main ($) { Line 3682  sub _tree_construction_main ($) {
3682                  !!!cp ('t133');                  !!!cp ('t133');
3683                  ## As if </noscript>                  ## As if </noscript>
3684                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3685                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:/head');
3686                                    
3687                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3688                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 3771  sub _tree_construction_main ($) { Line 3787  sub _tree_construction_main ($) {
3787    
3788                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3789              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3790    ## ISSUE: This case cannot be reached?
3791                !!!cp ('t148');                !!!cp ('t148');
3792                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3793                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
# Line 3824  sub _tree_construction_main ($) { Line 3841  sub _tree_construction_main ($) {
3841                  } # INSCOPE                  } # INSCOPE
3842                    unless (defined $tn) {                    unless (defined $tn) {
3843                      !!!cp ('t153');                      !!!cp ('t153');
3844    ## TODO: This error type is wrong.
3845                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3846                      ## Ignore the token                      ## Ignore the token
3847                      !!!next-token;                      !!!next-token;
# Line 3856  sub _tree_construction_main ($) { Line 3874  sub _tree_construction_main ($) {
3874                  } # INSCOPE                  } # INSCOPE
3875                    unless (defined $i) {                    unless (defined $i) {
3876                      !!!cp ('t157');                      !!!cp ('t157');
3877    ## TODO: this type is wrong.
3878                      !!!parse-error (type => 'unmatched end tag:caption');                      !!!parse-error (type => 'unmatched end tag:caption');
3879                      ## Ignore the token                      ## Ignore the token
3880                      !!!next-token;                      !!!next-token;
# Line 3863  sub _tree_construction_main ($) { Line 3882  sub _tree_construction_main ($) {
3882                    }                    }
3883                                    
3884                  ## generate implied end tags                  ## generate implied end tags
3885                  if ({                  while ({
3886                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3887                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
3888                    !!!cp ('t158');                    !!!cp ('t158');
3889                    !!!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;  
3890                  }                  }
3891    
3892                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 3927  sub _tree_construction_main ($) { Line 3939  sub _tree_construction_main ($) {
3939                    }                    }
3940                                    
3941                  ## generate implied end tags                  ## generate implied end tags
3942                  if ({                  while ({
3943                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3944                       td => ($token->{tag_name} eq 'th'),                         }->{$self->{open_elements}->[-1]->[1]}) {
                      th => ($token->{tag_name} eq 'td'),  
                      tr => 1,  
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
3945                    !!!cp ('t166');                    !!!cp ('t166');
3946                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
3947                  }                  }
3948                    
3949                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3950                    !!!cp ('t167');                    !!!cp ('t167');
3951                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
# Line 3992  sub _tree_construction_main ($) { Line 3997  sub _tree_construction_main ($) {
3997                    }                    }
3998                                    
3999                  ## generate implied end tags                  ## generate implied end tags
4000                  if ({                  while ({
4001                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4002                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
4003                    !!!cp ('t174');                    !!!cp ('t174');
4004                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4005                  }                  }
4006                                    
4007                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4098  sub _tree_construction_main ($) { Line 4098  sub _tree_construction_main ($) {
4098                }                }
4099                                
4100                ## generate implied end tags                ## generate implied end tags
4101                if ({                while ({
4102                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4103                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4104                  !!!cp ('t187');                  !!!cp ('t187');
4105                  !!!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;  
4106                }                }
4107    
4108                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4162  sub _tree_construction_main ($) { Line 4155  sub _tree_construction_main ($) {
4155        #        #
4156      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
4157        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4158              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if (not $open_tables->[-1]->[1] and # tainted
4159                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4160              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4161                                
4162                unless (length $token->{data}) {            unless (length $token->{data}) {
4163                  !!!cp ('t194');              !!!cp ('t194');
4164                  !!!next-token;              !!!next-token;
4165                  redo B;              redo B;
4166                } else {            } else {
4167                  !!!cp ('t195');              !!!cp ('t195');
4168                }            }
4169              }          }
4170    
4171              !!!parse-error (type => 'in table:#character');              !!!parse-error (type => 'in table:#character');
4172    
# Line 4219  sub _tree_construction_main ($) { Line 4213  sub _tree_construction_main ($) {
4213                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4214                     $next_sibling);                     $next_sibling);
4215                }                }
4216              } else {            $open_tables->[-1]->[1] = 1; # tainted
4217                !!!cp ('t200');          } else {
4218                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});            !!!cp ('t200');
4219              }            $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4220            }
4221                            
4222              !!!next-token;          !!!next-token;
4223              redo B;          redo B;
4224        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4225              if ({              if ({
4226                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
# Line 4236  sub _tree_construction_main ($) { Line 4231  sub _tree_construction_main ($) {
4231                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4232                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4233                    !!!cp ('t201');                    !!!cp ('t201');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4234                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4235                  }                  }
4236                                    
# Line 4256  sub _tree_construction_main ($) { Line 4250  sub _tree_construction_main ($) {
4250                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4251                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4252                    !!!cp ('t203');                    !!!cp ('t203');
4253                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this case be reached?
4254                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4255                  }                  }
4256                                    
# Line 4280  sub _tree_construction_main ($) { Line 4274  sub _tree_construction_main ($) {
4274                  tr => 1, html => 1,                  tr => 1, html => 1,
4275                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4276                  !!!cp ('t207');                  !!!cp ('t207');
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4277                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4278                }                }
4279                                
# Line 4307  sub _tree_construction_main ($) { Line 4300  sub _tree_construction_main ($) {
4300                      $i = $_;                      $i = $_;
4301                      last INSCOPE;                      last INSCOPE;
4302                    } elsif ({                    } elsif ({
4303                              table => 1, html => 1,                              html => 1,
4304    
4305                                ## NOTE: This element does not appear here, maybe.
4306                                table => 1,
4307                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4308                      !!!cp ('t209');                      !!!cp ('t209');
4309                      last INSCOPE;                      last INSCOPE;
# Line 4315  sub _tree_construction_main ($) { Line 4311  sub _tree_construction_main ($) {
4311                  } # INSCOPE                  } # INSCOPE
4312                  unless (defined $i) {                  unless (defined $i) {
4313                   !!!cp ('t210');                   !!!cp ('t210');
4314    ## TODO: This type is wrong.
4315                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4316                    ## Ignore the token                    ## Ignore the token
4317                    !!!next-token;                    !!!next-token;
# Line 4326  sub _tree_construction_main ($) { Line 4323  sub _tree_construction_main ($) {
4323                    tr => 1, html => 1,                    tr => 1, html => 1,
4324                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4325                    !!!cp ('t211');                    !!!cp ('t211');
4326                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this case be reached?
4327                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4328                  }                  }
4329                                    
# Line 4362  sub _tree_construction_main ($) { Line 4359  sub _tree_construction_main ($) {
4359                  } # INSCOPE                  } # INSCOPE
4360                  unless (defined $i) {                  unless (defined $i) {
4361                    !!!cp ('t216');                    !!!cp ('t216');
4362    ## TODO: This erorr type ios wrong.
4363                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4364                    ## Ignore the token                    ## Ignore the token
4365                    !!!next-token;                    !!!next-token;
# Line 4373  sub _tree_construction_main ($) { Line 4371  sub _tree_construction_main ($) {
4371                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4372                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4373                    !!!cp ('t217');                    !!!cp ('t217');
4374                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4375                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4376                  }                  }
4377                                    
# Line 4396  sub _tree_construction_main ($) { Line 4394  sub _tree_construction_main ($) {
4394                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4395                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4396                    !!!cp ('t219');                    !!!cp ('t219');
4397                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4398                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4399                  }                  }
4400                                    
# Line 4413  sub _tree_construction_main ($) { Line 4411  sub _tree_construction_main ($) {
4411                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4412                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4413                    !!!cp ('t220');                    !!!cp ('t220');
4414                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4415                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4416                  }                  }
4417                                    
# Line 4446  sub _tree_construction_main ($) { Line 4444  sub _tree_construction_main ($) {
4444                    $i = $_;                    $i = $_;
4445                    last INSCOPE;                    last INSCOPE;
4446                  } elsif ({                  } elsif ({
4447                            table => 1, html => 1,                            #table => 1,
4448                              html => 1,
4449                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4450                    !!!cp ('t222');                    !!!cp ('t222');
4451                    last INSCOPE;                    last INSCOPE;
# Line 4454  sub _tree_construction_main ($) { Line 4453  sub _tree_construction_main ($) {
4453                } # INSCOPE                } # INSCOPE
4454                unless (defined $i) {                unless (defined $i) {
4455                  !!!cp ('t223');                  !!!cp ('t223');
4456    ## TODO: The following is wrong, maybe.
4457                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table');
4458                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4459                  !!!next-token;                  !!!next-token;
# Line 4461  sub _tree_construction_main ($) { Line 4461  sub _tree_construction_main ($) {
4461                }                }
4462                                
4463                ## generate implied end tags                ## generate implied end tags
4464                if ({                while ({
4465                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4466                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4467                  !!!cp ('t224');                  !!!cp ('t224');
4468                  !!!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;  
4469                }                }
4470    
4471                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4472                  !!!cp ('t225');                  !!!cp ('t225');
4473    ## ISSUE: Can this case be reached?
4474                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4475                } else {                } else {
4476                  !!!cp ('t226');                  !!!cp ('t226');
4477                }                }
4478    
4479                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4480                  pop @{$open_tables};
4481    
4482                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4483    
# Line 4528  sub _tree_construction_main ($) { Line 4523  sub _tree_construction_main ($) {
4523                  tr => 1, html => 1,                  tr => 1, html => 1,
4524                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4525                  !!!cp ('t231');                  !!!cp ('t231');
4526                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this state be reached?
4527                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4528                }                }
4529    
# Line 4556  sub _tree_construction_main ($) { Line 4551  sub _tree_construction_main ($) {
4551                  } # INSCOPE                  } # INSCOPE
4552                  unless (defined $i) {                  unless (defined $i) {
4553                    !!!cp ('t235');                    !!!cp ('t235');
4554    ## TODO: The following is wrong.
4555                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4556                    ## Ignore the token                    ## Ignore the token
4557                    !!!next-token;                    !!!next-token;
# Line 4567  sub _tree_construction_main ($) { Line 4563  sub _tree_construction_main ($) {
4563                    tr => 1, html => 1,                    tr => 1, html => 1,
4564                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4565                    !!!cp ('t236');                    !!!cp ('t236');
4566                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this state be reached?
4567                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4568                  }                  }
4569                                    
# Line 4607  sub _tree_construction_main ($) { Line 4603  sub _tree_construction_main ($) {
4603                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4604                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4605                    !!!cp ('t240');                    !!!cp ('t240');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4606                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4607                  }                  }
4608                                    
# Line 4623  sub _tree_construction_main ($) { Line 4618  sub _tree_construction_main ($) {
4618                  ## reprocess in the "in table" insertion mode...                  ## reprocess in the "in table" insertion mode...
4619                }                }
4620    
4621                  ## NOTE: </table> in the "in table" insertion mode.
4622                  ## When you edit the code fragment below, please ensure that
4623                  ## the code for <table> in the "in table" insertion mode
4624                  ## is synced with it.
4625    
4626                ## have a table element in table scope                ## have a table element in table scope
4627                my $i;                my $i;
4628                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 4645  sub _tree_construction_main ($) { Line 4645  sub _tree_construction_main ($) {
4645                  !!!next-token;                  !!!next-token;
4646                  redo B;                  redo B;
4647                }                }
   
               ## 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');  
                 !!!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');  
               }  
4648                                    
4649                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4650                  pop @{$open_tables};
4651                                
4652                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4653                                
# Line 4729  sub _tree_construction_main ($) { Line 4710  sub _tree_construction_main ($) {
4710                    tr => 1, html => 1,                    tr => 1, html => 1,
4711                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4712                    !!!cp ('t253');                    !!!cp ('t253');
4713                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this case be reached?
4714                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4715                  }                  }
4716                                    
# Line 4766  sub _tree_construction_main ($) { Line 4747  sub _tree_construction_main ($) {
4747                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4748                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4749                  !!!cp ('t257');                  !!!cp ('t257');
4750                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this case be reached?
4751                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4752                }                }
4753    
# Line 4845  sub _tree_construction_main ($) { Line 4826  sub _tree_construction_main ($) {
4826                #                #
4827              }              }
4828            } else {            } else {
4829              !!!cp ('t268');              die "$0: $token->{type}: Unknown token type";
             #  
4830            }            }
4831    
4832            ## As if </colgroup>            ## As if </colgroup>
# Line 4903  sub _tree_construction_main ($) { Line 4883  sub _tree_construction_main ($) {
4883                !!!next-token;                !!!next-token;
4884                redo B;                redo B;
4885              } elsif ($token->{tag_name} eq 'select') {              } elsif ($token->{tag_name} eq 'select') {
4886    ## TODO: The type below is not good - <select> is replaced by </select>
4887                !!!parse-error (type => 'not closed:select');                !!!parse-error (type => 'not closed:select');
4888                ## As if </select> instead                ## As if </select> instead
4889                ## have an element in table scope                ## have an element in table scope
# Line 5005  sub _tree_construction_main ($) { Line 4986  sub _tree_construction_main ($) {
4986                        caption => 1, table => 1, tbody => 1,                        caption => 1, table => 1, tbody => 1,
4987                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
4988                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4989    ## TODO: The following is wrong?
4990                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4991                                
4992                ## have an element in table scope                ## have an element in table scope
# Line 5041  sub _tree_construction_main ($) { Line 5023  sub _tree_construction_main ($) {
5023                  } elsif ({                  } elsif ({
5024                            table => 1, html => 1,                            table => 1, html => 1,
5025                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5026    ## ISSUE: Can this state be reached?
5027                    !!!cp ('t296');                    !!!cp ('t296');
5028                    last INSCOPE;                    last INSCOPE;
5029                  }                  }
5030                } # INSCOPE                } # INSCOPE
5031                unless (defined $i) {                unless (defined $i) {
5032                  !!!cp ('t297');                  !!!cp ('t297');
5033    ## TODO: The following error type is correct?
5034                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5035                  ## Ignore the </select> token                  ## Ignore the </select> token
5036                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
# Line 5090  sub _tree_construction_main ($) { Line 5074  sub _tree_construction_main ($) {
5074            !!!cp ('t301');            !!!cp ('t301');
5075            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character');
5076    
5077            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5078          } else {          } else {
5079            !!!cp ('t302');            !!!cp ('t302');
5080          }          }
# Line 5106  sub _tree_construction_main ($) { Line 5090  sub _tree_construction_main ($) {
5090            !!!cp ('t303');            !!!cp ('t303');
5091            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5092                        
5093            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5094          } else {          } else {
5095            !!!cp ('t304');            !!!cp ('t304');
5096          }          }
# Line 5123  sub _tree_construction_main ($) { Line 5107  sub _tree_construction_main ($) {
5107            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5108                        
5109            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5110            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5111          } else {          } else {
5112            !!!cp ('t306');            !!!cp ('t306');
5113          }          }
# Line 5177  sub _tree_construction_main ($) { Line 5161  sub _tree_construction_main ($) {
5161              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character');
5162    
5163              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5164              ## Reprocess in the "main" phase, "after frameset"...              ## Reprocess in the "after frameset" insertion mode.
5165              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5166            }            }
5167                        
# Line 5199  sub _tree_construction_main ($) { Line 5183  sub _tree_construction_main ($) {
5183            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5184    
5185            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5186            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5187          } else {          } else {
5188            !!!cp ('t317');            !!!cp ('t317');
5189          }          }
# Line 5240  sub _tree_construction_main ($) { Line 5224  sub _tree_construction_main ($) {
5224            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5225    
5226            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5227            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5228          } else {          } else {
5229            !!!cp ('t324');            !!!cp ('t324');
5230          }          }
# Line 5401  sub _tree_construction_main ($) { Line 5385  sub _tree_construction_main ($) {
5385          redo B;          redo B;
5386        } elsif ({        } elsif ({
5387                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5388                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1,
5389                  menu => 1, ol => 1, p => 1, ul => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5390                    listing => 1, menu => 1, ol => 1, p => 1, ul => 1,
5391                  pre => 1,                  pre => 1,
5392                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5393          ## has a p element in scope          ## has a p element in scope
# Line 5604  sub _tree_construction_main ($) { Line 5589  sub _tree_construction_main ($) {
5589                        
5590          !!!next-token;          !!!next-token;
5591          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;  
5592        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
5593          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5594            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
# Line 5751  sub _tree_construction_main ($) { Line 5689  sub _tree_construction_main ($) {
5689          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5690                        
5691          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5692    
5693            ## TODO: associate with $self->{form_element} if defined
5694    
5695          push @$active_formatting_elements, ['#marker', ''];          push @$active_formatting_elements, ['#marker', ''];
5696    
5697          !!!next-token;          !!!next-token;
# Line 5788  sub _tree_construction_main ($) { Line 5729  sub _tree_construction_main ($) {
5729          } # INSCOPE          } # INSCOPE
5730                        
5731          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5732                      push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];
5733    
5734          $self->{insertion_mode} = IN_TABLE_IM;          $self->{insertion_mode} = IN_TABLE_IM;
5735                        
5736          !!!next-token;          !!!next-token;
# Line 5950  sub _tree_construction_main ($) { Line 5892  sub _tree_construction_main ($) {
5892          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5893                    
5894          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5895    
5896            ## TODO: associate with $self->{form_element} if defined
5897                    
5898          $self->{insertion_mode} = IN_SELECT_IM;          $self->{insertion_mode} = IN_SELECT_IM;
5899          !!!next-token;          !!!next-token;
# Line 6026  sub _tree_construction_main ($) { Line 5970  sub _tree_construction_main ($) {
5970                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5971                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
5972                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 p => 1,  
5973                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
5974                  button => 1, marquee => 1, object => 1,                  button => 1, marquee => 1, object => 1,
5975                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 6035  sub _tree_construction_main ($) { Line 5978  sub _tree_construction_main ($) {
5978          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5979            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5980            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;  
             }  
               
5981              !!!cp ('t410');              !!!cp ('t410');
5982              $i = $_;              $i = $_;
5983              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE;
5984            } elsif ({            } elsif ({
5985                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5986                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
# Line 6062  sub _tree_construction_main ($) { Line 5989  sub _tree_construction_main ($) {
5989              last INSCOPE;              last INSCOPE;
5990            }            }
5991          } # INSCOPE          } # INSCOPE
5992            
5993          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
5994            if (defined $i) {            !!!cp ('t413');
5995              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5996            } else {
5997              ## Step 1. generate implied end tags
5998              while ({
5999                      dd => ($token->{tag_name} ne 'dd'),
6000                      dt => ($token->{tag_name} ne 'dt'),
6001                      li => ($token->{tag_name} ne 'li'),
6002                      p => 1,
6003                     }->{$self->{open_elements}->[-1]->[1]}) {
6004                !!!cp ('t409');
6005                pop @{$self->{open_elements}};
6006              }
6007    
6008              ## Step 2.
6009              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6010              !!!cp ('t412');              !!!cp ('t412');
6011              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6012            } else {            } else {
6013              !!!cp ('t413');              !!!cp ('t414');
             !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
6014            }            }
6015          }  
6016                      ## Step 3.
         if (defined $i) {  
           !!!cp ('t414');  
6017            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6018          } elsif ($token->{tag_name} eq 'p') {  
6019            !!!cp ('t415');            ## Step 4.
6020            ## As if <p>, then reprocess the current token            $clear_up_to_marker->()
6021            my $el;                if {
6022            !!!create-element ($el, 'p');                  button => 1, marquee => 1, object => 1,
6023            $insert->($el);                }->{$token->{tag_name}};
         } else {  
           !!!cp ('t416');  
6024          }          }
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
6025          !!!next-token;          !!!next-token;
6026          redo B;          redo B;
6027        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
6028            undef $self->{form_element};
6029    
6030          ## has an element in scope          ## has an element in scope
6031            my $i;
6032          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6033            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6034            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,  
                  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;  
             }  
               
6035              !!!cp ('t418');              !!!cp ('t418');
6036                $i = $_;
6037              last INSCOPE;              last INSCOPE;
6038            } elsif ({            } elsif ({
6039                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 6119  sub _tree_construction_main ($) { Line 6043  sub _tree_construction_main ($) {
6043              last INSCOPE;              last INSCOPE;
6044            }            }
6045          } # INSCOPE          } # INSCOPE
6046            
6047          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 {  
6048            !!!cp ('t421');            !!!cp ('t421');
6049            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6050            } else {
6051              ## Step 1. generate implied end tags
6052              while ({
6053                      dd => 1, dt => 1, li => 1, p => 1,
6054                     }->{$self->{open_elements}->[-1]->[1]}) {
6055                !!!cp ('t417');
6056                pop @{$self->{open_elements}};
6057              }
6058              
6059              ## Step 2.
6060              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6061                !!!cp ('t417.1');
6062                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6063              } else {
6064                !!!cp ('t420');
6065              }  
6066              
6067              ## Step 3.
6068              splice @{$self->{open_elements}}, $i;
6069          }          }
6070    
         undef $self->{form_element};  
6071          !!!next-token;          !!!next-token;
6072          redo B;          redo B;
6073        } elsif ({        } elsif ({
# Line 6141  sub _tree_construction_main ($) { Line 6080  sub _tree_construction_main ($) {
6080            if ({            if ({
6081                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
6082                }->{$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;  
             }  
   
6083              !!!cp ('t423');              !!!cp ('t423');
6084              $i = $_;              $i = $_;
6085              last INSCOPE;              last INSCOPE;
# Line 6165  sub _tree_construction_main ($) { Line 6091  sub _tree_construction_main ($) {
6091              last INSCOPE;              last INSCOPE;
6092            }            }
6093          } # INSCOPE          } # INSCOPE
6094            
6095          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6096            !!!cp ('t425');            !!!cp ('t425.1');
6097            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6098          } else {          } else {
6099            !!!cp ('t426');            ## Step 1. generate implied end tags
6100              while ({
6101                      dd => 1, dt => 1, li => 1, p => 1,
6102                     }->{$self->{open_elements}->[-1]->[1]}) {
6103                !!!cp ('t422');
6104                pop @{$self->{open_elements}};
6105              }
6106              
6107              ## Step 2.
6108              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6109                !!!cp ('t425');
6110                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6111              } else {
6112                !!!cp ('t426');
6113              }
6114    
6115              ## Step 3.
6116              splice @{$self->{open_elements}}, $i;
6117          }          }
6118                    
6119          splice @{$self->{open_elements}}, $i if defined $i;          !!!next-token;
6120            redo B;
6121          } elsif ($token->{tag_name} eq 'p') {
6122            ## has an element in scope
6123            my $i;
6124            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6125              my $node = $self->{open_elements}->[$_];
6126              if ($node->[1] eq $token->{tag_name}) {
6127                !!!cp ('t410.1');
6128                $i = $_;
6129                last INSCOPE;
6130              } elsif ({
6131                        table => 1, caption => 1, td => 1, th => 1,
6132                        button => 1, marquee => 1, object => 1, html => 1,
6133                       }->{$node->[1]}) {
6134                !!!cp ('t411.1');
6135                last INSCOPE;
6136              }
6137            } # INSCOPE
6138    
6139            if (defined $i) {
6140              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6141                !!!cp ('t412.1');
6142                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6143              } else {
6144                !!!cp ('t414.1');
6145              }
6146    
6147              splice @{$self->{open_elements}}, $i;
6148            } else {
6149              !!!cp ('t413.1');
6150              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6151    
6152              !!!cp ('t415.1');
6153              ## As if <p>, then reprocess the current token
6154              my $el;
6155              !!!create-element ($el, 'p');
6156              $insert->($el);
6157              ## NOTE: Not inserted into |$self->{open_elements}|.
6158            }
6159    
6160          !!!next-token;          !!!next-token;
6161          redo B;          redo B;
6162        } elsif ({        } elsif ({
# Line 6229  sub _tree_construction_main ($) { Line 6212  sub _tree_construction_main ($) {
6212            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6213              ## Step 1              ## Step 1
6214              ## generate implied end tags              ## generate implied end tags
6215              if ({              while ({
6216                   dd => 1, dt => 1, li => 1, p => 1,                      dd => 1, dt => 1, li => 1, p => 1,
6217                   td => 1, th => 1, tr => 1,                     }->{$self->{open_elements}->[-1]->[1]}) {
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
6218                !!!cp ('t430');                !!!cp ('t430');
6219                !!!back-token;                ## ISSUE: Can this case be reached?
6220                $token = {type => END_TAG_TOKEN,                pop @{$self->{open_elements}};
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
6221              }              }
6222                    
6223              ## Step 2              ## Step 2
# Line 6284  sub _tree_construction_main ($) { Line 6263  sub _tree_construction_main ($) {
6263      redo B;      redo B;
6264    } # B    } # B
6265    
   ## NOTE: The "trailing end" phase in HTML5 is split into  
   ## two insertion modes: "after html body" and "after html frameset".  
   ## NOTE: States in the main stage is preserved while  
   ## the parser stays in the trailing end phase. # MUST  
   
6266    ## Stop parsing # MUST    ## Stop parsing # MUST
6267        
6268    ## TODO: script stuffs    ## TODO: script stuffs
# Line 6330  sub set_inner_html ($$$) { Line 6304  sub set_inner_html ($$$) {
6304      my $p = $class->new;      my $p = $class->new;
6305      $p->{document} = $doc;      $p->{document} = $doc;
6306    
6307      ## Step 9 # MUST      ## Step 8 # MUST
6308      my $i = 0;      my $i = 0;
6309      my $line = 1;      my $line = 1;
6310      my $column = 0;      my $column = 0;
# Line 6397  sub set_inner_html ($$$) { Line 6371  sub set_inner_html ($$$) {
6371    
6372      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
6373    
6374      ## Step 4      ## Step 3
6375      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
6376        ('http://www.w3.org/1999/xhtml', [undef, 'html']);        ('http://www.w3.org/1999/xhtml', [undef, 'html']);
6377    
6378      ## Step 5 # MUST      ## Step 4 # MUST
6379      $doc->append_child ($root);      $doc->append_child ($root);
6380    
6381      ## Step 6 # MUST      ## Step 5 # MUST
6382      push @{$p->{open_elements}}, [$root, 'html'];      push @{$p->{open_elements}}, [$root, 'html'];
6383    
6384      undef $p->{head_element};      undef $p->{head_element};
6385    
6386      ## Step 7 # MUST      ## Step 6 # MUST
6387      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;
6388    
6389      ## Step 8 # MUST      ## Step 7 # MUST
6390      my $anode = $node;      my $anode = $node;
6391      AN: while (defined $anode) {      AN: while (defined $anode) {
6392        if ($anode->node_type == 1) {        if ($anode->node_type == 1) {
# Line 6428  sub set_inner_html ($$$) { Line 6402  sub set_inner_html ($$$) {
6402        $anode = $anode->parent_node;        $anode = $anode->parent_node;
6403      } # AN      } # AN
6404            
6405      ## Step 3 # MUST      ## Step 9 # MUST
     ## Step 10 # MUST  
6406      {      {
6407        my $self = $p;        my $self = $p;
6408        !!!next-token;        !!!next-token;
6409      }      }
6410      $p->_tree_construction_main;      $p->_tree_construction_main;
6411    
6412      ## Step 11 # MUST      ## Step 10 # MUST
6413      my @cn = @{$node->child_nodes};      my @cn = @{$node->child_nodes};
6414      for (@cn) {      for (@cn) {
6415        $node->remove_child ($_);        $node->remove_child ($_);
6416      }      }
6417      ## ISSUE: mutation events? read-only?      ## ISSUE: mutation events? read-only?
6418    
6419      ## Step 12 # MUST      ## Step 11 # MUST
6420      @cn = @{$root->child_nodes};      @cn = @{$root->child_nodes};
6421      for (@cn) {      for (@cn) {
6422        $this_doc->adopt_node ($_);        $this_doc->adopt_node ($_);

Legend:
Removed from v.1.81  
changed lines
  Added in v.1.95

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24