/[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.96 by wakaba, Sat Mar 8 13:26:45 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 2880  sub _tree_construction_main ($) { Line 2903  sub _tree_construction_main ($) {
2903      !!!cp ('t39');      !!!cp ('t39');
2904    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2905    
2906    my $parse_rcdata = sub ($$) {    my $insert;
2907      my ($content_model_flag, $insert) = @_;  
2908      my $parse_rcdata = sub ($) {
2909        my ($content_model_flag) = @_;
2910    
2911      ## Step 1      ## Step 1
2912      my $start_tag_name = $token->{tag_name};      my $start_tag_name = $token->{tag_name};
# Line 2889  sub _tree_construction_main ($) { Line 2914  sub _tree_construction_main ($) {
2914      !!!create-element ($el, $start_tag_name, $token->{attributes});      !!!create-element ($el, $start_tag_name, $token->{attributes});
2915    
2916      ## Step 2      ## Step 2
2917      $insert->($el); # /context node/->append_child ($el)      $insert->($el);
2918    
2919      ## Step 3      ## Step 3
2920      $self->{content_model} = $content_model_flag; # CDATA or RCDATA      $self->{content_model} = $content_model_flag; # CDATA or RCDATA
# Line 2919  sub _tree_construction_main ($) { Line 2944  sub _tree_construction_main ($) {
2944          $token->{tag_name} eq $start_tag_name) {          $token->{tag_name} eq $start_tag_name) {
2945        !!!cp ('t42');        !!!cp ('t42');
2946        ## Ignore the token        ## Ignore the token
     } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {  
       !!!cp ('t43');  
       !!!parse-error (type => 'in CDATA:#'.$token->{type});  
     } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {  
       !!!cp ('t44');  
       !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
2947      } else {      } else {
2948        die "$0: $content_model_flag in parse_rcdata";        ## NOTE: An end-of-file token.
2949          if ($content_model_flag == CDATA_CONTENT_MODEL) {
2950            !!!cp ('t43');
2951            !!!parse-error (type => 'in CDATA:#'.$token->{type});
2952          } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2953            !!!cp ('t44');
2954            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2955          } else {
2956            die "$0: $content_model_flag in parse_rcdata";
2957          }
2958      }      }
2959      !!!next-token;      !!!next-token;
2960    }; # $parse_rcdata    }; # $parse_rcdata
2961    
2962    my $script_start_tag = sub ($) {    my $script_start_tag = sub () {
     my $insert = $_[0];  
2963      my $script_el;      my $script_el;
2964      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2965      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
# Line 3185  sub _tree_construction_main ($) { Line 3212  sub _tree_construction_main ($) {
3212      } # FET      } # FET
3213    }; # $formatting_end_tag    }; # $formatting_end_tag
3214    
3215    my $insert_to_current = sub {    ## NOTE: $open_tables->[-1]->[0] is the "current table".
3216      ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.
3217      my $open_tables = [[$self->{open_elements}->[0]->[0]]];
3218    
3219      $insert = my $insert_to_current = sub {
3220      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
3221    }; # $insert_to_current    }; # $insert_to_current
3222    
3223    my $insert_to_foster = sub {    my $insert_to_foster = sub {
3224                         my $child = shift;      my $child = shift;
3225                         if ({      if ({
3226                              table => 1, tbody => 1, tfoot => 1,           table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3227                              thead => 1, tr => 1,          }->{$self->{open_elements}->[-1]->[1]}) {
3228                             }->{$self->{open_elements}->[-1]->[1]}) {        # MUST
3229                           # MUST        my $foster_parent_element;
3230                           my $foster_parent_element;        my $next_sibling;
                          my $next_sibling;  
3231                           OE: for (reverse 0..$#{$self->{open_elements}}) {                           OE: for (reverse 0..$#{$self->{open_elements}}) {
3232                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3233                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
# Line 3217  sub _tree_construction_main ($) { Line 3247  sub _tree_construction_main ($) {
3247                             unless defined $foster_parent_element;                             unless defined $foster_parent_element;
3248                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3249                             ($child, $next_sibling);                             ($child, $next_sibling);
3250                         } else {        $open_tables->[-1]->[1] = 1; # tainted
3251                           !!!cp ('t72');      } else {
3252                           $self->{open_elements}->[-1]->[0]->append_child ($child);        !!!cp ('t72');
3253                         }        $self->{open_elements}->[-1]->[0]->append_child ($child);
3254        }
3255    }; # $insert_to_foster    }; # $insert_to_foster
3256    
   my $insert;  
   
3257    B: {    B: {
3258      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3259        !!!cp ('t73');        !!!cp ('t73');
# Line 3239  sub _tree_construction_main ($) { Line 3268  sub _tree_construction_main ($) {
3268          #          #
3269        } else {        } else {
3270          ## Generate implied end tags          ## Generate implied end tags
3271          if ({          while ({
3272               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,                  dd => 1, dt => 1, li => 1, p => 1,
3273               tbody => 1, tfoot=> 1, thead => 1,                 }->{$self->{open_elements}->[-1]->[1]}) {
             }->{$self->{open_elements}->[-1]->[1]}) {  
3274            !!!cp ('t75');            !!!cp ('t75');
3275            !!!back-token;            pop @{$self->{open_elements}};
           $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};  
           redo B;  
3276          }          }
3277                    
3278          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
# Line 3272  sub _tree_construction_main ($) { Line 3298  sub _tree_construction_main ($) {
3298               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3299        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
3300          !!!cp ('t79');          !!!cp ('t79');
         ## Turn into the main phase  
3301          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3302          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3303        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3304          !!!cp ('t80');          !!!cp ('t80');
         ## Turn into the main phase  
3305          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3306          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3307        } else {        } else {
3308          !!!cp ('t81');          !!!cp ('t81');
3309        }        }
3310    
3311  ## ISSUE: "aa<html>" is not a parse error.        !!!cp ('t82');
3312  ## 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');  
       }  
3313        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3314        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3315          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
# Line 3521  sub _tree_construction_main ($) { Line 3539  sub _tree_construction_main ($) {
3539                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3540                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3541                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3542                $parse_rcdata->(RCDATA_CONTENT_MODEL,                $parse_rcdata->(RCDATA_CONTENT_MODEL);
                               sub { $parent->append_child ($_[0]) });  
3543                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3544                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3545                redo B;                redo B;
# Line 3537  sub _tree_construction_main ($) { Line 3554  sub _tree_construction_main ($) {
3554                } else {                } else {
3555                  !!!cp ('t115');                  !!!cp ('t115');
3556                }                }
3557                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL);
3558                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3559                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3560                redo B;                redo B;
# Line 3666  sub _tree_construction_main ($) { Line 3683  sub _tree_construction_main ($) {
3683                  !!!cp ('t133');                  !!!cp ('t133');
3684                  ## As if </noscript>                  ## As if </noscript>
3685                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3686                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:/head');
3687                                    
3688                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3689                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 3771  sub _tree_construction_main ($) { Line 3788  sub _tree_construction_main ($) {
3788    
3789                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3790              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3791    ## ISSUE: This case cannot be reached?
3792                !!!cp ('t148');                !!!cp ('t148');
3793                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3794                ## 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 3842  sub _tree_construction_main ($) {
3842                  } # INSCOPE                  } # INSCOPE
3843                    unless (defined $tn) {                    unless (defined $tn) {
3844                      !!!cp ('t153');                      !!!cp ('t153');
3845    ## TODO: This error type is wrong.
3846                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3847                      ## Ignore the token                      ## Ignore the token
3848                      !!!next-token;                      !!!next-token;
# Line 3856  sub _tree_construction_main ($) { Line 3875  sub _tree_construction_main ($) {
3875                  } # INSCOPE                  } # INSCOPE
3876                    unless (defined $i) {                    unless (defined $i) {
3877                      !!!cp ('t157');                      !!!cp ('t157');
3878    ## TODO: this type is wrong.
3879                      !!!parse-error (type => 'unmatched end tag:caption');                      !!!parse-error (type => 'unmatched end tag:caption');
3880                      ## Ignore the token                      ## Ignore the token
3881                      !!!next-token;                      !!!next-token;
# Line 3863  sub _tree_construction_main ($) { Line 3883  sub _tree_construction_main ($) {
3883                    }                    }
3884                                    
3885                  ## generate implied end tags                  ## generate implied end tags
3886                  if ({                  while ({
3887                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3888                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
3889                    !!!cp ('t158');                    !!!cp ('t158');
3890                    !!!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;  
3891                  }                  }
3892    
3893                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 3927  sub _tree_construction_main ($) { Line 3940  sub _tree_construction_main ($) {
3940                    }                    }
3941                                    
3942                  ## generate implied end tags                  ## generate implied end tags
3943                  if ({                  while ({
3944                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3945                       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]}) {  
3946                    !!!cp ('t166');                    !!!cp ('t166');
3947                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
3948                  }                  }
3949                    
3950                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3951                    !!!cp ('t167');                    !!!cp ('t167');
3952                    !!!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 3998  sub _tree_construction_main ($) {
3998                    }                    }
3999                                    
4000                  ## generate implied end tags                  ## generate implied end tags
4001                  if ({                  while ({
4002                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4003                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
4004                    !!!cp ('t174');                    !!!cp ('t174');
4005                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4006                  }                  }
4007                                    
4008                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4098  sub _tree_construction_main ($) { Line 4099  sub _tree_construction_main ($) {
4099                }                }
4100                                
4101                ## generate implied end tags                ## generate implied end tags
4102                if ({                while ({
4103                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4104                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4105                  !!!cp ('t187');                  !!!cp ('t187');
4106                  !!!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;  
4107                }                }
4108    
4109                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4162  sub _tree_construction_main ($) { Line 4156  sub _tree_construction_main ($) {
4156        #        #
4157      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
4158        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4159              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if (not $open_tables->[-1]->[1] and # tainted
4160                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4161              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4162                                
4163                unless (length $token->{data}) {            unless (length $token->{data}) {
4164                  !!!cp ('t194');              !!!cp ('t194');
4165                  !!!next-token;              !!!next-token;
4166                  redo B;              redo B;
4167                } else {            } else {
4168                  !!!cp ('t195');              !!!cp ('t195');
4169                }            }
4170              }          }
4171    
4172              !!!parse-error (type => 'in table:#character');              !!!parse-error (type => 'in table:#character');
4173    
# Line 4219  sub _tree_construction_main ($) { Line 4214  sub _tree_construction_main ($) {
4214                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4215                     $next_sibling);                     $next_sibling);
4216                }                }
4217              } else {            $open_tables->[-1]->[1] = 1; # tainted
4218                !!!cp ('t200');          } else {
4219                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});            !!!cp ('t200');
4220              }            $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4221            }
4222                            
4223              !!!next-token;          !!!next-token;
4224              redo B;          redo B;
4225        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4226              if ({              if ({
4227                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
# Line 4236  sub _tree_construction_main ($) { Line 4232  sub _tree_construction_main ($) {
4232                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4233                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4234                    !!!cp ('t201');                    !!!cp ('t201');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4235                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4236                  }                  }
4237                                    
# Line 4256  sub _tree_construction_main ($) { Line 4251  sub _tree_construction_main ($) {
4251                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4252                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4253                    !!!cp ('t203');                    !!!cp ('t203');
4254                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this case be reached?
4255                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4256                  }                  }
4257                                    
# Line 4280  sub _tree_construction_main ($) { Line 4275  sub _tree_construction_main ($) {
4275                  tr => 1, html => 1,                  tr => 1, html => 1,
4276                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4277                  !!!cp ('t207');                  !!!cp ('t207');
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4278                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4279                }                }
4280                                
# Line 4307  sub _tree_construction_main ($) { Line 4301  sub _tree_construction_main ($) {
4301                      $i = $_;                      $i = $_;
4302                      last INSCOPE;                      last INSCOPE;
4303                    } elsif ({                    } elsif ({
4304                              table => 1, html => 1,                              html => 1,
4305    
4306                                ## NOTE: This element does not appear here, maybe.
4307                                table => 1,
4308                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4309                      !!!cp ('t209');                      !!!cp ('t209');
4310                      last INSCOPE;                      last INSCOPE;
# Line 4315  sub _tree_construction_main ($) { Line 4312  sub _tree_construction_main ($) {
4312                  } # INSCOPE                  } # INSCOPE
4313                  unless (defined $i) {                  unless (defined $i) {
4314                   !!!cp ('t210');                   !!!cp ('t210');
4315    ## TODO: This type is wrong.
4316                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4317                    ## Ignore the token                    ## Ignore the token
4318                    !!!next-token;                    !!!next-token;
# Line 4326  sub _tree_construction_main ($) { Line 4324  sub _tree_construction_main ($) {
4324                    tr => 1, html => 1,                    tr => 1, html => 1,
4325                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4326                    !!!cp ('t211');                    !!!cp ('t211');
4327                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this case be reached?
4328                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4329                  }                  }
4330                                    
# Line 4362  sub _tree_construction_main ($) { Line 4360  sub _tree_construction_main ($) {
4360                  } # INSCOPE                  } # INSCOPE
4361                  unless (defined $i) {                  unless (defined $i) {
4362                    !!!cp ('t216');                    !!!cp ('t216');
4363    ## TODO: This erorr type ios wrong.
4364                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4365                    ## Ignore the token                    ## Ignore the token
4366                    !!!next-token;                    !!!next-token;
# Line 4373  sub _tree_construction_main ($) { Line 4372  sub _tree_construction_main ($) {
4372                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4373                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4374                    !!!cp ('t217');                    !!!cp ('t217');
4375                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4376                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4377                  }                  }
4378                                    
# Line 4396  sub _tree_construction_main ($) { Line 4395  sub _tree_construction_main ($) {
4395                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4396                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4397                    !!!cp ('t219');                    !!!cp ('t219');
4398                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4399                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4400                  }                  }
4401                                    
# Line 4413  sub _tree_construction_main ($) { Line 4412  sub _tree_construction_main ($) {
4412                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4413                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4414                    !!!cp ('t220');                    !!!cp ('t220');
4415                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4416                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4417                  }                  }
4418                                    
# Line 4446  sub _tree_construction_main ($) { Line 4445  sub _tree_construction_main ($) {
4445                    $i = $_;                    $i = $_;
4446                    last INSCOPE;                    last INSCOPE;
4447                  } elsif ({                  } elsif ({
4448                            table => 1, html => 1,                            #table => 1,
4449                              html => 1,
4450                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4451                    !!!cp ('t222');                    !!!cp ('t222');
4452                    last INSCOPE;                    last INSCOPE;
# Line 4454  sub _tree_construction_main ($) { Line 4454  sub _tree_construction_main ($) {
4454                } # INSCOPE                } # INSCOPE
4455                unless (defined $i) {                unless (defined $i) {
4456                  !!!cp ('t223');                  !!!cp ('t223');
4457    ## TODO: The following is wrong, maybe.
4458                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table');
4459                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4460                  !!!next-token;                  !!!next-token;
# Line 4461  sub _tree_construction_main ($) { Line 4462  sub _tree_construction_main ($) {
4462                }                }
4463                                
4464                ## generate implied end tags                ## generate implied end tags
4465                if ({                while ({
4466                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4467                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4468                  !!!cp ('t224');                  !!!cp ('t224');
4469                  !!!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;  
4470                }                }
4471    
4472                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4473                  !!!cp ('t225');                  !!!cp ('t225');
4474    ## ISSUE: Can this case be reached?
4475                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4476                } else {                } else {
4477                  !!!cp ('t226');                  !!!cp ('t226');
4478                }                }
4479    
4480                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4481                  pop @{$open_tables};
4482    
4483                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4484    
# Line 4528  sub _tree_construction_main ($) { Line 4524  sub _tree_construction_main ($) {
4524                  tr => 1, html => 1,                  tr => 1, html => 1,
4525                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4526                  !!!cp ('t231');                  !!!cp ('t231');
4527                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this state be reached?
4528                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4529                }                }
4530    
# Line 4556  sub _tree_construction_main ($) { Line 4552  sub _tree_construction_main ($) {
4552                  } # INSCOPE                  } # INSCOPE
4553                  unless (defined $i) {                  unless (defined $i) {
4554                    !!!cp ('t235');                    !!!cp ('t235');
4555    ## TODO: The following is wrong.
4556                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4557                    ## Ignore the token                    ## Ignore the token
4558                    !!!next-token;                    !!!next-token;
# Line 4567  sub _tree_construction_main ($) { Line 4564  sub _tree_construction_main ($) {
4564                    tr => 1, html => 1,                    tr => 1, html => 1,
4565                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4566                    !!!cp ('t236');                    !!!cp ('t236');
4567                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this state be reached?
4568                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4569                  }                  }
4570                                    
# Line 4607  sub _tree_construction_main ($) { Line 4604  sub _tree_construction_main ($) {
4604                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4605                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4606                    !!!cp ('t240');                    !!!cp ('t240');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4607                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4608                  }                  }
4609                                    
# Line 4623  sub _tree_construction_main ($) { Line 4619  sub _tree_construction_main ($) {
4619                  ## reprocess in the "in table" insertion mode...                  ## reprocess in the "in table" insertion mode...
4620                }                }
4621    
4622                  ## NOTE: </table> in the "in table" insertion mode.
4623                  ## When you edit the code fragment below, please ensure that
4624                  ## the code for <table> in the "in table" insertion mode
4625                  ## is synced with it.
4626    
4627                ## have a table element in table scope                ## have a table element in table scope
4628                my $i;                my $i;
4629                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 4645  sub _tree_construction_main ($) { Line 4646  sub _tree_construction_main ($) {
4646                  !!!next-token;                  !!!next-token;
4647                  redo B;                  redo B;
4648                }                }
   
               ## 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');  
               }  
4649                                    
4650                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4651                  pop @{$open_tables};
4652                                
4653                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4654                                
# Line 4729  sub _tree_construction_main ($) { Line 4711  sub _tree_construction_main ($) {
4711                    tr => 1, html => 1,                    tr => 1, html => 1,
4712                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4713                    !!!cp ('t253');                    !!!cp ('t253');
4714                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this case be reached?
4715                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4716                  }                  }
4717                                    
# Line 4766  sub _tree_construction_main ($) { Line 4748  sub _tree_construction_main ($) {
4748                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4749                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4750                  !!!cp ('t257');                  !!!cp ('t257');
4751                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this case be reached?
4752                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4753                }                }
4754    
# Line 4845  sub _tree_construction_main ($) { Line 4827  sub _tree_construction_main ($) {
4827                #                #
4828              }              }
4829            } else {            } else {
4830              !!!cp ('t268');              die "$0: $token->{type}: Unknown token type";
             #  
4831            }            }
4832    
4833            ## As if </colgroup>            ## As if </colgroup>
# Line 4903  sub _tree_construction_main ($) { Line 4884  sub _tree_construction_main ($) {
4884                !!!next-token;                !!!next-token;
4885                redo B;                redo B;
4886              } elsif ($token->{tag_name} eq 'select') {              } elsif ($token->{tag_name} eq 'select') {
4887    ## TODO: The type below is not good - <select> is replaced by </select>
4888                !!!parse-error (type => 'not closed:select');                !!!parse-error (type => 'not closed:select');
4889                ## As if </select> instead                ## As if </select> instead
4890                ## have an element in table scope                ## have an element in table scope
# Line 5005  sub _tree_construction_main ($) { Line 4987  sub _tree_construction_main ($) {
4987                        caption => 1, table => 1, tbody => 1,                        caption => 1, table => 1, tbody => 1,
4988                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
4989                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4990    ## TODO: The following is wrong?
4991                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4992                                
4993                ## have an element in table scope                ## have an element in table scope
# Line 5041  sub _tree_construction_main ($) { Line 5024  sub _tree_construction_main ($) {
5024                  } elsif ({                  } elsif ({
5025                            table => 1, html => 1,                            table => 1, html => 1,
5026                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5027    ## ISSUE: Can this state be reached?
5028                    !!!cp ('t296');                    !!!cp ('t296');
5029                    last INSCOPE;                    last INSCOPE;
5030                  }                  }
5031                } # INSCOPE                } # INSCOPE
5032                unless (defined $i) {                unless (defined $i) {
5033                  !!!cp ('t297');                  !!!cp ('t297');
5034    ## TODO: The following error type is correct?
5035                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5036                  ## Ignore the </select> token                  ## Ignore the </select> token
5037                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
# Line 5090  sub _tree_construction_main ($) { Line 5075  sub _tree_construction_main ($) {
5075            !!!cp ('t301');            !!!cp ('t301');
5076            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character');
5077    
5078            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5079          } else {          } else {
5080            !!!cp ('t302');            !!!cp ('t302');
5081          }          }
# Line 5106  sub _tree_construction_main ($) { Line 5091  sub _tree_construction_main ($) {
5091            !!!cp ('t303');            !!!cp ('t303');
5092            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5093                        
5094            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5095          } else {          } else {
5096            !!!cp ('t304');            !!!cp ('t304');
5097          }          }
# Line 5123  sub _tree_construction_main ($) { Line 5108  sub _tree_construction_main ($) {
5108            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5109                        
5110            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5111            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5112          } else {          } else {
5113            !!!cp ('t306');            !!!cp ('t306');
5114          }          }
# Line 5177  sub _tree_construction_main ($) { Line 5162  sub _tree_construction_main ($) {
5162              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character');
5163    
5164              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5165              ## Reprocess in the "main" phase, "after frameset"...              ## Reprocess in the "after frameset" insertion mode.
5166              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5167            }            }
5168                        
# Line 5199  sub _tree_construction_main ($) { Line 5184  sub _tree_construction_main ($) {
5184            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5185    
5186            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5187            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5188          } else {          } else {
5189            !!!cp ('t317');            !!!cp ('t317');
5190          }          }
# Line 5220  sub _tree_construction_main ($) { Line 5205  sub _tree_construction_main ($) {
5205          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5206            !!!cp ('t320');            !!!cp ('t320');
5207            ## NOTE: As if in body.            ## NOTE: As if in body.
5208            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL);
5209            redo B;            redo B;
5210          } else {          } else {
5211            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
# Line 5240  sub _tree_construction_main ($) { Line 5225  sub _tree_construction_main ($) {
5225            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5226    
5227            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5228            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5229          } else {          } else {
5230            !!!cp ('t324');            !!!cp ('t324');
5231          }          }
# Line 5304  sub _tree_construction_main ($) { Line 5289  sub _tree_construction_main ($) {
5289        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5290          !!!cp ('t333');          !!!cp ('t333');
5291          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5292          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5293          redo B;          redo B;
5294        } elsif ({        } elsif ({
5295                  base => 1, link => 1,                  base => 1, link => 1,
# Line 5367  sub _tree_construction_main ($) { Line 5352  sub _tree_construction_main ($) {
5352          redo B;          redo B;
5353        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5354          !!!cp ('t341');          !!!cp ('t341');
         !!!parse-error (type => 'in body:title');  
5355          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5356          $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]);  
           }  
         });  
5357          redo B;          redo B;
5358        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
5359          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 5401  sub _tree_construction_main ($) { Line 5377  sub _tree_construction_main ($) {
5377          redo B;          redo B;
5378        } elsif ({        } elsif ({
5379                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5380                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1,
5381                  menu => 1, ol => 1, p => 1, ul => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5382                    listing => 1, menu => 1, ol => 1, p => 1, ul => 1,
5383                  pre => 1,                  pre => 1,
5384                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5385          ## has a p element in scope          ## has a p element in scope
# Line 5604  sub _tree_construction_main ($) { Line 5581  sub _tree_construction_main ($) {
5581                        
5582          !!!next-token;          !!!next-token;
5583          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;  
5584        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
5585          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5586            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
# Line 5751  sub _tree_construction_main ($) { Line 5681  sub _tree_construction_main ($) {
5681          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5682                        
5683          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5684    
5685            ## TODO: associate with $self->{form_element} if defined
5686    
5687          push @$active_formatting_elements, ['#marker', ''];          push @$active_formatting_elements, ['#marker', ''];
5688    
5689          !!!next-token;          !!!next-token;
# Line 5768  sub _tree_construction_main ($) { Line 5701  sub _tree_construction_main ($) {
5701        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5702          !!!cp ('t381');          !!!cp ('t381');
5703          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5704          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5705          redo B;          redo B;
5706        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
5707          ## has a p element in scope          ## has a p element in scope
# Line 5788  sub _tree_construction_main ($) { Line 5721  sub _tree_construction_main ($) {
5721          } # INSCOPE          } # INSCOPE
5722                        
5723          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5724                      push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];
5725    
5726          $self->{insertion_mode} = IN_TABLE_IM;          $self->{insertion_mode} = IN_TABLE_IM;
5727                        
5728          !!!next-token;          !!!next-token;
# Line 5943  sub _tree_construction_main ($) { Line 5877  sub _tree_construction_main ($) {
5877                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5878          !!!cp ('t399');          !!!cp ('t399');
5879          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
5880          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5881          redo B;          redo B;
5882        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
5883          !!!cp ('t400');          !!!cp ('t400');
5884          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5885                    
5886          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5887    
5888            ## TODO: associate with $self->{form_element} if defined
5889                    
5890          $self->{insertion_mode} = IN_SELECT_IM;          $self->{insertion_mode} = IN_SELECT_IM;
5891          !!!next-token;          !!!next-token;
# Line 6026  sub _tree_construction_main ($) { Line 5962  sub _tree_construction_main ($) {
5962                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5963                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
5964                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 p => 1,  
5965                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
5966                  button => 1, marquee => 1, object => 1,                  button => 1, marquee => 1, object => 1,
5967                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 6035  sub _tree_construction_main ($) { Line 5970  sub _tree_construction_main ($) {
5970          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5971            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5972            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;  
             }  
               
5973              !!!cp ('t410');              !!!cp ('t410');
5974              $i = $_;              $i = $_;
5975              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE;
5976            } elsif ({            } elsif ({
5977                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5978                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
# Line 6062  sub _tree_construction_main ($) { Line 5981  sub _tree_construction_main ($) {
5981              last INSCOPE;              last INSCOPE;
5982            }            }
5983          } # INSCOPE          } # INSCOPE
5984            
5985          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
5986            if (defined $i) {            !!!cp ('t413');
5987              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5988            } else {
5989              ## Step 1. generate implied end tags
5990              while ({
5991                      dd => ($token->{tag_name} ne 'dd'),
5992                      dt => ($token->{tag_name} ne 'dt'),
5993                      li => ($token->{tag_name} ne 'li'),
5994                      p => 1,
5995                     }->{$self->{open_elements}->[-1]->[1]}) {
5996                !!!cp ('t409');
5997                pop @{$self->{open_elements}};
5998              }
5999    
6000              ## Step 2.
6001              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6002              !!!cp ('t412');              !!!cp ('t412');
6003              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6004            } else {            } else {
6005              !!!cp ('t413');              !!!cp ('t414');
             !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
6006            }            }
6007          }  
6008                      ## Step 3.
         if (defined $i) {  
           !!!cp ('t414');  
6009            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6010          } elsif ($token->{tag_name} eq 'p') {  
6011            !!!cp ('t415');            ## Step 4.
6012            ## As if <p>, then reprocess the current token            $clear_up_to_marker->()
6013            my $el;                if {
6014            !!!create-element ($el, 'p');                  button => 1, marquee => 1, object => 1,
6015            $insert->($el);                }->{$token->{tag_name}};
         } else {  
           !!!cp ('t416');  
6016          }          }
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
6017          !!!next-token;          !!!next-token;
6018          redo B;          redo B;
6019        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
6020            undef $self->{form_element};
6021    
6022          ## has an element in scope          ## has an element in scope
6023            my $i;
6024          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6025            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6026            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;  
             }  
               
6027              !!!cp ('t418');              !!!cp ('t418');
6028                $i = $_;
6029              last INSCOPE;              last INSCOPE;
6030            } elsif ({            } elsif ({
6031                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
# Line 6119  sub _tree_construction_main ($) { Line 6035  sub _tree_construction_main ($) {
6035              last INSCOPE;              last INSCOPE;
6036            }            }
6037          } # INSCOPE          } # INSCOPE
6038            
6039          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 {  
6040            !!!cp ('t421');            !!!cp ('t421');
6041            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6042            } else {
6043              ## Step 1. generate implied end tags
6044              while ({
6045                      dd => 1, dt => 1, li => 1, p => 1,
6046                     }->{$self->{open_elements}->[-1]->[1]}) {
6047                !!!cp ('t417');
6048                pop @{$self->{open_elements}};
6049              }
6050              
6051              ## Step 2.
6052              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6053                !!!cp ('t417.1');
6054                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6055              } else {
6056                !!!cp ('t420');
6057              }  
6058              
6059              ## Step 3.
6060              splice @{$self->{open_elements}}, $i;
6061          }          }
6062    
         undef $self->{form_element};  
6063          !!!next-token;          !!!next-token;
6064          redo B;          redo B;
6065        } elsif ({        } elsif ({
# Line 6141  sub _tree_construction_main ($) { Line 6072  sub _tree_construction_main ($) {
6072            if ({            if ({
6073                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
6074                }->{$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;  
             }  
   
6075              !!!cp ('t423');              !!!cp ('t423');
6076              $i = $_;              $i = $_;
6077              last INSCOPE;              last INSCOPE;
# Line 6165  sub _tree_construction_main ($) { Line 6083  sub _tree_construction_main ($) {
6083              last INSCOPE;              last INSCOPE;
6084            }            }
6085          } # INSCOPE          } # INSCOPE
6086            
6087          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6088            !!!cp ('t425');            !!!cp ('t425.1');
6089            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6090          } else {          } else {
6091            !!!cp ('t426');            ## Step 1. generate implied end tags
6092              while ({
6093                      dd => 1, dt => 1, li => 1, p => 1,
6094                     }->{$self->{open_elements}->[-1]->[1]}) {
6095                !!!cp ('t422');
6096                pop @{$self->{open_elements}};
6097              }
6098              
6099              ## Step 2.
6100              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6101                !!!cp ('t425');
6102                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6103              } else {
6104                !!!cp ('t426');
6105              }
6106    
6107              ## Step 3.
6108              splice @{$self->{open_elements}}, $i;
6109          }          }
6110                    
6111          splice @{$self->{open_elements}}, $i if defined $i;          !!!next-token;
6112            redo B;
6113          } elsif ($token->{tag_name} eq 'p') {
6114            ## has an element in scope
6115            my $i;
6116            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6117              my $node = $self->{open_elements}->[$_];
6118              if ($node->[1] eq $token->{tag_name}) {
6119                !!!cp ('t410.1');
6120                $i = $_;
6121                last INSCOPE;
6122              } elsif ({
6123                        table => 1, caption => 1, td => 1, th => 1,
6124                        button => 1, marquee => 1, object => 1, html => 1,
6125                       }->{$node->[1]}) {
6126                !!!cp ('t411.1');
6127                last INSCOPE;
6128              }
6129            } # INSCOPE
6130    
6131            if (defined $i) {
6132              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6133                !!!cp ('t412.1');
6134                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6135              } else {
6136                !!!cp ('t414.1');
6137              }
6138    
6139              splice @{$self->{open_elements}}, $i;
6140            } else {
6141              !!!cp ('t413.1');
6142              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6143    
6144              !!!cp ('t415.1');
6145              ## As if <p>, then reprocess the current token
6146              my $el;
6147              !!!create-element ($el, 'p');
6148              $insert->($el);
6149              ## NOTE: Not inserted into |$self->{open_elements}|.
6150            }
6151    
6152          !!!next-token;          !!!next-token;
6153          redo B;          redo B;
6154        } elsif ({        } elsif ({
# Line 6229  sub _tree_construction_main ($) { Line 6204  sub _tree_construction_main ($) {
6204            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6205              ## Step 1              ## Step 1
6206              ## generate implied end tags              ## generate implied end tags
6207              if ({              while ({
6208                   dd => 1, dt => 1, li => 1, p => 1,                      dd => 1, dt => 1, li => 1, p => 1,
6209                   td => 1, th => 1, tr => 1,                     }->{$self->{open_elements}->[-1]->[1]}) {
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
6210                !!!cp ('t430');                !!!cp ('t430');
6211                !!!back-token;                ## ISSUE: Can this case be reached?
6212                $token = {type => END_TAG_TOKEN,                pop @{$self->{open_elements}};
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
6213              }              }
6214                    
6215              ## Step 2              ## Step 2
# Line 6284  sub _tree_construction_main ($) { Line 6255  sub _tree_construction_main ($) {
6255      redo B;      redo B;
6256    } # B    } # B
6257    
   ## 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  
   
6258    ## Stop parsing # MUST    ## Stop parsing # MUST
6259        
6260    ## TODO: script stuffs    ## TODO: script stuffs
# Line 6330  sub set_inner_html ($$$) { Line 6296  sub set_inner_html ($$$) {
6296      my $p = $class->new;      my $p = $class->new;
6297      $p->{document} = $doc;      $p->{document} = $doc;
6298    
6299      ## Step 9 # MUST      ## Step 8 # MUST
6300      my $i = 0;      my $i = 0;
6301      my $line = 1;      my $line = 1;
6302      my $column = 0;      my $column = 0;
# Line 6397  sub set_inner_html ($$$) { Line 6363  sub set_inner_html ($$$) {
6363    
6364      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
6365    
6366      ## Step 4      ## Step 3
6367      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
6368        ('http://www.w3.org/1999/xhtml', [undef, 'html']);        ('http://www.w3.org/1999/xhtml', [undef, 'html']);
6369    
6370      ## Step 5 # MUST      ## Step 4 # MUST
6371      $doc->append_child ($root);      $doc->append_child ($root);
6372    
6373      ## Step 6 # MUST      ## Step 5 # MUST
6374      push @{$p->{open_elements}}, [$root, 'html'];      push @{$p->{open_elements}}, [$root, 'html'];
6375    
6376      undef $p->{head_element};      undef $p->{head_element};
6377    
6378      ## Step 7 # MUST      ## Step 6 # MUST
6379      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;
6380    
6381      ## Step 8 # MUST      ## Step 7 # MUST
6382      my $anode = $node;      my $anode = $node;
6383      AN: while (defined $anode) {      AN: while (defined $anode) {
6384        if ($anode->node_type == 1) {        if ($anode->node_type == 1) {
# Line 6428  sub set_inner_html ($$$) { Line 6394  sub set_inner_html ($$$) {
6394        $anode = $anode->parent_node;        $anode = $anode->parent_node;
6395      } # AN      } # AN
6396            
6397      ## Step 3 # MUST      ## Step 9 # MUST
     ## Step 10 # MUST  
6398      {      {
6399        my $self = $p;        my $self = $p;
6400        !!!next-token;        !!!next-token;
6401      }      }
6402      $p->_tree_construction_main;      $p->_tree_construction_main;
6403    
6404      ## Step 11 # MUST      ## Step 10 # MUST
6405      my @cn = @{$node->child_nodes};      my @cn = @{$node->child_nodes};
6406      for (@cn) {      for (@cn) {
6407        $node->remove_child ($_);        $node->remove_child ($_);
6408      }      }
6409      ## ISSUE: mutation events? read-only?      ## ISSUE: mutation events? read-only?
6410    
6411      ## Step 12 # MUST      ## Step 11 # MUST
6412      @cn = @{$root->child_nodes};      @cn = @{$root->child_nodes};
6413      for (@cn) {      for (@cn) {
6414        $this_doc->adopt_node ($_);        $this_doc->adopt_node ($_);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24