/[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.78 by wakaba, Mon Mar 3 11:56:18 2008 UTC revision 1.82 by wakaba, Wed Mar 5 02:55:08 2008 UTC
# Line 2444  sub _tree_construction_initial ($) { Line 2444  sub _tree_construction_initial ($) {
2444        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
2445            defined $token->{public_identifier} or            defined $token->{public_identifier} or
2446            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
2447            !!!cp ('t1');
2448          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5');
2449        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
2450            !!!cp ('t2');
2451          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)
2452          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5');
2453          } else {
2454            !!!cp ('t3');
2455        }        }
2456                
2457        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 2461  sub _tree_construction_initial ($) { Line 2465  sub _tree_construction_initial ($) {
2465        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
2466                
2467        if ($token->{quirks} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'HTML') {
2468            !!!cp ('t4');
2469          $self->{document}->manakai_compat_mode ('quirks');          $self->{document}->manakai_compat_mode ('quirks');
2470        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
2471          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
# Line 2539  sub _tree_construction_initial ($) { Line 2544  sub _tree_construction_initial ($) {
2544            "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,            "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,
2545            "HTML" => 1,            "HTML" => 1,
2546          }->{$pubid}) {          }->{$pubid}) {
2547              !!!cp ('t5');
2548            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
2549          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or
2550                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {
2551            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
2552                !!!cp ('t6');
2553              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
2554            } else {            } else {
2555                !!!cp ('t7');
2556              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
2557            }            }
2558          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 Frameset//EN" or          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or
2559                   $pubid eq "-//W3C//DTD XHTML 1.0 Transitional//EN") {                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {
2560              !!!cp ('t8');
2561            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
2562            } else {
2563              !!!cp ('t9');
2564          }          }
2565          } else {
2566            !!!cp ('t10');
2567        }        }
2568        if (defined $token->{system_identifier}) {        if (defined $token->{system_identifier}) {
2569          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
2570          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
2571          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {
2572              ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"
2573            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
2574              !!!cp ('t11');
2575            } else {
2576              !!!cp ('t12');
2577          }          }
2578          } else {
2579            !!!cp ('t13');
2580        }        }
2581                
2582        ## Go to the root element phase.        ## Go to the root element phase.
# Line 2568  sub _tree_construction_initial ($) { Line 2587  sub _tree_construction_initial ($) {
2587                END_TAG_TOKEN, 1,                END_TAG_TOKEN, 1,
2588                END_OF_FILE_TOKEN, 1,                END_OF_FILE_TOKEN, 1,
2589               }->{$token->{type}}) {               }->{$token->{type}}) {
2590          !!!cp ('t14');
2591        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2592        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2593        ## Go to the root element phase        ## Go to the root element phase
# Line 2578  sub _tree_construction_initial ($) { Line 2598  sub _tree_construction_initial ($) {
2598          ## Ignore the token          ## Ignore the token
2599    
2600          unless (length $token->{data}) {          unless (length $token->{data}) {
2601              !!!cp ('t15');
2602            ## Stay in the phase            ## Stay in the phase
2603            !!!next-token;            !!!next-token;
2604            redo INITIAL;            redo INITIAL;
2605            } else {
2606              !!!cp ('t16');
2607          }          }
2608          } else {
2609            !!!cp ('t17');
2610        }        }
2611    
2612        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
# Line 2590  sub _tree_construction_initial ($) { Line 2615  sub _tree_construction_initial ($) {
2615        ## reprocess        ## reprocess
2616        return;        return;
2617      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
2618          !!!cp ('t18');
2619        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2620        $self->{document}->append_child ($comment);        $self->{document}->append_child ($comment);
2621                
# Line 2600  sub _tree_construction_initial ($) { Line 2626  sub _tree_construction_initial ($) {
2626        die "$0: $token->{type}: Unknown token type";        die "$0: $token->{type}: Unknown token type";
2627      }      }
2628    } # INITIAL    } # INITIAL
2629    
2630      die "$0: _tree_construction_initial: This should be never reached";
2631  } # _tree_construction_initial  } # _tree_construction_initial
2632    
2633  sub _tree_construction_root_element ($) {  sub _tree_construction_root_element ($) {
# Line 2607  sub _tree_construction_root_element ($) Line 2635  sub _tree_construction_root_element ($)
2635        
2636    B: {    B: {
2637        if ($token->{type} == DOCTYPE_TOKEN) {        if ($token->{type} == DOCTYPE_TOKEN) {
2638            !!!cp ('t19');
2639          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
2640          ## Ignore the token          ## Ignore the token
2641          ## Stay in the phase          ## Stay in the phase
2642          !!!next-token;          !!!next-token;
2643          redo B;          redo B;
2644        } elsif ($token->{type} == COMMENT_TOKEN) {        } elsif ($token->{type} == COMMENT_TOKEN) {
2645            !!!cp ('t20');
2646          my $comment = $self->{document}->create_comment ($token->{data});          my $comment = $self->{document}->create_comment ($token->{data});
2647          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2648          ## Stay in the phase          ## Stay in the phase
# Line 2623  sub _tree_construction_root_element ($) Line 2653  sub _tree_construction_root_element ($)
2653            ## Ignore the token.            ## Ignore the token.
2654    
2655            unless (length $token->{data}) {            unless (length $token->{data}) {
2656                !!!cp ('t21');
2657              ## Stay in the phase              ## Stay in the phase
2658              !!!next-token;              !!!next-token;
2659              redo B;              redo B;
2660              } else {
2661                !!!cp ('t22');
2662            }            }
2663            } else {
2664              !!!cp ('t23');
2665          }          }
2666    
2667          $self->{application_cache_selection}->(undef);          $self->{application_cache_selection}->(undef);
# Line 2635  sub _tree_construction_root_element ($) Line 2670  sub _tree_construction_root_element ($)
2670        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
2671          if ($token->{tag_name} eq 'html' and          if ($token->{tag_name} eq 'html' and
2672              $token->{attributes}->{manifest}) {              $token->{attributes}->{manifest}) {
2673              !!!cp ('t24');
2674            $self->{application_cache_selection}            $self->{application_cache_selection}
2675                 ->($token->{attributes}->{manifest}->{value});                 ->($token->{attributes}->{manifest}->{value});
2676            ## ISSUE: No relative reference resolution?            ## ISSUE: No relative reference resolution?
2677          } else {          } else {
2678              !!!cp ('t25');
2679            $self->{application_cache_selection}->(undef);            $self->{application_cache_selection}->(undef);
2680          }          }
2681    
# Line 2648  sub _tree_construction_root_element ($) Line 2685  sub _tree_construction_root_element ($)
2685                  END_TAG_TOKEN, 1,                  END_TAG_TOKEN, 1,
2686                  END_OF_FILE_TOKEN, 1,                  END_OF_FILE_TOKEN, 1,
2687                 }->{$token->{type}}) {                 }->{$token->{type}}) {
2688            !!!cp ('t26');
2689          $self->{application_cache_selection}->(undef);          $self->{application_cache_selection}->(undef);
2690    
2691          ## ISSUE: There is an issue in the spec          ## ISSUE: There is an issue in the spec
# Line 2663  sub _tree_construction_root_element ($) Line 2701  sub _tree_construction_root_element ($)
2701        #redo B;        #redo B;
2702        return; ## Go to the main phase.        return; ## Go to the main phase.
2703    } # B    } # B
2704    
2705      die "$0: _tree_construction_root_element: This should never be reached";
2706  } # _tree_construction_root_element  } # _tree_construction_root_element
2707    
2708  sub _reset_insertion_mode ($) {  sub _reset_insertion_mode ($) {
# Line 2687  sub _reset_insertion_mode ($) { Line 2727  sub _reset_insertion_mode ($) {
2727          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
2728            if ($self->{inner_html_node}->[1] eq 'td' or            if ($self->{inner_html_node}->[1] eq 'td' or
2729                $self->{inner_html_node}->[1] eq 'th') {                $self->{inner_html_node}->[1] eq 'th') {
2730                !!!cp ('t27');
2731              #              #
2732            } else {            } else {
2733                !!!cp ('t28');
2734              $node = $self->{inner_html_node};              $node = $self->{inner_html_node};
2735            }            }
2736          }          }
# Line 2715  sub _reset_insertion_mode ($) { Line 2757  sub _reset_insertion_mode ($) {
2757        ## Step 14        ## Step 14
2758        if ($node->[1] eq 'html') {        if ($node->[1] eq 'html') {
2759          unless (defined $self->{head_element}) {          unless (defined $self->{head_element}) {
2760              !!!cp ('t29');
2761            $self->{insertion_mode} = BEFORE_HEAD_IM;            $self->{insertion_mode} = BEFORE_HEAD_IM;
2762          } else {          } else {
2763              ## ISSUE: Can this state be reached?
2764              !!!cp ('t30');
2765            $self->{insertion_mode} = AFTER_HEAD_IM;            $self->{insertion_mode} = AFTER_HEAD_IM;
2766          }          }
2767          return;          return;
2768          } else {
2769            !!!cp ('t31');
2770        }        }
2771                
2772        ## Step 15        ## Step 15
# Line 2732  sub _reset_insertion_mode ($) { Line 2779  sub _reset_insertion_mode ($) {
2779        ## Step 17        ## Step 17
2780        redo S3;        redo S3;
2781      } # S3      } # S3
2782    
2783      die "$0: _reset_insertion_mode: This line should never be reached";
2784  } # _reset_insertion_mode  } # _reset_insertion_mode
2785    
2786  sub _tree_construction_main ($) {  sub _tree_construction_main ($) {
# Line 2753  sub _tree_construction_main ($) { Line 2802  sub _tree_construction_main ($) {
2802      return if $entry->[0] eq '#marker';      return if $entry->[0] eq '#marker';
2803      for (@{$self->{open_elements}}) {      for (@{$self->{open_elements}}) {
2804        if ($entry->[0] eq $_->[0]) {        if ($entry->[0] eq $_->[0]) {
2805            !!!cp ('t32');
2806          return;          return;
2807        }        }
2808      }      }
# Line 2767  sub _tree_construction_main ($) { Line 2817  sub _tree_construction_main ($) {
2817    
2818        ## Step 6        ## Step 6
2819        if ($entry->[0] eq '#marker') {        if ($entry->[0] eq '#marker') {
2820            !!!cp ('t33_1');
2821          #          #
2822        } else {        } else {
2823          my $in_open_elements;          my $in_open_elements;
2824          OE: for (@{$self->{open_elements}}) {          OE: for (@{$self->{open_elements}}) {
2825            if ($entry->[0] eq $_->[0]) {            if ($entry->[0] eq $_->[0]) {
2826                !!!cp ('t33');
2827              $in_open_elements = 1;              $in_open_elements = 1;
2828              last OE;              last OE;
2829            }            }
2830          }          }
2831          if ($in_open_elements) {          if ($in_open_elements) {
2832              !!!cp ('t34');
2833            #            #
2834          } else {          } else {
2835              ## NOTE: <!DOCTYPE HTML><p><b><i><u></p> <p>X
2836              !!!cp ('t35');
2837            redo S4;            redo S4;
2838          }          }
2839        }        }
# Line 2801  sub _tree_construction_main ($) { Line 2856  sub _tree_construction_main ($) {
2856    
2857        ## Step 11        ## Step 11
2858        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {
2859            !!!cp ('t36');
2860          ## Step 7'          ## Step 7'
2861          $i++;          $i++;
2862          $entry = $active_formatting_elements->[$i];          $entry = $active_formatting_elements->[$i];
2863                    
2864          redo S7;          redo S7;
2865        }        }
2866    
2867          !!!cp ('t37');
2868      } # S7      } # S7
2869    }; # $reconstruct_active_formatting_elements    }; # $reconstruct_active_formatting_elements
2870    
2871    my $clear_up_to_marker = sub {    my $clear_up_to_marker = sub {
2872      for (reverse 0..$#$active_formatting_elements) {      for (reverse 0..$#$active_formatting_elements) {
2873        if ($active_formatting_elements->[$_]->[0] eq '#marker') {        if ($active_formatting_elements->[$_]->[0] eq '#marker') {
2874            !!!cp ('t38');
2875          splice @$active_formatting_elements, $_;          splice @$active_formatting_elements, $_;
2876          return;          return;
2877        }        }
2878      }      }
2879    
2880        !!!cp ('t39');
2881    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2882    
2883    my $parse_rcdata = sub ($$) {    my $parse_rcdata = sub ($$) {
# Line 2838  sub _tree_construction_main ($) { Line 2899  sub _tree_construction_main ($) {
2899      my $text = '';      my $text = '';
2900      !!!next-token;      !!!next-token;
2901      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing
2902          !!!cp ('t40');
2903        $text .= $token->{data};        $text .= $token->{data};
2904        !!!next-token;        !!!next-token;
2905      }      }
2906    
2907      ## Step 5      ## Step 5
2908      if (length $text) {      if (length $text) {
2909          !!!cp ('t41');
2910        my $text = $self->{document}->create_text_node ($text);        my $text = $self->{document}->create_text_node ($text);
2911        $el->append_child ($text);        $el->append_child ($text);
2912      }      }
# Line 2852  sub _tree_construction_main ($) { Line 2915  sub _tree_construction_main ($) {
2915      $self->{content_model} = PCDATA_CONTENT_MODEL;      $self->{content_model} = PCDATA_CONTENT_MODEL;
2916    
2917      ## Step 7      ## Step 7
2918      if ($token->{type} == END_TAG_TOKEN and $token->{tag_name} eq $start_tag_name) {      if ($token->{type} == END_TAG_TOKEN and
2919            $token->{tag_name} eq $start_tag_name) {
2920          !!!cp ('t42');
2921        ## Ignore the token        ## Ignore the token
2922      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2923          !!!cp ('t43');
2924        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2925      } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2926          !!!cp ('t44');
2927        !!!parse-error (type => 'in RCDATA:#'.$token->{type});        !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2928      } else {      } else {
2929        die "$0: $content_model_flag in parse_rcdata";        die "$0: $content_model_flag in parse_rcdata";
# Line 2876  sub _tree_construction_main ($) { Line 2943  sub _tree_construction_main ($) {
2943      my $text = '';      my $text = '';
2944      !!!next-token;      !!!next-token;
2945      while ($token->{type} == CHARACTER_TOKEN) {      while ($token->{type} == CHARACTER_TOKEN) {
2946          !!!cp ('t45');
2947        $text .= $token->{data};        $text .= $token->{data};
2948        !!!next-token;        !!!next-token;
2949      } # stop if non-character token or tokenizer stops tokenising      } # stop if non-character token or tokenizer stops tokenising
2950      if (length $text) {      if (length $text) {
2951          !!!cp ('t46');
2952        $script_el->manakai_append_text ($text);        $script_el->manakai_append_text ($text);
2953      }      }
2954                                
# Line 2887  sub _tree_construction_main ($) { Line 2956  sub _tree_construction_main ($) {
2956    
2957      if ($token->{type} == END_TAG_TOKEN and      if ($token->{type} == END_TAG_TOKEN and
2958          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
2959          !!!cp ('t47');
2960        ## Ignore the token        ## Ignore the token
2961      } else {      } else {
2962          !!!cp ('t48');
2963        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2964        ## ISSUE: And ignore?        ## ISSUE: And ignore?
2965        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
2966      }      }
2967            
2968      if (defined $self->{inner_html_node}) {      if (defined $self->{inner_html_node}) {
2969          !!!cp ('t49');
2970        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
2971      } else {      } else {
2972          !!!cp ('t50');
2973        ## TODO: $old_insertion_point = current insertion point        ## TODO: $old_insertion_point = current insertion point
2974        ## TODO: insertion point = just before the next input character        ## TODO: insertion point = just before the next input character
2975    
# Line 2919  sub _tree_construction_main ($) { Line 2992  sub _tree_construction_main ($) {
2992        my $formatting_element_i_in_active;        my $formatting_element_i_in_active;
2993        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
2994          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {
2995              !!!cp ('t51');
2996            $formatting_element = $active_formatting_elements->[$_];            $formatting_element = $active_formatting_elements->[$_];
2997            $formatting_element_i_in_active = $_;            $formatting_element_i_in_active = $_;
2998            last AFE;            last AFE;
2999          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {
3000              !!!cp ('t52');
3001            last AFE;            last AFE;
3002          }          }
3003        } # AFE        } # AFE
3004        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3005            !!!cp ('t53');
3006          !!!parse-error (type => 'unmatched end tag:'.$tag_name);          !!!parse-error (type => 'unmatched end tag:'.$tag_name);
3007          ## Ignore the token          ## Ignore the token
3008          !!!next-token;          !!!next-token;
# Line 2939  sub _tree_construction_main ($) { Line 3015  sub _tree_construction_main ($) {
3015          my $node = $self->{open_elements}->[$_];          my $node = $self->{open_elements}->[$_];
3016          if ($node->[0] eq $formatting_element->[0]) {          if ($node->[0] eq $formatting_element->[0]) {
3017            if ($in_scope) {            if ($in_scope) {
3018                !!!cp ('t54');
3019              $formatting_element_i_in_open = $_;              $formatting_element_i_in_open = $_;
3020              last INSCOPE;              last INSCOPE;
3021            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3022                !!!cp ('t55');
3023              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3024              ## Ignore the token              ## Ignore the token
3025              !!!next-token;              !!!next-token;
# Line 2951  sub _tree_construction_main ($) { Line 3029  sub _tree_construction_main ($) {
3029                    table => 1, caption => 1, td => 1, th => 1,                    table => 1, caption => 1, td => 1, th => 1,
3030                    button => 1, marquee => 1, object => 1, html => 1,                    button => 1, marquee => 1, object => 1, html => 1,
3031                   }->{$node->[1]}) {                   }->{$node->[1]}) {
3032              !!!cp ('t56');
3033            $in_scope = 0;            $in_scope = 0;
3034          }          }
3035        } # INSCOPE        } # INSCOPE
3036        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3037            !!!cp ('t57');
3038          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3039          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3040          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
3041          return;          return;
3042        }        }
3043        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3044            !!!cp ('t58');
3045          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3046        }        }
3047                
# Line 2973  sub _tree_construction_main ($) { Line 3054  sub _tree_construction_main ($) {
3054              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3055              ($special_category->{$node->[1]} or              ($special_category->{$node->[1]} or
3056               $scoping_category->{$node->[1]})) {               $scoping_category->{$node->[1]})) {
3057              !!!cp ('t59');
3058            $furthest_block = $node;            $furthest_block = $node;
3059            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
3060          } elsif ($node->[0] eq $formatting_element->[0]) {          } elsif ($node->[0] eq $formatting_element->[0]) {
3061              !!!cp ('t60');
3062            last OE;            last OE;
3063          }          }
3064        } # OE        } # OE
3065                
3066        ## Step 3        ## Step 3
3067        unless (defined $furthest_block) { # MUST        unless (defined $furthest_block) { # MUST
3068            !!!cp ('t61');
3069          splice @{$self->{open_elements}}, $formatting_element_i_in_open;          splice @{$self->{open_elements}}, $formatting_element_i_in_open;
3070          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;
3071          !!!next-token;          !!!next-token;
# Line 2994  sub _tree_construction_main ($) { Line 3078  sub _tree_construction_main ($) {
3078        ## Step 5        ## Step 5
3079        my $furthest_block_parent = $furthest_block->[0]->parent_node;        my $furthest_block_parent = $furthest_block->[0]->parent_node;
3080        if (defined $furthest_block_parent) {        if (defined $furthest_block_parent) {
3081            !!!cp ('t62');
3082          $furthest_block_parent->remove_child ($furthest_block->[0]);          $furthest_block_parent->remove_child ($furthest_block->[0]);
3083        }        }
3084                
# Line 3016  sub _tree_construction_main ($) { Line 3101  sub _tree_construction_main ($) {
3101          S7S2: {          S7S2: {
3102            for (reverse 0..$#$active_formatting_elements) {            for (reverse 0..$#$active_formatting_elements) {
3103              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
3104                  !!!cp ('t63');
3105                $node_i_in_active = $_;                $node_i_in_active = $_;
3106                last S7S2;                last S7S2;
3107              }              }
# Line 3029  sub _tree_construction_main ($) { Line 3115  sub _tree_construction_main ($) {
3115                    
3116          ## Step 4          ## Step 4
3117          if ($last_node->[0] eq $furthest_block->[0]) {          if ($last_node->[0] eq $furthest_block->[0]) {
3118              !!!cp ('t64');
3119            $bookmark_prev_el = $node->[0];            $bookmark_prev_el = $node->[0];
3120          }          }
3121                    
3122          ## Step 5          ## Step 5
3123          if ($node->[0]->has_child_nodes ()) {          if ($node->[0]->has_child_nodes ()) {
3124              !!!cp ('t65');
3125            my $clone = [$node->[0]->clone_node (0), $node->[1]];            my $clone = [$node->[0]->clone_node (0), $node->[1]];
3126            $active_formatting_elements->[$node_i_in_active] = $clone;            $active_formatting_elements->[$node_i_in_active] = $clone;
3127            $self->{open_elements}->[$node_i_in_open] = $clone;            $self->{open_elements}->[$node_i_in_open] = $clone;
# Line 3068  sub _tree_construction_main ($) { Line 3156  sub _tree_construction_main ($) {
3156        my $i;        my $i;
3157        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
3158          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {
3159              !!!cp ('t66');
3160            splice @$active_formatting_elements, $_, 1;            splice @$active_formatting_elements, $_, 1;
3161            $i-- and last AFE if defined $i;            $i-- and last AFE if defined $i;
3162          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {
3163              !!!cp ('t67');
3164            $i = $_;            $i = $_;
3165          }          }
3166        } # AFE        } # AFE
# Line 3080  sub _tree_construction_main ($) { Line 3170  sub _tree_construction_main ($) {
3170        undef $i;        undef $i;
3171        OE: for (reverse 0..$#{$self->{open_elements}}) {        OE: for (reverse 0..$#{$self->{open_elements}}) {
3172          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {
3173              !!!cp ('t68');
3174            splice @{$self->{open_elements}}, $_, 1;            splice @{$self->{open_elements}}, $_, 1;
3175            $i-- and last OE if defined $i;            $i-- and last OE if defined $i;
3176          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {
3177              !!!cp ('t69');
3178            $i = $_;            $i = $_;
3179          }          }
3180        } # OE        } # OE
# Line 3110  sub _tree_construction_main ($) { Line 3202  sub _tree_construction_main ($) {
3202                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3203                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3204                               if (defined $parent and $parent->node_type == 1) {                               if (defined $parent and $parent->node_type == 1) {
3205                                   !!!cp ('t70');
3206                                 $foster_parent_element = $parent;                                 $foster_parent_element = $parent;
3207                                 $next_sibling = $self->{open_elements}->[$_]->[0];                                 $next_sibling = $self->{open_elements}->[$_]->[0];
3208                               } else {                               } else {
3209                                   !!!cp ('t71');
3210                                 $foster_parent_element                                 $foster_parent_element
3211                                   = $self->{open_elements}->[$_ - 1]->[0];                                   = $self->{open_elements}->[$_ - 1]->[0];
3212                               }                               }
# Line 3124  sub _tree_construction_main ($) { Line 3218  sub _tree_construction_main ($) {
3218                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3219                             ($child, $next_sibling);                             ($child, $next_sibling);
3220                         } else {                         } else {
3221                             !!!cp ('t72');
3222                           $self->{open_elements}->[-1]->[0]->append_child ($child);                           $self->{open_elements}->[-1]->[0]->append_child ($child);
3223                         }                         }
3224    }; # $insert_to_foster    }; # $insert_to_foster
# Line 3132  sub _tree_construction_main ($) { Line 3227  sub _tree_construction_main ($) {
3227    
3228    B: {    B: {
3229      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3230          !!!cp ('t73');
3231        !!!parse-error (type => 'DOCTYPE in the middle');        !!!parse-error (type => 'DOCTYPE in the middle');
3232        ## Ignore the token        ## Ignore the token
3233        ## Stay in the phase        ## Stay in the phase
# Line 3139  sub _tree_construction_main ($) { Line 3235  sub _tree_construction_main ($) {
3235        redo B;        redo B;
3236      } elsif ($token->{type} == END_OF_FILE_TOKEN) {      } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3237        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3238            !!!cp ('t74');
3239          #          #
3240        } else {        } else {
3241          ## Generate implied end tags          ## Generate implied end tags
# Line 3146  sub _tree_construction_main ($) { Line 3243  sub _tree_construction_main ($) {
3243               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,               dd => 1, dt => 1, li => 1, p => 1, td => 1, th => 1, tr => 1,
3244               tbody => 1, tfoot=> 1, thead => 1,               tbody => 1, tfoot=> 1, thead => 1,
3245              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
3246              !!!cp ('t75');
3247            !!!back-token;            !!!back-token;
3248            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};
3249            redo B;            redo B;
# Line 3153  sub _tree_construction_main ($) { Line 3251  sub _tree_construction_main ($) {
3251                    
3252          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
3253              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {
3254              !!!cp ('t76');
3255            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3256          } elsif (defined $self->{inner_html_node} and          } elsif (defined $self->{inner_html_node} and
3257                   @{$self->{open_elements}} > 1 and                   @{$self->{open_elements}} > 1 and
3258                   $self->{open_elements}->[1]->[1] ne 'body') {                   $self->{open_elements}->[1]->[1] ne 'body') {
3259    ## ISSUE: This case is never reached.
3260              !!!cp ('t77');
3261            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3262            } else {
3263              !!!cp ('t78');
3264          }          }
3265    
3266          ## ISSUE: There is an issue in the spec.          ## ISSUE: There is an issue in the spec.
# Line 3168  sub _tree_construction_main ($) { Line 3271  sub _tree_construction_main ($) {
3271      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3272               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3273        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
3274            !!!cp ('t79');
3275          ## Turn into the main phase          ## Turn into the main phase
3276          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3277          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3278        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3279            !!!cp ('t80');
3280          ## Turn into the main phase          ## Turn into the main phase
3281          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3282          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3283          } else {
3284            !!!cp ('t81');
3285        }        }
3286    
3287  ## ISSUE: "aa<html>" is not a parse error.  ## ISSUE: "aa<html>" is not a parse error.
3288  ## ISSUE: "<html>" in fragment is not a parse error.  ## ISSUE: "<html>" in fragment is not a parse error.
3289        unless ($token->{first_start_tag}) {        unless ($token->{first_start_tag}) {
3290            !!!cp ('t82');
3291          !!!parse-error (type => 'not first start tag');          !!!parse-error (type => 'not first start tag');
3292          } else {
3293            !!!cp ('t83');
3294        }        }
3295        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3296        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3297          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
3298              !!!cp ('t84');
3299            $top_el->set_attribute_ns            $top_el->set_attribute_ns
3300              (undef, [undef, $attr_name],              (undef, [undef, $attr_name],
3301               $token->{attributes}->{$attr_name}->{value});               $token->{attributes}->{$attr_name}->{value});
# Line 3195  sub _tree_construction_main ($) { Line 3306  sub _tree_construction_main ($) {
3306      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
3307        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
3308        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3309            !!!cp ('t85');
3310          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
3311        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {
3312            !!!cp ('t86');
3313          $self->{open_elements}->[0]->[0]->append_child ($comment);          $self->{open_elements}->[0]->[0]->append_child ($comment);
3314        } else {        } else {
3315            !!!cp ('t87');
3316          $self->{open_elements}->[-1]->[0]->append_child ($comment);          $self->{open_elements}->[-1]->[0]->append_child ($comment);
3317        }        }
3318        !!!next-token;        !!!next-token;
# Line 3208  sub _tree_construction_main ($) { Line 3322  sub _tree_construction_main ($) {
3322          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3323            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3324            unless (length $token->{data}) {            unless (length $token->{data}) {
3325                !!!cp ('t88');
3326              !!!next-token;              !!!next-token;
3327              redo B;              redo B;
3328            }            }
3329          }          }
3330    
3331          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3332              !!!cp ('t89');
3333            ## As if <head>            ## As if <head>
3334            !!!create-element ($self->{head_element}, 'head');            !!!create-element ($self->{head_element}, 'head');
3335            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3224  sub _tree_construction_main ($) { Line 3340  sub _tree_construction_main ($) {
3340    
3341            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3342          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3343              !!!cp ('t90');
3344            ## As if </noscript>            ## As if </noscript>
3345            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3346            !!!parse-error (type => 'in noscript:#character');            !!!parse-error (type => 'in noscript:#character');
# Line 3234  sub _tree_construction_main ($) { Line 3351  sub _tree_construction_main ($) {
3351    
3352            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3353          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3354              !!!cp ('t91');
3355            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3356    
3357            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3358            } else {
3359              !!!cp ('t92');
3360          }          }
3361    
3362              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3248  sub _tree_construction_main ($) { Line 3368  sub _tree_construction_main ($) {
3368            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
3369              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3370                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3371                    !!!cp ('t93');
3372                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});
3373                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
3374                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];
# Line 3255  sub _tree_construction_main ($) { Line 3376  sub _tree_construction_main ($) {
3376                  !!!next-token;                  !!!next-token;
3377                  redo B;                  redo B;
3378                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3379                    !!!cp ('t94');
3380                  #                  #
3381                } else {                } else {
3382                    !!!cp ('t95');
3383                  !!!parse-error (type => 'in head:head'); # or in head noscript                  !!!parse-error (type => 'in head:head'); # or in head noscript
3384                  ## Ignore the token                  ## Ignore the token
3385                  !!!next-token;                  !!!next-token;
3386                  redo B;                  redo B;
3387                }                }
3388              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3389                  !!!cp ('t96');
3390                ## As if <head>                ## As if <head>
3391                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3392                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3270  sub _tree_construction_main ($) { Line 3394  sub _tree_construction_main ($) {
3394    
3395                $self->{insertion_mode} = IN_HEAD_IM;                $self->{insertion_mode} = IN_HEAD_IM;
3396                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
3397                } else {
3398                  !!!cp ('t97');
3399              }              }
3400    
3401              if ($token->{tag_name} eq 'base') {              if ($token->{tag_name} eq 'base') {
3402                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3403                    !!!cp ('t98');
3404                  ## As if </noscript>                  ## As if </noscript>
3405                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3406                  !!!parse-error (type => 'in noscript:base');                  !!!parse-error (type => 'in noscript:base');
3407                                
3408                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3409                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3410                  } else {
3411                    !!!cp ('t99');
3412                }                }
3413    
3414                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3415                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3416                    !!!cp ('t100');
3417                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3418                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3419                  } else {
3420                    !!!cp ('t101');
3421                }                }
3422                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3423                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
# Line 3296  sub _tree_construction_main ($) { Line 3428  sub _tree_construction_main ($) {
3428              } elsif ($token->{tag_name} eq 'link') {              } elsif ($token->{tag_name} eq 'link') {
3429                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3430                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3431                    !!!cp ('t102');
3432                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3433                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3434                  } else {
3435                    !!!cp ('t103');
3436                }                }
3437                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3438                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
# Line 3308  sub _tree_construction_main ($) { Line 3443  sub _tree_construction_main ($) {
3443              } elsif ($token->{tag_name} eq 'meta') {              } elsif ($token->{tag_name} eq 'meta') {
3444                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3445                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3446                    !!!cp ('t104');
3447                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3448                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3449                  } else {
3450                    !!!cp ('t105');
3451                }                }
3452                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3453                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3454    
3455                unless ($self->{confident}) {                unless ($self->{confident}) {
3456                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) { ## TODO: And if supported
3457                      !!!cp ('t106');
3458                    $self->{change_encoding}                    $self->{change_encoding}
3459                        ->($self, $token->{attributes}->{charset}->{value});                        ->($self, $token->{attributes}->{charset}->{value});
3460                                        
# Line 3330  sub _tree_construction_main ($) { Line 3469  sub _tree_construction_main ($) {
3469                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
3470                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
3471                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
3472                        !!!cp ('t107');
3473                      $self->{change_encoding}                      $self->{change_encoding}
3474                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
3475                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3476                          ->set_user_data (manakai_has_reference =>                          ->set_user_data (manakai_has_reference =>
3477                                               $token->{attributes}->{content}                                               $token->{attributes}->{content}
3478                                                     ->{has_reference});                                                     ->{has_reference});
3479                      } else {
3480                        !!!cp ('t108');
3481                    }                    }
3482                  }                  }
3483                } else {                } else {
3484                  if ($token->{attributes}->{charset}) {                  if ($token->{attributes}->{charset}) {
3485                      !!!cp ('t109');
3486                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
3487                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3488                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
3489                                                 ->{has_reference});                                                 ->{has_reference});
3490                  }                  }
3491                  if ($token->{attributes}->{content}) {                  if ($token->{attributes}->{content}) {
3492                      !!!cp ('t110');
3493                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3494                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3495                                             $token->{attributes}->{content}                                             $token->{attributes}->{content}
# Line 3359  sub _tree_construction_main ($) { Line 3503  sub _tree_construction_main ($) {
3503                redo B;                redo B;
3504              } elsif ($token->{tag_name} eq 'title') {              } elsif ($token->{tag_name} eq 'title') {
3505                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3506                    !!!cp ('t111');
3507                  ## As if </noscript>                  ## As if </noscript>
3508                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3509                  !!!parse-error (type => 'in noscript:title');                  !!!parse-error (type => 'in noscript:title');
# Line 3366  sub _tree_construction_main ($) { Line 3511  sub _tree_construction_main ($) {
3511                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3512                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3513                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3514                    !!!cp ('t112');
3515                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3516                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3517                  } else {
3518                    !!!cp ('t113');
3519                }                }
3520    
3521                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 3383  sub _tree_construction_main ($) { Line 3531  sub _tree_construction_main ($) {
3531                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
3532                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3533                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3534                    !!!cp ('t114');
3535                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3536                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3537                  } else {
3538                    !!!cp ('t115');
3539                }                }
3540                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
3541                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
# Line 3392  sub _tree_construction_main ($) { Line 3543  sub _tree_construction_main ($) {
3543                redo B;                redo B;
3544              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3545                if ($self->{insertion_mode} == IN_HEAD_IM) {                if ($self->{insertion_mode} == IN_HEAD_IM) {
3546                    !!!cp ('t116');
3547                  ## NOTE: and scripting is disalbed                  ## NOTE: and scripting is disalbed
3548                  !!!insert-element ($token->{tag_name}, $token->{attributes});                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3549                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;
3550                  !!!next-token;                  !!!next-token;
3551                  redo B;                  redo B;
3552                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3553                    !!!cp ('t117');
3554                  !!!parse-error (type => 'in noscript:noscript');                  !!!parse-error (type => 'in noscript:noscript');
3555                  ## Ignore the token                  ## Ignore the token
3556                  !!!next-token;                  !!!next-token;
3557                  redo B;                  redo B;
3558                } else {                } else {
3559                    !!!cp ('t118');
3560                  #                  #
3561                }                }
3562              } elsif ($token->{tag_name} eq 'script') {              } elsif ($token->{tag_name} eq 'script') {
3563                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3564                    !!!cp ('t119');
3565                  ## As if </noscript>                  ## As if </noscript>
3566                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3567                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:script');
# Line 3414  sub _tree_construction_main ($) { Line 3569  sub _tree_construction_main ($) {
3569                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3570                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3571                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3572                    !!!cp ('t120');
3573                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3574                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3575                  } else {
3576                    !!!cp ('t121');
3577                }                }
3578    
3579                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 3426  sub _tree_construction_main ($) { Line 3584  sub _tree_construction_main ($) {
3584              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
3585                       $token->{tag_name} eq 'frameset') {                       $token->{tag_name} eq 'frameset') {
3586                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3587                    !!!cp ('t122');
3588                  ## As if </noscript>                  ## As if </noscript>
3589                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3590                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});
# Line 3436  sub _tree_construction_main ($) { Line 3595  sub _tree_construction_main ($) {
3595                                    
3596                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3597                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3598                    !!!cp ('t124');
3599                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3600                                    
3601                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3602                  } else {
3603                    !!!cp ('t125');
3604                }                }
3605    
3606                ## "after head" insertion mode                ## "after head" insertion mode
3607                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3608                if ($token->{tag_name} eq 'body') {                if ($token->{tag_name} eq 'body') {
3609                    !!!cp ('t126');
3610                  $self->{insertion_mode} = IN_BODY_IM;                  $self->{insertion_mode} = IN_BODY_IM;
3611                } elsif ($token->{tag_name} eq 'frameset') {                } elsif ($token->{tag_name} eq 'frameset') {
3612                    !!!cp ('t127');
3613                  $self->{insertion_mode} = IN_FRAMESET_IM;                  $self->{insertion_mode} = IN_FRAMESET_IM;
3614                } else {                } else {
3615                  die "$0: tag name: $self->{tag_name}";                  die "$0: tag name: $self->{tag_name}";
# Line 3453  sub _tree_construction_main ($) { Line 3617  sub _tree_construction_main ($) {
3617                !!!next-token;                !!!next-token;
3618                redo B;                redo B;
3619              } else {              } else {
3620                  !!!cp ('t128');
3621                #                #
3622              }              }
3623    
3624              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3625                  !!!cp ('t129');
3626                ## As if </noscript>                ## As if </noscript>
3627                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3628                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3467  sub _tree_construction_main ($) { Line 3633  sub _tree_construction_main ($) {
3633    
3634                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3635              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3636                  !!!cp ('t130');
3637                ## As if </head>                ## As if </head>
3638                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3639    
3640                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3641                } else {
3642                  !!!cp ('t131');
3643              }              }
3644    
3645              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3482  sub _tree_construction_main ($) { Line 3651  sub _tree_construction_main ($) {
3651            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
3652              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3653                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3654                    !!!cp ('t132');
3655                  ## As if <head>                  ## As if <head>
3656                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3657                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3493  sub _tree_construction_main ($) { Line 3663  sub _tree_construction_main ($) {
3663                  !!!next-token;                  !!!next-token;
3664                  redo B;                  redo B;
3665                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3666                    !!!cp ('t133');
3667                  ## As if </noscript>                  ## As if </noscript>
3668                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3669                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:/head');
3670                                    
3671                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3672                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 3503  sub _tree_construction_main ($) { Line 3674  sub _tree_construction_main ($) {
3674                  !!!next-token;                  !!!next-token;
3675                  redo B;                  redo B;
3676                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3677                    !!!cp ('t134');
3678                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3679                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
3680                  !!!next-token;                  !!!next-token;
3681                  redo B;                  redo B;
3682                } else {                } else {
3683                    !!!cp ('t135');
3684                  #                  #
3685                }                }
3686              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3687                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3688                    !!!cp ('t136');
3689                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3690                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3691                  !!!next-token;                  !!!next-token;
3692                  redo B;                  redo B;
3693                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3694                    !!!cp ('t137');
3695                  !!!parse-error (type => 'unmatched end tag:noscript');                  !!!parse-error (type => 'unmatched end tag:noscript');
3696                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
3697                  !!!next-token;                  !!!next-token;
3698                  redo B;                  redo B;
3699                } else {                } else {
3700                    !!!cp ('t138');
3701                  #                  #
3702                }                }
3703              } elsif ({              } elsif ({
3704                        body => 1, html => 1,                        body => 1, html => 1,
3705                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3706                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3707                    !!!cp ('t139');
3708                  ## As if <head>                  ## As if <head>
3709                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3710                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3536  sub _tree_construction_main ($) { Line 3713  sub _tree_construction_main ($) {
3713                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3714                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3715                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3716                    !!!cp ('t140');
3717                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3718                  ## Ignore the token                  ## Ignore the token
3719                  !!!next-token;                  !!!next-token;
3720                  redo B;                  redo B;
3721                  } else {
3722                    !!!cp ('t141');
3723                }                }
3724                                
3725                #                #
# Line 3547  sub _tree_construction_main ($) { Line 3727  sub _tree_construction_main ($) {
3727                        p => 1, br => 1,                        p => 1, br => 1,
3728                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3729                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3730                    !!!cp ('t142');
3731                  ## As if <head>                  ## As if <head>
3732                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3733                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3554  sub _tree_construction_main ($) { Line 3735  sub _tree_construction_main ($) {
3735    
3736                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3737                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3738                  } else {
3739                    !!!cp ('t143');
3740                }                }
3741    
3742                #                #
3743              } else {              } else {
3744                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3745                    !!!cp ('t144');
3746                  #                  #
3747                } else {                } else {
3748                    !!!cp ('t145');
3749                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3750                  ## Ignore the token                  ## Ignore the token
3751                  !!!next-token;                  !!!next-token;
# Line 3569  sub _tree_construction_main ($) { Line 3754  sub _tree_construction_main ($) {
3754              }              }
3755    
3756              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3757                  !!!cp ('t146');
3758                ## As if </noscript>                ## As if </noscript>
3759                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3760                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3579  sub _tree_construction_main ($) { Line 3765  sub _tree_construction_main ($) {
3765    
3766                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3767              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3768                  !!!cp ('t147');
3769                ## As if </head>                ## As if </head>
3770                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3771    
3772                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3773              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3774    ## ISSUE: This case cannot be reached?
3775                  !!!cp ('t148');
3776                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3777                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
3778                !!!next-token;                !!!next-token;
3779                redo B;                redo B;
3780                } else {
3781                  !!!cp ('t149');
3782              }              }
3783    
3784              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3603  sub _tree_construction_main ($) { Line 3794  sub _tree_construction_main ($) {
3794            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3795      } elsif ($self->{insertion_mode} & BODY_IMS) {      } elsif ($self->{insertion_mode} & BODY_IMS) {
3796            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
3797                !!!cp ('t150');
3798              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
3799              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
3800                            
# Line 3621  sub _tree_construction_main ($) { Line 3813  sub _tree_construction_main ($) {
3813                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3814                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3815                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {
3816                        !!!cp ('t151');
3817                      $tn = $node->[1];                      $tn = $node->[1];
3818                      last INSCOPE;                      last INSCOPE;
3819                    } elsif ({                    } elsif ({
3820                              table => 1, html => 1,                              table => 1, html => 1,
3821                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3822                        !!!cp ('t152');
3823                      last INSCOPE;                      last INSCOPE;
3824                    }                    }
3825                  } # INSCOPE                  } # INSCOPE
3826                    unless (defined $tn) {                    unless (defined $tn) {
3827                        !!!cp ('t153');
3828    ## TODO: This error type is wrong.
3829                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3830                      ## Ignore the token                      ## Ignore the token
3831                      !!!next-token;                      !!!next-token;
3832                      redo B;                      redo B;
3833                    }                    }
3834                                    
3835                    !!!cp ('t154');
3836                  ## Close the cell                  ## Close the cell
3837                  !!!back-token; # <?>                  !!!back-token; # <?>
3838                  $token = {type => END_TAG_TOKEN, tag_name => $tn};                  $token = {type => END_TAG_TOKEN, tag_name => $tn};
# Line 3649  sub _tree_construction_main ($) { Line 3846  sub _tree_construction_main ($) {
3846                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3847                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3848                    if ($node->[1] eq 'caption') {                    if ($node->[1] eq 'caption') {
3849                        !!!cp ('t155');
3850                      $i = $_;                      $i = $_;
3851                      last INSCOPE;                      last INSCOPE;
3852                    } elsif ({                    } elsif ({
3853                              table => 1, html => 1,                              table => 1, html => 1,
3854                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3855                        !!!cp ('t156');
3856                      last INSCOPE;                      last INSCOPE;
3857                    }                    }
3858                  } # INSCOPE                  } # INSCOPE
3859                    unless (defined $i) {                    unless (defined $i) {
3860                        !!!cp ('t157');
3861                      !!!parse-error (type => 'unmatched end tag:caption');                      !!!parse-error (type => 'unmatched end tag:caption');
3862                      ## Ignore the token                      ## Ignore the token
3863                      !!!next-token;                      !!!next-token;
# Line 3670  sub _tree_construction_main ($) { Line 3870  sub _tree_construction_main ($) {
3870                       td => 1, th => 1, tr => 1,                       td => 1, th => 1, tr => 1,
3871                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3872                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3873                      !!!cp ('t158');
3874                    !!!back-token; # <?>                    !!!back-token; # <?>
3875                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
3876                    !!!back-token;                    !!!back-token;
# Line 3679  sub _tree_construction_main ($) { Line 3880  sub _tree_construction_main ($) {
3880                  }                  }
3881    
3882                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3883                      !!!cp ('t159');
3884                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3885                    } else {
3886                      !!!cp ('t160');
3887                  }                  }
3888                                    
3889                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3691  sub _tree_construction_main ($) { Line 3895  sub _tree_construction_main ($) {
3895                  ## reprocess                  ## reprocess
3896                  redo B;                  redo B;
3897                } else {                } else {
3898                    !!!cp ('t161');
3899                  #                  #
3900                }                }
3901              } else {              } else {
3902                  !!!cp ('t162');
3903                #                #
3904              }              }
3905            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
# Line 3704  sub _tree_construction_main ($) { Line 3910  sub _tree_construction_main ($) {
3910                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3911                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3912                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
3913                        !!!cp ('t163');
3914                      $i = $_;                      $i = $_;
3915                      last INSCOPE;                      last INSCOPE;
3916                    } elsif ({                    } elsif ({
3917                              table => 1, html => 1,                              table => 1, html => 1,
3918                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3919                        !!!cp ('t164');
3920                      last INSCOPE;                      last INSCOPE;
3921                    }                    }
3922                  } # INSCOPE                  } # INSCOPE
3923                    unless (defined $i) {                    unless (defined $i) {
3924                        !!!cp ('t165');
3925                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3926                      ## Ignore the token                      ## Ignore the token
3927                      !!!next-token;                      !!!next-token;
# Line 3727  sub _tree_construction_main ($) { Line 3936  sub _tree_construction_main ($) {
3936                       tr => 1,                       tr => 1,
3937                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
3938                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3939                      !!!cp ('t166');
3940                    !!!back-token;                    !!!back-token;
3941                    $token = {type => END_TAG_TOKEN,                    $token = {type => END_TAG_TOKEN,
3942                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 3734  sub _tree_construction_main ($) { Line 3944  sub _tree_construction_main ($) {
3944                  }                  }
3945                                    
3946                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3947                      !!!cp ('t167');
3948                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3949                    } else {
3950                      !!!cp ('t168');
3951                  }                  }
3952                                    
3953                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3746  sub _tree_construction_main ($) { Line 3959  sub _tree_construction_main ($) {
3959                  !!!next-token;                  !!!next-token;
3960                  redo B;                  redo B;
3961                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
3962                    !!!cp ('t169');
3963                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3964                  ## Ignore the token                  ## Ignore the token
3965                  !!!next-token;                  !!!next-token;
3966                  redo B;                  redo B;
3967                } else {                } else {
3968                    !!!cp ('t170');
3969                  #                  #
3970                }                }
3971              } elsif ($token->{tag_name} eq 'caption') {              } elsif ($token->{tag_name} eq 'caption') {
# Line 3760  sub _tree_construction_main ($) { Line 3975  sub _tree_construction_main ($) {
3975                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3976                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3977                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
3978                        !!!cp ('t171');
3979                      $i = $_;                      $i = $_;
3980                      last INSCOPE;                      last INSCOPE;
3981                    } elsif ({                    } elsif ({
3982                              table => 1, html => 1,                              table => 1, html => 1,
3983                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3984                        !!!cp ('t172');
3985                      last INSCOPE;                      last INSCOPE;
3986                    }                    }
3987                  } # INSCOPE                  } # INSCOPE
3988                    unless (defined $i) {                    unless (defined $i) {
3989                        !!!cp ('t173');
3990                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3991                      ## Ignore the token                      ## Ignore the token
3992                      !!!next-token;                      !!!next-token;
# Line 3781  sub _tree_construction_main ($) { Line 3999  sub _tree_construction_main ($) {
3999                       td => 1, th => 1, tr => 1,                       td => 1, th => 1, tr => 1,
4000                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot=> 1, thead => 1,
4001                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
4002                      !!!cp ('t174');
4003                    !!!back-token;                    !!!back-token;
4004                    $token = {type => END_TAG_TOKEN,                    $token = {type => END_TAG_TOKEN,
4005                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 3788  sub _tree_construction_main ($) { Line 4007  sub _tree_construction_main ($) {
4007                  }                  }
4008                                    
4009                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4010                      !!!cp ('t175');
4011                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4012                    } else {
4013                      !!!cp ('t176');
4014                  }                  }
4015                                    
4016                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3800  sub _tree_construction_main ($) { Line 4022  sub _tree_construction_main ($) {
4022                  !!!next-token;                  !!!next-token;
4023                  redo B;                  redo B;
4024                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
4025                    !!!cp ('t177');
4026                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4027                  ## Ignore the token                  ## Ignore the token
4028                  !!!next-token;                  !!!next-token;
4029                  redo B;                  redo B;
4030                } else {                } else {
4031                    !!!cp ('t178');
4032                  #                  #
4033                }                }
4034              } elsif ({              } elsif ({
# Line 3818  sub _tree_construction_main ($) { Line 4042  sub _tree_construction_main ($) {
4042                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4043                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4044                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4045                      !!!cp ('t179');
4046                    $i = $_;                    $i = $_;
4047                    last INSCOPE;                    last INSCOPE;
4048                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
4049                      !!!cp ('t180');
4050                    $tn = $node->[1];                    $tn = $node->[1];
4051                    ## NOTE: There is exactly one |td| or |th| element                    ## NOTE: There is exactly one |td| or |th| element
4052                    ## in scope in the stack of open elements by definition.                    ## in scope in the stack of open elements by definition.
4053                  } elsif ({                  } elsif ({
4054                            table => 1, html => 1,                            table => 1, html => 1,
4055                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4056                      !!!cp ('t181');
4057                    last INSCOPE;                    last INSCOPE;
4058                  }                  }
4059                } # INSCOPE                } # INSCOPE
4060                unless (defined $i) {                unless (defined $i) {
4061                    !!!cp ('t182');
4062                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4063                  ## Ignore the token                  ## Ignore the token
4064                  !!!next-token;                  !!!next-token;
4065                  redo B;                  redo B;
4066                  } else {
4067                    !!!cp ('t183');
4068                }                }
4069    
4070                ## Close the cell                ## Close the cell
# Line 3851  sub _tree_construction_main ($) { Line 4081  sub _tree_construction_main ($) {
4081                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4082                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4083                  if ($node->[1] eq 'caption') {                  if ($node->[1] eq 'caption') {
4084                      !!!cp ('t184');
4085                    $i = $_;                    $i = $_;
4086                    last INSCOPE;                    last INSCOPE;
4087                  } elsif ({                  } elsif ({
4088                            table => 1, html => 1,                            table => 1, html => 1,
4089                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4090                      !!!cp ('t185');
4091                    last INSCOPE;                    last INSCOPE;
4092                  }                  }
4093                } # INSCOPE                } # INSCOPE
4094                unless (defined $i) {                unless (defined $i) {
4095                    !!!cp ('t186');
4096                  !!!parse-error (type => 'unmatched end tag:caption');                  !!!parse-error (type => 'unmatched end tag:caption');
4097                  ## Ignore the token                  ## Ignore the token
4098                  !!!next-token;                  !!!next-token;
# Line 3872  sub _tree_construction_main ($) { Line 4105  sub _tree_construction_main ($) {
4105                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4106                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4107                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4108                    !!!cp ('t187');
4109                  !!!back-token; # </table>                  !!!back-token; # </table>
4110                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
4111                  !!!back-token;                  !!!back-token;
# Line 3881  sub _tree_construction_main ($) { Line 4115  sub _tree_construction_main ($) {
4115                }                }
4116    
4117                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4118                    !!!cp ('t188');
4119                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4120                  } else {
4121                    !!!cp ('t189');
4122                }                }
4123    
4124                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 3896  sub _tree_construction_main ($) { Line 4133  sub _tree_construction_main ($) {
4133                        body => 1, col => 1, colgroup => 1, html => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
4134                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4135                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
4136                    !!!cp ('t190');
4137                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4138                  ## Ignore the token                  ## Ignore the token
4139                  !!!next-token;                  !!!next-token;
4140                  redo B;                  redo B;
4141                } else {                } else {
4142                    !!!cp ('t191');
4143                  #                  #
4144                }                }
4145              } elsif ({              } elsif ({
# Line 3908  sub _tree_construction_main ($) { Line 4147  sub _tree_construction_main ($) {
4147                        thead => 1, tr => 1,                        thead => 1, tr => 1,
4148                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
4149                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
4150                  !!!cp ('t192');
4151                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4152                ## Ignore the token                ## Ignore the token
4153                !!!next-token;                !!!next-token;
4154                redo B;                redo B;
4155              } else {              } else {
4156                  !!!cp ('t193');
4157                #                #
4158              }              }
4159        } else {        } else {
# Line 3927  sub _tree_construction_main ($) { Line 4168  sub _tree_construction_main ($) {
4168                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4169                                
4170                unless (length $token->{data}) {                unless (length $token->{data}) {
4171                    !!!cp ('t194');
4172                  !!!next-token;                  !!!next-token;
4173                  redo B;                  redo B;
4174                  } else {
4175                    !!!cp ('t195');
4176                }                }
4177              }              }
4178    
# Line 3952  sub _tree_construction_main ($) { Line 4196  sub _tree_construction_main ($) {
4196                  if ($self->{open_elements}->[$_]->[1] eq 'table') {                  if ($self->{open_elements}->[$_]->[1] eq 'table') {
4197                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
4198                    if (defined $parent and $parent->node_type == 1) {                    if (defined $parent and $parent->node_type == 1) {
4199                        !!!cp ('t196');
4200                      $foster_parent_element = $parent;                      $foster_parent_element = $parent;
4201                      $next_sibling = $self->{open_elements}->[$_]->[0];                      $next_sibling = $self->{open_elements}->[$_]->[0];
4202                      $prev_sibling = $next_sibling->previous_sibling;                      $prev_sibling = $next_sibling->previous_sibling;
4203                    } else {                    } else {
4204                        !!!cp ('t197');
4205                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
4206                      $prev_sibling = $foster_parent_element->last_child;                      $prev_sibling = $foster_parent_element->last_child;
4207                    }                    }
# Line 3967  sub _tree_construction_main ($) { Line 4213  sub _tree_construction_main ($) {
4213                  unless defined $foster_parent_element;                  unless defined $foster_parent_element;
4214                if (defined $prev_sibling and                if (defined $prev_sibling and
4215                    $prev_sibling->node_type == 3) {                    $prev_sibling->node_type == 3) {
4216                    !!!cp ('t198');
4217                  $prev_sibling->manakai_append_text ($token->{data});                  $prev_sibling->manakai_append_text ($token->{data});
4218                } else {                } else {
4219                    !!!cp ('t199');
4220                  $foster_parent_element->insert_before                  $foster_parent_element->insert_before
4221                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4222                     $next_sibling);                     $next_sibling);
4223                }                }
4224              } else {              } else {
4225                  !!!cp ('t200');
4226                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4227              }              }
4228                            
# Line 3988  sub _tree_construction_main ($) { Line 4237  sub _tree_construction_main ($) {
4237                  ## Clear back to table context                  ## Clear back to table context
4238                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4239                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4240                      !!!cp ('t201');
4241                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4242                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4243                  }                  }
# Line 3999  sub _tree_construction_main ($) { Line 4249  sub _tree_construction_main ($) {
4249    
4250                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
4251                  unless ($token->{tag_name} eq 'tr') {                  unless ($token->{tag_name} eq 'tr') {
4252                      !!!cp ('t202');
4253                    !!!parse-error (type => 'missing start tag:tr');                    !!!parse-error (type => 'missing start tag:tr');
4254                  }                  }
4255                                    
# Line 4006  sub _tree_construction_main ($) { Line 4257  sub _tree_construction_main ($) {
4257                  while (not {                  while (not {
4258                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4259                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4260                      !!!cp ('t203');
4261                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4262                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4263                  }                  }
4264                                    
4265                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
4266                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4267                      !!!cp ('t204');
4268                    !!!insert-element ($token->{tag_name}, $token->{attributes});                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4269                    !!!next-token;                    !!!next-token;
4270                    redo B;                    redo B;
4271                  } else {                  } else {
4272                      !!!cp ('t205');
4273                    !!!insert-element ('tr');                    !!!insert-element ('tr');
4274                    ## reprocess in the "in row" insertion mode                    ## reprocess in the "in row" insertion mode
4275                  }                  }
4276                  } else {
4277                    !!!cp ('t206');
4278                }                }
4279    
4280                ## Clear back to table row context                ## Clear back to table row context
4281                while (not {                while (not {
4282                  tr => 1, html => 1,                  tr => 1, html => 1,
4283                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4284                    !!!cp ('t207');
4285                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4286                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4287                }                }
# Line 4048  sub _tree_construction_main ($) { Line 4305  sub _tree_construction_main ($) {
4305                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4306                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4307                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4308                        !!!cp ('t208');
4309                      $i = $_;                      $i = $_;
4310                      last INSCOPE;                      last INSCOPE;
4311                    } elsif ({                    } elsif ({
4312                              table => 1, html => 1,                              table => 1, html => 1,
4313                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4314                        !!!cp ('t209');
4315                      last INSCOPE;                      last INSCOPE;
4316                    }                    }
4317                  } # INSCOPE                  } # INSCOPE
4318                  unless (defined $i) {                  unless (defined $i) {
4319                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!cp ('t210');
4320                     !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4321                    ## Ignore the token                    ## Ignore the token
4322                    !!!next-token;                    !!!next-token;
4323                    redo B;                    redo B;
# Line 4067  sub _tree_construction_main ($) { Line 4327  sub _tree_construction_main ($) {
4327                  while (not {                  while (not {
4328                    tr => 1, html => 1,                    tr => 1, html => 1,
4329                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4330                      !!!cp ('t211');
4331                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4332                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4333                  }                  }
# Line 4074  sub _tree_construction_main ($) { Line 4335  sub _tree_construction_main ($) {
4335                  pop @{$self->{open_elements}}; # tr                  pop @{$self->{open_elements}}; # tr
4336                  $self->{insertion_mode} = IN_TABLE_BODY_IM;                  $self->{insertion_mode} = IN_TABLE_BODY_IM;
4337                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4338                      !!!cp ('t212');
4339                    ## reprocess                    ## reprocess
4340                    redo B;                    redo B;
4341                  } else {                  } else {
4342                      !!!cp ('t213');
4343                    ## reprocess in the "in table body" insertion mode...                    ## reprocess in the "in table body" insertion mode...
4344                  }                  }
4345                }                }
# Line 4089  sub _tree_construction_main ($) { Line 4352  sub _tree_construction_main ($) {
4352                    if ({                    if ({
4353                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4354                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4355                        !!!cp ('t214');
4356                      $i = $_;                      $i = $_;
4357                      last INSCOPE;                      last INSCOPE;
4358                    } elsif ({                    } elsif ({
4359                              table => 1, html => 1,                              table => 1, html => 1,
4360                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4361                        !!!cp ('t215');
4362                      last INSCOPE;                      last INSCOPE;
4363                    }                    }
4364                  } # INSCOPE                  } # INSCOPE
4365                  unless (defined $i) {                  unless (defined $i) {
4366                      !!!cp ('t216');
4367    ## TODO: This erorr type ios wrong.
4368                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4369                    ## Ignore the token                    ## Ignore the token
4370                    !!!next-token;                    !!!next-token;
# Line 4108  sub _tree_construction_main ($) { Line 4375  sub _tree_construction_main ($) {
4375                  while (not {                  while (not {
4376                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4377                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4378                      !!!cp ('t217');
4379                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4380                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4381                  }                  }
# Line 4122  sub _tree_construction_main ($) { Line 4390  sub _tree_construction_main ($) {
4390                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4391                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4392                  ## reprocess in "in table" insertion mode...                  ## reprocess in "in table" insertion mode...
4393                  } else {
4394                    !!!cp ('t218');
4395                }                }
4396    
4397                if ($token->{tag_name} eq 'col') {                if ($token->{tag_name} eq 'col') {
4398                  ## Clear back to table context                  ## Clear back to table context
4399                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4400                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4401                      !!!cp ('t219');
4402                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4403                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4404                  }                  }
# Line 4144  sub _tree_construction_main ($) { Line 4415  sub _tree_construction_main ($) {
4415                  ## Clear back to table context                  ## Clear back to table context
4416                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4417                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4418                      !!!cp ('t220');
4419                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4420                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4421                  }                  }
# Line 4173  sub _tree_construction_main ($) { Line 4445  sub _tree_construction_main ($) {
4445                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4446                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4447                  if ($node->[1] eq 'table') {                  if ($node->[1] eq 'table') {
4448                      !!!cp ('t221');
4449                    $i = $_;                    $i = $_;
4450                    last INSCOPE;                    last INSCOPE;
4451                  } elsif ({                  } elsif ({
4452                            table => 1, html => 1,                            table => 1, html => 1,
4453                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4454                      !!!cp ('t222');
4455                    last INSCOPE;                    last INSCOPE;
4456                  }                  }
4457                } # INSCOPE                } # INSCOPE
4458                unless (defined $i) {                unless (defined $i) {
4459                    !!!cp ('t223');
4460                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table');
4461                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4462                  !!!next-token;                  !!!next-token;
# Line 4194  sub _tree_construction_main ($) { Line 4469  sub _tree_construction_main ($) {
4469                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4470                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4471                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4472                    !!!cp ('t224');
4473                  !!!back-token; # <table>                  !!!back-token; # <table>
4474                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};
4475                  !!!back-token;                  !!!back-token;
# Line 4203  sub _tree_construction_main ($) { Line 4479  sub _tree_construction_main ($) {
4479                }                }
4480    
4481                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4482                    !!!cp ('t225');
4483                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4484                  } else {
4485                    !!!cp ('t226');
4486                }                }
4487    
4488                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 4213  sub _tree_construction_main ($) { Line 4492  sub _tree_construction_main ($) {
4492                ## reprocess                ## reprocess
4493                redo B;                redo B;
4494          } else {          } else {
4495              !!!cp ('t227');
4496            !!!parse-error (type => 'in table:'.$token->{tag_name});            !!!parse-error (type => 'in table:'.$token->{tag_name});
4497    
4498            $insert = $insert_to_foster;            $insert = $insert_to_foster;
# Line 4226  sub _tree_construction_main ($) { Line 4506  sub _tree_construction_main ($) {
4506                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4507                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4508                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4509                      !!!cp ('t228');
4510                    $i = $_;                    $i = $_;
4511                    last INSCOPE;                    last INSCOPE;
4512                  } elsif ({                  } elsif ({
4513                            table => 1, html => 1,                            table => 1, html => 1,
4514                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4515                      !!!cp ('t229');
4516                    last INSCOPE;                    last INSCOPE;
4517                  }                  }
4518                } # INSCOPE                } # INSCOPE
4519                unless (defined $i) {                unless (defined $i) {
4520                    !!!cp ('t230');
4521                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4522                  ## Ignore the token                  ## Ignore the token
4523                  !!!next-token;                  !!!next-token;
4524                  redo B;                  redo B;
4525                  } else {
4526                    !!!cp ('t232');
4527                }                }
4528    
4529                ## Clear back to table row context                ## Clear back to table row context
4530                while (not {                while (not {
4531                  tr => 1, html => 1,                  tr => 1, html => 1,
4532                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4533                    !!!cp ('t231');
4534                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4535                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4536                }                }
# Line 4261  sub _tree_construction_main ($) { Line 4547  sub _tree_construction_main ($) {
4547                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4548                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4549                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4550                        !!!cp ('t233');
4551                      $i = $_;                      $i = $_;
4552                      last INSCOPE;                      last INSCOPE;
4553                    } elsif ({                    } elsif ({
4554                              table => 1, html => 1,                              table => 1, html => 1,
4555                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4556                        !!!cp ('t234');
4557                      last INSCOPE;                      last INSCOPE;
4558                    }                    }
4559                  } # INSCOPE                  } # INSCOPE
4560                  unless (defined $i) {                  unless (defined $i) {
4561                      !!!cp ('t235');
4562                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4563                    ## Ignore the token                    ## Ignore the token
4564                    !!!next-token;                    !!!next-token;
# Line 4280  sub _tree_construction_main ($) { Line 4569  sub _tree_construction_main ($) {
4569                  while (not {                  while (not {
4570                    tr => 1, html => 1,                    tr => 1, html => 1,
4571                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4572                      !!!cp ('t236');
4573                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4574                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4575                  }                  }
# Line 4297  sub _tree_construction_main ($) { Line 4587  sub _tree_construction_main ($) {
4587                    if ({                    if ({
4588                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4589                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4590                        !!!cp ('t237');
4591                      $i = $_;                      $i = $_;
4592                      last INSCOPE;                      last INSCOPE;
4593                    } elsif ({                    } elsif ({
4594                              table => 1, html => 1,                              table => 1, html => 1,
4595                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4596                        !!!cp ('t238');
4597                      last INSCOPE;                      last INSCOPE;
4598                    }                    }
4599                  } # INSCOPE                  } # INSCOPE
4600                  unless (defined $i) {                  unless (defined $i) {
4601                      !!!cp ('t239');
4602                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4603                    ## Ignore the token                    ## Ignore the token
4604                    !!!next-token;                    !!!next-token;
# Line 4316  sub _tree_construction_main ($) { Line 4609  sub _tree_construction_main ($) {
4609                  while (not {                  while (not {
4610                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4611                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4612                      !!!cp ('t240');
4613                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4614                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4615                  }                  }
# Line 4337  sub _tree_construction_main ($) { Line 4631  sub _tree_construction_main ($) {
4631                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4632                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4633                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4634                      !!!cp ('t241');
4635                    $i = $_;                    $i = $_;
4636                    last INSCOPE;                    last INSCOPE;
4637                  } elsif ({                  } elsif ({
4638                            table => 1, html => 1,                            table => 1, html => 1,
4639                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4640                      !!!cp ('t242');
4641                    last INSCOPE;                    last INSCOPE;
4642                  }                  }
4643                } # INSCOPE                } # INSCOPE
4644                unless (defined $i) {                unless (defined $i) {
4645                    !!!cp ('t243');
4646                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4647                  ## Ignore the token                  ## Ignore the token
4648                  !!!next-token;                  !!!next-token;
# Line 4358  sub _tree_construction_main ($) { Line 4655  sub _tree_construction_main ($) {
4655                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4656                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4657                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4658                    !!!cp ('t244');
4659                  !!!back-token;                  !!!back-token;
4660                  $token = {type => END_TAG_TOKEN,                  $token = {type => END_TAG_TOKEN,
4661                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 4365  sub _tree_construction_main ($) { Line 4663  sub _tree_construction_main ($) {
4663                }                }
4664                                
4665                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4666                    !!!cp ('t245');
4667                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4668                  } else {
4669                    !!!cp ('t246');
4670                }                }
4671                                    
4672                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 4384  sub _tree_construction_main ($) { Line 4685  sub _tree_construction_main ($) {
4685                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4686                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4687                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
4688                        !!!cp ('t247');
4689                      $i = $_;                      $i = $_;
4690                      last INSCOPE;                      last INSCOPE;
4691                    } elsif ({                    } elsif ({
4692                              table => 1, html => 1,                              table => 1, html => 1,
4693                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4694                        !!!cp ('t248');
4695                      last INSCOPE;                      last INSCOPE;
4696                    }                    }
4697                  } # INSCOPE                  } # INSCOPE
4698                    unless (defined $i) {                    unless (defined $i) {
4699                        !!!cp ('t249');
4700                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4701                      ## Ignore the token                      ## Ignore the token
4702                      !!!next-token;                      !!!next-token;
# Line 4405  sub _tree_construction_main ($) { Line 4709  sub _tree_construction_main ($) {
4709                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4710                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4711                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4712                        !!!cp ('t250');
4713                      $i = $_;                      $i = $_;
4714                      last INSCOPE;                      last INSCOPE;
4715                    } elsif ({                    } elsif ({
4716                              table => 1, html => 1,                              table => 1, html => 1,
4717                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4718                        !!!cp ('t251');
4719                      last INSCOPE;                      last INSCOPE;
4720                    }                    }
4721                  } # INSCOPE                  } # INSCOPE
4722                    unless (defined $i) {                    unless (defined $i) {
4723                        !!!cp ('t252');
4724                      !!!parse-error (type => 'unmatched end tag:tr');                      !!!parse-error (type => 'unmatched end tag:tr');
4725                      ## Ignore the token                      ## Ignore the token
4726                      !!!next-token;                      !!!next-token;
# Line 4424  sub _tree_construction_main ($) { Line 4731  sub _tree_construction_main ($) {
4731                  while (not {                  while (not {
4732                    tr => 1, html => 1,                    tr => 1, html => 1,
4733                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4734                      !!!cp ('t253');
4735                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4736                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4737                  }                  }
# Line 4438  sub _tree_construction_main ($) { Line 4746  sub _tree_construction_main ($) {
4746                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4747                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4748                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4749                      !!!cp ('t254');
4750                    $i = $_;                    $i = $_;
4751                    last INSCOPE;                    last INSCOPE;
4752                  } elsif ({                  } elsif ({
4753                            table => 1, html => 1,                            table => 1, html => 1,
4754                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4755                      !!!cp ('t255');
4756                    last INSCOPE;                    last INSCOPE;
4757                  }                  }
4758                } # INSCOPE                } # INSCOPE
4759                unless (defined $i) {                unless (defined $i) {
4760                    !!!cp ('t256');
4761                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4762                  ## Ignore the token                  ## Ignore the token
4763                  !!!next-token;                  !!!next-token;
# Line 4457  sub _tree_construction_main ($) { Line 4768  sub _tree_construction_main ($) {
4768                while (not {                while (not {
4769                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4770                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4771                    !!!cp ('t257');
4772                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4773                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4774                }                }
# Line 4471  sub _tree_construction_main ($) { Line 4783  sub _tree_construction_main ($) {
4783                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM
4784                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
4785                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4786                  !!!cp ('t258');
4787                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4788                ## Ignore the token                ## Ignore the token
4789                !!!next-token;                !!!next-token;
4790                redo B;                redo B;
4791          } else {          } else {
4792              !!!cp ('t259');
4793            !!!parse-error (type => 'in table:/'.$token->{tag_name});            !!!parse-error (type => 'in table:/'.$token->{tag_name});
4794    
4795            $insert = $insert_to_foster;            $insert = $insert_to_foster;
# Line 4489  sub _tree_construction_main ($) { Line 4803  sub _tree_construction_main ($) {
4803              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4804                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4805                unless (length $token->{data}) {                unless (length $token->{data}) {
4806                    !!!cp ('t260');
4807                  !!!next-token;                  !!!next-token;
4808                  redo B;                  redo B;
4809                }                }
4810              }              }
4811                            
4812                !!!cp ('t261');
4813              #              #
4814            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
4815              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
4816                  !!!cp ('t262');
4817                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4818                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4819                !!!next-token;                !!!next-token;
4820                redo B;                redo B;
4821              } else {              } else {
4822                  !!!cp ('t263');
4823                #                #
4824              }              }
4825            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
4826              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
4827                if ($self->{open_elements}->[-1]->[1] eq 'html') {                if ($self->{open_elements}->[-1]->[1] eq 'html') {
4828                    !!!cp ('t264');
4829                  !!!parse-error (type => 'unmatched end tag:colgroup');                  !!!parse-error (type => 'unmatched end tag:colgroup');
4830                  ## Ignore the token                  ## Ignore the token
4831                  !!!next-token;                  !!!next-token;
4832                  redo B;                  redo B;
4833                } else {                } else {
4834                    !!!cp ('t265');
4835                  pop @{$self->{open_elements}}; # colgroup                  pop @{$self->{open_elements}}; # colgroup
4836                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4837                  !!!next-token;                  !!!next-token;
4838                  redo B;                              redo B;            
4839                }                }
4840              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
4841                  !!!cp ('t266');
4842                !!!parse-error (type => 'unmatched end tag:col');                !!!parse-error (type => 'unmatched end tag:col');
4843                ## Ignore the token                ## Ignore the token
4844                !!!next-token;                !!!next-token;
4845                redo B;                redo B;
4846              } else {              } else {
4847                  !!!cp ('t267');
4848                #                #
4849              }              }
4850            } else {            } else {
4851                !!!cp ('t268');
4852              #              #
4853            }            }
4854    
4855            ## As if </colgroup>            ## As if </colgroup>
4856            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] eq 'html') {
4857                !!!cp ('t269');
4858              !!!parse-error (type => 'unmatched end tag:colgroup');              !!!parse-error (type => 'unmatched end tag:colgroup');
4859              ## Ignore the token              ## Ignore the token
4860              !!!next-token;              !!!next-token;
4861              redo B;              redo B;
4862            } else {            } else {
4863                !!!cp ('t270');
4864              pop @{$self->{open_elements}}; # colgroup              pop @{$self->{open_elements}}; # colgroup
4865              $self->{insertion_mode} = IN_TABLE_IM;              $self->{insertion_mode} = IN_TABLE_IM;
4866              ## reprocess              ## reprocess
# Line 4543  sub _tree_construction_main ($) { Line 4868  sub _tree_construction_main ($) {
4868            }            }
4869      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {
4870        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4871            !!!cp ('t271');
4872          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4873          !!!next-token;          !!!next-token;
4874          redo B;          redo B;
4875        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4876              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
4877                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4878                    !!!cp ('t272');
4879                  ## As if </option>                  ## As if </option>
4880                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4881                  } else {
4882                    !!!cp ('t273');
4883                }                }
4884    
4885                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4558  sub _tree_construction_main ($) { Line 4887  sub _tree_construction_main ($) {
4887                redo B;                redo B;
4888              } elsif ($token->{tag_name} eq 'optgroup') {              } elsif ($token->{tag_name} eq 'optgroup') {
4889                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4890                    !!!cp ('t274');
4891                  ## As if </option>                  ## As if </option>
4892                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4893                  } else {
4894                    !!!cp ('t275');
4895                }                }
4896    
4897                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
4898                    !!!cp ('t276');
4899                  ## As if </optgroup>                  ## As if </optgroup>
4900                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4901                  } else {
4902                    !!!cp ('t277');
4903                }                }
4904    
4905                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4578  sub _tree_construction_main ($) { Line 4913  sub _tree_construction_main ($) {
4913                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4914                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4915                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4916                      !!!cp ('t278');
4917                    $i = $_;                    $i = $_;
4918                    last INSCOPE;                    last INSCOPE;
4919                  } elsif ({                  } elsif ({
4920                            table => 1, html => 1,                            table => 1, html => 1,
4921                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4922                      !!!cp ('t279');
4923                    last INSCOPE;                    last INSCOPE;
4924                  }                  }
4925                } # INSCOPE                } # INSCOPE
4926                unless (defined $i) {                unless (defined $i) {
4927                    !!!cp ('t280');
4928                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
4929                  ## Ignore the token                  ## Ignore the token
4930                  !!!next-token;                  !!!next-token;
4931                  redo B;                  redo B;
4932                }                }
4933                                
4934                  !!!cp ('t281');
4935                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4936    
4937                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4600  sub _tree_construction_main ($) { Line 4939  sub _tree_construction_main ($) {
4939                !!!next-token;                !!!next-token;
4940                redo B;                redo B;
4941          } else {          } else {
4942              !!!cp ('t282');
4943            !!!parse-error (type => 'in select:'.$token->{tag_name});            !!!parse-error (type => 'in select:'.$token->{tag_name});
4944            ## Ignore the token            ## Ignore the token
4945            !!!next-token;            !!!next-token;
# Line 4609  sub _tree_construction_main ($) { Line 4949  sub _tree_construction_main ($) {
4949              if ($token->{tag_name} eq 'optgroup') {              if ($token->{tag_name} eq 'optgroup') {
4950                if ($self->{open_elements}->[-1]->[1] eq 'option' and                if ($self->{open_elements}->[-1]->[1] eq 'option' and
4951                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {
4952                    !!!cp ('t283');
4953                  ## As if </option>                  ## As if </option>
4954                  splice @{$self->{open_elements}}, -2;                  splice @{$self->{open_elements}}, -2;
4955                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
4956                    !!!cp ('t284');
4957                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4958                } else {                } else {
4959                    !!!cp ('t285');
4960                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4961                  ## Ignore the token                  ## Ignore the token
4962                }                }
# Line 4621  sub _tree_construction_main ($) { Line 4964  sub _tree_construction_main ($) {
4964                redo B;                redo B;
4965              } elsif ($token->{tag_name} eq 'option') {              } elsif ($token->{tag_name} eq 'option') {
4966                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4967                    !!!cp ('t286');
4968                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4969                } else {                } else {
4970                    !!!cp ('t287');
4971                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4972                  ## Ignore the token                  ## Ignore the token
4973                }                }
# Line 4634  sub _tree_construction_main ($) { Line 4979  sub _tree_construction_main ($) {
4979                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4980                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4981                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4982                      !!!cp ('t288');
4983                    $i = $_;                    $i = $_;
4984                    last INSCOPE;                    last INSCOPE;
4985                  } elsif ({                  } elsif ({
4986                            table => 1, html => 1,                            table => 1, html => 1,
4987                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4988                      !!!cp ('t289');
4989                    last INSCOPE;                    last INSCOPE;
4990                  }                  }
4991                } # INSCOPE                } # INSCOPE
4992                unless (defined $i) {                unless (defined $i) {
4993                    !!!cp ('t290');
4994                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4995                  ## Ignore the token                  ## Ignore the token
4996                  !!!next-token;                  !!!next-token;
4997                  redo B;                  redo B;
4998                }                }
4999                                
5000                  !!!cp ('t291');
5001                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5002    
5003                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4666  sub _tree_construction_main ($) { Line 5015  sub _tree_construction_main ($) {
5015                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5016                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5017                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
5018                      !!!cp ('t292');
5019                    $i = $_;                    $i = $_;
5020                    last INSCOPE;                    last INSCOPE;
5021                  } elsif ({                  } elsif ({
5022                            table => 1, html => 1,                            table => 1, html => 1,
5023                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5024                      !!!cp ('t293');
5025                    last INSCOPE;                    last INSCOPE;
5026                  }                  }
5027                } # INSCOPE                } # INSCOPE
5028                unless (defined $i) {                unless (defined $i) {
5029                    !!!cp ('t294');
5030                  ## Ignore the token                  ## Ignore the token
5031                  !!!next-token;                  !!!next-token;
5032                  redo B;                  redo B;
# Line 4686  sub _tree_construction_main ($) { Line 5038  sub _tree_construction_main ($) {
5038                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5039                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5040                  if ($node->[1] eq 'select') {                  if ($node->[1] eq 'select') {
5041                      !!!cp ('t295');
5042                    $i = $_;                    $i = $_;
5043                    last INSCOPE;                    last INSCOPE;
5044                  } elsif ({                  } elsif ({
5045                            table => 1, html => 1,                            table => 1, html => 1,
5046                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5047                      !!!cp ('t296');
5048                    last INSCOPE;                    last INSCOPE;
5049                  }                  }
5050                } # INSCOPE                } # INSCOPE
5051                unless (defined $i) {                unless (defined $i) {
5052                    !!!cp ('t297');
5053                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5054                  ## Ignore the </select> token                  ## Ignore the </select> token
5055                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
5056                  redo B;                  redo B;
5057                }                }
5058                                
5059                  !!!cp ('t298');
5060                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5061    
5062                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4708  sub _tree_construction_main ($) { Line 5064  sub _tree_construction_main ($) {
5064                ## reprocess                ## reprocess
5065                redo B;                redo B;
5066          } else {          } else {
5067              !!!cp ('t299');
5068            !!!parse-error (type => 'in select:/'.$token->{tag_name});            !!!parse-error (type => 'in select:/'.$token->{tag_name});
5069            ## Ignore the token            ## Ignore the token
5070            !!!next-token;            !!!next-token;
# Line 4726  sub _tree_construction_main ($) { Line 5083  sub _tree_construction_main ($) {
5083            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5084                        
5085            unless (length $token->{data}) {            unless (length $token->{data}) {
5086                !!!cp ('t300');
5087              !!!next-token;              !!!next-token;
5088              redo B;              redo B;
5089            }            }
5090          }          }
5091                    
5092          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5093              !!!cp ('t301');
5094            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character');
5095    
5096            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "main" phase, "after body" insertion mode...
5097            } else {
5098              !!!cp ('t302');
5099          }          }
5100                    
5101          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4745  sub _tree_construction_main ($) { Line 5106  sub _tree_construction_main ($) {
5106          redo B;          redo B;
5107        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5108          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5109              !!!cp ('t303');
5110            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5111                        
5112            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "main" phase, "after body" insertion mode...
5113            } else {
5114              !!!cp ('t304');
5115          }          }
5116    
5117          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4758  sub _tree_construction_main ($) { Line 5122  sub _tree_construction_main ($) {
5122          redo B;          redo B;
5123        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5124          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5125              !!!cp ('t305');
5126            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5127                        
5128            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5129            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "main" phase, "after body" insertion mode...
5130            } else {
5131              !!!cp ('t306');
5132          }          }
5133    
5134          ## "after body" insertion mode          ## "after body" insertion mode
5135          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
5136            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
5137                !!!cp ('t307');
5138              !!!parse-error (type => 'unmatched end tag:html');              !!!parse-error (type => 'unmatched end tag:html');
5139              ## Ignore the token              ## Ignore the token
5140              !!!next-token;              !!!next-token;
5141              redo B;              redo B;
5142            } else {            } else {
5143                !!!cp ('t308');
5144              $self->{insertion_mode} = AFTER_HTML_BODY_IM;              $self->{insertion_mode} = AFTER_HTML_BODY_IM;
5145              !!!next-token;              !!!next-token;
5146              redo B;              redo B;
5147            }            }
5148          } else {          } else {
5149              !!!cp ('t309');
5150            !!!parse-error (type => 'after body:/'.$token->{tag_name});            !!!parse-error (type => 'after body:/'.$token->{tag_name});
5151    
5152            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
# Line 4792  sub _tree_construction_main ($) { Line 5162  sub _tree_construction_main ($) {
5162            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5163                        
5164            unless (length $token->{data}) {            unless (length $token->{data}) {
5165                !!!cp ('t310');
5166              !!!next-token;              !!!next-token;
5167              redo B;              redo B;
5168            }            }
# Line 4799  sub _tree_construction_main ($) { Line 5170  sub _tree_construction_main ($) {
5170                    
5171          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
5172            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5173                !!!cp ('t311');
5174              !!!parse-error (type => 'in frameset:#character');              !!!parse-error (type => 'in frameset:#character');
5175            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
5176                !!!cp ('t312');
5177              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5178            } else { # "after html frameset"            } else { # "after html frameset"
5179                !!!cp ('t313');
5180              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character');
5181    
5182              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
# Line 4812  sub _tree_construction_main ($) { Line 5186  sub _tree_construction_main ($) {
5186                        
5187            ## Ignore the token.            ## Ignore the token.
5188            if (length $token->{data}) {            if (length $token->{data}) {
5189                !!!cp ('t314');
5190              ## reprocess the rest of characters              ## reprocess the rest of characters
5191            } else {            } else {
5192                !!!cp ('t315');
5193              !!!next-token;              !!!next-token;
5194            }            }
5195            redo B;            redo B;
# Line 4822  sub _tree_construction_main ($) { Line 5198  sub _tree_construction_main ($) {
5198          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
5199        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5200          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5201              !!!cp ('t316');
5202            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5203    
5204            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5205            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "main" phase, "after frameset" insertion mode...
5206          }          } else {
5207              !!!cp ('t317');
5208            }
5209    
5210          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5211              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5212              !!!cp ('t318');
5213            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5214            !!!next-token;            !!!next-token;
5215            redo B;            redo B;
5216          } elsif ($token->{tag_name} eq 'frame' and          } elsif ($token->{tag_name} eq 'frame' and
5217                   $self->{insertion_mode} == IN_FRAMESET_IM) {                   $self->{insertion_mode} == IN_FRAMESET_IM) {
5218              !!!cp ('t319');
5219            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5220            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
5221            !!!next-token;            !!!next-token;
5222            redo B;            redo B;
5223          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5224              !!!cp ('t320');
5225            ## NOTE: As if in body.            ## NOTE: As if in body.
5226            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
5227            redo B;            redo B;
5228          } else {          } else {
5229            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5230                !!!cp ('t321');
5231              !!!parse-error (type => 'in frameset:'.$token->{tag_name});              !!!parse-error (type => 'in frameset:'.$token->{tag_name});
5232            } else {            } else {
5233                !!!cp ('t322');
5234              !!!parse-error (type => 'after frameset:'.$token->{tag_name});              !!!parse-error (type => 'after frameset:'.$token->{tag_name});
5235            }            }
5236            ## Ignore the token            ## Ignore the token
# Line 4855  sub _tree_construction_main ($) { Line 5239  sub _tree_construction_main ($) {
5239          }          }
5240        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5241          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5242              !!!cp ('t323');
5243            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5244    
5245            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5246            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "main" phase, "after frameset" insertion mode...
5247            } else {
5248              !!!cp ('t324');
5249          }          }
5250    
5251          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5252              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5253            if ($self->{open_elements}->[-1]->[1] eq 'html' and            if ($self->{open_elements}->[-1]->[1] eq 'html' and
5254                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
5255                !!!cp ('t325');
5256              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5257              ## Ignore the token              ## Ignore the token
5258              !!!next-token;              !!!next-token;
5259            } else {            } else {
5260                !!!cp ('t326');
5261              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
5262              !!!next-token;              !!!next-token;
5263            }            }
5264    
5265            if (not defined $self->{inner_html_node} and            if (not defined $self->{inner_html_node} and
5266                $self->{open_elements}->[-1]->[1] ne 'frameset') {                $self->{open_elements}->[-1]->[1] ne 'frameset') {
5267                !!!cp ('t327');
5268              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5269              } else {
5270                !!!cp ('t328');
5271            }            }
5272            redo B;            redo B;
5273          } elsif ($token->{tag_name} eq 'html' and          } elsif ($token->{tag_name} eq 'html' and
5274                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {
5275              !!!cp ('t329');
5276            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;
5277            !!!next-token;            !!!next-token;
5278            redo B;            redo B;
5279          } else {          } else {
5280            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5281                !!!cp ('t330');
5282              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
5283            } else {            } else {
5284                !!!cp ('t331');
5285              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
5286            }            }
5287            ## Ignore the token            ## Ignore the token
# Line 4905  sub _tree_construction_main ($) { Line 5300  sub _tree_construction_main ($) {
5300      ## "in body" insertion mode      ## "in body" insertion mode
5301      if ($token->{type} == START_TAG_TOKEN) {      if ($token->{type} == START_TAG_TOKEN) {
5302        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5303            !!!cp ('t332');
5304          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5305          $script_start_tag->($insert);          $script_start_tag->($insert);
5306          redo B;          redo B;
5307        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5308            !!!cp ('t333');
5309          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5310          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5311          redo B;          redo B;
5312        } elsif ({        } elsif ({
5313                  base => 1, link => 1,                  base => 1, link => 1,
5314                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5315            !!!cp ('t334');
5316          ## NOTE: This is an "as if in head" code clone, only "-t" differs          ## NOTE: This is an "as if in head" code clone, only "-t" differs
5317          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5318          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
# Line 4927  sub _tree_construction_main ($) { Line 5325  sub _tree_construction_main ($) {
5325    
5326          unless ($self->{confident}) {          unless ($self->{confident}) {
5327            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) { ## TODO: And if supported
5328                !!!cp ('t335');
5329              $self->{change_encoding}              $self->{change_encoding}
5330                  ->($self, $token->{attributes}->{charset}->{value});                  ->($self, $token->{attributes}->{charset}->{value});
5331                            
# Line 4941  sub _tree_construction_main ($) { Line 5340  sub _tree_construction_main ($) {
5340                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
5341                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
5342                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
5343                  !!!cp ('t336');
5344                $self->{change_encoding}                $self->{change_encoding}
5345                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
5346                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 4951  sub _tree_construction_main ($) { Line 5351  sub _tree_construction_main ($) {
5351            }            }
5352          } else {          } else {
5353            if ($token->{attributes}->{charset}) {            if ($token->{attributes}->{charset}) {
5354                !!!cp ('t337');
5355              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
5356                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5357                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
5358                                           ->{has_reference});                                           ->{has_reference});
5359            }            }
5360            if ($token->{attributes}->{content}) {            if ($token->{attributes}->{content}) {
5361                !!!cp ('t338');
5362              $meta_el->[0]->get_attribute_node_ns (undef, 'content')              $meta_el->[0]->get_attribute_node_ns (undef, 'content')
5363                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5364                                       $token->{attributes}->{content}                                       $token->{attributes}->{content}
# Line 4967  sub _tree_construction_main ($) { Line 5369  sub _tree_construction_main ($) {
5369          !!!next-token;          !!!next-token;
5370          redo B;          redo B;
5371        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5372            !!!cp ('t341');
5373          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
5374          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5375          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {
5376            if (defined $self->{head_element}) {            if (defined $self->{head_element}) {
5377                !!!cp ('t339');
5378              $self->{head_element}->append_child ($_[0]);              $self->{head_element}->append_child ($_[0]);
5379            } else {            } else {
5380                !!!cp ('t340');
5381              $insert->($_[0]);              $insert->($_[0]);
5382            }            }
5383          });          });
# Line 4982  sub _tree_construction_main ($) { Line 5387  sub _tree_construction_main ($) {
5387                                
5388          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
5389              $self->{open_elements}->[1]->[1] ne 'body') {              $self->{open_elements}->[1]->[1] ne 'body') {
5390              !!!cp ('t342');
5391            ## Ignore the token            ## Ignore the token
5392          } else {          } else {
5393            my $body_el = $self->{open_elements}->[1]->[0];            my $body_el = $self->{open_elements}->[1]->[0];
5394            for my $attr_name (keys %{$token->{attributes}}) {            for my $attr_name (keys %{$token->{attributes}}) {
5395              unless ($body_el->has_attribute_ns (undef, $attr_name)) {              unless ($body_el->has_attribute_ns (undef, $attr_name)) {
5396                  !!!cp ('t343');
5397                $body_el->set_attribute_ns                $body_el->set_attribute_ns
5398                  (undef, [undef, $attr_name],                  (undef, [undef, $attr_name],
5399                   $token->{attributes}->{$attr_name}->{value});                   $token->{attributes}->{$attr_name}->{value});
# Line 5004  sub _tree_construction_main ($) { Line 5411  sub _tree_construction_main ($) {
5411          ## has a p element in scope          ## has a p element in scope
5412          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5413            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5414                !!!cp ('t344');
5415              !!!back-token;              !!!back-token;
5416              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5417              redo B;              redo B;
# Line 5011  sub _tree_construction_main ($) { Line 5419  sub _tree_construction_main ($) {
5419                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5420                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5421                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5422                !!!cp ('t345');
5423              last INSCOPE;              last INSCOPE;
5424            }            }
5425          } # INSCOPE          } # INSCOPE
# Line 5021  sub _tree_construction_main ($) { Line 5430  sub _tree_construction_main ($) {
5430            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
5431              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
5432              unless (length $token->{data}) {              unless (length $token->{data}) {
5433                  !!!cp ('t346');
5434                !!!next-token;                !!!next-token;
5435                } else {
5436                  !!!cp ('t349');
5437              }              }
5438              } else {
5439                !!!cp ('t348');
5440            }            }
5441          } else {          } else {
5442              !!!cp ('t347');
5443            !!!next-token;            !!!next-token;
5444          }          }
5445          redo B;          redo B;
5446        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
5447          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5448              !!!cp ('t350');
5449            !!!parse-error (type => 'in form:form');            !!!parse-error (type => 'in form:form');
5450            ## Ignore the token            ## Ignore the token
5451            !!!next-token;            !!!next-token;
# Line 5038  sub _tree_construction_main ($) { Line 5454  sub _tree_construction_main ($) {
5454            ## has a p element in scope            ## has a p element in scope
5455            INSCOPE: for (reverse @{$self->{open_elements}}) {            INSCOPE: for (reverse @{$self->{open_elements}}) {
5456              if ($_->[1] eq 'p') {              if ($_->[1] eq 'p') {
5457                  !!!cp ('t351');
5458                !!!back-token;                !!!back-token;
5459                $token = {type => END_TAG_TOKEN, tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5460                redo B;                redo B;
# Line 5045  sub _tree_construction_main ($) { Line 5462  sub _tree_construction_main ($) {
5462                        table => 1, caption => 1, td => 1, th => 1,                        table => 1, caption => 1, td => 1, th => 1,
5463                        button => 1, marquee => 1, object => 1, html => 1,                        button => 1, marquee => 1, object => 1, html => 1,
5464                       }->{$_->[1]}) {                       }->{$_->[1]}) {
5465                  !!!cp ('t352');
5466                last INSCOPE;                last INSCOPE;
5467              }              }
5468            } # INSCOPE            } # INSCOPE
# Line 5058  sub _tree_construction_main ($) { Line 5476  sub _tree_construction_main ($) {
5476          ## has a p element in scope          ## has a p element in scope
5477          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5478            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5479                !!!cp ('t353');
5480              !!!back-token;              !!!back-token;
5481              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5482              redo B;              redo B;
# Line 5065  sub _tree_construction_main ($) { Line 5484  sub _tree_construction_main ($) {
5484                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5485                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5486                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5487                !!!cp ('t354');
5488              last INSCOPE;              last INSCOPE;
5489            }            }
5490          } # INSCOPE          } # INSCOPE
# Line 5076  sub _tree_construction_main ($) { Line 5496  sub _tree_construction_main ($) {
5496            ## Step 2            ## Step 2
5497            if ($node->[1] eq 'li') {            if ($node->[1] eq 'li') {
5498              if ($i != -1) {              if ($i != -1) {
5499                  !!!cp ('t355');
5500                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5501                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5502                } else {
5503                  !!!cp ('t356');
5504              }              }
5505              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5506              last LI;              last LI;
5507              } else {
5508                !!!cp ('t357');
5509            }            }
5510                        
5511            ## Step 3            ## Step 3
# Line 5089  sub _tree_construction_main ($) { Line 5514  sub _tree_construction_main ($) {
5514                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5515                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5516                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5517                !!!cp ('t358');
5518              last LI;              last LI;
5519            }            }
5520                        
5521              !!!cp ('t359');
5522            ## Step 4            ## Step 4
5523            $i--;            $i--;
5524            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 5105  sub _tree_construction_main ($) { Line 5532  sub _tree_construction_main ($) {
5532          ## has a p element in scope          ## has a p element in scope
5533          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5534            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5535                !!!cp ('t360');
5536              !!!back-token;              !!!back-token;
5537              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5538              redo B;              redo B;
# Line 5112  sub _tree_construction_main ($) { Line 5540  sub _tree_construction_main ($) {
5540                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5541                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5542                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5543                !!!cp ('t361');
5544              last INSCOPE;              last INSCOPE;
5545            }            }
5546          } # INSCOPE          } # INSCOPE
# Line 5123  sub _tree_construction_main ($) { Line 5552  sub _tree_construction_main ($) {
5552            ## Step 2            ## Step 2
5553            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {
5554              if ($i != -1) {              if ($i != -1) {
5555                  !!!cp ('t362');
5556                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5557                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5558                } else {
5559                  !!!cp ('t363');
5560              }              }
5561              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5562              last LI;              last LI;
5563              } else {
5564                !!!cp ('t364');
5565            }            }
5566                        
5567            ## Step 3            ## Step 3
# Line 5136  sub _tree_construction_main ($) { Line 5570  sub _tree_construction_main ($) {
5570                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5571                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5572                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5573                !!!cp ('t365');
5574              last LI;              last LI;
5575            }            }
5576                        
5577              !!!cp ('t366');
5578            ## Step 4            ## Step 4
5579            $i--;            $i--;
5580            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 5152  sub _tree_construction_main ($) { Line 5588  sub _tree_construction_main ($) {
5588          ## has a p element in scope          ## has a p element in scope
5589          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5590            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5591                !!!cp ('t367');
5592              !!!back-token;              !!!back-token;
5593              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5594              redo B;              redo B;
# Line 5159  sub _tree_construction_main ($) { Line 5596  sub _tree_construction_main ($) {
5596                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5597                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5598                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5599                !!!cp ('t368');
5600              last INSCOPE;              last INSCOPE;
5601            }            }
5602          } # INSCOPE          } # INSCOPE
# Line 5176  sub _tree_construction_main ($) { Line 5614  sub _tree_construction_main ($) {
5614          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5615            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5616            if ($node->[1] eq 'p') {            if ($node->[1] eq 'p') {
5617                !!!cp ('t369');
5618              !!!back-token;              !!!back-token;
5619              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5620              redo B;              redo B;
# Line 5183  sub _tree_construction_main ($) { Line 5622  sub _tree_construction_main ($) {
5622                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5623                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5624                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5625                !!!cp ('t370');
5626              last INSCOPE;              last INSCOPE;
5627            }            }
5628          } # INSCOPE          } # INSCOPE
# Line 5218  sub _tree_construction_main ($) { Line 5658  sub _tree_construction_main ($) {
5658          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5659            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
5660            if ($node->[1] eq 'a') {            if ($node->[1] eq 'a') {
5661                !!!cp ('t371');
5662              !!!parse-error (type => 'in a:a');              !!!parse-error (type => 'in a:a');
5663                            
5664              !!!back-token;              !!!back-token;
# Line 5226  sub _tree_construction_main ($) { Line 5667  sub _tree_construction_main ($) {
5667                            
5668              AFE2: for (reverse 0..$#$active_formatting_elements) {              AFE2: for (reverse 0..$#$active_formatting_elements) {
5669                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
5670                    !!!cp ('t372');
5671                  splice @$active_formatting_elements, $_, 1;                  splice @$active_formatting_elements, $_, 1;
5672                  last AFE2;                  last AFE2;
5673                }                }
5674              } # AFE2              } # AFE2
5675              OE: for (reverse 0..$#{$self->{open_elements}}) {              OE: for (reverse 0..$#{$self->{open_elements}}) {
5676                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {
5677                    !!!cp ('t373');
5678                  splice @{$self->{open_elements}}, $_, 1;                  splice @{$self->{open_elements}}, $_, 1;
5679                  last OE;                  last OE;
5680                }                }
5681              } # OE              } # OE
5682              last AFE;              last AFE;
5683            } elsif ($node->[0] eq '#marker') {            } elsif ($node->[0] eq '#marker') {
5684                !!!cp ('t374');
5685              last AFE;              last AFE;
5686            }            }
5687          } # AFE          } # AFE
# Line 5254  sub _tree_construction_main ($) { Line 5698  sub _tree_construction_main ($) {
5698                  s => 1, small => 1, strile => 1,                  s => 1, small => 1, strile => 1,
5699                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
5700                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5701            !!!cp ('t375');
5702          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5703                    
5704          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5268  sub _tree_construction_main ($) { Line 5713  sub _tree_construction_main ($) {
5713          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5714            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5715            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
5716                !!!cp ('t376');
5717              !!!parse-error (type => 'in nobr:nobr');              !!!parse-error (type => 'in nobr:nobr');
5718              !!!back-token;              !!!back-token;
5719              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
# Line 5276  sub _tree_construction_main ($) { Line 5722  sub _tree_construction_main ($) {
5722                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5723                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5724                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5725                !!!cp ('t377');
5726              last INSCOPE;              last INSCOPE;
5727            }            }
5728          } # INSCOPE          } # INSCOPE
# Line 5290  sub _tree_construction_main ($) { Line 5737  sub _tree_construction_main ($) {
5737          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5738            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5739            if ($node->[1] eq 'button') {            if ($node->[1] eq 'button') {
5740                !!!cp ('t378');
5741              !!!parse-error (type => 'in button:button');              !!!parse-error (type => 'in button:button');
5742              !!!back-token;              !!!back-token;
5743              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
# Line 5298  sub _tree_construction_main ($) { Line 5746  sub _tree_construction_main ($) {
5746                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5747                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5748                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5749                !!!cp ('t379');
5750              last INSCOPE;              last INSCOPE;
5751            }            }
5752          } # INSCOPE          } # INSCOPE
# Line 5311  sub _tree_construction_main ($) { Line 5760  sub _tree_construction_main ($) {
5760          redo B;          redo B;
5761        } elsif ($token->{tag_name} eq 'marquee' or        } elsif ($token->{tag_name} eq 'marquee' or
5762                 $token->{tag_name} eq 'object') {                 $token->{tag_name} eq 'object') {
5763            !!!cp ('t380');
5764          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5765                    
5766          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5319  sub _tree_construction_main ($) { Line 5769  sub _tree_construction_main ($) {
5769          !!!next-token;          !!!next-token;
5770          redo B;          redo B;
5771        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5772            !!!cp ('t381');
5773          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5774          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5775          redo B;          redo B;
# Line 5326  sub _tree_construction_main ($) { Line 5777  sub _tree_construction_main ($) {
5777          ## has a p element in scope          ## has a p element in scope
5778          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5779            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5780                !!!cp ('t382');
5781              !!!back-token;              !!!back-token;
5782              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5783              redo B;              redo B;
# Line 5333  sub _tree_construction_main ($) { Line 5785  sub _tree_construction_main ($) {
5785                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5786                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5787                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5788                !!!cp ('t383');
5789              last INSCOPE;              last INSCOPE;
5790            }            }
5791          } # INSCOPE          } # INSCOPE
# Line 5349  sub _tree_construction_main ($) { Line 5802  sub _tree_construction_main ($) {
5802                  image => 1,                  image => 1,
5803                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5804          if ($token->{tag_name} eq 'image') {          if ($token->{tag_name} eq 'image') {
5805              !!!cp ('t384');
5806            !!!parse-error (type => 'image');            !!!parse-error (type => 'image');
5807            $token->{tag_name} = 'img';            $token->{tag_name} = 'img';
5808            } else {
5809              !!!cp ('t385');
5810          }          }
5811    
5812          ## NOTE: There is an "as if <br>" code clone.          ## NOTE: There is an "as if <br>" code clone.
# Line 5365  sub _tree_construction_main ($) { Line 5821  sub _tree_construction_main ($) {
5821          ## has a p element in scope          ## has a p element in scope
5822          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5823            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5824                !!!cp ('t386');
5825              !!!back-token;              !!!back-token;
5826              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5827              redo B;              redo B;
# Line 5372  sub _tree_construction_main ($) { Line 5829  sub _tree_construction_main ($) {
5829                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5830                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5831                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5832                !!!cp ('t387');
5833              last INSCOPE;              last INSCOPE;
5834            }            }
5835          } # INSCOPE          } # INSCOPE
# Line 5382  sub _tree_construction_main ($) { Line 5840  sub _tree_construction_main ($) {
5840          !!!next-token;          !!!next-token;
5841          redo B;          redo B;
5842        } elsif ($token->{tag_name} eq 'input') {        } elsif ($token->{tag_name} eq 'input') {
5843            !!!cp ('t388');
5844          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5845                    
5846          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5394  sub _tree_construction_main ($) { Line 5853  sub _tree_construction_main ($) {
5853          !!!parse-error (type => 'isindex');          !!!parse-error (type => 'isindex');
5854                    
5855          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5856              !!!cp ('t389');
5857            ## Ignore the token            ## Ignore the token
5858            !!!next-token;            !!!next-token;
5859            redo B;            redo B;
# Line 5413  sub _tree_construction_main ($) { Line 5873  sub _tree_construction_main ($) {
5873                          {type => START_TAG_TOKEN, tag_name => 'label'},                          {type => START_TAG_TOKEN, tag_name => 'label'},
5874                         );                         );
5875            if ($prompt_attr) {            if ($prompt_attr) {
5876                !!!cp ('t390');
5877              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};
5878            } else {            } else {
5879                !!!cp ('t391');
5880              push @tokens, {type => CHARACTER_TOKEN,              push @tokens, {type => CHARACTER_TOKEN,
5881                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
5882              ## TODO: make this configurable              ## TODO: make this configurable
# Line 5446  sub _tree_construction_main ($) { Line 5908  sub _tree_construction_main ($) {
5908          if ($token->{type} == CHARACTER_TOKEN) {          if ($token->{type} == CHARACTER_TOKEN) {
5909            $token->{data} =~ s/^\x0A//;            $token->{data} =~ s/^\x0A//;
5910            unless (length $token->{data}) {            unless (length $token->{data}) {
5911                !!!cp ('t392');
5912              !!!next-token;              !!!next-token;
5913              } else {
5914                !!!cp ('t393');
5915            }            }
5916            } else {
5917              !!!cp ('t394');
5918          }          }
5919          while ($token->{type} == CHARACTER_TOKEN) {          while ($token->{type} == CHARACTER_TOKEN) {
5920              !!!cp ('t395');
5921            $text .= $token->{data};            $text .= $token->{data};
5922            !!!next-token;            !!!next-token;
5923          }          }
5924          if (length $text) {          if (length $text) {
5925              !!!cp ('t396');
5926            $el->manakai_append_text ($text);            $el->manakai_append_text ($text);
5927          }          }
5928                    
# Line 5461  sub _tree_construction_main ($) { Line 5930  sub _tree_construction_main ($) {
5930                    
5931          if ($token->{type} == END_TAG_TOKEN and          if ($token->{type} == END_TAG_TOKEN and
5932              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
5933              !!!cp ('t397');
5934            ## Ignore the token            ## Ignore the token
5935          } else {          } else {
5936              !!!cp ('t398');
5937            !!!parse-error (type => 'in RCDATA:#'.$token->{type});            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
5938          }          }
5939          !!!next-token;          !!!next-token;
# Line 5473  sub _tree_construction_main ($) { Line 5944  sub _tree_construction_main ($) {
5944                  noframes => 1,                  noframes => 1,
5945                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
5946                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5947            !!!cp ('t399');
5948          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
5949          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5950          redo B;          redo B;
5951        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
5952            !!!cp ('t400');
5953          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5954                    
5955          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5490  sub _tree_construction_main ($) { Line 5963  sub _tree_construction_main ($) {
5963                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
5964                  thead => 1, tr => 1,                  thead => 1, tr => 1,
5965                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5966            !!!cp ('t401');
5967          !!!parse-error (type => 'in body:'.$token->{tag_name});          !!!parse-error (type => 'in body:'.$token->{tag_name});
5968          ## Ignore the token          ## Ignore the token
5969          !!!next-token;          !!!next-token;
# Line 5497  sub _tree_construction_main ($) { Line 5971  sub _tree_construction_main ($) {
5971                    
5972          ## ISSUE: An issue on HTML5 new elements in the spec.          ## ISSUE: An issue on HTML5 new elements in the spec.
5973        } else {        } else {
5974            !!!cp ('t402');
5975          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5976                    
5977          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5514  sub _tree_construction_main ($) { Line 5989  sub _tree_construction_main ($) {
5989                         th => 1, tr => 1, body => 1, html => 1,                         th => 1, tr => 1, body => 1, html => 1,
5990                       tbody => 1, tfoot => 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
5991                      }->{$_->[1]}) {                      }->{$_->[1]}) {
5992                  !!!cp ('t403');
5993                !!!parse-error (type => 'not closed:'.$_->[1]);                !!!parse-error (type => 'not closed:'.$_->[1]);
5994                } else {
5995                  !!!cp ('t404');
5996              }              }
5997            }            }
5998    
# Line 5522  sub _tree_construction_main ($) { Line 6000  sub _tree_construction_main ($) {
6000            !!!next-token;            !!!next-token;
6001            redo B;            redo B;
6002          } else {          } else {
6003              !!!cp ('t405');
6004            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6005            ## Ignore the token            ## Ignore the token
6006            !!!next-token;            !!!next-token;
# Line 5531  sub _tree_construction_main ($) { Line 6010  sub _tree_construction_main ($) {
6010          if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {          if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {
6011            ## ISSUE: There is an issue in the spec.            ## ISSUE: There is an issue in the spec.
6012            if ($self->{open_elements}->[-1]->[1] ne 'body') {            if ($self->{open_elements}->[-1]->[1] ne 'body') {
6013                !!!cp ('t406');
6014              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);
6015              } else {
6016                !!!cp ('t407');
6017            }            }
6018            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6019            ## reprocess            ## reprocess
6020            redo B;            redo B;
6021          } else {          } else {
6022              !!!cp ('t408');
6023            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6024            ## Ignore the token            ## Ignore the token
6025            !!!next-token;            !!!next-token;
# Line 5564  sub _tree_construction_main ($) { Line 6047  sub _tree_construction_main ($) {
6047                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6048                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6049                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6050                  !!!cp ('t409');
6051                !!!back-token;                !!!back-token;
6052                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6053                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6054                redo B;                redo B;
6055              }              }
6056                
6057                !!!cp ('t410');
6058              $i = $_;              $i = $_;
6059              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE unless $token->{tag_name} eq 'p';
6060            } elsif ({            } elsif ({
6061                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6062                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6063                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6064                !!!cp ('t411');
6065              last INSCOPE;              last INSCOPE;
6066            }            }
6067          } # INSCOPE          } # INSCOPE
6068                    
6069          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6070            if (defined $i) {            if (defined $i) {
6071                !!!cp ('t412');
6072              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6073            } else {            } else {
6074                !!!cp ('t413');
6075              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6076            }            }
6077          }          }
6078                    
6079          if (defined $i) {          if (defined $i) {
6080              !!!cp ('t414');
6081            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6082          } elsif ($token->{tag_name} eq 'p') {          } elsif ($token->{tag_name} eq 'p') {
6083              !!!cp ('t415');
6084            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
6085            my $el;            my $el;
6086            !!!create-element ($el, 'p');            !!!create-element ($el, 'p');
6087            $insert->($el);            $insert->($el);
6088            } else {
6089              !!!cp ('t416');
6090          }          }
6091          $clear_up_to_marker->()          $clear_up_to_marker->()
6092            if {            if {
# Line 5612  sub _tree_construction_main ($) { Line 6105  sub _tree_construction_main ($) {
6105                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6106                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6107                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6108                  !!!cp ('t417');
6109                !!!back-token;                !!!back-token;
6110                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6111                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6112                redo B;                redo B;
6113              }              }
6114                
6115                !!!cp ('t418');
6116              last INSCOPE;              last INSCOPE;
6117            } elsif ({            } elsif ({
6118                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6119                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6120                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6121                !!!cp ('t419');
6122              last INSCOPE;              last INSCOPE;
6123            }            }
6124          } # INSCOPE          } # INSCOPE
6125                    
6126          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {
6127              !!!cp ('t420');
6128            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
6129          } else {          } else {
6130              !!!cp ('t421');
6131            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6132          }          }
6133    
# Line 5651  sub _tree_construction_main ($) { Line 6150  sub _tree_construction_main ($) {
6150                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6151                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6152                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6153                  !!!cp ('t422');
6154                !!!back-token;                !!!back-token;
6155                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6156                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6157                redo B;                redo B;
6158              }              }
6159    
6160                !!!cp ('t423');
6161              $i = $_;              $i = $_;
6162              last INSCOPE;              last INSCOPE;
6163            } elsif ({            } elsif ({
6164                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6165                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6166                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6167                !!!cp ('t424');
6168              last INSCOPE;              last INSCOPE;
6169            }            }
6170          } # INSCOPE          } # INSCOPE
6171                    
6172          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6173              !!!cp ('t425');
6174            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6175            } else {
6176              !!!cp ('t426');
6177          }          }
6178                    
6179          splice @{$self->{open_elements}}, $i if defined $i;          splice @{$self->{open_elements}}, $i if defined $i;
# Line 5679  sub _tree_construction_main ($) { Line 6185  sub _tree_construction_main ($) {
6185                  nobr => 1, s => 1, small => 1, strile => 1,                  nobr => 1, s => 1, small => 1, strile => 1,
6186                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
6187                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6188            !!!cp ('t427');
6189          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
6190          redo B;          redo B;
6191        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
6192            !!!cp ('t428');
6193          !!!parse-error (type => 'unmatched end tag:br');          !!!parse-error (type => 'unmatched end tag:br');
6194    
6195          ## As if <br>          ## As if <br>
# Line 5706  sub _tree_construction_main ($) { Line 6214  sub _tree_construction_main ($) {
6214                  table => 1, textarea => 1, wbr => 1,                  table => 1, textarea => 1, wbr => 1,
6215                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
6216                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6217            !!!cp ('t429');
6218          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6219          ## Ignore the token          ## Ignore the token
6220          !!!next-token;          !!!next-token;
# Line 5728  sub _tree_construction_main ($) { Line 6237  sub _tree_construction_main ($) {
6237                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6238                   tbody => 1, tfoot => 1, thead => 1,                   tbody => 1, tfoot => 1, thead => 1,
6239                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6240                  !!!cp ('t430');
6241                !!!back-token;                !!!back-token;
6242                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6243                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 5736  sub _tree_construction_main ($) { Line 6246  sub _tree_construction_main ($) {
6246                    
6247              ## Step 2              ## Step 2
6248              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {
6249                  !!!cp ('t431');
6250                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
6251                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6252                } else {
6253                  !!!cp ('t432');
6254              }              }
6255                            
6256              ## Step 3              ## Step 3
# Line 5751  sub _tree_construction_main ($) { Line 6264  sub _tree_construction_main ($) {
6264                  #not $phrasing_category->{$node->[1]} and                  #not $phrasing_category->{$node->[1]} and
6265                  ($special_category->{$node->[1]} or                  ($special_category->{$node->[1]} or
6266                   $scoping_category->{$node->[1]})) {                   $scoping_category->{$node->[1]})) {
6267                  !!!cp ('t433');
6268                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6269                ## Ignore the token                ## Ignore the token
6270                !!!next-token;                !!!next-token;
6271                last S2;                last S2;
6272              }              }
6273    
6274                !!!cp ('t434');
6275            }            }
6276                        
6277            ## Step 4            ## Step 4
# Line 5834  sub set_inner_html ($$$) { Line 6350  sub set_inner_html ($$$) {
6350        if ($self->{next_char} == 0x000A) { # LF        if ($self->{next_char} == 0x000A) { # LF
6351          $line++;          $line++;
6352          $column = 0;          $column = 0;
6353            !!!cp ('i1');
6354        } elsif ($self->{next_char} == 0x000D) { # CR        } elsif ($self->{next_char} == 0x000D) { # CR
6355          $i++ if substr ($$s, $i, 1) eq "\x0A";          $i++ if substr ($$s, $i, 1) eq "\x0A";
6356          $self->{next_char} = 0x000A; # LF # MUST          $self->{next_char} = 0x000A; # LF # MUST
6357          $line++;          $line++;
6358          $column = 0;          $column = 0;
6359            !!!cp ('i2');
6360        } elsif ($self->{next_char} > 0x10FFFF) {        } elsif ($self->{next_char} > 0x10FFFF) {
6361          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6362            !!!cp ('i3');
6363        } elsif ($self->{next_char} == 0x0000) { # NULL        } elsif ($self->{next_char} == 0x0000) { # NULL
6364            !!!cp ('i4');
6365          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
6366          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6367        }        }
# Line 5902  sub set_inner_html ($$$) { Line 6422  sub set_inner_html ($$$) {
6422          my $nsuri = $anode->namespace_uri;          my $nsuri = $anode->namespace_uri;
6423          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {
6424            if ($anode->manakai_local_name eq 'form') {            if ($anode->manakai_local_name eq 'form') {
6425                !!!cp ('i5');
6426              $p->{form_element} = $anode;              $p->{form_element} = $anode;
6427              last AN;              last AN;
6428            }            }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24