/[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.82 by wakaba, Wed Mar 5 02:55:08 2008 UTC revision 1.103 by wakaba, Sun Mar 9 07:57:29 2008 UTC
# Line 74  my $special_category = { Line 74  my $special_category = {
74    textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1,    textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1,
75  };  };
76  my $scoping_category = {  my $scoping_category = {
77    button => 1, caption => 1, html => 1, marquee => 1, object => 1,    applet => 1, button => 1, caption => 1, html => 1, marquee => 1, object => 1,
78    table => 1, td => 1, th => 1,    table => 1, td => 1, th => 1,
79  };  };
80  my $formatting_category = {  my $formatting_category = {
# Line 303  sub TABLE_IMS ()      { 0b1000000 } Line 303  sub TABLE_IMS ()      { 0b1000000 }
303  sub ROW_IMS ()        { 0b10000000 }  sub ROW_IMS ()        { 0b10000000 }
304  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
305  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
306    sub SELECT_IMS ()     { 0b10000000000 }
307    
308    ## NOTE: "initial" and "before html" insertion modes have no constants.
309    
310    ## NOTE: "after after body" insertion mode.
311  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }
312    
313    ## NOTE: "after after frameset" insertion mode.
314  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }
315    
316  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }
317  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }
318  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }
# Line 319  sub IN_TABLE_IM () { TABLE_IMS } Line 326  sub IN_TABLE_IM () { TABLE_IMS }
326  sub AFTER_BODY_IM () { BODY_AFTER_IMS }  sub AFTER_BODY_IM () { BODY_AFTER_IMS }
327  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }  sub IN_FRAMESET_IM () { FRAME_IMS | 0b01 }
328  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }  sub AFTER_FRAMESET_IM () { FRAME_IMS | 0b10 }
329  sub IN_SELECT_IM () { 0b01 }  sub IN_SELECT_IM () { SELECT_IMS | 0b01 }
330    sub IN_SELECT_IN_TABLE_IM () { SELECT_IMS | 0b10 }
331  sub IN_COLUMN_GROUP_IM () { 0b10 }  sub IN_COLUMN_GROUP_IM () { 0b10 }
332    
333  ## Implementations MUST act as if state machine in the spec  ## Implementations MUST act as if state machine in the spec
# Line 2420  sub _construct_tree ($) { Line 2428  sub _construct_tree ($) {
2428        
2429    !!!next-token;    !!!next-token;
2430    
   $self->{insertion_mode} = BEFORE_HEAD_IM;  
2431    undef $self->{form_element};    undef $self->{form_element};
2432    undef $self->{head_element};    undef $self->{head_element};
2433    $self->{open_elements} = [];    $self->{open_elements} = [];
2434    undef $self->{inner_html_node};    undef $self->{inner_html_node};
2435    
2436      ## NOTE: The "initial" insertion mode.
2437    $self->_tree_construction_initial; # MUST    $self->_tree_construction_initial; # MUST
2438    
2439      ## NOTE: The "before html" insertion mode.
2440    $self->_tree_construction_root_element;    $self->_tree_construction_root_element;
2441      $self->{insertion_mode} = BEFORE_HEAD_IM;
2442    
2443      ## NOTE: The "before head" insertion mode and so on.
2444    $self->_tree_construction_main;    $self->_tree_construction_main;
2445  } # _construct_tree  } # _construct_tree
2446    
2447  sub _tree_construction_initial ($) {  sub _tree_construction_initial ($) {
2448    my $self = shift;    my $self = shift;
2449    
2450      ## NOTE: "initial" insertion mode
2451    
2452    INITIAL: {    INITIAL: {
2453      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
2454        ## 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 2595  sub _tree_construction_initial ($) {
2595          !!!cp ('t13');          !!!cp ('t13');
2596        }        }
2597                
2598        ## Go to the root element phase.        ## Go to the "before html" insertion mode.
2599        !!!next-token;        !!!next-token;
2600        return;        return;
2601      } elsif ({      } elsif ({
# Line 2590  sub _tree_construction_initial ($) { Line 2606  sub _tree_construction_initial ($) {
2606        !!!cp ('t14');        !!!cp ('t14');
2607        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2608        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2609        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2610        ## reprocess        ## reprocess
2611        return;        return;
2612      } elsif ($token->{type} == CHARACTER_TOKEN) {      } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2599  sub _tree_construction_initial ($) { Line 2615  sub _tree_construction_initial ($) {
2615    
2616          unless (length $token->{data}) {          unless (length $token->{data}) {
2617            !!!cp ('t15');            !!!cp ('t15');
2618            ## Stay in the phase            ## Stay in the insertion mode.
2619            !!!next-token;            !!!next-token;
2620            redo INITIAL;            redo INITIAL;
2621          } else {          } else {
# Line 2611  sub _tree_construction_initial ($) { Line 2627  sub _tree_construction_initial ($) {
2627    
2628        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2629        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2630        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2631        ## reprocess        ## reprocess
2632        return;        return;
2633      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
# Line 2619  sub _tree_construction_initial ($) { Line 2635  sub _tree_construction_initial ($) {
2635        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2636        $self->{document}->append_child ($comment);        $self->{document}->append_child ($comment);
2637                
2638        ## Stay in the phase.        ## Stay in the insertion mode.
2639        !!!next-token;        !!!next-token;
2640        redo INITIAL;        redo INITIAL;
2641      } else {      } else {
# Line 2632  sub _tree_construction_initial ($) { Line 2648  sub _tree_construction_initial ($) {
2648    
2649  sub _tree_construction_root_element ($) {  sub _tree_construction_root_element ($) {
2650    my $self = shift;    my $self = shift;
2651    
2652      ## NOTE: "before html" insertion mode.
2653        
2654    B: {    B: {
2655        if ($token->{type} == DOCTYPE_TOKEN) {        if ($token->{type} == DOCTYPE_TOKEN) {
2656          !!!cp ('t19');          !!!cp ('t19');
2657          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
2658          ## Ignore the token          ## Ignore the token
2659          ## Stay in the phase          ## Stay in the insertion mode.
2660          !!!next-token;          !!!next-token;
2661          redo B;          redo B;
2662        } elsif ($token->{type} == COMMENT_TOKEN) {        } elsif ($token->{type} == COMMENT_TOKEN) {
2663          !!!cp ('t20');          !!!cp ('t20');
2664          my $comment = $self->{document}->create_comment ($token->{data});          my $comment = $self->{document}->create_comment ($token->{data});
2665          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2666          ## Stay in the phase          ## Stay in the insertion mode.
2667          !!!next-token;          !!!next-token;
2668          redo B;          redo B;
2669        } elsif ($token->{type} == CHARACTER_TOKEN) {        } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2654  sub _tree_construction_root_element ($) Line 2672  sub _tree_construction_root_element ($)
2672    
2673            unless (length $token->{data}) {            unless (length $token->{data}) {
2674              !!!cp ('t21');              !!!cp ('t21');
2675              ## Stay in the phase              ## Stay in the insertion mode.
2676              !!!next-token;              !!!next-token;
2677              redo B;              redo B;
2678            } else {            } else {
# Line 2668  sub _tree_construction_root_element ($) Line 2686  sub _tree_construction_root_element ($)
2686    
2687          #          #
2688        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
2689          if ($token->{tag_name} eq 'html' and          if ($token->{tag_name} eq 'html') {
2690              $token->{attributes}->{manifest}) {            my $root_element;
2691            !!!cp ('t24');            !!!create-element ($root_element, $token->{tag_name}, $token->{attributes});
2692            $self->{application_cache_selection}            $self->{document}->append_child ($root_element);
2693                 ->($token->{attributes}->{manifest}->{value});            push @{$self->{open_elements}}, [$root_element, 'html'];
2694            ## ISSUE: No relative reference resolution?  
2695              if ($token->{attributes}->{manifest}) {
2696                !!!cp ('t24');
2697                $self->{application_cache_selection}
2698                    ->($token->{attributes}->{manifest}->{value});
2699                ## ISSUE: No relative reference resolution?
2700              } else {
2701                !!!cp ('t25');
2702                $self->{application_cache_selection}->(undef);
2703              }
2704    
2705              !!!next-token;
2706              return; ## Go to the "before head" insertion mode.
2707          } else {          } else {
2708            !!!cp ('t25');            !!!cp ('t25.1');
2709            $self->{application_cache_selection}->(undef);            #
2710          }          }
   
         ## ISSUE: There is an issue in the spec  
         #  
2711        } elsif ({        } elsif ({
2712                  END_TAG_TOKEN, 1,                  END_TAG_TOKEN, 1,
2713                  END_OF_FILE_TOKEN, 1,                  END_OF_FILE_TOKEN, 1,
2714                 }->{$token->{type}}) {                 }->{$token->{type}}) {
2715          !!!cp ('t26');          !!!cp ('t26');
         $self->{application_cache_selection}->(undef);  
   
         ## ISSUE: There is an issue in the spec  
2716          #          #
2717        } else {        } else {
2718          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
2719        }        }
2720    
2721        my $root_element; !!!create-element ($root_element, 'html');      my $root_element; !!!create-element ($root_element, 'html');
2722        $self->{document}->append_child ($root_element);      $self->{document}->append_child ($root_element);
2723        push @{$self->{open_elements}}, [$root_element, 'html'];      push @{$self->{open_elements}}, [$root_element, 'html'];
2724        ## reprocess  
2725        #redo B;      $self->{application_cache_selection}->(undef);
2726        return; ## Go to the main phase.  
2727        ## NOTE: Reprocess the token.
2728        return; ## Go to the "before head" insertion mode.
2729    
2730        ## ISSUE: There is an issue in the spec
2731    } # B    } # B
2732    
2733    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 2745  sub _reset_insertion_mode ($) {
2745            
2746      ## Step 3      ## Step 3
2747      S3: {      S3: {
       ## ISSUE: Oops! "If node is the first node in the stack of open  
       ## elements, then set last to true. If the context element of the  
       ## HTML fragment parsing algorithm is neither a td element nor a  
       ## th element, then set node to the context element. (fragment case)":  
       ## The second "if" is in the scope of the first "if"!?  
2748        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
2749          $last = 1;          $last = 1;
2750          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
# Line 2739  sub _reset_insertion_mode ($) { Line 2762  sub _reset_insertion_mode ($) {
2762        ## Step 4..13        ## Step 4..13
2763        my $new_mode = {        my $new_mode = {
2764                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
2765                          ## NOTE: |option| and |optgroup| do not set
2766                          ## insertion mode to "in select" by themselves.
2767                        td => IN_CELL_IM,                        td => IN_CELL_IM,
2768                        th => IN_CELL_IM,                        th => IN_CELL_IM,
2769                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
# Line 2880  sub _tree_construction_main ($) { Line 2905  sub _tree_construction_main ($) {
2905      !!!cp ('t39');      !!!cp ('t39');
2906    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2907    
2908    my $parse_rcdata = sub ($$) {    my $insert;
2909      my ($content_model_flag, $insert) = @_;  
2910      my $parse_rcdata = sub ($) {
2911        my ($content_model_flag) = @_;
2912    
2913      ## Step 1      ## Step 1
2914      my $start_tag_name = $token->{tag_name};      my $start_tag_name = $token->{tag_name};
# Line 2889  sub _tree_construction_main ($) { Line 2916  sub _tree_construction_main ($) {
2916      !!!create-element ($el, $start_tag_name, $token->{attributes});      !!!create-element ($el, $start_tag_name, $token->{attributes});
2917    
2918      ## Step 2      ## Step 2
2919      $insert->($el); # /context node/->append_child ($el)      $insert->($el);
2920    
2921      ## Step 3      ## Step 3
2922      $self->{content_model} = $content_model_flag; # CDATA or RCDATA      $self->{content_model} = $content_model_flag; # CDATA or RCDATA
# Line 2919  sub _tree_construction_main ($) { Line 2946  sub _tree_construction_main ($) {
2946          $token->{tag_name} eq $start_tag_name) {          $token->{tag_name} eq $start_tag_name) {
2947        !!!cp ('t42');        !!!cp ('t42');
2948        ## Ignore the token        ## Ignore the token
     } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {  
       !!!cp ('t43');  
       !!!parse-error (type => 'in CDATA:#'.$token->{type});  
     } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {  
       !!!cp ('t44');  
       !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
2949      } else {      } else {
2950        die "$0: $content_model_flag in parse_rcdata";        ## NOTE: An end-of-file token.
2951          if ($content_model_flag == CDATA_CONTENT_MODEL) {
2952            !!!cp ('t43');
2953            !!!parse-error (type => 'in CDATA:#'.$token->{type});
2954          } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2955            !!!cp ('t44');
2956            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2957          } else {
2958            die "$0: $content_model_flag in parse_rcdata";
2959          }
2960      }      }
2961      !!!next-token;      !!!next-token;
2962    }; # $parse_rcdata    }; # $parse_rcdata
2963    
2964    my $script_start_tag = sub ($) {    my $script_start_tag = sub () {
     my $insert = $_[0];  
2965      my $script_el;      my $script_el;
2966      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2967      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
# Line 2983  sub _tree_construction_main ($) { Line 3012  sub _tree_construction_main ($) {
3012      !!!next-token;      !!!next-token;
3013    }; # $script_start_tag    }; # $script_start_tag
3014    
3015      ## NOTE: $open_tables->[-1]->[0] is the "current table" element node.
3016      ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.
3017      my $open_tables = [[$self->{open_elements}->[0]->[0]]];
3018    
3019    my $formatting_end_tag = sub {    my $formatting_end_tag = sub {
3020      my $tag_name = shift;      my $tag_name = shift;
3021    
3022        ## NOTE: The adoption agency algorithm (AAA).
3023    
3024      FET: {      FET: {
3025        ## Step 1        ## Step 1
3026        my $formatting_element;        my $formatting_element;
# Line 3026  sub _tree_construction_main ($) { Line 3061  sub _tree_construction_main ($) {
3061              return;              return;
3062            }            }
3063          } elsif ({          } elsif ({
3064                    table => 1, caption => 1, td => 1, th => 1,                    applet => 1, table => 1, caption => 1, td => 1, th => 1,
3065                    button => 1, marquee => 1, object => 1, html => 1,                    button => 1, marquee => 1, object => 1, html => 1,
3066                   }->{$node->[1]}) {                   }->{$node->[1]}) {
3067            !!!cp ('t56');            !!!cp ('t56');
# Line 3053  sub _tree_construction_main ($) { Line 3088  sub _tree_construction_main ($) {
3088          if (not $formatting_category->{$node->[1]} and          if (not $formatting_category->{$node->[1]} and
3089              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3090              ($special_category->{$node->[1]} or              ($special_category->{$node->[1]} or
3091               $scoping_category->{$node->[1]})) {               $scoping_category->{$node->[1]})) { ## Scoping is redundant, maybe
3092            !!!cp ('t59');            !!!cp ('t59');
3093            $furthest_block = $node;            $furthest_block = $node;
3094            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
# Line 3139  sub _tree_construction_main ($) { Line 3174  sub _tree_construction_main ($) {
3174        } # S7          } # S7  
3175                
3176        ## Step 8        ## Step 8
3177        $common_ancestor_node->[0]->append_child ($last_node->[0]);        if ({
3178               table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3179              }->{$common_ancestor_node->[1]}) {
3180            my $foster_parent_element;
3181            my $next_sibling;
3182                             OE: for (reverse 0..$#{$self->{open_elements}}) {
3183                               if ($self->{open_elements}->[$_]->[1] eq 'table') {
3184                                 my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3185                                 if (defined $parent and $parent->node_type == 1) {
3186                                   !!!cp ('t65.1');
3187                                   $foster_parent_element = $parent;
3188                                   $next_sibling = $self->{open_elements}->[$_]->[0];
3189                                 } else {
3190                                   !!!cp ('t65.2');
3191                                   $foster_parent_element
3192                                     = $self->{open_elements}->[$_ - 1]->[0];
3193                                 }
3194                                 last OE;
3195                               }
3196                             } # OE
3197                             $foster_parent_element = $self->{open_elements}->[0]->[0]
3198                               unless defined $foster_parent_element;
3199            $foster_parent_element->insert_before ($last_node->[0], $next_sibling);
3200            $open_tables->[-1]->[1] = 1; # tainted
3201          } else {
3202            !!!cp ('t65.3');
3203            $common_ancestor_node->[0]->append_child ($last_node->[0]);
3204          }
3205                
3206        ## Step 9        ## Step 9
3207        my $clone = [$formatting_element->[0]->clone_node (0),        my $clone = [$formatting_element->[0]->clone_node (0),
# Line 3185  sub _tree_construction_main ($) { Line 3247  sub _tree_construction_main ($) {
3247      } # FET      } # FET
3248    }; # $formatting_end_tag    }; # $formatting_end_tag
3249    
3250    my $insert_to_current = sub {    $insert = my $insert_to_current = sub {
3251      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
3252    }; # $insert_to_current    }; # $insert_to_current
3253    
3254    my $insert_to_foster = sub {    my $insert_to_foster = sub {
3255                         my $child = shift;      my $child = shift;
3256                         if ({      if ({
3257                              table => 1, tbody => 1, tfoot => 1,           table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,
3258                              thead => 1, tr => 1,          }->{$self->{open_elements}->[-1]->[1]}) {
3259                             }->{$self->{open_elements}->[-1]->[1]}) {        # MUST
3260                           # MUST        my $foster_parent_element;
3261                           my $foster_parent_element;        my $next_sibling;
                          my $next_sibling;  
3262                           OE: for (reverse 0..$#{$self->{open_elements}}) {                           OE: for (reverse 0..$#{$self->{open_elements}}) {
3263                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3264                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
# Line 3217  sub _tree_construction_main ($) { Line 3278  sub _tree_construction_main ($) {
3278                             unless defined $foster_parent_element;                             unless defined $foster_parent_element;
3279                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3280                             ($child, $next_sibling);                             ($child, $next_sibling);
3281                         } else {        $open_tables->[-1]->[1] = 1; # tainted
3282                           !!!cp ('t72');      } else {
3283                           $self->{open_elements}->[-1]->[0]->append_child ($child);        !!!cp ('t72');
3284                         }        $self->{open_elements}->[-1]->[0]->append_child ($child);
3285        }
3286    }; # $insert_to_foster    }; # $insert_to_foster
3287    
   my $insert;  
   
3288    B: {    B: {
3289      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3290        !!!cp ('t73');        !!!cp ('t73');
# Line 3239  sub _tree_construction_main ($) { Line 3299  sub _tree_construction_main ($) {
3299          #          #
3300        } else {        } else {
3301          ## Generate implied end tags          ## Generate implied end tags
3302          if ({          while ({
3303               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,                  dd => 1, dt => 1, li => 1, p => 1,
3304               tbody => 1, tfoot=> 1, thead => 1,                 }->{$self->{open_elements}->[-1]->[1]}) {
             }->{$self->{open_elements}->[-1]->[1]}) {  
3305            !!!cp ('t75');            !!!cp ('t75');
3306            !!!back-token;            pop @{$self->{open_elements}};
           $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};  
           redo B;  
3307          }          }
3308                    
3309          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
# Line 3272  sub _tree_construction_main ($) { Line 3329  sub _tree_construction_main ($) {
3329               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3330        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
3331          !!!cp ('t79');          !!!cp ('t79');
         ## Turn into the main phase  
3332          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3333          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3334        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3335          !!!cp ('t80');          !!!cp ('t80');
         ## Turn into the main phase  
3336          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3337          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3338        } else {        } else {
3339          !!!cp ('t81');          !!!cp ('t81');
3340        }        }
3341    
3342  ## ISSUE: "aa<html>" is not a parse error.        !!!cp ('t82');
3343  ## 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');  
       }  
3344        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3345        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3346          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
# Line 3320  sub _tree_construction_main ($) { Line 3369  sub _tree_construction_main ($) {
3369      } elsif ($self->{insertion_mode} & HEAD_IMS) {      } elsif ($self->{insertion_mode} & HEAD_IMS) {
3370        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
3371          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3372            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3373                !!!cp ('t88.2');
3374                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3375              } else {
3376                !!!cp ('t88.1');
3377                ## Ignore the token.
3378                !!!next-token;
3379                redo B;
3380              }
3381            unless (length $token->{data}) {            unless (length $token->{data}) {
3382              !!!cp ('t88');              !!!cp ('t88');
3383              !!!next-token;              !!!next-token;
# Line 3421  sub _tree_construction_main ($) { Line 3478  sub _tree_construction_main ($) {
3478                }                }
3479                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3480                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3481                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3482                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3483                !!!next-token;                !!!next-token;
3484                redo B;                redo B;
# Line 3436  sub _tree_construction_main ($) { Line 3493  sub _tree_construction_main ($) {
3493                }                }
3494                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3495                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3496                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3497                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3498                !!!next-token;                !!!next-token;
3499                redo B;                redo B;
# Line 3497  sub _tree_construction_main ($) { Line 3554  sub _tree_construction_main ($) {
3554                  }                  }
3555                }                }
3556    
3557                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3558                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3559                !!!next-token;                !!!next-token;
3560                redo B;                redo B;
# Line 3521  sub _tree_construction_main ($) { Line 3578  sub _tree_construction_main ($) {
3578                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3579                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3580                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3581                $parse_rcdata->(RCDATA_CONTENT_MODEL,                $parse_rcdata->(RCDATA_CONTENT_MODEL);
3582                                sub { $parent->append_child ($_[0]) });                pop @{$self->{open_elements}} # <head>
               pop @{$self->{open_elements}}  
3583                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3584                redo B;                redo B;
3585              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style') {
# Line 3537  sub _tree_construction_main ($) { Line 3593  sub _tree_construction_main ($) {
3593                } else {                } else {
3594                  !!!cp ('t115');                  !!!cp ('t115');
3595                }                }
3596                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL);
3597                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3598                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3599                redo B;                redo B;
3600              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
# Line 3577  sub _tree_construction_main ($) { Line 3633  sub _tree_construction_main ($) {
3633                }                }
3634    
3635                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3636                $script_start_tag->($insert_to_current);                $script_start_tag->();
3637                pop @{$self->{open_elements}}                pop @{$self->{open_elements}} # <head>
3638                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
3639                redo B;                redo B;
3640              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
# Line 3858  sub _tree_construction_main ($) { Line 3914  sub _tree_construction_main ($) {
3914                  } # INSCOPE                  } # INSCOPE
3915                    unless (defined $i) {                    unless (defined $i) {
3916                      !!!cp ('t157');                      !!!cp ('t157');
3917    ## TODO: this type is wrong.
3918                      !!!parse-error (type => 'unmatched end tag:caption');                      !!!parse-error (type => 'unmatched end tag:caption');
3919                      ## Ignore the token                      ## Ignore the token
3920                      !!!next-token;                      !!!next-token;
# Line 3865  sub _tree_construction_main ($) { Line 3922  sub _tree_construction_main ($) {
3922                    }                    }
3923                                    
3924                  ## generate implied end tags                  ## generate implied end tags
3925                  if ({                  while ({
3926                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3927                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
3928                    !!!cp ('t158');                    !!!cp ('t158');
3929                    !!!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;  
3930                  }                  }
3931    
3932                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 3929  sub _tree_construction_main ($) { Line 3979  sub _tree_construction_main ($) {
3979                    }                    }
3980                                    
3981                  ## generate implied end tags                  ## generate implied end tags
3982                  if ({                  while ({
3983                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
3984                       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]}) {  
3985                    !!!cp ('t166');                    !!!cp ('t166');
3986                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
3987                  }                  }
3988                    
3989                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3990                    !!!cp ('t167');                    !!!cp ('t167');
3991                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
# Line 3994  sub _tree_construction_main ($) { Line 4037  sub _tree_construction_main ($) {
4037                    }                    }
4038                                    
4039                  ## generate implied end tags                  ## generate implied end tags
4040                  if ({                  while ({
4041                       dd => 1, dt => 1, li => 1, p => 1,                          dd => 1, dt => 1, li => 1, p => 1,
4042                       td => 1, th => 1, tr => 1,                         }->{$self->{open_elements}->[-1]->[1]}) {
                      tbody => 1, tfoot=> 1, thead => 1,  
                     }->{$self->{open_elements}->[-1]->[1]}) {  
4043                    !!!cp ('t174');                    !!!cp ('t174');
4044                    !!!back-token;                    pop @{$self->{open_elements}};
                   $token = {type => END_TAG_TOKEN,  
                             tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                   redo B;  
4045                  }                  }
4046                                    
4047                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4100  sub _tree_construction_main ($) { Line 4138  sub _tree_construction_main ($) {
4138                }                }
4139                                
4140                ## generate implied end tags                ## generate implied end tags
4141                if ({                while ({
4142                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4143                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4144                  !!!cp ('t187');                  !!!cp ('t187');
4145                  !!!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;  
4146                }                }
4147    
4148                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
# Line 4164  sub _tree_construction_main ($) { Line 4195  sub _tree_construction_main ($) {
4195        #        #
4196      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
4197        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4198              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if (not $open_tables->[-1]->[1] and # tainted
4199                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4200              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4201                                
4202                unless (length $token->{data}) {            unless (length $token->{data}) {
4203                  !!!cp ('t194');              !!!cp ('t194');
4204                  !!!next-token;              !!!next-token;
4205                  redo B;              redo B;
4206                } else {            } else {
4207                  !!!cp ('t195');              !!!cp ('t195');
4208                }            }
4209              }          }
4210    
4211              !!!parse-error (type => 'in table:#character');              !!!parse-error (type => 'in table:#character');
4212    
# Line 4221  sub _tree_construction_main ($) { Line 4253  sub _tree_construction_main ($) {
4253                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4254                     $next_sibling);                     $next_sibling);
4255                }                }
4256              } else {            $open_tables->[-1]->[1] = 1; # tainted
4257                !!!cp ('t200');          } else {
4258                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});            !!!cp ('t200');
4259              }            $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4260            }
4261                            
4262              !!!next-token;          !!!next-token;
4263              redo B;          redo B;
4264        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4265              if ({              if ({
4266                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
# Line 4238  sub _tree_construction_main ($) { Line 4271  sub _tree_construction_main ($) {
4271                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4272                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4273                    !!!cp ('t201');                    !!!cp ('t201');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4274                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4275                  }                  }
4276                                    
# Line 4258  sub _tree_construction_main ($) { Line 4290  sub _tree_construction_main ($) {
4290                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4291                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4292                    !!!cp ('t203');                    !!!cp ('t203');
4293                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this case be reached?
4294                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4295                  }                  }
4296                                    
# Line 4282  sub _tree_construction_main ($) { Line 4314  sub _tree_construction_main ($) {
4314                  tr => 1, html => 1,                  tr => 1, html => 1,
4315                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4316                  !!!cp ('t207');                  !!!cp ('t207');
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4317                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4318                }                }
4319                                
# Line 4309  sub _tree_construction_main ($) { Line 4340  sub _tree_construction_main ($) {
4340                      $i = $_;                      $i = $_;
4341                      last INSCOPE;                      last INSCOPE;
4342                    } elsif ({                    } elsif ({
4343                              table => 1, html => 1,                              html => 1,
4344    
4345                                ## NOTE: This element does not appear here, maybe.
4346                                table => 1,
4347                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4348                      !!!cp ('t209');                      !!!cp ('t209');
4349                      last INSCOPE;                      last INSCOPE;
# Line 4317  sub _tree_construction_main ($) { Line 4351  sub _tree_construction_main ($) {
4351                  } # INSCOPE                  } # INSCOPE
4352                  unless (defined $i) {                  unless (defined $i) {
4353                   !!!cp ('t210');                   !!!cp ('t210');
4354    ## TODO: This type is wrong.
4355                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4356                    ## Ignore the token                    ## Ignore the token
4357                    !!!next-token;                    !!!next-token;
# Line 4328  sub _tree_construction_main ($) { Line 4363  sub _tree_construction_main ($) {
4363                    tr => 1, html => 1,                    tr => 1, html => 1,
4364                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4365                    !!!cp ('t211');                    !!!cp ('t211');
4366                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this case be reached?
4367                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4368                  }                  }
4369                                    
# Line 4376  sub _tree_construction_main ($) { Line 4411  sub _tree_construction_main ($) {
4411                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4412                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4413                    !!!cp ('t217');                    !!!cp ('t217');
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 4399  sub _tree_construction_main ($) { Line 4434  sub _tree_construction_main ($) {
4434                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4435                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4436                    !!!cp ('t219');                    !!!cp ('t219');
4437                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4438                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4439                  }                  }
4440                                    
# Line 4416  sub _tree_construction_main ($) { Line 4451  sub _tree_construction_main ($) {
4451                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4452                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4453                    !!!cp ('t220');                    !!!cp ('t220');
4454                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    ## ISSUE: Can this state be reached?
4455                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4456                  }                  }
4457                                    
# Line 4449  sub _tree_construction_main ($) { Line 4484  sub _tree_construction_main ($) {
4484                    $i = $_;                    $i = $_;
4485                    last INSCOPE;                    last INSCOPE;
4486                  } elsif ({                  } elsif ({
4487                            table => 1, html => 1,                            #table => 1,
4488                              html => 1,
4489                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4490                    !!!cp ('t222');                    !!!cp ('t222');
4491                    last INSCOPE;                    last INSCOPE;
# Line 4457  sub _tree_construction_main ($) { Line 4493  sub _tree_construction_main ($) {
4493                } # INSCOPE                } # INSCOPE
4494                unless (defined $i) {                unless (defined $i) {
4495                  !!!cp ('t223');                  !!!cp ('t223');
4496    ## TODO: The following is wrong, maybe.
4497                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table');
4498                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4499                  !!!next-token;                  !!!next-token;
# Line 4464  sub _tree_construction_main ($) { Line 4501  sub _tree_construction_main ($) {
4501                }                }
4502                                
4503                ## generate implied end tags                ## generate implied end tags
4504                if ({                while ({
4505                     dd => 1, dt => 1, li => 1, p => 1,                        dd => 1, dt => 1, li => 1, p => 1,
4506                     td => 1, th => 1, tr => 1,                       }->{$self->{open_elements}->[-1]->[1]}) {
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
4507                  !!!cp ('t224');                  !!!cp ('t224');
4508                  !!!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;  
4509                }                }
4510    
4511                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4512                  !!!cp ('t225');                  !!!cp ('t225');
4513    ## ISSUE: Can this case be reached?
4514                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4515                } else {                } else {
4516                  !!!cp ('t226');                  !!!cp ('t226');
4517                }                }
4518    
4519                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4520                  pop @{$open_tables};
4521    
4522                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4523    
4524                ## reprocess                ## reprocess
4525                redo B;                redo B;
4526            } elsif ($token->{tag_name} eq 'style') {
4527              if (not $open_tables->[-1]->[1]) { # tainted
4528                !!!cp ('t227.8');
4529                ## NOTE: This is a "as if in head" code clone.
4530                $parse_rcdata->(CDATA_CONTENT_MODEL);
4531                redo B;
4532              } else {
4533                !!!cp ('t227.7');
4534                #
4535              }
4536            } elsif ($token->{tag_name} eq 'script') {
4537              if (not $open_tables->[-1]->[1]) { # tainted
4538                !!!cp ('t227.6');
4539                ## NOTE: This is a "as if in head" code clone.
4540                $script_start_tag->();
4541                redo B;
4542              } else {
4543                !!!cp ('t227.5');
4544                #
4545              }
4546            } elsif ($token->{tag_name} eq 'input') {
4547              if (not $open_tables->[-1]->[1]) { # tainted
4548                if ($token->{attributes}->{type}) { ## TODO: case
4549                  my $type = lc $token->{attributes}->{type}->{value};
4550                  if ($type eq 'hidden') {
4551                    !!!cp ('t227.3');
4552                    !!!parse-error (type => 'in table:'.$token->{tag_name});
4553    
4554                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4555    
4556                    ## TODO: form element pointer
4557    
4558                    pop @{$self->{open_elements}};
4559    
4560                    !!!next-token;
4561                    redo B;
4562                  } else {
4563                    !!!cp ('t227.2');
4564                    #
4565                  }
4566                } else {
4567                  !!!cp ('t227.1');
4568                  #
4569                }
4570              } else {
4571                !!!cp ('t227.4');
4572                #
4573              }
4574          } else {          } else {
4575            !!!cp ('t227');            !!!cp ('t227');
           !!!parse-error (type => 'in table:'.$token->{tag_name});  
   
           $insert = $insert_to_foster;  
4576            #            #
4577          }          }
4578    
4579            !!!parse-error (type => 'in table:'.$token->{tag_name});
4580    
4581            $insert = $insert_to_foster;
4582            #
4583        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
4584              if ($token->{tag_name} eq 'tr' and              if ($token->{tag_name} eq 'tr' and
4585                  $self->{insertion_mode} == IN_ROW_IM) {                  $self->{insertion_mode} == IN_ROW_IM) {
# Line 4531  sub _tree_construction_main ($) { Line 4613  sub _tree_construction_main ($) {
4613                  tr => 1, html => 1,                  tr => 1, html => 1,
4614                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4615                  !!!cp ('t231');                  !!!cp ('t231');
4616                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this state be reached?
4617                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4618                }                }
4619    
# Line 4559  sub _tree_construction_main ($) { Line 4641  sub _tree_construction_main ($) {
4641                  } # INSCOPE                  } # INSCOPE
4642                  unless (defined $i) {                  unless (defined $i) {
4643                    !!!cp ('t235');                    !!!cp ('t235');
4644    ## TODO: The following is wrong.
4645                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4646                    ## Ignore the token                    ## Ignore the token
4647                    !!!next-token;                    !!!next-token;
# Line 4570  sub _tree_construction_main ($) { Line 4653  sub _tree_construction_main ($) {
4653                    tr => 1, html => 1,                    tr => 1, html => 1,
4654                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4655                    !!!cp ('t236');                    !!!cp ('t236');
4656                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this state be reached?
4657                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4658                  }                  }
4659                                    
# Line 4610  sub _tree_construction_main ($) { Line 4693  sub _tree_construction_main ($) {
4693                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4694                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4695                    !!!cp ('t240');                    !!!cp ('t240');
                   !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
4696                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4697                  }                  }
4698                                    
# Line 4626  sub _tree_construction_main ($) { Line 4708  sub _tree_construction_main ($) {
4708                  ## reprocess in the "in table" insertion mode...                  ## reprocess in the "in table" insertion mode...
4709                }                }
4710    
4711                  ## NOTE: </table> in the "in table" insertion mode.
4712                  ## When you edit the code fragment below, please ensure that
4713                  ## the code for <table> in the "in table" insertion mode
4714                  ## is synced with it.
4715    
4716                ## have a table element in table scope                ## have a table element in table scope
4717                my $i;                my $i;
4718                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 4648  sub _tree_construction_main ($) { Line 4735  sub _tree_construction_main ($) {
4735                  !!!next-token;                  !!!next-token;
4736                  redo B;                  redo B;
4737                }                }
   
               ## 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');  
               }  
4738                                    
4739                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4740                  pop @{$open_tables};
4741                                
4742                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
4743                                
# Line 4732  sub _tree_construction_main ($) { Line 4800  sub _tree_construction_main ($) {
4800                    tr => 1, html => 1,                    tr => 1, html => 1,
4801                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4802                    !!!cp ('t253');                    !!!cp ('t253');
4803                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this case be reached?
4804                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4805                  }                  }
4806                                    
# Line 4769  sub _tree_construction_main ($) { Line 4837  sub _tree_construction_main ($) {
4837                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4838                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4839                  !!!cp ('t257');                  !!!cp ('t257');
4840                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  ## ISSUE: Can this case be reached?
4841                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4842                }                }
4843    
# Line 4848  sub _tree_construction_main ($) { Line 4916  sub _tree_construction_main ($) {
4916                #                #
4917              }              }
4918            } else {            } else {
4919              !!!cp ('t268');              die "$0: $token->{type}: Unknown token type";
             #  
4920            }            }
4921    
4922            ## As if </colgroup>            ## As if </colgroup>
# Line 4866  sub _tree_construction_main ($) { Line 4933  sub _tree_construction_main ($) {
4933              ## reprocess              ## reprocess
4934              redo B;              redo B;
4935            }            }
4936      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} & SELECT_IMS) {
4937        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4938          !!!cp ('t271');          !!!cp ('t271');
4939          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
# Line 4905  sub _tree_construction_main ($) { Line 4972  sub _tree_construction_main ($) {
4972                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4973                !!!next-token;                !!!next-token;
4974                redo B;                redo B;
4975              } elsif ($token->{tag_name} eq 'select') {          } elsif ($token->{tag_name} eq 'select' or
4976                !!!parse-error (type => 'not closed:select');                   $token->{tag_name} eq 'input' or
4977                ## As if </select> instead                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
4978                      {
4979                       caption => 1, table => 1,
4980                       tbody => 1, tfoot => 1, thead => 1,
4981                       tr => 1, td => 1, th => 1,
4982                      }->{$token->{tag_name}})) {
4983              ## TODO: The type below is not good - <select> is replaced by </select>
4984              !!!parse-error (type => 'not closed:select');
4985              ## NOTE: As if the token were </select> (<select> case) or
4986              ## as if there were </select> (otherwise).
4987                ## have an element in table scope                ## have an element in table scope
4988                my $i;                my $i;
4989                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4990                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4991                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq 'select') {
4992                    !!!cp ('t278');                    !!!cp ('t278');
4993                    $i = $_;                    $i = $_;
4994                    last INSCOPE;                    last INSCOPE;
# Line 4936  sub _tree_construction_main ($) { Line 5012  sub _tree_construction_main ($) {
5012    
5013                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
5014    
5015                !!!next-token;            if ($token->{tag_name} eq 'select') {
5016                redo B;              !!!cp ('t281.2');
5017                !!!next-token;
5018                redo B;
5019              } else {
5020                !!!cp ('t281.1');
5021                ## Reprocess the token.
5022                redo B;
5023              }
5024          } else {          } else {
5025            !!!cp ('t282');            !!!cp ('t282');
5026            !!!parse-error (type => 'in select:'.$token->{tag_name});            !!!parse-error (type => 'in select:'.$token->{tag_name});
# Line 5004  sub _tree_construction_main ($) { Line 5087  sub _tree_construction_main ($) {
5087    
5088                !!!next-token;                !!!next-token;
5089                redo B;                redo B;
5090              } elsif ({          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5091                        caption => 1, table => 1, tbody => 1,                   {
5092                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    caption => 1, table => 1, tbody => 1,
5093                       }->{$token->{tag_name}}) {                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
5094                     }->{$token->{tag_name}}) {
5095    ## TODO: The following is wrong?
5096                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5097                                
5098                ## have an element in table scope                ## have an element in table scope
# Line 5044  sub _tree_construction_main ($) { Line 5129  sub _tree_construction_main ($) {
5129                  } elsif ({                  } elsif ({
5130                            table => 1, html => 1,                            table => 1, html => 1,
5131                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5132    ## ISSUE: Can this state be reached?
5133                    !!!cp ('t296');                    !!!cp ('t296');
5134                    last INSCOPE;                    last INSCOPE;
5135                  }                  }
5136                } # INSCOPE                } # INSCOPE
5137                unless (defined $i) {                unless (defined $i) {
5138                  !!!cp ('t297');                  !!!cp ('t297');
5139    ## TODO: The following error type is correct?
5140                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5141                  ## Ignore the </select> token                  ## Ignore the </select> token
5142                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
# Line 5093  sub _tree_construction_main ($) { Line 5180  sub _tree_construction_main ($) {
5180            !!!cp ('t301');            !!!cp ('t301');
5181            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character');
5182    
5183            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5184          } else {          } else {
5185            !!!cp ('t302');            !!!cp ('t302');
5186          }          }
# Line 5109  sub _tree_construction_main ($) { Line 5196  sub _tree_construction_main ($) {
5196            !!!cp ('t303');            !!!cp ('t303');
5197            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5198                        
5199            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5200          } else {          } else {
5201            !!!cp ('t304');            !!!cp ('t304');
5202          }          }
# Line 5126  sub _tree_construction_main ($) { Line 5213  sub _tree_construction_main ($) {
5213            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5214                        
5215            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5216            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5217          } else {          } else {
5218            !!!cp ('t306');            !!!cp ('t306');
5219          }          }
# Line 5180  sub _tree_construction_main ($) { Line 5267  sub _tree_construction_main ($) {
5267              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character');
5268    
5269              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5270              ## Reprocess in the "main" phase, "after frameset"...              ## Reprocess in the "after frameset" insertion mode.
5271              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5272            }            }
5273                        
# Line 5202  sub _tree_construction_main ($) { Line 5289  sub _tree_construction_main ($) {
5289            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5290    
5291            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5292            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5293          } else {          } else {
5294            !!!cp ('t317');            !!!cp ('t317');
5295          }          }
# Line 5223  sub _tree_construction_main ($) { Line 5310  sub _tree_construction_main ($) {
5310          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5311            !!!cp ('t320');            !!!cp ('t320');
5312            ## NOTE: As if in body.            ## NOTE: As if in body.
5313            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL);
5314            redo B;            redo B;
5315          } else {          } else {
5316            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
# Line 5243  sub _tree_construction_main ($) { Line 5330  sub _tree_construction_main ($) {
5330            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5331    
5332            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5333            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5334          } else {          } else {
5335            !!!cp ('t324');            !!!cp ('t324');
5336          }          }
# Line 5302  sub _tree_construction_main ($) { Line 5389  sub _tree_construction_main ($) {
5389        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5390          !!!cp ('t332');          !!!cp ('t332');
5391          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5392          $script_start_tag->($insert);          $script_start_tag->();
5393          redo B;          redo B;
5394        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5395          !!!cp ('t333');          !!!cp ('t333');
5396          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5397          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5398          redo B;          redo B;
5399        } elsif ({        } elsif ({
5400                  base => 1, link => 1,                  base => 1, link => 1,
# Line 5370  sub _tree_construction_main ($) { Line 5457  sub _tree_construction_main ($) {
5457          redo B;          redo B;
5458        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5459          !!!cp ('t341');          !!!cp ('t341');
         !!!parse-error (type => 'in body:title');  
5460          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5461          $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]);  
           }  
         });  
5462          redo B;          redo B;
5463        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
5464          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 5404  sub _tree_construction_main ($) { Line 5482  sub _tree_construction_main ($) {
5482          redo B;          redo B;
5483        } elsif ({        } elsif ({
5484                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5485                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1,
5486                    h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5487                  menu => 1, ol => 1, p => 1, ul => 1,                  menu => 1, ol => 1, p => 1, ul => 1,
5488                  pre => 1,                  pre => 1, listing => 1,
5489                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5490          ## has a p element in scope          ## has a p element in scope
5491          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
# Line 5416  sub _tree_construction_main ($) { Line 5495  sub _tree_construction_main ($) {
5495              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5496              redo B;              redo B;
5497            } elsif ({            } elsif ({
5498                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5499                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5500                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5501              !!!cp ('t345');              !!!cp ('t345');
# Line 5425  sub _tree_construction_main ($) { Line 5504  sub _tree_construction_main ($) {
5504          } # INSCOPE          } # INSCOPE
5505                        
5506          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5507          if ($token->{tag_name} eq 'pre') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
5508            !!!next-token;            !!!next-token;
5509            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
5510              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
# Line 5459  sub _tree_construction_main ($) { Line 5538  sub _tree_construction_main ($) {
5538                $token = {type => END_TAG_TOKEN, tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5539                redo B;                redo B;
5540              } elsif ({              } elsif ({
5541                        table => 1, caption => 1, td => 1, th => 1,                        applet => 1, table => 1, caption => 1, td => 1, th => 1,
5542                        button => 1, marquee => 1, object => 1, html => 1,                        button => 1, marquee => 1, object => 1, html => 1,
5543                       }->{$_->[1]}) {                       }->{$_->[1]}) {
5544                !!!cp ('t352');                !!!cp ('t352');
# Line 5481  sub _tree_construction_main ($) { Line 5560  sub _tree_construction_main ($) {
5560              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5561              redo B;              redo B;
5562            } elsif ({            } elsif ({
5563                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5564                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5565                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5566              !!!cp ('t354');              !!!cp ('t354');
# Line 5537  sub _tree_construction_main ($) { Line 5616  sub _tree_construction_main ($) {
5616              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5617              redo B;              redo B;
5618            } elsif ({            } elsif ({
5619                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5620                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5621                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5622              !!!cp ('t361');              !!!cp ('t361');
# Line 5593  sub _tree_construction_main ($) { Line 5672  sub _tree_construction_main ($) {
5672              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5673              redo B;              redo B;
5674            } elsif ({            } elsif ({
5675                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5676                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5677                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5678              !!!cp ('t368');              !!!cp ('t368');
# Line 5607  sub _tree_construction_main ($) { Line 5686  sub _tree_construction_main ($) {
5686                        
5687          !!!next-token;          !!!next-token;
5688          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;  
5689        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
5690          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5691            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
# Line 5719  sub _tree_construction_main ($) { Line 5751  sub _tree_construction_main ($) {
5751              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
5752              redo B;              redo B;
5753            } elsif ({            } elsif ({
5754                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5755                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5756                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5757              !!!cp ('t377');              !!!cp ('t377');
# Line 5743  sub _tree_construction_main ($) { Line 5775  sub _tree_construction_main ($) {
5775              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
5776              redo B;              redo B;
5777            } elsif ({            } elsif ({
5778                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5779                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5780                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5781              !!!cp ('t379');              !!!cp ('t379');
# Line 5754  sub _tree_construction_main ($) { Line 5786  sub _tree_construction_main ($) {
5786          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5787                        
5788          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5789    
5790            ## TODO: associate with $self->{form_element} if defined
5791    
5792          push @$active_formatting_elements, ['#marker', ''];          push @$active_formatting_elements, ['#marker', ''];
5793    
5794          !!!next-token;          !!!next-token;
5795          redo B;          redo B;
5796        } elsif ($token->{tag_name} eq 'marquee' or        } elsif ({
5797                 $token->{tag_name} eq 'object') {                  applet => 1, marquee => 1, object => 1,
5798                   }->{$token->{tag_name}}) {
5799          !!!cp ('t380');          !!!cp ('t380');
5800          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5801                    
# Line 5771  sub _tree_construction_main ($) { Line 5807  sub _tree_construction_main ($) {
5807        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5808          !!!cp ('t381');          !!!cp ('t381');
5809          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5810          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5811          redo B;          redo B;
5812        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
5813          ## has a p element in scope          ## has a p element in scope
# Line 5782  sub _tree_construction_main ($) { Line 5818  sub _tree_construction_main ($) {
5818              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5819              redo B;              redo B;
5820            } elsif ({            } elsif ({
5821                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5822                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5823                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5824              !!!cp ('t383');              !!!cp ('t383');
# Line 5791  sub _tree_construction_main ($) { Line 5827  sub _tree_construction_main ($) {
5827          } # INSCOPE          } # INSCOPE
5828                        
5829          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5830                      push @{$open_tables}, [$self->{open_elements}->[-1]->[0]];
5831    
5832          $self->{insertion_mode} = IN_TABLE_IM;          $self->{insertion_mode} = IN_TABLE_IM;
5833                        
5834          !!!next-token;          !!!next-token;
# Line 5826  sub _tree_construction_main ($) { Line 5863  sub _tree_construction_main ($) {
5863              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5864              redo B;              redo B;
5865            } elsif ({            } elsif ({
5866                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
5867                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5868                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5869              !!!cp ('t387');              !!!cp ('t387');
# Line 5946  sub _tree_construction_main ($) { Line 5983  sub _tree_construction_main ($) {
5983                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5984          !!!cp ('t399');          !!!cp ('t399');
5985          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
5986          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL);
5987          redo B;          redo B;
5988        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
5989          !!!cp ('t400');          !!!cp ('t400');
5990          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5991                    
5992          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5993    
5994            ## TODO: associate with $self->{form_element} if defined
5995                    
5996          $self->{insertion_mode} = IN_SELECT_IM;          if ($self->{insertion_mode} & TABLE_IMS or
5997                $self->{insertion_mode} & BODY_TABLE_IMS or
5998                $self->{insertion_mode} == IN_COLUMN_GROUP_IM) {
5999              !!!cp ('t400.1');
6000              $self->{insertion_mode} = IN_SELECT_IN_TABLE_IM;
6001            } else {
6002              !!!cp ('t400.2');
6003              $self->{insertion_mode} = IN_SELECT_IM;
6004            }
6005          !!!next-token;          !!!next-token;
6006          redo B;          redo B;
6007        } elsif ({        } elsif ({
# Line 6029  sub _tree_construction_main ($) { Line 6076  sub _tree_construction_main ($) {
6076                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
6077                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
6078                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 p => 1,  
6079                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
6080                  button => 1, marquee => 1, object => 1,                  applet => 1, button => 1, marquee => 1, object => 1,
6081                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6082          ## has an element in scope          ## has an element in scope
6083          my $i;          my $i;
6084          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6085            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6086            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;  
             }  
               
6087              !!!cp ('t410');              !!!cp ('t410');
6088              $i = $_;              $i = $_;
6089              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE;
6090            } elsif ({            } elsif ({
6091                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6092                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6093                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6094              !!!cp ('t411');              !!!cp ('t411');
6095              last INSCOPE;              last INSCOPE;
6096            }            }
6097          } # INSCOPE          } # INSCOPE
6098            
6099          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6100            if (defined $i) {            !!!cp ('t413');
6101              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6102            } else {
6103              ## Step 1. generate implied end tags
6104              while ({
6105                      dd => ($token->{tag_name} ne 'dd'),
6106                      dt => ($token->{tag_name} ne 'dt'),
6107                      li => ($token->{tag_name} ne 'li'),
6108                      p => 1,
6109                     }->{$self->{open_elements}->[-1]->[1]}) {
6110                !!!cp ('t409');
6111                pop @{$self->{open_elements}};
6112              }
6113    
6114              ## Step 2.
6115              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6116              !!!cp ('t412');              !!!cp ('t412');
6117              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6118            } else {            } else {
6119              !!!cp ('t413');              !!!cp ('t414');
             !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
6120            }            }
6121          }  
6122                      ## Step 3.
         if (defined $i) {  
           !!!cp ('t414');  
6123            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6124          } elsif ($token->{tag_name} eq 'p') {  
6125            !!!cp ('t415');            ## Step 4.
6126            ## As if <p>, then reprocess the current token            $clear_up_to_marker->()
6127            my $el;                if {
6128            !!!create-element ($el, 'p');                  applet => 1, button => 1, marquee => 1, object => 1,
6129            $insert->($el);                }->{$token->{tag_name}};
         } else {  
           !!!cp ('t416');  
6130          }          }
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
6131          !!!next-token;          !!!next-token;
6132          redo B;          redo B;
6133        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
6134            undef $self->{form_element};
6135    
6136          ## has an element in scope          ## has an element in scope
6137            my $i;
6138          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6139            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6140            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;  
             }  
               
6141              !!!cp ('t418');              !!!cp ('t418');
6142                $i = $_;
6143              last INSCOPE;              last INSCOPE;
6144            } elsif ({            } elsif ({
6145                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6146                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6147                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6148              !!!cp ('t419');              !!!cp ('t419');
6149              last INSCOPE;              last INSCOPE;
6150            }            }
6151          } # INSCOPE          } # INSCOPE
6152            
6153          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 {  
6154            !!!cp ('t421');            !!!cp ('t421');
6155            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6156            } else {
6157              ## Step 1. generate implied end tags
6158              while ({
6159                      dd => 1, dt => 1, li => 1, p => 1,
6160                     }->{$self->{open_elements}->[-1]->[1]}) {
6161                !!!cp ('t417');
6162                pop @{$self->{open_elements}};
6163              }
6164              
6165              ## Step 2.
6166              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6167                !!!cp ('t417.1');
6168                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6169              } else {
6170                !!!cp ('t420');
6171              }  
6172              
6173              ## Step 3.
6174              splice @{$self->{open_elements}}, $i;
6175          }          }
6176    
         undef $self->{form_element};  
6177          !!!next-token;          !!!next-token;
6178          redo B;          redo B;
6179        } elsif ({        } elsif ({
# Line 6144  sub _tree_construction_main ($) { Line 6186  sub _tree_construction_main ($) {
6186            if ({            if ({
6187                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
6188                }->{$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;  
             }  
   
6189              !!!cp ('t423');              !!!cp ('t423');
6190              $i = $_;              $i = $_;
6191              last INSCOPE;              last INSCOPE;
6192            } elsif ({            } elsif ({
6193                      table => 1, caption => 1, td => 1, th => 1,                      applet => 1, table => 1, caption => 1, td => 1, th => 1,
6194                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6195                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6196              !!!cp ('t424');              !!!cp ('t424');
6197              last INSCOPE;              last INSCOPE;
6198            }            }
6199          } # INSCOPE          } # INSCOPE
6200            
6201          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          unless (defined $i) { # has an element in scope
6202            !!!cp ('t425');            !!!cp ('t425.1');
6203            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6204          } else {          } else {
6205            !!!cp ('t426');            ## Step 1. generate implied end tags
6206              while ({
6207                      dd => 1, dt => 1, li => 1, p => 1,
6208                     }->{$self->{open_elements}->[-1]->[1]}) {
6209                !!!cp ('t422');
6210                pop @{$self->{open_elements}};
6211              }
6212              
6213              ## Step 2.
6214              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6215                !!!cp ('t425');
6216                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6217              } else {
6218                !!!cp ('t426');
6219              }
6220    
6221              ## Step 3.
6222              splice @{$self->{open_elements}}, $i;
6223          }          }
6224                    
6225          splice @{$self->{open_elements}}, $i if defined $i;          !!!next-token;
6226            redo B;
6227          } elsif ($token->{tag_name} eq 'p') {
6228            ## has an element in scope
6229            my $i;
6230            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6231              my $node = $self->{open_elements}->[$_];
6232              if ($node->[1] eq $token->{tag_name}) {
6233                !!!cp ('t410.1');
6234                $i = $_;
6235                last INSCOPE;
6236              } elsif ({
6237                        applet => 1, table => 1, caption => 1, td => 1, th => 1,
6238                        button => 1, marquee => 1, object => 1, html => 1,
6239                       }->{$node->[1]}) {
6240                !!!cp ('t411.1');
6241                last INSCOPE;
6242              }
6243            } # INSCOPE
6244    
6245            if (defined $i) {
6246              if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6247                !!!cp ('t412.1');
6248                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6249              } else {
6250                !!!cp ('t414.1');
6251              }
6252    
6253              splice @{$self->{open_elements}}, $i;
6254            } else {
6255              !!!cp ('t413.1');
6256              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6257    
6258              !!!cp ('t415.1');
6259              ## As if <p>, then reprocess the current token
6260              my $el;
6261              !!!create-element ($el, 'p');
6262              $insert->($el);
6263              ## NOTE: Not inserted into |$self->{open_elements}|.
6264            }
6265    
6266          !!!next-token;          !!!next-token;
6267          redo B;          redo B;
6268        } elsif ({        } elsif ({
# Line 6232  sub _tree_construction_main ($) { Line 6318  sub _tree_construction_main ($) {
6318            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] eq $token->{tag_name}) {
6319              ## Step 1              ## Step 1
6320              ## generate implied end tags              ## generate implied end tags
6321              if ({              while ({
6322                   dd => 1, dt => 1, li => 1, p => 1,                      dd => 1, dt => 1, li => 1, p => 1,
6323                   td => 1, th => 1, tr => 1,                     }->{$self->{open_elements}->[-1]->[1]}) {
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
6324                !!!cp ('t430');                !!!cp ('t430');
6325                !!!back-token;                ## ISSUE: Can this case be reached?
6326                $token = {type => END_TAG_TOKEN,                pop @{$self->{open_elements}};
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               redo B;  
6327              }              }
6328                    
6329              ## Step 2              ## Step 2
# Line 6287  sub _tree_construction_main ($) { Line 6369  sub _tree_construction_main ($) {
6369      redo B;      redo B;
6370    } # B    } # B
6371    
   ## 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  
   
6372    ## Stop parsing # MUST    ## Stop parsing # MUST
6373        
6374    ## TODO: script stuffs    ## TODO: script stuffs
# Line 6333  sub set_inner_html ($$$) { Line 6410  sub set_inner_html ($$$) {
6410      my $p = $class->new;      my $p = $class->new;
6411      $p->{document} = $doc;      $p->{document} = $doc;
6412    
6413      ## Step 9 # MUST      ## Step 8 # MUST
6414      my $i = 0;      my $i = 0;
6415      my $line = 1;      my $line = 1;
6416      my $column = 0;      my $column = 0;
# Line 6400  sub set_inner_html ($$$) { Line 6477  sub set_inner_html ($$$) {
6477    
6478      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
6479    
6480      ## Step 4      ## Step 3
6481      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
6482        ('http://www.w3.org/1999/xhtml', [undef, 'html']);        ('http://www.w3.org/1999/xhtml', [undef, 'html']);
6483    
6484      ## Step 5 # MUST      ## Step 4 # MUST
6485      $doc->append_child ($root);      $doc->append_child ($root);
6486    
6487      ## Step 6 # MUST      ## Step 5 # MUST
6488      push @{$p->{open_elements}}, [$root, 'html'];      push @{$p->{open_elements}}, [$root, 'html'];
6489    
6490      undef $p->{head_element};      undef $p->{head_element};
6491    
6492      ## Step 7 # MUST      ## Step 6 # MUST
6493      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;
6494    
6495      ## Step 8 # MUST      ## Step 7 # MUST
6496      my $anode = $node;      my $anode = $node;
6497      AN: while (defined $anode) {      AN: while (defined $anode) {
6498        if ($anode->node_type == 1) {        if ($anode->node_type == 1) {
# Line 6431  sub set_inner_html ($$$) { Line 6508  sub set_inner_html ($$$) {
6508        $anode = $anode->parent_node;        $anode = $anode->parent_node;
6509      } # AN      } # AN
6510            
6511      ## Step 3 # MUST      ## Step 9 # MUST
     ## Step 10 # MUST  
6512      {      {
6513        my $self = $p;        my $self = $p;
6514        !!!next-token;        !!!next-token;
6515      }      }
6516      $p->_tree_construction_main;      $p->_tree_construction_main;
6517    
6518      ## Step 11 # MUST      ## Step 10 # MUST
6519      my @cn = @{$node->child_nodes};      my @cn = @{$node->child_nodes};
6520      for (@cn) {      for (@cn) {
6521        $node->remove_child ($_);        $node->remove_child ($_);
6522      }      }
6523      ## ISSUE: mutation events? read-only?      ## ISSUE: mutation events? read-only?
6524    
6525      ## Step 12 # MUST      ## Step 11 # MUST
6526      @cn = @{$root->child_nodes};      @cn = @{$root->child_nodes};
6527      for (@cn) {      for (@cn) {
6528        $this_doc->adopt_node ($_);        $this_doc->adopt_node ($_);

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.103

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24