/[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.77 by wakaba, Mon Mar 3 10:20:19 2008 UTC revision 1.85 by wakaba, Thu Mar 6 15:29:39 2008 UTC
# Line 304  sub ROW_IMS ()        { 0b10000000 } Line 304  sub ROW_IMS ()        { 0b10000000 }
304  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
305  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
306    
307    ## NOTE: "initial" and "before html" insertion modes have no constants.
308    
309    ## NOTE: "after after body" insertion mode.
310  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }  sub AFTER_HTML_BODY_IM () { AFTER_HTML_IMS | BODY_AFTER_IMS }
311    
312    ## NOTE: "after after frameset" insertion mode.
313  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }  sub AFTER_HTML_FRAMESET_IM () { AFTER_HTML_IMS | FRAME_IMS }
314    
315  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }  sub IN_HEAD_IM () { HEAD_IMS | 0b00 }
316  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }  sub IN_HEAD_NOSCRIPT_IM () { HEAD_IMS | 0b01 }
317  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }  sub AFTER_HEAD_IM () { HEAD_IMS | 0b10 }
# Line 656  sub _get_next_token ($) { Line 662  sub _get_next_token ($) {
662            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
663          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
664            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
665            if ($self->{current_token}->{attributes}) {            #if ($self->{current_token}->{attributes}) {
666              !!!cp (36);            #  ## NOTE: This should never be reached.
667              !!!parse-error (type => 'end tag attribute');            #  !!! cp (36);
668            } else {            #  !!! parse-error (type => 'end tag attribute');
669              #} else {
670              !!!cp (37);              !!!cp (37);
671            }            #}
672          } else {          } else {
673            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
674          }          }
# Line 688  sub _get_next_token ($) { Line 695  sub _get_next_token ($) {
695            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
696          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
697            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
698            if ($self->{current_token}->{attributes}) {            #if ($self->{current_token}->{attributes}) {
699              !!!cp (40);            #  ## NOTE: This state should never be reached.
700              !!!parse-error (type => 'end tag attribute');            #  !!! cp (40);
701            } else {            #  !!! parse-error (type => 'end tag attribute');
702              #} else {
703              !!!cp (41);              !!!cp (41);
704            }            #}
705          } else {          } else {
706            die "$0: $self->{current_token}->{type}: Unknown token type";            die "$0: $self->{current_token}->{type}: Unknown token type";
707          }          }
# Line 912  sub _get_next_token ($) { Line 920  sub _get_next_token ($) {
920              !!!cp (67);              !!!cp (67);
921              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
922            } else {            } else {
923                ## NOTE: This state should never be reached.
924              !!!cp (68);              !!!cp (68);
925            }            }
926          } else {          } else {
# Line 963  sub _get_next_token ($) { Line 972  sub _get_next_token ($) {
972              !!!cp (74);              !!!cp (74);
973              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
974            } else {            } else {
975                ## NOTE: This state should never be reached.
976              !!!cp (75);              !!!cp (75);
977            }            }
978          } else {          } else {
# Line 1011  sub _get_next_token ($) { Line 1021  sub _get_next_token ($) {
1021              !!!cp (80);              !!!cp (80);
1022              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1023            } else {            } else {
1024                ## NOTE: This state should never be reached.
1025              !!!cp (81);              !!!cp (81);
1026            }            }
1027          } else {          } else {
# Line 1067  sub _get_next_token ($) { Line 1078  sub _get_next_token ($) {
1078              !!!cp (88);              !!!cp (88);
1079              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1080            } else {            } else {
1081                ## NOTE: This state should never be reached.
1082              !!!cp (89);              !!!cp (89);
1083            }            }
1084          } else {          } else {
# Line 1091  sub _get_next_token ($) { Line 1103  sub _get_next_token ($) {
1103              !!!cp (91);              !!!cp (91);
1104              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1105            } else {            } else {
1106                ## NOTE: This state should never be reached.
1107              !!!cp (92);              !!!cp (92);
1108            }            }
1109          } else {          } else {
# Line 1139  sub _get_next_token ($) { Line 1152  sub _get_next_token ($) {
1152              !!!cp (98);              !!!cp (98);
1153              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1154            } else {            } else {
1155                ## NOTE: This state should never be reached.
1156              !!!cp (99);              !!!cp (99);
1157            }            }
1158          } else {          } else {
# Line 1182  sub _get_next_token ($) { Line 1196  sub _get_next_token ($) {
1196              !!!cp (104);              !!!cp (104);
1197              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1198            } else {            } else {
1199                ## NOTE: This state should never be reached.
1200              !!!cp (105);              !!!cp (105);
1201            }            }
1202          } else {          } else {
# Line 1228  sub _get_next_token ($) { Line 1243  sub _get_next_token ($) {
1243              !!!cp (110);              !!!cp (110);
1244              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1245            } else {            } else {
1246                ## NOTE: This state should never be reached.
1247              !!!cp (111);              !!!cp (111);
1248            }            }
1249          } else {          } else {
# Line 1252  sub _get_next_token ($) { Line 1268  sub _get_next_token ($) {
1268              !!!cp (113);              !!!cp (113);
1269              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1270            } else {            } else {
1271                ## NOTE: This state should never be reached.
1272              !!!cp (114);              !!!cp (114);
1273            }            }
1274          } else {          } else {
# Line 1323  sub _get_next_token ($) { Line 1340  sub _get_next_token ($) {
1340              !!!cp (120);              !!!cp (120);
1341              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
1342            } else {            } else {
1343                ## NOTE: This state should never be reached.
1344              !!!cp (121);              !!!cp (121);
1345            }            }
1346          } else {          } else {
# Line 2190  sub _tokenize_attempt_to_consume_an_enti Line 2208  sub _tokenize_attempt_to_consume_an_enti
2208         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR         0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR
2209         $additional => 1,         $additional => 1,
2210        }->{$self->{next_char}}) {        }->{$self->{next_char}}) {
2211        !!!cp (1001);
2212      ## Don't consume      ## Don't consume
2213      ## No error      ## No error
2214      return undef;      return undef;
# Line 2203  sub _tokenize_attempt_to_consume_an_enti Line 2222  sub _tokenize_attempt_to_consume_an_enti
2222          !!!next-input-character;          !!!next-input-character;
2223          if (0x0030 <= $self->{next_char} and          if (0x0030 <= $self->{next_char} and
2224              $self->{next_char} <= 0x0039) { # 0..9              $self->{next_char} <= 0x0039) { # 0..9
2225              !!!cp (1002);
2226            $code ||= 0;            $code ||= 0;
2227            $code *= 0x10;            $code *= 0x10;
2228            $code += $self->{next_char} - 0x0030;            $code += $self->{next_char} - 0x0030;
2229            redo X;            redo X;
2230          } elsif (0x0061 <= $self->{next_char} and          } elsif (0x0061 <= $self->{next_char} and
2231                   $self->{next_char} <= 0x0066) { # a..f                   $self->{next_char} <= 0x0066) { # a..f
2232              !!!cp (1003);
2233            $code ||= 0;            $code ||= 0;
2234            $code *= 0x10;            $code *= 0x10;
2235            $code += $self->{next_char} - 0x0060 + 9;            $code += $self->{next_char} - 0x0060 + 9;
2236            redo X;            redo X;
2237          } elsif (0x0041 <= $self->{next_char} and          } elsif (0x0041 <= $self->{next_char} and
2238                   $self->{next_char} <= 0x0046) { # A..F                   $self->{next_char} <= 0x0046) { # A..F
2239              !!!cp (1004);
2240            $code ||= 0;            $code ||= 0;
2241            $code *= 0x10;            $code *= 0x10;
2242            $code += $self->{next_char} - 0x0040 + 9;            $code += $self->{next_char} - 0x0040 + 9;
2243            redo X;            redo X;
2244          } elsif (not defined $code) { # no hexadecimal digit          } elsif (not defined $code) { # no hexadecimal digit
2245              !!!cp (1005);
2246            !!!parse-error (type => 'bare hcro');            !!!parse-error (type => 'bare hcro');
2247            !!!back-next-input-character ($x_char, $self->{next_char});            !!!back-next-input-character ($x_char, $self->{next_char});
2248            $self->{next_char} = 0x0023; # #            $self->{next_char} = 0x0023; # #
2249            return undef;            return undef;
2250          } elsif ($self->{next_char} == 0x003B) { # ;          } elsif ($self->{next_char} == 0x003B) { # ;
2251              !!!cp (1006);
2252            !!!next-input-character;            !!!next-input-character;
2253          } else {          } else {
2254              !!!cp (1007);
2255            !!!parse-error (type => 'no refc');            !!!parse-error (type => 'no refc');
2256          }          }
2257    
2258          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2259              !!!cp (1008);
2260            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
2261            $code = 0xFFFD;            $code = 0xFFFD;
2262          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2263              !!!cp (1009);
2264            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
2265            $code = 0xFFFD;            $code = 0xFFFD;
2266          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2267              !!!cp (1010);
2268            !!!parse-error (type => 'CR character reference');            !!!parse-error (type => 'CR character reference');
2269            $code = 0x000A;            $code = 0x000A;
2270          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2271              !!!cp (1011);
2272            !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);            !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
2273            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2274          }          }
# Line 2254  sub _tokenize_attempt_to_consume_an_enti Line 2283  sub _tokenize_attempt_to_consume_an_enti
2283                
2284        while (0x0030 <= $self->{next_char} and        while (0x0030 <= $self->{next_char} and
2285                  $self->{next_char} <= 0x0039) { # 0..9                  $self->{next_char} <= 0x0039) { # 0..9
2286            !!!cp (1012);
2287          $code *= 10;          $code *= 10;
2288          $code += $self->{next_char} - 0x0030;          $code += $self->{next_char} - 0x0030;
2289                    
# Line 2261  sub _tokenize_attempt_to_consume_an_enti Line 2291  sub _tokenize_attempt_to_consume_an_enti
2291        }        }
2292    
2293        if ($self->{next_char} == 0x003B) { # ;        if ($self->{next_char} == 0x003B) { # ;
2294            !!!cp (1013);
2295          !!!next-input-character;          !!!next-input-character;
2296        } else {        } else {
2297            !!!cp (1014);
2298          !!!parse-error (type => 'no refc');          !!!parse-error (type => 'no refc');
2299        }        }
2300    
2301        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2302            !!!cp (1015);
2303          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
2304          $code = 0xFFFD;          $code = 0xFFFD;
2305        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
2306            !!!cp (1016);
2307          !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);          !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
2308          $code = 0xFFFD;          $code = 0xFFFD;
2309        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
2310            !!!cp (1017);
2311          !!!parse-error (type => 'CR character reference');          !!!parse-error (type => 'CR character reference');
2312          $code = 0x000A;          $code = 0x000A;
2313        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
2314            !!!cp (1018);
2315          !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);          !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
2316          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
2317        }        }
2318                
2319        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1};        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1};
2320      } else {      } else {
2321          !!!cp (1019);
2322        !!!parse-error (type => 'bare nero');        !!!parse-error (type => 'bare nero');
2323        !!!back-next-input-character ($self->{next_char});        !!!back-next-input-character ($self->{next_char});
2324        $self->{next_char} = 0x0023; # #        $self->{next_char} = 0x0023; # #
# Line 2311  sub _tokenize_attempt_to_consume_an_enti Line 2348  sub _tokenize_attempt_to_consume_an_enti
2348        $entity_name .= chr $self->{next_char};        $entity_name .= chr $self->{next_char};
2349        if (defined $EntityChar->{$entity_name}) {        if (defined $EntityChar->{$entity_name}) {
2350          if ($self->{next_char} == 0x003B) { # ;          if ($self->{next_char} == 0x003B) { # ;
2351              !!!cp (1020);
2352            $value = $EntityChar->{$entity_name};            $value = $EntityChar->{$entity_name};
2353            $match = 1;            $match = 1;
2354            !!!next-input-character;            !!!next-input-character;
2355            last;            last;
2356          } else {          } else {
2357              !!!cp (1021);
2358            $value = $EntityChar->{$entity_name};            $value = $EntityChar->{$entity_name};
2359            $match = -1;            $match = -1;
2360            !!!next-input-character;            !!!next-input-character;
2361          }          }
2362        } else {        } else {
2363            !!!cp (1022);
2364          $value .= chr $self->{next_char};          $value .= chr $self->{next_char};
2365          $match *= 2;          $match *= 2;
2366          !!!next-input-character;          !!!next-input-character;
# Line 2328  sub _tokenize_attempt_to_consume_an_enti Line 2368  sub _tokenize_attempt_to_consume_an_enti
2368      }      }
2369            
2370      if ($match > 0) {      if ($match > 0) {
2371          !!!cp (1023);
2372        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};
2373      } elsif ($match < 0) {      } elsif ($match < 0) {
2374        !!!parse-error (type => 'no refc');        !!!parse-error (type => 'no refc');
2375        if ($in_attr and $match < -1) {        if ($in_attr and $match < -1) {
2376            !!!cp (1024);
2377          return {type => CHARACTER_TOKEN, data => '&'.$entity_name};          return {type => CHARACTER_TOKEN, data => '&'.$entity_name};
2378        } else {        } else {
2379            !!!cp (1025);
2380          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1};
2381        }        }
2382      } else {      } else {
2383          !!!cp (1026);
2384        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
2385        ## NOTE: "No characters are consumed" in the spec.        ## NOTE: "No characters are consumed" in the spec.
2386        return {type => CHARACTER_TOKEN, data => '&'.$value};        return {type => CHARACTER_TOKEN, data => '&'.$value};
2387      }      }
2388    } else {    } else {
2389        !!!cp (1027);
2390      ## no characters are consumed      ## no characters are consumed
2391      !!!parse-error (type => 'bare ero');      !!!parse-error (type => 'bare ero');
2392      return undef;      return undef;
# Line 2381  sub _construct_tree ($) { Line 2426  sub _construct_tree ($) {
2426        
2427    !!!next-token;    !!!next-token;
2428    
   $self->{insertion_mode} = BEFORE_HEAD_IM;  
2429    undef $self->{form_element};    undef $self->{form_element};
2430    undef $self->{head_element};    undef $self->{head_element};
2431    $self->{open_elements} = [];    $self->{open_elements} = [];
2432    undef $self->{inner_html_node};    undef $self->{inner_html_node};
2433    
2434      ## NOTE: The "initial" insertion mode.
2435    $self->_tree_construction_initial; # MUST    $self->_tree_construction_initial; # MUST
2436    
2437      ## NOTE: The "before html" insertion mode.
2438    $self->_tree_construction_root_element;    $self->_tree_construction_root_element;
2439      $self->{insertion_mode} = BEFORE_HEAD_IM;
2440    
2441      ## NOTE: The "before head" insertion mode and so on.
2442    $self->_tree_construction_main;    $self->_tree_construction_main;
2443  } # _construct_tree  } # _construct_tree
2444    
2445  sub _tree_construction_initial ($) {  sub _tree_construction_initial ($) {
2446    my $self = shift;    my $self = shift;
2447    
2448      ## NOTE: "initial" insertion mode
2449    
2450    INITIAL: {    INITIAL: {
2451      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
2452        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"
# Line 2405  sub _tree_construction_initial ($) { Line 2458  sub _tree_construction_initial ($) {
2458        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
2459            defined $token->{public_identifier} or            defined $token->{public_identifier} or
2460            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
2461            !!!cp ('t1');
2462          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5');
2463        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
2464            !!!cp ('t2');
2465          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)
2466          !!!parse-error (type => 'not HTML5');          !!!parse-error (type => 'not HTML5');
2467          } else {
2468            !!!cp ('t3');
2469        }        }
2470                
2471        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 2422  sub _tree_construction_initial ($) { Line 2479  sub _tree_construction_initial ($) {
2479        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
2480                
2481        if ($token->{quirks} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'HTML') {
2482            !!!cp ('t4');
2483          $self->{document}->manakai_compat_mode ('quirks');          $self->{document}->manakai_compat_mode ('quirks');
2484        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
2485          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
# Line 2500  sub _tree_construction_initial ($) { Line 2558  sub _tree_construction_initial ($) {
2558            "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,            "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,
2559            "HTML" => 1,            "HTML" => 1,
2560          }->{$pubid}) {          }->{$pubid}) {
2561              !!!cp ('t5');
2562            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
2563          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or
2564                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {
2565            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
2566                !!!cp ('t6');
2567              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
2568            } else {            } else {
2569                !!!cp ('t7');
2570              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
2571            }            }
2572          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 Frameset//EN" or          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or
2573                   $pubid eq "-//W3C//DTD XHTML 1.0 Transitional//EN") {                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {
2574              !!!cp ('t8');
2575            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
2576            } else {
2577              !!!cp ('t9');
2578          }          }
2579          } else {
2580            !!!cp ('t10');
2581        }        }
2582        if (defined $token->{system_identifier}) {        if (defined $token->{system_identifier}) {
2583          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
2584          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
2585          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") {
2586              ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"
2587            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
2588              !!!cp ('t11');
2589            } else {
2590              !!!cp ('t12');
2591          }          }
2592          } else {
2593            !!!cp ('t13');
2594        }        }
2595                
2596        ## Go to the root element phase.        ## Go to the "before html" insertion mode.
2597        !!!next-token;        !!!next-token;
2598        return;        return;
2599      } elsif ({      } elsif ({
# Line 2529  sub _tree_construction_initial ($) { Line 2601  sub _tree_construction_initial ($) {
2601                END_TAG_TOKEN, 1,                END_TAG_TOKEN, 1,
2602                END_OF_FILE_TOKEN, 1,                END_OF_FILE_TOKEN, 1,
2603               }->{$token->{type}}) {               }->{$token->{type}}) {
2604          !!!cp ('t14');
2605        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2606        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2607        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2608        ## reprocess        ## reprocess
2609        return;        return;
2610      } elsif ($token->{type} == CHARACTER_TOKEN) {      } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2539  sub _tree_construction_initial ($) { Line 2612  sub _tree_construction_initial ($) {
2612          ## Ignore the token          ## Ignore the token
2613    
2614          unless (length $token->{data}) {          unless (length $token->{data}) {
2615            ## Stay in the phase            !!!cp ('t15');
2616              ## Stay in the insertion mode.
2617            !!!next-token;            !!!next-token;
2618            redo INITIAL;            redo INITIAL;
2619            } else {
2620              !!!cp ('t16');
2621          }          }
2622          } else {
2623            !!!cp ('t17');
2624        }        }
2625    
2626        !!!parse-error (type => 'no DOCTYPE');        !!!parse-error (type => 'no DOCTYPE');
2627        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
2628        ## Go to the root element phase        ## Go to the "before html" insertion mode.
2629        ## reprocess        ## reprocess
2630        return;        return;
2631      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
2632          !!!cp ('t18');
2633        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2634        $self->{document}->append_child ($comment);        $self->{document}->append_child ($comment);
2635                
2636        ## Stay in the phase.        ## Stay in the insertion mode.
2637        !!!next-token;        !!!next-token;
2638        redo INITIAL;        redo INITIAL;
2639      } else {      } else {
2640        die "$0: $token->{type}: Unknown token type";        die "$0: $token->{type}: Unknown token type";
2641      }      }
2642    } # INITIAL    } # INITIAL
2643    
2644      die "$0: _tree_construction_initial: This should be never reached";
2645  } # _tree_construction_initial  } # _tree_construction_initial
2646    
2647  sub _tree_construction_root_element ($) {  sub _tree_construction_root_element ($) {
2648    my $self = shift;    my $self = shift;
2649    
2650      ## NOTE: "before html" insertion mode.
2651        
2652    B: {    B: {
2653        if ($token->{type} == DOCTYPE_TOKEN) {        if ($token->{type} == DOCTYPE_TOKEN) {
2654            !!!cp ('t19');
2655          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
2656          ## Ignore the token          ## Ignore the token
2657          ## Stay in the phase          ## Stay in the insertion mode.
2658          !!!next-token;          !!!next-token;
2659          redo B;          redo B;
2660        } elsif ($token->{type} == COMMENT_TOKEN) {        } elsif ($token->{type} == COMMENT_TOKEN) {
2661            !!!cp ('t20');
2662          my $comment = $self->{document}->create_comment ($token->{data});          my $comment = $self->{document}->create_comment ($token->{data});
2663          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2664          ## Stay in the phase          ## Stay in the insertion mode.
2665          !!!next-token;          !!!next-token;
2666          redo B;          redo B;
2667        } elsif ($token->{type} == CHARACTER_TOKEN) {        } elsif ($token->{type} == CHARACTER_TOKEN) {
# Line 2584  sub _tree_construction_root_element ($) Line 2669  sub _tree_construction_root_element ($)
2669            ## Ignore the token.            ## Ignore the token.
2670    
2671            unless (length $token->{data}) {            unless (length $token->{data}) {
2672              ## Stay in the phase              !!!cp ('t21');
2673                ## Stay in the insertion mode.
2674              !!!next-token;              !!!next-token;
2675              redo B;              redo B;
2676              } else {
2677                !!!cp ('t22');
2678            }            }
2679            } else {
2680              !!!cp ('t23');
2681          }          }
2682    
2683          $self->{application_cache_selection}->(undef);          $self->{application_cache_selection}->(undef);
2684    
2685          #          #
2686        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
2687          if ($token->{tag_name} eq 'html' and          if ($token->{tag_name} eq 'html') {
2688              $token->{attributes}->{manifest}) {            my $root_element;
2689            $self->{application_cache_selection}            !!!create-element ($root_element, $token->{tag_name}, $token->{attributes});
2690                 ->($token->{attributes}->{manifest}->{value});            $self->{document}->append_child ($root_element);
2691            ## ISSUE: No relative reference resolution?            push @{$self->{open_elements}}, [$root_element, 'html'];
2692    
2693              if ($token->{attributes}->{manifest}) {
2694                !!!cp ('t24');
2695                $self->{application_cache_selection}
2696                    ->($token->{attributes}->{manifest}->{value});
2697                ## ISSUE: No relative reference resolution?
2698              } else {
2699                !!!cp ('t25');
2700                $self->{application_cache_selection}->(undef);
2701              }
2702    
2703              !!!next-token;
2704              return; ## Go to the "before head" insertion mode.
2705          } else {          } else {
2706            $self->{application_cache_selection}->(undef);            !!!cp ('t25.1');
2707              #
2708          }          }
   
         ## ISSUE: There is an issue in the spec  
         #  
2709        } elsif ({        } elsif ({
2710                  END_TAG_TOKEN, 1,                  END_TAG_TOKEN, 1,
2711                  END_OF_FILE_TOKEN, 1,                  END_OF_FILE_TOKEN, 1,
2712                 }->{$token->{type}}) {                 }->{$token->{type}}) {
2713          $self->{application_cache_selection}->(undef);          !!!cp ('t26');
   
         ## ISSUE: There is an issue in the spec  
2714          #          #
2715        } else {        } else {
2716          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
2717        }        }
2718    
2719        my $root_element; !!!create-element ($root_element, 'html');      my $root_element; !!!create-element ($root_element, 'html');
2720        $self->{document}->append_child ($root_element);      $self->{document}->append_child ($root_element);
2721        push @{$self->{open_elements}}, [$root_element, 'html'];      push @{$self->{open_elements}}, [$root_element, 'html'];
2722        ## reprocess  
2723        #redo B;      $self->{application_cache_selection}->(undef);
2724        return; ## Go to the main phase.  
2725        ## NOTE: Reprocess the token.
2726        return; ## Go to the "before head" insertion mode.
2727    
2728        ## ISSUE: There is an issue in the spec
2729    } # B    } # B
2730    
2731      die "$0: _tree_construction_root_element: This should never be reached";
2732  } # _tree_construction_root_element  } # _tree_construction_root_element
2733    
2734  sub _reset_insertion_mode ($) {  sub _reset_insertion_mode ($) {
# Line 2648  sub _reset_insertion_mode ($) { Line 2753  sub _reset_insertion_mode ($) {
2753          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
2754            if ($self->{inner_html_node}->[1] eq 'td' or            if ($self->{inner_html_node}->[1] eq 'td' or
2755                $self->{inner_html_node}->[1] eq 'th') {                $self->{inner_html_node}->[1] eq 'th') {
2756                !!!cp ('t27');
2757              #              #
2758            } else {            } else {
2759                !!!cp ('t28');
2760              $node = $self->{inner_html_node};              $node = $self->{inner_html_node};
2761            }            }
2762          }          }
# Line 2658  sub _reset_insertion_mode ($) { Line 2765  sub _reset_insertion_mode ($) {
2765        ## Step 4..13        ## Step 4..13
2766        my $new_mode = {        my $new_mode = {
2767                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
2768                          ## NOTE: |option| and |optgroup| do not set
2769                          ## insertion mode to "in select" by themselves.
2770                        td => IN_CELL_IM,                        td => IN_CELL_IM,
2771                        th => IN_CELL_IM,                        th => IN_CELL_IM,
2772                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
# Line 2676  sub _reset_insertion_mode ($) { Line 2785  sub _reset_insertion_mode ($) {
2785        ## Step 14        ## Step 14
2786        if ($node->[1] eq 'html') {        if ($node->[1] eq 'html') {
2787          unless (defined $self->{head_element}) {          unless (defined $self->{head_element}) {
2788              !!!cp ('t29');
2789            $self->{insertion_mode} = BEFORE_HEAD_IM;            $self->{insertion_mode} = BEFORE_HEAD_IM;
2790          } else {          } else {
2791              ## ISSUE: Can this state be reached?
2792              !!!cp ('t30');
2793            $self->{insertion_mode} = AFTER_HEAD_IM;            $self->{insertion_mode} = AFTER_HEAD_IM;
2794          }          }
2795          return;          return;
2796          } else {
2797            !!!cp ('t31');
2798        }        }
2799                
2800        ## Step 15        ## Step 15
# Line 2693  sub _reset_insertion_mode ($) { Line 2807  sub _reset_insertion_mode ($) {
2807        ## Step 17        ## Step 17
2808        redo S3;        redo S3;
2809      } # S3      } # S3
2810    
2811      die "$0: _reset_insertion_mode: This line should never be reached";
2812  } # _reset_insertion_mode  } # _reset_insertion_mode
2813    
2814  sub _tree_construction_main ($) {  sub _tree_construction_main ($) {
# Line 2714  sub _tree_construction_main ($) { Line 2830  sub _tree_construction_main ($) {
2830      return if $entry->[0] eq '#marker';      return if $entry->[0] eq '#marker';
2831      for (@{$self->{open_elements}}) {      for (@{$self->{open_elements}}) {
2832        if ($entry->[0] eq $_->[0]) {        if ($entry->[0] eq $_->[0]) {
2833            !!!cp ('t32');
2834          return;          return;
2835        }        }
2836      }      }
# Line 2728  sub _tree_construction_main ($) { Line 2845  sub _tree_construction_main ($) {
2845    
2846        ## Step 6        ## Step 6
2847        if ($entry->[0] eq '#marker') {        if ($entry->[0] eq '#marker') {
2848            !!!cp ('t33_1');
2849          #          #
2850        } else {        } else {
2851          my $in_open_elements;          my $in_open_elements;
2852          OE: for (@{$self->{open_elements}}) {          OE: for (@{$self->{open_elements}}) {
2853            if ($entry->[0] eq $_->[0]) {            if ($entry->[0] eq $_->[0]) {
2854                !!!cp ('t33');
2855              $in_open_elements = 1;              $in_open_elements = 1;
2856              last OE;              last OE;
2857            }            }
2858          }          }
2859          if ($in_open_elements) {          if ($in_open_elements) {
2860              !!!cp ('t34');
2861            #            #
2862          } else {          } else {
2863              ## NOTE: <!DOCTYPE HTML><p><b><i><u></p> <p>X
2864              !!!cp ('t35');
2865            redo S4;            redo S4;
2866          }          }
2867        }        }
# Line 2762  sub _tree_construction_main ($) { Line 2884  sub _tree_construction_main ($) {
2884    
2885        ## Step 11        ## Step 11
2886        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {        unless ($clone->[0] eq $active_formatting_elements->[-1]->[0]) {
2887            !!!cp ('t36');
2888          ## Step 7'          ## Step 7'
2889          $i++;          $i++;
2890          $entry = $active_formatting_elements->[$i];          $entry = $active_formatting_elements->[$i];
2891                    
2892          redo S7;          redo S7;
2893        }        }
2894    
2895          !!!cp ('t37');
2896      } # S7      } # S7
2897    }; # $reconstruct_active_formatting_elements    }; # $reconstruct_active_formatting_elements
2898    
2899    my $clear_up_to_marker = sub {    my $clear_up_to_marker = sub {
2900      for (reverse 0..$#$active_formatting_elements) {      for (reverse 0..$#$active_formatting_elements) {
2901        if ($active_formatting_elements->[$_]->[0] eq '#marker') {        if ($active_formatting_elements->[$_]->[0] eq '#marker') {
2902            !!!cp ('t38');
2903          splice @$active_formatting_elements, $_;          splice @$active_formatting_elements, $_;
2904          return;          return;
2905        }        }
2906      }      }
2907    
2908        !!!cp ('t39');
2909    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2910    
2911    my $parse_rcdata = sub ($$) {    my $parse_rcdata = sub ($$) {
# Line 2799  sub _tree_construction_main ($) { Line 2927  sub _tree_construction_main ($) {
2927      my $text = '';      my $text = '';
2928      !!!next-token;      !!!next-token;
2929      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing
2930          !!!cp ('t40');
2931        $text .= $token->{data};        $text .= $token->{data};
2932        !!!next-token;        !!!next-token;
2933      }      }
2934    
2935      ## Step 5      ## Step 5
2936      if (length $text) {      if (length $text) {
2937          !!!cp ('t41');
2938        my $text = $self->{document}->create_text_node ($text);        my $text = $self->{document}->create_text_node ($text);
2939        $el->append_child ($text);        $el->append_child ($text);
2940      }      }
# Line 2813  sub _tree_construction_main ($) { Line 2943  sub _tree_construction_main ($) {
2943      $self->{content_model} = PCDATA_CONTENT_MODEL;      $self->{content_model} = PCDATA_CONTENT_MODEL;
2944    
2945      ## Step 7      ## Step 7
2946      if ($token->{type} == END_TAG_TOKEN and $token->{tag_name} eq $start_tag_name) {      if ($token->{type} == END_TAG_TOKEN and
2947            $token->{tag_name} eq $start_tag_name) {
2948          !!!cp ('t42');
2949        ## Ignore the token        ## Ignore the token
2950      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2951          !!!cp ('t43');
2952        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2953      } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {      } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2954          !!!cp ('t44');
2955        !!!parse-error (type => 'in RCDATA:#'.$token->{type});        !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2956      } else {      } else {
2957        die "$0: $content_model_flag in parse_rcdata";        die "$0: $content_model_flag in parse_rcdata";
# Line 2837  sub _tree_construction_main ($) { Line 2971  sub _tree_construction_main ($) {
2971      my $text = '';      my $text = '';
2972      !!!next-token;      !!!next-token;
2973      while ($token->{type} == CHARACTER_TOKEN) {      while ($token->{type} == CHARACTER_TOKEN) {
2974          !!!cp ('t45');
2975        $text .= $token->{data};        $text .= $token->{data};
2976        !!!next-token;        !!!next-token;
2977      } # stop if non-character token or tokenizer stops tokenising      } # stop if non-character token or tokenizer stops tokenising
2978      if (length $text) {      if (length $text) {
2979          !!!cp ('t46');
2980        $script_el->manakai_append_text ($text);        $script_el->manakai_append_text ($text);
2981      }      }
2982                                
# Line 2848  sub _tree_construction_main ($) { Line 2984  sub _tree_construction_main ($) {
2984    
2985      if ($token->{type} == END_TAG_TOKEN and      if ($token->{type} == END_TAG_TOKEN and
2986          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
2987          !!!cp ('t47');
2988        ## Ignore the token        ## Ignore the token
2989      } else {      } else {
2990          !!!cp ('t48');
2991        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2992        ## ISSUE: And ignore?        ## ISSUE: And ignore?
2993        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
2994      }      }
2995            
2996      if (defined $self->{inner_html_node}) {      if (defined $self->{inner_html_node}) {
2997          !!!cp ('t49');
2998        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
2999      } else {      } else {
3000          !!!cp ('t50');
3001        ## TODO: $old_insertion_point = current insertion point        ## TODO: $old_insertion_point = current insertion point
3002        ## TODO: insertion point = just before the next input character        ## TODO: insertion point = just before the next input character
3003    
# Line 2880  sub _tree_construction_main ($) { Line 3020  sub _tree_construction_main ($) {
3020        my $formatting_element_i_in_active;        my $formatting_element_i_in_active;
3021        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
3022          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {
3023              !!!cp ('t51');
3024            $formatting_element = $active_formatting_elements->[$_];            $formatting_element = $active_formatting_elements->[$_];
3025            $formatting_element_i_in_active = $_;            $formatting_element_i_in_active = $_;
3026            last AFE;            last AFE;
3027          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {          } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {
3028              !!!cp ('t52');
3029            last AFE;            last AFE;
3030          }          }
3031        } # AFE        } # AFE
3032        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3033            !!!cp ('t53');
3034          !!!parse-error (type => 'unmatched end tag:'.$tag_name);          !!!parse-error (type => 'unmatched end tag:'.$tag_name);
3035          ## Ignore the token          ## Ignore the token
3036          !!!next-token;          !!!next-token;
# Line 2900  sub _tree_construction_main ($) { Line 3043  sub _tree_construction_main ($) {
3043          my $node = $self->{open_elements}->[$_];          my $node = $self->{open_elements}->[$_];
3044          if ($node->[0] eq $formatting_element->[0]) {          if ($node->[0] eq $formatting_element->[0]) {
3045            if ($in_scope) {            if ($in_scope) {
3046                !!!cp ('t54');
3047              $formatting_element_i_in_open = $_;              $formatting_element_i_in_open = $_;
3048              last INSCOPE;              last INSCOPE;
3049            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3050                !!!cp ('t55');
3051              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3052              ## Ignore the token              ## Ignore the token
3053              !!!next-token;              !!!next-token;
# Line 2912  sub _tree_construction_main ($) { Line 3057  sub _tree_construction_main ($) {
3057                    table => 1, caption => 1, td => 1, th => 1,                    table => 1, caption => 1, td => 1, th => 1,
3058                    button => 1, marquee => 1, object => 1, html => 1,                    button => 1, marquee => 1, object => 1, html => 1,
3059                   }->{$node->[1]}) {                   }->{$node->[1]}) {
3060              !!!cp ('t56');
3061            $in_scope = 0;            $in_scope = 0;
3062          }          }
3063        } # INSCOPE        } # INSCOPE
3064        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3065            !!!cp ('t57');
3066          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3067          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3068          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
3069          return;          return;
3070        }        }
3071        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3072            !!!cp ('t58');
3073          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3074        }        }
3075                
# Line 2934  sub _tree_construction_main ($) { Line 3082  sub _tree_construction_main ($) {
3082              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3083              ($special_category->{$node->[1]} or              ($special_category->{$node->[1]} or
3084               $scoping_category->{$node->[1]})) {               $scoping_category->{$node->[1]})) {
3085              !!!cp ('t59');
3086            $furthest_block = $node;            $furthest_block = $node;
3087            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
3088          } elsif ($node->[0] eq $formatting_element->[0]) {          } elsif ($node->[0] eq $formatting_element->[0]) {
3089              !!!cp ('t60');
3090            last OE;            last OE;
3091          }          }
3092        } # OE        } # OE
3093                
3094        ## Step 3        ## Step 3
3095        unless (defined $furthest_block) { # MUST        unless (defined $furthest_block) { # MUST
3096            !!!cp ('t61');
3097          splice @{$self->{open_elements}}, $formatting_element_i_in_open;          splice @{$self->{open_elements}}, $formatting_element_i_in_open;
3098          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;          splice @$active_formatting_elements, $formatting_element_i_in_active, 1;
3099          !!!next-token;          !!!next-token;
# Line 2955  sub _tree_construction_main ($) { Line 3106  sub _tree_construction_main ($) {
3106        ## Step 5        ## Step 5
3107        my $furthest_block_parent = $furthest_block->[0]->parent_node;        my $furthest_block_parent = $furthest_block->[0]->parent_node;
3108        if (defined $furthest_block_parent) {        if (defined $furthest_block_parent) {
3109            !!!cp ('t62');
3110          $furthest_block_parent->remove_child ($furthest_block->[0]);          $furthest_block_parent->remove_child ($furthest_block->[0]);
3111        }        }
3112                
# Line 2977  sub _tree_construction_main ($) { Line 3129  sub _tree_construction_main ($) {
3129          S7S2: {          S7S2: {
3130            for (reverse 0..$#$active_formatting_elements) {            for (reverse 0..$#$active_formatting_elements) {
3131              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {              if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
3132                  !!!cp ('t63');
3133                $node_i_in_active = $_;                $node_i_in_active = $_;
3134                last S7S2;                last S7S2;
3135              }              }
# Line 2990  sub _tree_construction_main ($) { Line 3143  sub _tree_construction_main ($) {
3143                    
3144          ## Step 4          ## Step 4
3145          if ($last_node->[0] eq $furthest_block->[0]) {          if ($last_node->[0] eq $furthest_block->[0]) {
3146              !!!cp ('t64');
3147            $bookmark_prev_el = $node->[0];            $bookmark_prev_el = $node->[0];
3148          }          }
3149                    
3150          ## Step 5          ## Step 5
3151          if ($node->[0]->has_child_nodes ()) {          if ($node->[0]->has_child_nodes ()) {
3152              !!!cp ('t65');
3153            my $clone = [$node->[0]->clone_node (0), $node->[1]];            my $clone = [$node->[0]->clone_node (0), $node->[1]];
3154            $active_formatting_elements->[$node_i_in_active] = $clone;            $active_formatting_elements->[$node_i_in_active] = $clone;
3155            $self->{open_elements}->[$node_i_in_open] = $clone;            $self->{open_elements}->[$node_i_in_open] = $clone;
# Line 3029  sub _tree_construction_main ($) { Line 3184  sub _tree_construction_main ($) {
3184        my $i;        my $i;
3185        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
3186          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {          if ($active_formatting_elements->[$_]->[0] eq $formatting_element->[0]) {
3187              !!!cp ('t66');
3188            splice @$active_formatting_elements, $_, 1;            splice @$active_formatting_elements, $_, 1;
3189            $i-- and last AFE if defined $i;            $i-- and last AFE if defined $i;
3190          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {          } elsif ($active_formatting_elements->[$_]->[0] eq $bookmark_prev_el) {
3191              !!!cp ('t67');
3192            $i = $_;            $i = $_;
3193          }          }
3194        } # AFE        } # AFE
# Line 3041  sub _tree_construction_main ($) { Line 3198  sub _tree_construction_main ($) {
3198        undef $i;        undef $i;
3199        OE: for (reverse 0..$#{$self->{open_elements}}) {        OE: for (reverse 0..$#{$self->{open_elements}}) {
3200          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {          if ($self->{open_elements}->[$_]->[0] eq $formatting_element->[0]) {
3201              !!!cp ('t68');
3202            splice @{$self->{open_elements}}, $_, 1;            splice @{$self->{open_elements}}, $_, 1;
3203            $i-- and last OE if defined $i;            $i-- and last OE if defined $i;
3204          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {          } elsif ($self->{open_elements}->[$_]->[0] eq $furthest_block->[0]) {
3205              !!!cp ('t69');
3206            $i = $_;            $i = $_;
3207          }          }
3208        } # OE        } # OE
# Line 3071  sub _tree_construction_main ($) { Line 3230  sub _tree_construction_main ($) {
3230                             if ($self->{open_elements}->[$_]->[1] eq 'table') {                             if ($self->{open_elements}->[$_]->[1] eq 'table') {
3231                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3232                               if (defined $parent and $parent->node_type == 1) {                               if (defined $parent and $parent->node_type == 1) {
3233                                   !!!cp ('t70');
3234                                 $foster_parent_element = $parent;                                 $foster_parent_element = $parent;
3235                                 $next_sibling = $self->{open_elements}->[$_]->[0];                                 $next_sibling = $self->{open_elements}->[$_]->[0];
3236                               } else {                               } else {
3237                                   !!!cp ('t71');
3238                                 $foster_parent_element                                 $foster_parent_element
3239                                   = $self->{open_elements}->[$_ - 1]->[0];                                   = $self->{open_elements}->[$_ - 1]->[0];
3240                               }                               }
# Line 3085  sub _tree_construction_main ($) { Line 3246  sub _tree_construction_main ($) {
3246                           $foster_parent_element->insert_before                           $foster_parent_element->insert_before
3247                             ($child, $next_sibling);                             ($child, $next_sibling);
3248                         } else {                         } else {
3249                             !!!cp ('t72');
3250                           $self->{open_elements}->[-1]->[0]->append_child ($child);                           $self->{open_elements}->[-1]->[0]->append_child ($child);
3251                         }                         }
3252    }; # $insert_to_foster    }; # $insert_to_foster
# Line 3093  sub _tree_construction_main ($) { Line 3255  sub _tree_construction_main ($) {
3255    
3256    B: {    B: {
3257      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3258          !!!cp ('t73');
3259        !!!parse-error (type => 'DOCTYPE in the middle');        !!!parse-error (type => 'DOCTYPE in the middle');
3260        ## Ignore the token        ## Ignore the token
3261        ## Stay in the phase        ## Stay in the phase
# Line 3100  sub _tree_construction_main ($) { Line 3263  sub _tree_construction_main ($) {
3263        redo B;        redo B;
3264      } elsif ($token->{type} == END_OF_FILE_TOKEN) {      } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3265        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3266            !!!cp ('t74');
3267          #          #
3268        } else {        } else {
3269          ## Generate implied end tags          ## Generate implied end tags
# Line 3107  sub _tree_construction_main ($) { Line 3271  sub _tree_construction_main ($) {
3271               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,
3272               tbody => 1, tfoot=> 1, thead => 1,               tbody => 1, tfoot=> 1, thead => 1,
3273              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
3274              !!!cp ('t75');
3275            !!!back-token;            !!!back-token;
3276            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => END_TAG_TOKEN, tag_name => $self->{open_elements}->[-1]->[1]};
3277            redo B;            redo B;
# Line 3114  sub _tree_construction_main ($) { Line 3279  sub _tree_construction_main ($) {
3279                    
3280          if (@{$self->{open_elements}} > 2 or          if (@{$self->{open_elements}} > 2 or
3281              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {              (@{$self->{open_elements}} == 2 and $self->{open_elements}->[1]->[1] ne 'body')) {
3282              !!!cp ('t76');
3283            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3284          } elsif (defined $self->{inner_html_node} and          } elsif (defined $self->{inner_html_node} and
3285                   @{$self->{open_elements}} > 1 and                   @{$self->{open_elements}} > 1 and
3286                   $self->{open_elements}->[1]->[1] ne 'body') {                   $self->{open_elements}->[1]->[1] ne 'body') {
3287    ## ISSUE: This case is never reached.
3288              !!!cp ('t77');
3289            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3290            } else {
3291              !!!cp ('t78');
3292          }          }
3293    
3294          ## ISSUE: There is an issue in the spec.          ## ISSUE: There is an issue in the spec.
# Line 3129  sub _tree_construction_main ($) { Line 3299  sub _tree_construction_main ($) {
3299      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3300               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3301        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
3302          ## Turn into the main phase          !!!cp ('t79');
3303          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3304          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
3305        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
3306          ## Turn into the main phase          !!!cp ('t80');
3307          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
3308          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
3309          } else {
3310            !!!cp ('t81');
3311        }        }
3312    
3313  ## ISSUE: "aa<html>" is not a parse error.        !!!cp ('t82');
3314  ## ISSUE: "<html>" in fragment is not a parse error.        !!!parse-error (type => 'not first start tag');
       unless ($token->{first_start_tag}) {  
         !!!parse-error (type => 'not first start tag');  
       }  
3315        my $top_el = $self->{open_elements}->[0]->[0];        my $top_el = $self->{open_elements}->[0]->[0];
3316        for my $attr_name (keys %{$token->{attributes}}) {        for my $attr_name (keys %{$token->{attributes}}) {
3317          unless ($top_el->has_attribute_ns (undef, $attr_name)) {          unless ($top_el->has_attribute_ns (undef, $attr_name)) {
3318              !!!cp ('t84');
3319            $top_el->set_attribute_ns            $top_el->set_attribute_ns
3320              (undef, [undef, $attr_name],              (undef, [undef, $attr_name],
3321               $token->{attributes}->{$attr_name}->{value});               $token->{attributes}->{$attr_name}->{value});
# Line 3156  sub _tree_construction_main ($) { Line 3326  sub _tree_construction_main ($) {
3326      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
3327        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
3328        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
3329            !!!cp ('t85');
3330          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
3331        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {        } elsif ($self->{insertion_mode} == AFTER_BODY_IM) {
3332            !!!cp ('t86');
3333          $self->{open_elements}->[0]->[0]->append_child ($comment);          $self->{open_elements}->[0]->[0]->append_child ($comment);
3334        } else {        } else {
3335            !!!cp ('t87');
3336          $self->{open_elements}->[-1]->[0]->append_child ($comment);          $self->{open_elements}->[-1]->[0]->append_child ($comment);
3337        }        }
3338        !!!next-token;        !!!next-token;
# Line 3169  sub _tree_construction_main ($) { Line 3342  sub _tree_construction_main ($) {
3342          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3343            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3344            unless (length $token->{data}) {            unless (length $token->{data}) {
3345                !!!cp ('t88');
3346              !!!next-token;              !!!next-token;
3347              redo B;              redo B;
3348            }            }
3349          }          }
3350    
3351          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3352              !!!cp ('t89');
3353            ## As if <head>            ## As if <head>
3354            !!!create-element ($self->{head_element}, 'head');            !!!create-element ($self->{head_element}, 'head');
3355            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3185  sub _tree_construction_main ($) { Line 3360  sub _tree_construction_main ($) {
3360    
3361            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3362          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3363              !!!cp ('t90');
3364            ## As if </noscript>            ## As if </noscript>
3365            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3366            !!!parse-error (type => 'in noscript:#character');            !!!parse-error (type => 'in noscript:#character');
# Line 3195  sub _tree_construction_main ($) { Line 3371  sub _tree_construction_main ($) {
3371    
3372            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3373          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {          } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3374              !!!cp ('t91');
3375            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
3376    
3377            ## Reprocess in the "after head" insertion mode...            ## Reprocess in the "after head" insertion mode...
3378            } else {
3379              !!!cp ('t92');
3380          }          }
3381    
3382              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3209  sub _tree_construction_main ($) { Line 3388  sub _tree_construction_main ($) {
3388            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
3389              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3390                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3391                    !!!cp ('t93');
3392                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});
3393                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
3394                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];
# Line 3216  sub _tree_construction_main ($) { Line 3396  sub _tree_construction_main ($) {
3396                  !!!next-token;                  !!!next-token;
3397                  redo B;                  redo B;
3398                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3399                    !!!cp ('t94');
3400                  #                  #
3401                } else {                } else {
3402                    !!!cp ('t95');
3403                  !!!parse-error (type => 'in head:head'); # or in head noscript                  !!!parse-error (type => 'in head:head'); # or in head noscript
3404                  ## Ignore the token                  ## Ignore the token
3405                  !!!next-token;                  !!!next-token;
3406                  redo B;                  redo B;
3407                }                }
3408              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3409                  !!!cp ('t96');
3410                ## As if <head>                ## As if <head>
3411                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3412                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3231  sub _tree_construction_main ($) { Line 3414  sub _tree_construction_main ($) {
3414    
3415                $self->{insertion_mode} = IN_HEAD_IM;                $self->{insertion_mode} = IN_HEAD_IM;
3416                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
3417                } else {
3418                  !!!cp ('t97');
3419              }              }
3420    
3421              if ($token->{tag_name} eq 'base') {              if ($token->{tag_name} eq 'base') {
3422                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3423                    !!!cp ('t98');
3424                  ## As if </noscript>                  ## As if </noscript>
3425                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3426                  !!!parse-error (type => 'in noscript:base');                  !!!parse-error (type => 'in noscript:base');
3427                                
3428                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3429                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3430                  } else {
3431                    !!!cp ('t99');
3432                }                }
3433    
3434                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3435                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3436                    !!!cp ('t100');
3437                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3438                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3439                  } else {
3440                    !!!cp ('t101');
3441                }                }
3442                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3443                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 3257  sub _tree_construction_main ($) { Line 3448  sub _tree_construction_main ($) {
3448              } elsif ($token->{tag_name} eq 'link') {              } elsif ($token->{tag_name} eq 'link') {
3449                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3450                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3451                    !!!cp ('t102');
3452                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3453                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3454                  } else {
3455                    !!!cp ('t103');
3456                }                }
3457                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3458                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 3269  sub _tree_construction_main ($) { Line 3463  sub _tree_construction_main ($) {
3463              } elsif ($token->{tag_name} eq 'meta') {              } elsif ($token->{tag_name} eq 'meta') {
3464                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3465                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3466                    !!!cp ('t104');
3467                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3468                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3469                  } else {
3470                    !!!cp ('t105');
3471                }                }
3472                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3473                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.
3474    
3475                unless ($self->{confident}) {                unless ($self->{confident}) {
3476                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) { ## TODO: And if supported
3477                      !!!cp ('t106');
3478                    $self->{change_encoding}                    $self->{change_encoding}
3479                        ->($self, $token->{attributes}->{charset}->{value});                        ->($self, $token->{attributes}->{charset}->{value});
3480                                        
# Line 3291  sub _tree_construction_main ($) { Line 3489  sub _tree_construction_main ($) {
3489                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
3490                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
3491                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
3492                        !!!cp ('t107');
3493                      $self->{change_encoding}                      $self->{change_encoding}
3494                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
3495                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3496                          ->set_user_data (manakai_has_reference =>                          ->set_user_data (manakai_has_reference =>
3497                                               $token->{attributes}->{content}                                               $token->{attributes}->{content}
3498                                                     ->{has_reference});                                                     ->{has_reference});
3499                      } else {
3500                        !!!cp ('t108');
3501                    }                    }
3502                  }                  }
3503                } else {                } else {
3504                  if ($token->{attributes}->{charset}) {                  if ($token->{attributes}->{charset}) {
3505                      !!!cp ('t109');
3506                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
3507                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3508                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
3509                                                 ->{has_reference});                                                 ->{has_reference});
3510                  }                  }
3511                  if ($token->{attributes}->{content}) {                  if ($token->{attributes}->{content}) {
3512                      !!!cp ('t110');
3513                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')                    $meta_el->[0]->get_attribute_node_ns (undef, 'content')
3514                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
3515                                             $token->{attributes}->{content}                                             $token->{attributes}->{content}
# Line 3320  sub _tree_construction_main ($) { Line 3523  sub _tree_construction_main ($) {
3523                redo B;                redo B;
3524              } elsif ($token->{tag_name} eq 'title') {              } elsif ($token->{tag_name} eq 'title') {
3525                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3526                    !!!cp ('t111');
3527                  ## As if </noscript>                  ## As if </noscript>
3528                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3529                  !!!parse-error (type => 'in noscript:title');                  !!!parse-error (type => 'in noscript:title');
# Line 3327  sub _tree_construction_main ($) { Line 3531  sub _tree_construction_main ($) {
3531                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3532                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3533                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3534                    !!!cp ('t112');
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 ('t113');
3539                }                }
3540    
3541                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 3344  sub _tree_construction_main ($) { Line 3551  sub _tree_construction_main ($) {
3551                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
3552                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3553                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3554                    !!!cp ('t114');
3555                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3556                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3557                  } else {
3558                    !!!cp ('t115');
3559                }                }
3560                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
3561                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
# Line 3353  sub _tree_construction_main ($) { Line 3563  sub _tree_construction_main ($) {
3563                redo B;                redo B;
3564              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3565                if ($self->{insertion_mode} == IN_HEAD_IM) {                if ($self->{insertion_mode} == IN_HEAD_IM) {
3566                    !!!cp ('t116');
3567                  ## NOTE: and scripting is disalbed                  ## NOTE: and scripting is disalbed
3568                  !!!insert-element ($token->{tag_name}, $token->{attributes});                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3569                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;
3570                  !!!next-token;                  !!!next-token;
3571                  redo B;                  redo B;
3572                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3573                    !!!cp ('t117');
3574                  !!!parse-error (type => 'in noscript:noscript');                  !!!parse-error (type => 'in noscript:noscript');
3575                  ## Ignore the token                  ## Ignore the token
3576                  !!!next-token;                  !!!next-token;
3577                  redo B;                  redo B;
3578                } else {                } else {
3579                    !!!cp ('t118');
3580                  #                  #
3581                }                }
3582              } elsif ($token->{tag_name} eq 'script') {              } elsif ($token->{tag_name} eq 'script') {
3583                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3584                    !!!cp ('t119');
3585                  ## As if </noscript>                  ## As if </noscript>
3586                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3587                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:script');
# Line 3375  sub _tree_construction_main ($) { Line 3589  sub _tree_construction_main ($) {
3589                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3590                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3591                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3592                    !!!cp ('t120');
3593                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3594                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3595                  } else {
3596                    !!!cp ('t121');
3597                }                }
3598    
3599                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 3387  sub _tree_construction_main ($) { Line 3604  sub _tree_construction_main ($) {
3604              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
3605                       $token->{tag_name} eq 'frameset') {                       $token->{tag_name} eq 'frameset') {
3606                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3607                    !!!cp ('t122');
3608                  ## As if </noscript>                  ## As if </noscript>
3609                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3610                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});                  !!!parse-error (type => 'in noscript:'.$token->{tag_name});
# Line 3397  sub _tree_construction_main ($) { Line 3615  sub _tree_construction_main ($) {
3615                                    
3616                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3617                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3618                    !!!cp ('t124');
3619                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3620                                    
3621                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
3622                  } else {
3623                    !!!cp ('t125');
3624                }                }
3625    
3626                ## "after head" insertion mode                ## "after head" insertion mode
3627                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3628                if ($token->{tag_name} eq 'body') {                if ($token->{tag_name} eq 'body') {
3629                    !!!cp ('t126');
3630                  $self->{insertion_mode} = IN_BODY_IM;                  $self->{insertion_mode} = IN_BODY_IM;
3631                } elsif ($token->{tag_name} eq 'frameset') {                } elsif ($token->{tag_name} eq 'frameset') {
3632                    !!!cp ('t127');
3633                  $self->{insertion_mode} = IN_FRAMESET_IM;                  $self->{insertion_mode} = IN_FRAMESET_IM;
3634                } else {                } else {
3635                  die "$0: tag name: $self->{tag_name}";                  die "$0: tag name: $self->{tag_name}";
# Line 3414  sub _tree_construction_main ($) { Line 3637  sub _tree_construction_main ($) {
3637                !!!next-token;                !!!next-token;
3638                redo B;                redo B;
3639              } else {              } else {
3640                  !!!cp ('t128');
3641                #                #
3642              }              }
3643    
3644              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3645                  !!!cp ('t129');
3646                ## As if </noscript>                ## As if </noscript>
3647                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3648                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3428  sub _tree_construction_main ($) { Line 3653  sub _tree_construction_main ($) {
3653    
3654                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3655              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3656                  !!!cp ('t130');
3657                ## As if </head>                ## As if </head>
3658                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3659    
3660                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3661                } else {
3662                  !!!cp ('t131');
3663              }              }
3664    
3665              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3443  sub _tree_construction_main ($) { Line 3671  sub _tree_construction_main ($) {
3671            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
3672              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
3673                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3674                    !!!cp ('t132');
3675                  ## As if <head>                  ## As if <head>
3676                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3677                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3454  sub _tree_construction_main ($) { Line 3683  sub _tree_construction_main ($) {
3683                  !!!next-token;                  !!!next-token;
3684                  redo B;                  redo B;
3685                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3686                    !!!cp ('t133');
3687                  ## As if </noscript>                  ## As if </noscript>
3688                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3689                  !!!parse-error (type => 'in noscript:script');                  !!!parse-error (type => 'in noscript:/head');
3690                                    
3691                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3692                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 3464  sub _tree_construction_main ($) { Line 3694  sub _tree_construction_main ($) {
3694                  !!!next-token;                  !!!next-token;
3695                  redo B;                  redo B;
3696                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3697                    !!!cp ('t134');
3698                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3699                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
3700                  !!!next-token;                  !!!next-token;
3701                  redo B;                  redo B;
3702                } else {                } else {
3703                    !!!cp ('t135');
3704                  #                  #
3705                }                }
3706              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
3707                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3708                    !!!cp ('t136');
3709                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3710                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3711                  !!!next-token;                  !!!next-token;
3712                  redo B;                  redo B;
3713                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3714                    !!!cp ('t137');
3715                  !!!parse-error (type => 'unmatched end tag:noscript');                  !!!parse-error (type => 'unmatched end tag:noscript');
3716                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
3717                  !!!next-token;                  !!!next-token;
3718                  redo B;                  redo B;
3719                } else {                } else {
3720                    !!!cp ('t138');
3721                  #                  #
3722                }                }
3723              } elsif ({              } elsif ({
3724                        body => 1, html => 1,                        body => 1, html => 1,
3725                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3726                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3727                    !!!cp ('t139');
3728                  ## As if <head>                  ## As if <head>
3729                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3730                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3497  sub _tree_construction_main ($) { Line 3733  sub _tree_construction_main ($) {
3733                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3734                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3735                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3736                    !!!cp ('t140');
3737                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3738                  ## Ignore the token                  ## Ignore the token
3739                  !!!next-token;                  !!!next-token;
3740                  redo B;                  redo B;
3741                  } else {
3742                    !!!cp ('t141');
3743                }                }
3744                                
3745                #                #
# Line 3508  sub _tree_construction_main ($) { Line 3747  sub _tree_construction_main ($) {
3747                        p => 1, br => 1,                        p => 1, br => 1,
3748                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3749                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3750                    !!!cp ('t142');
3751                  ## As if <head>                  ## As if <head>
3752                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, 'head');
3753                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3515  sub _tree_construction_main ($) { Line 3755  sub _tree_construction_main ($) {
3755    
3756                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
3757                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
3758                  } else {
3759                    !!!cp ('t143');
3760                }                }
3761    
3762                #                #
3763              } else {              } else {
3764                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
3765                    !!!cp ('t144');
3766                  #                  #
3767                } else {                } else {
3768                    !!!cp ('t145');
3769                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3770                  ## Ignore the token                  ## Ignore the token
3771                  !!!next-token;                  !!!next-token;
# Line 3530  sub _tree_construction_main ($) { Line 3774  sub _tree_construction_main ($) {
3774              }              }
3775    
3776              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
3777                  !!!cp ('t146');
3778                ## As if </noscript>                ## As if </noscript>
3779                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3780                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
# Line 3540  sub _tree_construction_main ($) { Line 3785  sub _tree_construction_main ($) {
3785    
3786                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3787              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {              } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
3788                  !!!cp ('t147');
3789                ## As if </head>                ## As if </head>
3790                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3791    
3792                ## Reprocess in the "after head" insertion mode...                ## Reprocess in the "after head" insertion mode...
3793              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3794    ## ISSUE: This case cannot be reached?
3795                  !!!cp ('t148');
3796                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3797                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
3798                !!!next-token;                !!!next-token;
3799                redo B;                redo B;
3800                } else {
3801                  !!!cp ('t149');
3802              }              }
3803    
3804              ## "after head" insertion mode              ## "after head" insertion mode
# Line 3564  sub _tree_construction_main ($) { Line 3814  sub _tree_construction_main ($) {
3814            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3815      } elsif ($self->{insertion_mode} & BODY_IMS) {      } elsif ($self->{insertion_mode} & BODY_IMS) {
3816            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
3817                !!!cp ('t150');
3818              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
3819              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
3820                            
# Line 3582  sub _tree_construction_main ($) { Line 3833  sub _tree_construction_main ($) {
3833                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3834                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3835                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {
3836                        !!!cp ('t151');
3837                      $tn = $node->[1];                      $tn = $node->[1];
3838                      last INSCOPE;                      last INSCOPE;
3839                    } elsif ({                    } elsif ({
3840                              table => 1, html => 1,                              table => 1, html => 1,
3841                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3842                        !!!cp ('t152');
3843                      last INSCOPE;                      last INSCOPE;
3844                    }                    }
3845                  } # INSCOPE                  } # INSCOPE
3846                    unless (defined $tn) {                    unless (defined $tn) {
3847                        !!!cp ('t153');
3848    ## TODO: This error type is wrong.
3849                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3850                      ## Ignore the token                      ## Ignore the token
3851                      !!!next-token;                      !!!next-token;
3852                      redo B;                      redo B;
3853                    }                    }
3854                                    
3855                    !!!cp ('t154');
3856                  ## Close the cell                  ## Close the cell
3857                  !!!back-token; # <?>                  !!!back-token; # <?>
3858                  $token = {type => END_TAG_TOKEN, tag_name => $tn};                  $token = {type => END_TAG_TOKEN, tag_name => $tn};
# Line 3610  sub _tree_construction_main ($) { Line 3866  sub _tree_construction_main ($) {
3866                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3867                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3868                    if ($node->[1] eq 'caption') {                    if ($node->[1] eq 'caption') {
3869                        !!!cp ('t155');
3870                      $i = $_;                      $i = $_;
3871                      last INSCOPE;                      last INSCOPE;
3872                    } elsif ({                    } elsif ({
3873                              table => 1, html => 1,                              table => 1, html => 1,
3874                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3875                        !!!cp ('t156');
3876                      last INSCOPE;                      last INSCOPE;
3877                    }                    }
3878                  } # INSCOPE                  } # INSCOPE
3879                    unless (defined $i) {                    unless (defined $i) {
3880                        !!!cp ('t157');
3881    ## TODO: this type is wrong.
3882                      !!!parse-error (type => 'unmatched end tag:caption');                      !!!parse-error (type => 'unmatched end tag:caption');
3883                      ## Ignore the token                      ## Ignore the token
3884                      !!!next-token;                      !!!next-token;
# Line 3628  sub _tree_construction_main ($) { Line 3888  sub _tree_construction_main ($) {
3888                  ## generate implied end tags                  ## generate implied end tags
3889                  if ({                  if ({
3890                       dd => 1, dt => 1, li => 1, p => 1,                       dd => 1, dt => 1, li => 1, p => 1,
3891    
3892                         ## NOTE: Maybe the following elements never appear here.
3893                       td => 1, th => 1, tr => 1,                       td => 1, th => 1, tr => 1,
3894                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
3895                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3896                      !!!cp ('t158');
3897                    !!!back-token; # <?>                    !!!back-token; # <?>
3898                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};                    $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
3899                    !!!back-token;                    !!!back-token;
# Line 3640  sub _tree_construction_main ($) { Line 3903  sub _tree_construction_main ($) {
3903                  }                  }
3904    
3905                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3906                      !!!cp ('t159');
3907                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3908                    } else {
3909                      !!!cp ('t160');
3910                  }                  }
3911                                    
3912                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3652  sub _tree_construction_main ($) { Line 3918  sub _tree_construction_main ($) {
3918                  ## reprocess                  ## reprocess
3919                  redo B;                  redo B;
3920                } else {                } else {
3921                    !!!cp ('t161');
3922                  #                  #
3923                }                }
3924              } else {              } else {
3925                  !!!cp ('t162');
3926                #                #
3927              }              }
3928            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
# Line 3665  sub _tree_construction_main ($) { Line 3933  sub _tree_construction_main ($) {
3933                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3934                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
3935                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
3936                        !!!cp ('t163');
3937                      $i = $_;                      $i = $_;
3938                      last INSCOPE;                      last INSCOPE;
3939                    } elsif ({                    } elsif ({
3940                              table => 1, html => 1,                              table => 1, html => 1,
3941                             }->{$node->[1]}) {                             }->{$node->[1]}) {
3942                        !!!cp ('t164');
3943                      last INSCOPE;                      last INSCOPE;
3944                    }                    }
3945                  } # INSCOPE                  } # INSCOPE
3946                    unless (defined $i) {                    unless (defined $i) {
3947                        !!!cp ('t165');
3948                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3949                      ## Ignore the token                      ## Ignore the token
3950                      !!!next-token;                      !!!next-token;
# Line 3685  sub _tree_construction_main ($) { Line 3956  sub _tree_construction_main ($) {
3956                       dd => 1, dt => 1, li => 1, p => 1,                       dd => 1, dt => 1, li => 1, p => 1,
3957                       td => ($token->{tag_name} eq 'th'),                       td => ($token->{tag_name} eq 'th'),
3958                       th => ($token->{tag_name} eq 'td'),                       th => ($token->{tag_name} eq 'td'),
3959    
3960                         ## NOTE: Maybe the following elements never appear here.
3961                       tr => 1,                       tr => 1,
3962                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
3963                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
3964                      !!!cp ('t166');
3965                    !!!back-token;                    !!!back-token;
3966                    $token = {type => END_TAG_TOKEN,                    $token = {type => END_TAG_TOKEN,
3967                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 3695  sub _tree_construction_main ($) { Line 3969  sub _tree_construction_main ($) {
3969                  }                  }
3970                                    
3971                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3972                      !!!cp ('t167');
3973                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3974                    } else {
3975                      !!!cp ('t168');
3976                  }                  }
3977                                    
3978                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3707  sub _tree_construction_main ($) { Line 3984  sub _tree_construction_main ($) {
3984                  !!!next-token;                  !!!next-token;
3985                  redo B;                  redo B;
3986                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
3987                    !!!cp ('t169');
3988                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3989                  ## Ignore the token                  ## Ignore the token
3990                  !!!next-token;                  !!!next-token;
3991                  redo B;                  redo B;
3992                } else {                } else {
3993                    !!!cp ('t170');
3994                  #                  #
3995                }                }
3996              } elsif ($token->{tag_name} eq 'caption') {              } elsif ($token->{tag_name} eq 'caption') {
# Line 3721  sub _tree_construction_main ($) { Line 4000  sub _tree_construction_main ($) {
4000                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4001                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4002                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
4003                        !!!cp ('t171');
4004                      $i = $_;                      $i = $_;
4005                      last INSCOPE;                      last INSCOPE;
4006                    } elsif ({                    } elsif ({
4007                              table => 1, html => 1,                              table => 1, html => 1,
4008                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4009                        !!!cp ('t172');
4010                      last INSCOPE;                      last INSCOPE;
4011                    }                    }
4012                  } # INSCOPE                  } # INSCOPE
4013                    unless (defined $i) {                    unless (defined $i) {
4014                        !!!cp ('t173');
4015                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4016                      ## Ignore the token                      ## Ignore the token
4017                      !!!next-token;                      !!!next-token;
# Line 3739  sub _tree_construction_main ($) { Line 4021  sub _tree_construction_main ($) {
4021                  ## generate implied end tags                  ## generate implied end tags
4022                  if ({                  if ({
4023                       dd => 1, dt => 1, li => 1, p => 1,                       dd => 1, dt => 1, li => 1, p => 1,
4024    
4025                         ## NOTE: The following elements never appear here, maybe.
4026                       td => 1, th => 1, tr => 1,                       td => 1, th => 1, tr => 1,
4027                       tbody => 1, tfoot=> 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
4028                      }->{$self->{open_elements}->[-1]->[1]}) {                      }->{$self->{open_elements}->[-1]->[1]}) {
4029                      !!!cp ('t174');
4030                    !!!back-token;                    !!!back-token;
4031                    $token = {type => END_TAG_TOKEN,                    $token = {type => END_TAG_TOKEN,
4032                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 3749  sub _tree_construction_main ($) { Line 4034  sub _tree_construction_main ($) {
4034                  }                  }
4035                                    
4036                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4037                      !!!cp ('t175');
4038                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4039                    } else {
4040                      !!!cp ('t176');
4041                  }                  }
4042                                    
4043                  splice @{$self->{open_elements}}, $i;                  splice @{$self->{open_elements}}, $i;
# Line 3761  sub _tree_construction_main ($) { Line 4049  sub _tree_construction_main ($) {
4049                  !!!next-token;                  !!!next-token;
4050                  redo B;                  redo B;
4051                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
4052                    !!!cp ('t177');
4053                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4054                  ## Ignore the token                  ## Ignore the token
4055                  !!!next-token;                  !!!next-token;
4056                  redo B;                  redo B;
4057                } else {                } else {
4058                    !!!cp ('t178');
4059                  #                  #
4060                }                }
4061              } elsif ({              } elsif ({
# Line 3779  sub _tree_construction_main ($) { Line 4069  sub _tree_construction_main ($) {
4069                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4070                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4071                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4072                      !!!cp ('t179');
4073                    $i = $_;                    $i = $_;
4074                    last INSCOPE;                    last INSCOPE;
4075                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {                  } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
4076                      !!!cp ('t180');
4077                    $tn = $node->[1];                    $tn = $node->[1];
4078                    ## NOTE: There is exactly one |td| or |th| element                    ## NOTE: There is exactly one |td| or |th| element
4079                    ## in scope in the stack of open elements by definition.                    ## in scope in the stack of open elements by definition.
4080                  } elsif ({                  } elsif ({
4081                            table => 1, html => 1,                            table => 1, html => 1,
4082                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4083                      !!!cp ('t181');
4084                    last INSCOPE;                    last INSCOPE;
4085                  }                  }
4086                } # INSCOPE                } # INSCOPE
4087                unless (defined $i) {                unless (defined $i) {
4088                    !!!cp ('t182');
4089                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4090                  ## Ignore the token                  ## Ignore the token
4091                  !!!next-token;                  !!!next-token;
4092                  redo B;                  redo B;
4093                  } else {
4094                    !!!cp ('t183');
4095                }                }
4096    
4097                ## Close the cell                ## Close the cell
# Line 3812  sub _tree_construction_main ($) { Line 4108  sub _tree_construction_main ($) {
4108                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4109                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4110                  if ($node->[1] eq 'caption') {                  if ($node->[1] eq 'caption') {
4111                      !!!cp ('t184');
4112                    $i = $_;                    $i = $_;
4113                    last INSCOPE;                    last INSCOPE;
4114                  } elsif ({                  } elsif ({
4115                            table => 1, html => 1,                            table => 1, html => 1,
4116                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4117                      !!!cp ('t185');
4118                    last INSCOPE;                    last INSCOPE;
4119                  }                  }
4120                } # INSCOPE                } # INSCOPE
4121                unless (defined $i) {                unless (defined $i) {
4122                    !!!cp ('t186');
4123                  !!!parse-error (type => 'unmatched end tag:caption');                  !!!parse-error (type => 'unmatched end tag:caption');
4124                  ## Ignore the token                  ## Ignore the token
4125                  !!!next-token;                  !!!next-token;
# Line 3830  sub _tree_construction_main ($) { Line 4129  sub _tree_construction_main ($) {
4129                ## generate implied end tags                ## generate implied end tags
4130                if ({                if ({
4131                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4132    
4133                       ## NOTE: The following elements never appear, maybe.
4134                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4135                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot => 1, thead => 1,
4136                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4137                    !!!cp ('t187');
4138                  !!!back-token; # </table>                  !!!back-token; # </table>
4139                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};                  $token = {type => END_TAG_TOKEN, tag_name => 'caption'};
4140                  !!!back-token;                  !!!back-token;
# Line 3842  sub _tree_construction_main ($) { Line 4144  sub _tree_construction_main ($) {
4144                }                }
4145    
4146                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
4147                    !!!cp ('t188');
4148                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4149                  } else {
4150                    !!!cp ('t189');
4151                }                }
4152    
4153                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 3857  sub _tree_construction_main ($) { Line 4162  sub _tree_construction_main ($) {
4162                        body => 1, col => 1, colgroup => 1, html => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
4163                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4164                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
4165                    !!!cp ('t190');
4166                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4167                  ## Ignore the token                  ## Ignore the token
4168                  !!!next-token;                  !!!next-token;
4169                  redo B;                  redo B;
4170                } else {                } else {
4171                    !!!cp ('t191');
4172                  #                  #
4173                }                }
4174              } elsif ({              } elsif ({
# Line 3869  sub _tree_construction_main ($) { Line 4176  sub _tree_construction_main ($) {
4176                        thead => 1, tr => 1,                        thead => 1, tr => 1,
4177                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
4178                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
4179                  !!!cp ('t192');
4180                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4181                ## Ignore the token                ## Ignore the token
4182                !!!next-token;                !!!next-token;
4183                redo B;                redo B;
4184              } else {              } else {
4185                  !!!cp ('t193');
4186                #                #
4187              }              }
4188        } else {        } else {
# Line 3888  sub _tree_construction_main ($) { Line 4197  sub _tree_construction_main ($) {
4197                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4198                                
4199                unless (length $token->{data}) {                unless (length $token->{data}) {
4200                    !!!cp ('t194');
4201                  !!!next-token;                  !!!next-token;
4202                  redo B;                  redo B;
4203                  } else {
4204                    !!!cp ('t195');
4205                }                }
4206              }              }
4207    
# Line 3913  sub _tree_construction_main ($) { Line 4225  sub _tree_construction_main ($) {
4225                  if ($self->{open_elements}->[$_]->[1] eq 'table') {                  if ($self->{open_elements}->[$_]->[1] eq 'table') {
4226                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
4227                    if (defined $parent and $parent->node_type == 1) {                    if (defined $parent and $parent->node_type == 1) {
4228                        !!!cp ('t196');
4229                      $foster_parent_element = $parent;                      $foster_parent_element = $parent;
4230                      $next_sibling = $self->{open_elements}->[$_]->[0];                      $next_sibling = $self->{open_elements}->[$_]->[0];
4231                      $prev_sibling = $next_sibling->previous_sibling;                      $prev_sibling = $next_sibling->previous_sibling;
4232                    } else {                    } else {
4233                        !!!cp ('t197');
4234                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
4235                      $prev_sibling = $foster_parent_element->last_child;                      $prev_sibling = $foster_parent_element->last_child;
4236                    }                    }
# Line 3928  sub _tree_construction_main ($) { Line 4242  sub _tree_construction_main ($) {
4242                  unless defined $foster_parent_element;                  unless defined $foster_parent_element;
4243                if (defined $prev_sibling and                if (defined $prev_sibling and
4244                    $prev_sibling->node_type == 3) {                    $prev_sibling->node_type == 3) {
4245                    !!!cp ('t198');
4246                  $prev_sibling->manakai_append_text ($token->{data});                  $prev_sibling->manakai_append_text ($token->{data});
4247                } else {                } else {
4248                    !!!cp ('t199');
4249                  $foster_parent_element->insert_before                  $foster_parent_element->insert_before
4250                    ($self->{document}->create_text_node ($token->{data}),                    ($self->{document}->create_text_node ($token->{data}),
4251                     $next_sibling);                     $next_sibling);
4252                }                }
4253              } else {              } else {
4254                  !!!cp ('t200');
4255                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4256              }              }
4257                            
# Line 3949  sub _tree_construction_main ($) { Line 4266  sub _tree_construction_main ($) {
4266                  ## Clear back to table context                  ## Clear back to table context
4267                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4268                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4269                      !!!cp ('t201');
4270                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4271                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4272                  }                  }
# Line 3960  sub _tree_construction_main ($) { Line 4278  sub _tree_construction_main ($) {
4278    
4279                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
4280                  unless ($token->{tag_name} eq 'tr') {                  unless ($token->{tag_name} eq 'tr') {
4281                      !!!cp ('t202');
4282                    !!!parse-error (type => 'missing start tag:tr');                    !!!parse-error (type => 'missing start tag:tr');
4283                  }                  }
4284                                    
# Line 3967  sub _tree_construction_main ($) { Line 4286  sub _tree_construction_main ($) {
4286                  while (not {                  while (not {
4287                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4288                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4289                      !!!cp ('t203');
4290                      ## ISSUE: Can this case be reached?
4291                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4292                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4293                  }                  }
4294                                    
4295                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
4296                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4297                      !!!cp ('t204');
4298                    !!!insert-element ($token->{tag_name}, $token->{attributes});                    !!!insert-element ($token->{tag_name}, $token->{attributes});
4299                    !!!next-token;                    !!!next-token;
4300                    redo B;                    redo B;
4301                  } else {                  } else {
4302                      !!!cp ('t205');
4303                    !!!insert-element ('tr');                    !!!insert-element ('tr');
4304                    ## reprocess in the "in row" insertion mode                    ## reprocess in the "in row" insertion mode
4305                  }                  }
4306                  } else {
4307                    !!!cp ('t206');
4308                }                }
4309    
4310                ## Clear back to table row context                ## Clear back to table row context
4311                while (not {                while (not {
4312                  tr => 1, html => 1,                  tr => 1, html => 1,
4313                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4314                    !!!cp ('t207');
4315                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4316                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4317                }                }
# Line 4009  sub _tree_construction_main ($) { Line 4335  sub _tree_construction_main ($) {
4335                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4336                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4337                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4338                        !!!cp ('t208');
4339                      $i = $_;                      $i = $_;
4340                      last INSCOPE;                      last INSCOPE;
4341                    } elsif ({                    } elsif ({
4342                              table => 1, html => 1,                              html => 1,
4343    
4344                                ## NOTE: This element does not appear here, maybe.
4345                                table => 1,
4346                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4347                        !!!cp ('t209');
4348                      last INSCOPE;                      last INSCOPE;
4349                    }                    }
4350                  } # INSCOPE                  } # INSCOPE
4351                  unless (defined $i) {                  unless (defined $i) {
4352                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                   !!!cp ('t210');
4353    ## TODO: This type is wrong.
4354                     !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
4355                    ## Ignore the token                    ## Ignore the token
4356                    !!!next-token;                    !!!next-token;
4357                    redo B;                    redo B;
# Line 4028  sub _tree_construction_main ($) { Line 4361  sub _tree_construction_main ($) {
4361                  while (not {                  while (not {
4362                    tr => 1, html => 1,                    tr => 1, html => 1,
4363                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4364                      !!!cp ('t211');
4365                      ## ISSUE: Can this case be reached?
4366                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4367                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4368                  }                  }
# Line 4035  sub _tree_construction_main ($) { Line 4370  sub _tree_construction_main ($) {
4370                  pop @{$self->{open_elements}}; # tr                  pop @{$self->{open_elements}}; # tr
4371                  $self->{insertion_mode} = IN_TABLE_BODY_IM;                  $self->{insertion_mode} = IN_TABLE_BODY_IM;
4372                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4373                      !!!cp ('t212');
4374                    ## reprocess                    ## reprocess
4375                    redo B;                    redo B;
4376                  } else {                  } else {
4377                      !!!cp ('t213');
4378                    ## reprocess in the "in table body" insertion mode...                    ## reprocess in the "in table body" insertion mode...
4379                  }                  }
4380                }                }
# Line 4050  sub _tree_construction_main ($) { Line 4387  sub _tree_construction_main ($) {
4387                    if ({                    if ({
4388                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4389                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4390                        !!!cp ('t214');
4391                      $i = $_;                      $i = $_;
4392                      last INSCOPE;                      last INSCOPE;
4393                    } elsif ({                    } elsif ({
4394                              table => 1, html => 1,                              table => 1, html => 1,
4395                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4396                        !!!cp ('t215');
4397                      last INSCOPE;                      last INSCOPE;
4398                    }                    }
4399                  } # INSCOPE                  } # INSCOPE
4400                  unless (defined $i) {                  unless (defined $i) {
4401                      !!!cp ('t216');
4402    ## TODO: This erorr type ios wrong.
4403                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4404                    ## Ignore the token                    ## Ignore the token
4405                    !!!next-token;                    !!!next-token;
# Line 4069  sub _tree_construction_main ($) { Line 4410  sub _tree_construction_main ($) {
4410                  while (not {                  while (not {
4411                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4412                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4413                      !!!cp ('t217');
4414                      ## ISSUE: Can this state be reached?
4415                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4416                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4417                  }                  }
# Line 4083  sub _tree_construction_main ($) { Line 4426  sub _tree_construction_main ($) {
4426                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4427                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4428                  ## reprocess in "in table" insertion mode...                  ## reprocess in "in table" insertion mode...
4429                  } else {
4430                    !!!cp ('t218');
4431                }                }
4432    
4433                if ($token->{tag_name} eq 'col') {                if ($token->{tag_name} eq 'col') {
4434                  ## Clear back to table context                  ## Clear back to table context
4435                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4436                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4437                      !!!cp ('t219');
4438                      ## ISSUE: Can this state be reached?
4439                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4440                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4441                  }                  }
# Line 4105  sub _tree_construction_main ($) { Line 4452  sub _tree_construction_main ($) {
4452                  ## Clear back to table context                  ## Clear back to table context
4453                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
4454                         $self->{open_elements}->[-1]->[1] ne 'html') {                         $self->{open_elements}->[-1]->[1] ne 'html') {
4455                      !!!cp ('t220');
4456                      ## ISSUE: Can this state be reached?
4457                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4458                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4459                  }                  }
# Line 4134  sub _tree_construction_main ($) { Line 4483  sub _tree_construction_main ($) {
4483                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4484                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4485                  if ($node->[1] eq 'table') {                  if ($node->[1] eq 'table') {
4486                      !!!cp ('t221');
4487                    $i = $_;                    $i = $_;
4488                    last INSCOPE;                    last INSCOPE;
4489                  } elsif ({                  } elsif ({
4490                            table => 1, html => 1,                            #table => 1,
4491                              html => 1,
4492                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4493                      !!!cp ('t222');
4494                    last INSCOPE;                    last INSCOPE;
4495                  }                  }
4496                } # INSCOPE                } # INSCOPE
4497                unless (defined $i) {                unless (defined $i) {
4498                    !!!cp ('t223');
4499    ## TODO: The following is wrong, maybe.
4500                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:table');
4501                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
4502                  !!!next-token;                  !!!next-token;
# Line 4155  sub _tree_construction_main ($) { Line 4509  sub _tree_construction_main ($) {
4509                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4510                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4511                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4512                    !!!cp ('t224');
4513                  !!!back-token; # <table>                  !!!back-token; # <table>
4514                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};                  $token = {type => END_TAG_TOKEN, tag_name => 'table'};
4515                  !!!back-token;                  !!!back-token;
# Line 4164  sub _tree_construction_main ($) { Line 4519  sub _tree_construction_main ($) {
4519                }                }
4520    
4521                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4522                    !!!cp ('t225');
4523    ## ISSUE: Can this case be reached?
4524                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4525                  } else {
4526                    !!!cp ('t226');
4527                }                }
4528    
4529                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 4174  sub _tree_construction_main ($) { Line 4533  sub _tree_construction_main ($) {
4533                ## reprocess                ## reprocess
4534                redo B;                redo B;
4535          } else {          } else {
4536              !!!cp ('t227');
4537            !!!parse-error (type => 'in table:'.$token->{tag_name});            !!!parse-error (type => 'in table:'.$token->{tag_name});
4538    
4539            $insert = $insert_to_foster;            $insert = $insert_to_foster;
# Line 4187  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 $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4550                      !!!cp ('t228');
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 ('t229');
4557                    last INSCOPE;                    last INSCOPE;
4558                  }                  }
4559                } # INSCOPE                } # INSCOPE
4560                unless (defined $i) {                unless (defined $i) {
4561                    !!!cp ('t230');
4562                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4563                  ## Ignore the token                  ## Ignore the token
4564                  !!!next-token;                  !!!next-token;
4565                  redo B;                  redo B;
4566                  } else {
4567                    !!!cp ('t232');
4568                }                }
4569    
4570                ## Clear back to table row context                ## Clear back to table row context
4571                while (not {                while (not {
4572                  tr => 1, html => 1,                  tr => 1, html => 1,
4573                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4574                    !!!cp ('t231');
4575    ## ISSUE: Can this state be reached?
4576                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4577                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4578                }                }
# Line 4222  sub _tree_construction_main ($) { Line 4589  sub _tree_construction_main ($) {
4589                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4590                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4591                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4592                        !!!cp ('t233');
4593                      $i = $_;                      $i = $_;
4594                      last INSCOPE;                      last INSCOPE;
4595                    } elsif ({                    } elsif ({
4596                              table => 1, html => 1,                              table => 1, html => 1,
4597                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4598                        !!!cp ('t234');
4599                      last INSCOPE;                      last INSCOPE;
4600                    }                    }
4601                  } # INSCOPE                  } # INSCOPE
4602                  unless (defined $i) {                  unless (defined $i) {
4603                      !!!cp ('t235');
4604    ## TODO: The following is wrong.
4605                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});                    !!!parse-error (type => 'unmatched end tag:'.$token->{type});
4606                    ## Ignore the token                    ## Ignore the token
4607                    !!!next-token;                    !!!next-token;
# Line 4241  sub _tree_construction_main ($) { Line 4612  sub _tree_construction_main ($) {
4612                  while (not {                  while (not {
4613                    tr => 1, html => 1,                    tr => 1, html => 1,
4614                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4615                      !!!cp ('t236');
4616    ## ISSUE: Can this state be reached?
4617                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4618                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4619                  }                  }
# Line 4258  sub _tree_construction_main ($) { Line 4631  sub _tree_construction_main ($) {
4631                    if ({                    if ({
4632                         tbody => 1, thead => 1, tfoot => 1,                         tbody => 1, thead => 1, tfoot => 1,
4633                        }->{$node->[1]}) {                        }->{$node->[1]}) {
4634                        !!!cp ('t237');
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 ('t238');
4641                      last INSCOPE;                      last INSCOPE;
4642                    }                    }
4643                  } # INSCOPE                  } # INSCOPE
4644                  unless (defined $i) {                  unless (defined $i) {
4645                      !!!cp ('t239');
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 4277  sub _tree_construction_main ($) { Line 4653  sub _tree_construction_main ($) {
4653                  while (not {                  while (not {
4654                    tbody => 1, tfoot => 1, thead => 1, html => 1,                    tbody => 1, tfoot => 1, thead => 1, html => 1,
4655                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4656                      !!!cp ('t240');
4657                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4658                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4659                  }                  }
# Line 4298  sub _tree_construction_main ($) { Line 4675  sub _tree_construction_main ($) {
4675                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4676                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4677                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4678                      !!!cp ('t241');
4679                    $i = $_;                    $i = $_;
4680                    last INSCOPE;                    last INSCOPE;
4681                  } elsif ({                  } elsif ({
4682                            table => 1, html => 1,                            table => 1, html => 1,
4683                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4684                      !!!cp ('t242');
4685                    last INSCOPE;                    last INSCOPE;
4686                  }                  }
4687                } # INSCOPE                } # INSCOPE
4688                unless (defined $i) {                unless (defined $i) {
4689                    !!!cp ('t243');
4690                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4691                  ## Ignore the token                  ## Ignore the token
4692                  !!!next-token;                  !!!next-token;
# Line 4319  sub _tree_construction_main ($) { Line 4699  sub _tree_construction_main ($) {
4699                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4700                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4701                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4702                    !!!cp ('t244');
4703    ## ISSUE: Can this case be reached?
4704                  !!!back-token;                  !!!back-token;
4705                  $token = {type => END_TAG_TOKEN,                  $token = {type => END_TAG_TOKEN,
4706                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 4326  sub _tree_construction_main ($) { Line 4708  sub _tree_construction_main ($) {
4708                }                }
4709                                
4710                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4711                    !!!cp ('t245');
4712                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4713                  } else {
4714                    !!!cp ('t246');
4715                }                }
4716                                    
4717                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 4345  sub _tree_construction_main ($) { Line 4730  sub _tree_construction_main ($) {
4730                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4731                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4732                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[1] eq $token->{tag_name}) {
4733                        !!!cp ('t247');
4734                      $i = $_;                      $i = $_;
4735                      last INSCOPE;                      last INSCOPE;
4736                    } elsif ({                    } elsif ({
4737                              table => 1, html => 1,                              table => 1, html => 1,
4738                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4739                        !!!cp ('t248');
4740                      last INSCOPE;                      last INSCOPE;
4741                    }                    }
4742                  } # INSCOPE                  } # INSCOPE
4743                    unless (defined $i) {                    unless (defined $i) {
4744                        !!!cp ('t249');
4745                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4746                      ## Ignore the token                      ## Ignore the token
4747                      !!!next-token;                      !!!next-token;
# Line 4366  sub _tree_construction_main ($) { Line 4754  sub _tree_construction_main ($) {
4754                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4755                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4756                    if ($node->[1] eq 'tr') {                    if ($node->[1] eq 'tr') {
4757                        !!!cp ('t250');
4758                      $i = $_;                      $i = $_;
4759                      last INSCOPE;                      last INSCOPE;
4760                    } elsif ({                    } elsif ({
4761                              table => 1, html => 1,                              table => 1, html => 1,
4762                             }->{$node->[1]}) {                             }->{$node->[1]}) {
4763                        !!!cp ('t251');
4764                      last INSCOPE;                      last INSCOPE;
4765                    }                    }
4766                  } # INSCOPE                  } # INSCOPE
4767                    unless (defined $i) {                    unless (defined $i) {
4768                        !!!cp ('t252');
4769                      !!!parse-error (type => 'unmatched end tag:tr');                      !!!parse-error (type => 'unmatched end tag:tr');
4770                      ## Ignore the token                      ## Ignore the token
4771                      !!!next-token;                      !!!next-token;
# Line 4385  sub _tree_construction_main ($) { Line 4776  sub _tree_construction_main ($) {
4776                  while (not {                  while (not {
4777                    tr => 1, html => 1,                    tr => 1, html => 1,
4778                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
4779                      !!!cp ('t253');
4780    ## ISSUE: Can this case be reached?
4781                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4782                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4783                  }                  }
# Line 4399  sub _tree_construction_main ($) { Line 4792  sub _tree_construction_main ($) {
4792                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4793                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4794                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4795                      !!!cp ('t254');
4796                    $i = $_;                    $i = $_;
4797                    last INSCOPE;                    last INSCOPE;
4798                  } elsif ({                  } elsif ({
4799                            table => 1, html => 1,                            table => 1, html => 1,
4800                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4801                      !!!cp ('t255');
4802                    last INSCOPE;                    last INSCOPE;
4803                  }                  }
4804                } # INSCOPE                } # INSCOPE
4805                unless (defined $i) {                unless (defined $i) {
4806                    !!!cp ('t256');
4807                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4808                  ## Ignore the token                  ## Ignore the token
4809                  !!!next-token;                  !!!next-token;
# Line 4418  sub _tree_construction_main ($) { Line 4814  sub _tree_construction_main ($) {
4814                while (not {                while (not {
4815                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
4816                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
4817                    !!!cp ('t257');
4818    ## ISSUE: Can this case be reached?
4819                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4820                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4821                }                }
# Line 4432  sub _tree_construction_main ($) { Line 4830  sub _tree_construction_main ($) {
4830                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM
4831                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
4832                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4833                  !!!cp ('t258');
4834                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4835                ## Ignore the token                ## Ignore the token
4836                !!!next-token;                !!!next-token;
4837                redo B;                redo B;
4838          } else {          } else {
4839              !!!cp ('t259');
4840            !!!parse-error (type => 'in table:/'.$token->{tag_name});            !!!parse-error (type => 'in table:/'.$token->{tag_name});
4841    
4842            $insert = $insert_to_foster;            $insert = $insert_to_foster;
# Line 4450  sub _tree_construction_main ($) { Line 4850  sub _tree_construction_main ($) {
4850              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4851                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4852                unless (length $token->{data}) {                unless (length $token->{data}) {
4853                    !!!cp ('t260');
4854                  !!!next-token;                  !!!next-token;
4855                  redo B;                  redo B;
4856                }                }
4857              }              }
4858                            
4859                !!!cp ('t261');
4860              #              #
4861            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
4862              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
4863                  !!!cp ('t262');
4864                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4865                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4866                !!!next-token;                !!!next-token;
4867                redo B;                redo B;
4868              } else {              } else {
4869                  !!!cp ('t263');
4870                #                #
4871              }              }
4872            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
4873              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
4874                if ($self->{open_elements}->[-1]->[1] eq 'html') {                if ($self->{open_elements}->[-1]->[1] eq 'html') {
4875                    !!!cp ('t264');
4876                  !!!parse-error (type => 'unmatched end tag:colgroup');                  !!!parse-error (type => 'unmatched end tag:colgroup');
4877                  ## Ignore the token                  ## Ignore the token
4878                  !!!next-token;                  !!!next-token;
4879                  redo B;                  redo B;
4880                } else {                } else {
4881                    !!!cp ('t265');
4882                  pop @{$self->{open_elements}}; # colgroup                  pop @{$self->{open_elements}}; # colgroup
4883                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4884                  !!!next-token;                  !!!next-token;
4885                  redo B;                              redo B;            
4886                }                }
4887              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
4888                  !!!cp ('t266');
4889                !!!parse-error (type => 'unmatched end tag:col');                !!!parse-error (type => 'unmatched end tag:col');
4890                ## Ignore the token                ## Ignore the token
4891                !!!next-token;                !!!next-token;
4892                redo B;                redo B;
4893              } else {              } else {
4894                  !!!cp ('t267');
4895                #                #
4896              }              }
4897            } else {            } else {
4898              #              die "$0: $token->{type}: Unknown token type";
4899            }            }
4900    
4901            ## As if </colgroup>            ## As if </colgroup>
4902            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] eq 'html') {
4903                !!!cp ('t269');
4904              !!!parse-error (type => 'unmatched end tag:colgroup');              !!!parse-error (type => 'unmatched end tag:colgroup');
4905              ## Ignore the token              ## Ignore the token
4906              !!!next-token;              !!!next-token;
4907              redo B;              redo B;
4908            } else {            } else {
4909                !!!cp ('t270');
4910              pop @{$self->{open_elements}}; # colgroup              pop @{$self->{open_elements}}; # colgroup
4911              $self->{insertion_mode} = IN_TABLE_IM;              $self->{insertion_mode} = IN_TABLE_IM;
4912              ## reprocess              ## reprocess
# Line 4504  sub _tree_construction_main ($) { Line 4914  sub _tree_construction_main ($) {
4914            }            }
4915      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {      } elsif ($self->{insertion_mode} == IN_SELECT_IM) {
4916        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4917            !!!cp ('t271');
4918          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4919          !!!next-token;          !!!next-token;
4920          redo B;          redo B;
4921        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4922              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
4923                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4924                    !!!cp ('t272');
4925                  ## As if </option>                  ## As if </option>
4926                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4927                  } else {
4928                    !!!cp ('t273');
4929                }                }
4930    
4931                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4519  sub _tree_construction_main ($) { Line 4933  sub _tree_construction_main ($) {
4933                redo B;                redo B;
4934              } elsif ($token->{tag_name} eq 'optgroup') {              } elsif ($token->{tag_name} eq 'optgroup') {
4935                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
4936                    !!!cp ('t274');
4937                  ## As if </option>                  ## As if </option>
4938                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4939                  } else {
4940                    !!!cp ('t275');
4941                }                }
4942    
4943                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
4944                    !!!cp ('t276');
4945                  ## As if </optgroup>                  ## As if </optgroup>
4946                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4947                  } else {
4948                    !!!cp ('t277');
4949                }                }
4950    
4951                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
4952                !!!next-token;                !!!next-token;
4953                redo B;                redo B;
4954              } elsif ($token->{tag_name} eq 'select') {              } elsif ($token->{tag_name} eq 'select') {
4955    ## TODO: The type below is not good - <select> is replaced by </select>
4956                !!!parse-error (type => 'not closed:select');                !!!parse-error (type => 'not closed:select');
4957                ## As if </select> instead                ## As if </select> instead
4958                ## have an element in table scope                ## have an element in table scope
# Line 4539  sub _tree_construction_main ($) { Line 4960  sub _tree_construction_main ($) {
4960                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4961                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4962                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
4963                      !!!cp ('t278');
4964                    $i = $_;                    $i = $_;
4965                    last INSCOPE;                    last INSCOPE;
4966                  } elsif ({                  } elsif ({
4967                            table => 1, html => 1,                            table => 1, html => 1,
4968                           }->{$node->[1]}) {                           }->{$node->[1]}) {
4969                      !!!cp ('t279');
4970                    last INSCOPE;                    last INSCOPE;
4971                  }                  }
4972                } # INSCOPE                } # INSCOPE
4973                unless (defined $i) {                unless (defined $i) {
4974                    !!!cp ('t280');
4975                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
4976                  ## Ignore the token                  ## Ignore the token
4977                  !!!next-token;                  !!!next-token;
4978                  redo B;                  redo B;
4979                }                }
4980                                
4981                  !!!cp ('t281');
4982                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4983    
4984                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4561  sub _tree_construction_main ($) { Line 4986  sub _tree_construction_main ($) {
4986                !!!next-token;                !!!next-token;
4987                redo B;                redo B;
4988          } else {          } else {
4989              !!!cp ('t282');
4990            !!!parse-error (type => 'in select:'.$token->{tag_name});            !!!parse-error (type => 'in select:'.$token->{tag_name});
4991            ## Ignore the token            ## Ignore the token
4992            !!!next-token;            !!!next-token;
# Line 4570  sub _tree_construction_main ($) { Line 4996  sub _tree_construction_main ($) {
4996              if ($token->{tag_name} eq 'optgroup') {              if ($token->{tag_name} eq 'optgroup') {
4997                if ($self->{open_elements}->[-1]->[1] eq 'option' and                if ($self->{open_elements}->[-1]->[1] eq 'option' and
4998                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {
4999                    !!!cp ('t283');
5000                  ## As if </option>                  ## As if </option>
5001                  splice @{$self->{open_elements}}, -2;                  splice @{$self->{open_elements}}, -2;
5002                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {
5003                    !!!cp ('t284');
5004                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5005                } else {                } else {
5006                    !!!cp ('t285');
5007                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5008                  ## Ignore the token                  ## Ignore the token
5009                }                }
# Line 4582  sub _tree_construction_main ($) { Line 5011  sub _tree_construction_main ($) {
5011                redo B;                redo B;
5012              } elsif ($token->{tag_name} eq 'option') {              } elsif ($token->{tag_name} eq 'option') {
5013                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
5014                    !!!cp ('t286');
5015                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5016                } else {                } else {
5017                    !!!cp ('t287');
5018                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5019                  ## Ignore the token                  ## Ignore the token
5020                }                }
# Line 4595  sub _tree_construction_main ($) { Line 5026  sub _tree_construction_main ($) {
5026                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5027                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5028                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
5029                      !!!cp ('t288');
5030                    $i = $_;                    $i = $_;
5031                    last INSCOPE;                    last INSCOPE;
5032                  } elsif ({                  } elsif ({
5033                            table => 1, html => 1,                            table => 1, html => 1,
5034                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5035                      !!!cp ('t289');
5036                    last INSCOPE;                    last INSCOPE;
5037                  }                  }
5038                } # INSCOPE                } # INSCOPE
5039                unless (defined $i) {                unless (defined $i) {
5040                    !!!cp ('t290');
5041                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5042                  ## Ignore the token                  ## Ignore the token
5043                  !!!next-token;                  !!!next-token;
5044                  redo B;                  redo B;
5045                }                }
5046                                
5047                  !!!cp ('t291');
5048                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5049    
5050                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4620  sub _tree_construction_main ($) { Line 5055  sub _tree_construction_main ($) {
5055                        caption => 1, table => 1, tbody => 1,                        caption => 1, table => 1, tbody => 1,
5056                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                        tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
5057                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5058    ## TODO: The following is wrong?
5059                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5060                                
5061                ## have an element in table scope                ## have an element in table scope
# Line 4627  sub _tree_construction_main ($) { Line 5063  sub _tree_construction_main ($) {
5063                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5064                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5065                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
5066                      !!!cp ('t292');
5067                    $i = $_;                    $i = $_;
5068                    last INSCOPE;                    last INSCOPE;
5069                  } elsif ({                  } elsif ({
5070                            table => 1, html => 1,                            table => 1, html => 1,
5071                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5072                      !!!cp ('t293');
5073                    last INSCOPE;                    last INSCOPE;
5074                  }                  }
5075                } # INSCOPE                } # INSCOPE
5076                unless (defined $i) {                unless (defined $i) {
5077                    !!!cp ('t294');
5078                  ## Ignore the token                  ## Ignore the token
5079                  !!!next-token;                  !!!next-token;
5080                  redo B;                  redo B;
# Line 4647  sub _tree_construction_main ($) { Line 5086  sub _tree_construction_main ($) {
5086                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5087                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5088                  if ($node->[1] eq 'select') {                  if ($node->[1] eq 'select') {
5089                      !!!cp ('t295');
5090                    $i = $_;                    $i = $_;
5091                    last INSCOPE;                    last INSCOPE;
5092                  } elsif ({                  } elsif ({
5093                            table => 1, html => 1,                            table => 1, html => 1,
5094                           }->{$node->[1]}) {                           }->{$node->[1]}) {
5095    ## ISSUE: Can this state be reached?
5096                      !!!cp ('t296');
5097                    last INSCOPE;                    last INSCOPE;
5098                  }                  }
5099                } # INSCOPE                } # INSCOPE
5100                unless (defined $i) {                unless (defined $i) {
5101                    !!!cp ('t297');
5102    ## TODO: The following error type is correct?
5103                  !!!parse-error (type => 'unmatched end tag:select');                  !!!parse-error (type => 'unmatched end tag:select');
5104                  ## Ignore the </select> token                  ## Ignore the </select> token
5105                  !!!next-token; ## TODO: ok?                  !!!next-token; ## TODO: ok?
5106                  redo B;                  redo B;
5107                }                }
5108                                
5109                  !!!cp ('t298');
5110                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
5111    
5112                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
# Line 4669  sub _tree_construction_main ($) { Line 5114  sub _tree_construction_main ($) {
5114                ## reprocess                ## reprocess
5115                redo B;                redo B;
5116          } else {          } else {
5117              !!!cp ('t299');
5118            !!!parse-error (type => 'in select:/'.$token->{tag_name});            !!!parse-error (type => 'in select:/'.$token->{tag_name});
5119            ## Ignore the token            ## Ignore the token
5120            !!!next-token;            !!!next-token;
# Line 4687  sub _tree_construction_main ($) { Line 5133  sub _tree_construction_main ($) {
5133            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5134                        
5135            unless (length $token->{data}) {            unless (length $token->{data}) {
5136                !!!cp ('t300');
5137              !!!next-token;              !!!next-token;
5138              redo B;              redo B;
5139            }            }
5140          }          }
5141                    
5142          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5143              !!!cp ('t301');
5144            !!!parse-error (type => 'after html:#character');            !!!parse-error (type => 'after html:#character');
5145    
5146            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5147            } else {
5148              !!!cp ('t302');
5149          }          }
5150                    
5151          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4706  sub _tree_construction_main ($) { Line 5156  sub _tree_construction_main ($) {
5156          redo B;          redo B;
5157        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5158          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5159              !!!cp ('t303');
5160            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5161                        
5162            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5163            } else {
5164              !!!cp ('t304');
5165          }          }
5166    
5167          ## "after body" insertion mode          ## "after body" insertion mode
# Line 4719  sub _tree_construction_main ($) { Line 5172  sub _tree_construction_main ($) {
5172          redo B;          redo B;
5173        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5174          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5175              !!!cp ('t305');
5176            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5177                        
5178            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
5179            ## Reprocess in the "main" phase, "after body" insertion mode...            ## Reprocess in the "after body" insertion mode.
5180            } else {
5181              !!!cp ('t306');
5182          }          }
5183    
5184          ## "after body" insertion mode          ## "after body" insertion mode
5185          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
5186            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
5187                !!!cp ('t307');
5188              !!!parse-error (type => 'unmatched end tag:html');              !!!parse-error (type => 'unmatched end tag:html');
5189              ## Ignore the token              ## Ignore the token
5190              !!!next-token;              !!!next-token;
5191              redo B;              redo B;
5192            } else {            } else {
5193                !!!cp ('t308');
5194              $self->{insertion_mode} = AFTER_HTML_BODY_IM;              $self->{insertion_mode} = AFTER_HTML_BODY_IM;
5195              !!!next-token;              !!!next-token;
5196              redo B;              redo B;
5197            }            }
5198          } else {          } else {
5199              !!!cp ('t309');
5200            !!!parse-error (type => 'after body:/'.$token->{tag_name});            !!!parse-error (type => 'after body:/'.$token->{tag_name});
5201    
5202            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
# Line 4753  sub _tree_construction_main ($) { Line 5212  sub _tree_construction_main ($) {
5212            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5213                        
5214            unless (length $token->{data}) {            unless (length $token->{data}) {
5215                !!!cp ('t310');
5216              !!!next-token;              !!!next-token;
5217              redo B;              redo B;
5218            }            }
# Line 4760  sub _tree_construction_main ($) { Line 5220  sub _tree_construction_main ($) {
5220                    
5221          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
5222            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5223                !!!cp ('t311');
5224              !!!parse-error (type => 'in frameset:#character');              !!!parse-error (type => 'in frameset:#character');
5225            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
5226                !!!cp ('t312');
5227              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5228            } else { # "after html frameset"            } else { # "after html frameset"
5229                !!!cp ('t313');
5230              !!!parse-error (type => 'after html:#character');              !!!parse-error (type => 'after html:#character');
5231    
5232              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5233              ## Reprocess in the "main" phase, "after frameset"...              ## Reprocess in the "after frameset" insertion mode.
5234              !!!parse-error (type => 'after frameset:#character');              !!!parse-error (type => 'after frameset:#character');
5235            }            }
5236                        
5237            ## Ignore the token.            ## Ignore the token.
5238            if (length $token->{data}) {            if (length $token->{data}) {
5239                !!!cp ('t314');
5240              ## reprocess the rest of characters              ## reprocess the rest of characters
5241            } else {            } else {
5242                !!!cp ('t315');
5243              !!!next-token;              !!!next-token;
5244            }            }
5245            redo B;            redo B;
# Line 4783  sub _tree_construction_main ($) { Line 5248  sub _tree_construction_main ($) {
5248          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
5249        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5250          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5251              !!!cp ('t316');
5252            !!!parse-error (type => 'after html:'.$token->{tag_name});            !!!parse-error (type => 'after html:'.$token->{tag_name});
5253    
5254            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5255            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5256          }          } else {
5257              !!!cp ('t317');
5258            }
5259    
5260          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5261              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5262              !!!cp ('t318');
5263            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5264            !!!next-token;            !!!next-token;
5265            redo B;            redo B;
5266          } elsif ($token->{tag_name} eq 'frame' and          } elsif ($token->{tag_name} eq 'frame' and
5267                   $self->{insertion_mode} == IN_FRAMESET_IM) {                   $self->{insertion_mode} == IN_FRAMESET_IM) {
5268              !!!cp ('t319');
5269            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
5270            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
5271            !!!next-token;            !!!next-token;
5272            redo B;            redo B;
5273          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5274              !!!cp ('t320');
5275            ## NOTE: As if in body.            ## NOTE: As if in body.
5276            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
5277            redo B;            redo B;
5278          } else {          } else {
5279            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5280                !!!cp ('t321');
5281              !!!parse-error (type => 'in frameset:'.$token->{tag_name});              !!!parse-error (type => 'in frameset:'.$token->{tag_name});
5282            } else {            } else {
5283                !!!cp ('t322');
5284              !!!parse-error (type => 'after frameset:'.$token->{tag_name});              !!!parse-error (type => 'after frameset:'.$token->{tag_name});
5285            }            }
5286            ## Ignore the token            ## Ignore the token
# Line 4816  sub _tree_construction_main ($) { Line 5289  sub _tree_construction_main ($) {
5289          }          }
5290        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5291          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
5292              !!!cp ('t323');
5293            !!!parse-error (type => 'after html:/'.$token->{tag_name});            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5294    
5295            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
5296            ## Process in the "main" phase, "after frameset" insertion mode...            ## Process in the "after frameset" insertion mode.
5297            } else {
5298              !!!cp ('t324');
5299          }          }
5300    
5301          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5302              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5303            if ($self->{open_elements}->[-1]->[1] eq 'html' and            if ($self->{open_elements}->[-1]->[1] eq 'html' and
5304                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
5305                !!!cp ('t325');
5306              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5307              ## Ignore the token              ## Ignore the token
5308              !!!next-token;              !!!next-token;
5309            } else {            } else {
5310                !!!cp ('t326');
5311              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
5312              !!!next-token;              !!!next-token;
5313            }            }
5314    
5315            if (not defined $self->{inner_html_node} and            if (not defined $self->{inner_html_node} and
5316                $self->{open_elements}->[-1]->[1] ne 'frameset') {                $self->{open_elements}->[-1]->[1] ne 'frameset') {
5317                !!!cp ('t327');
5318              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
5319              } else {
5320                !!!cp ('t328');
5321            }            }
5322            redo B;            redo B;
5323          } elsif ($token->{tag_name} eq 'html' and          } elsif ($token->{tag_name} eq 'html' and
5324                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {
5325              !!!cp ('t329');
5326            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;
5327            !!!next-token;            !!!next-token;
5328            redo B;            redo B;
5329          } else {          } else {
5330            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5331                !!!cp ('t330');
5332              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
5333            } else {            } else {
5334                !!!cp ('t331');
5335              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});              !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
5336            }            }
5337            ## Ignore the token            ## Ignore the token
# Line 4866  sub _tree_construction_main ($) { Line 5350  sub _tree_construction_main ($) {
5350      ## "in body" insertion mode      ## "in body" insertion mode
5351      if ($token->{type} == START_TAG_TOKEN) {      if ($token->{type} == START_TAG_TOKEN) {
5352        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
5353            !!!cp ('t332');
5354          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5355          $script_start_tag->($insert);          $script_start_tag->($insert);
5356          redo B;          redo B;
5357        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
5358            !!!cp ('t333');
5359          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5360          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5361          redo B;          redo B;
5362        } elsif ({        } elsif ({
5363                  base => 1, link => 1,                  base => 1, link => 1,
5364                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5365            !!!cp ('t334');
5366          ## 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
5367          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5368          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 4888  sub _tree_construction_main ($) { Line 5375  sub _tree_construction_main ($) {
5375    
5376          unless ($self->{confident}) {          unless ($self->{confident}) {
5377            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) { ## TODO: And if supported
5378                !!!cp ('t335');
5379              $self->{change_encoding}              $self->{change_encoding}
5380                  ->($self, $token->{attributes}->{charset}->{value});                  ->($self, $token->{attributes}->{charset}->{value});
5381                            
# Line 4902  sub _tree_construction_main ($) { Line 5390  sub _tree_construction_main ($) {
5390                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
5391                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
5392                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
5393                  !!!cp ('t336');
5394                $self->{change_encoding}                $self->{change_encoding}
5395                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);
5396                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 4912  sub _tree_construction_main ($) { Line 5401  sub _tree_construction_main ($) {
5401            }            }
5402          } else {          } else {
5403            if ($token->{attributes}->{charset}) {            if ($token->{attributes}->{charset}) {
5404                !!!cp ('t337');
5405              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
5406                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5407                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
5408                                           ->{has_reference});                                           ->{has_reference});
5409            }            }
5410            if ($token->{attributes}->{content}) {            if ($token->{attributes}->{content}) {
5411                !!!cp ('t338');
5412              $meta_el->[0]->get_attribute_node_ns (undef, 'content')              $meta_el->[0]->get_attribute_node_ns (undef, 'content')
5413                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
5414                                       $token->{attributes}->{content}                                       $token->{attributes}->{content}
# Line 4928  sub _tree_construction_main ($) { Line 5419  sub _tree_construction_main ($) {
5419          !!!next-token;          !!!next-token;
5420          redo B;          redo B;
5421        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
5422            !!!cp ('t341');
5423          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
5424          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
5425          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {
5426            if (defined $self->{head_element}) {            if (defined $self->{head_element}) {
5427                !!!cp ('t339');
5428              $self->{head_element}->append_child ($_[0]);              $self->{head_element}->append_child ($_[0]);
5429            } else {            } else {
5430                !!!cp ('t340');
5431              $insert->($_[0]);              $insert->($_[0]);
5432            }            }
5433          });          });
# Line 4943  sub _tree_construction_main ($) { Line 5437  sub _tree_construction_main ($) {
5437                                
5438          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
5439              $self->{open_elements}->[1]->[1] ne 'body') {              $self->{open_elements}->[1]->[1] ne 'body') {
5440              !!!cp ('t342');
5441            ## Ignore the token            ## Ignore the token
5442          } else {          } else {
5443            my $body_el = $self->{open_elements}->[1]->[0];            my $body_el = $self->{open_elements}->[1]->[0];
5444            for my $attr_name (keys %{$token->{attributes}}) {            for my $attr_name (keys %{$token->{attributes}}) {
5445              unless ($body_el->has_attribute_ns (undef, $attr_name)) {              unless ($body_el->has_attribute_ns (undef, $attr_name)) {
5446                  !!!cp ('t343');
5447                $body_el->set_attribute_ns                $body_el->set_attribute_ns
5448                  (undef, [undef, $attr_name],                  (undef, [undef, $attr_name],
5449                   $token->{attributes}->{$attr_name}->{value});                   $token->{attributes}->{$attr_name}->{value});
# Line 4958  sub _tree_construction_main ($) { Line 5454  sub _tree_construction_main ($) {
5454          redo B;          redo B;
5455        } elsif ({        } elsif ({
5456                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
5457                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1,
5458                  menu => 1, ol => 1, p => 1, ul => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
5459                    listing => 1, menu => 1, ol => 1, p => 1, ul => 1,
5460                  pre => 1,                  pre => 1,
5461                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5462          ## has a p element in scope          ## has a p element in scope
5463          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5464            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5465                !!!cp ('t344');
5466              !!!back-token;              !!!back-token;
5467              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5468              redo B;              redo B;
# Line 4972  sub _tree_construction_main ($) { Line 5470  sub _tree_construction_main ($) {
5470                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5471                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5472                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5473                !!!cp ('t345');
5474              last INSCOPE;              last INSCOPE;
5475            }            }
5476          } # INSCOPE          } # INSCOPE
# Line 4982  sub _tree_construction_main ($) { Line 5481  sub _tree_construction_main ($) {
5481            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
5482              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
5483              unless (length $token->{data}) {              unless (length $token->{data}) {
5484                  !!!cp ('t346');
5485                !!!next-token;                !!!next-token;
5486                } else {
5487                  !!!cp ('t349');
5488              }              }
5489              } else {
5490                !!!cp ('t348');
5491            }            }
5492          } else {          } else {
5493              !!!cp ('t347');
5494            !!!next-token;            !!!next-token;
5495          }          }
5496          redo B;          redo B;
5497        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
5498          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5499              !!!cp ('t350');
5500            !!!parse-error (type => 'in form:form');            !!!parse-error (type => 'in form:form');
5501            ## Ignore the token            ## Ignore the token
5502            !!!next-token;            !!!next-token;
# Line 4999  sub _tree_construction_main ($) { Line 5505  sub _tree_construction_main ($) {
5505            ## has a p element in scope            ## has a p element in scope
5506            INSCOPE: for (reverse @{$self->{open_elements}}) {            INSCOPE: for (reverse @{$self->{open_elements}}) {
5507              if ($_->[1] eq 'p') {              if ($_->[1] eq 'p') {
5508                  !!!cp ('t351');
5509                !!!back-token;                !!!back-token;
5510                $token = {type => END_TAG_TOKEN, tag_name => 'p'};                $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5511                redo B;                redo B;
# Line 5006  sub _tree_construction_main ($) { Line 5513  sub _tree_construction_main ($) {
5513                        table => 1, caption => 1, td => 1, th => 1,                        table => 1, caption => 1, td => 1, th => 1,
5514                        button => 1, marquee => 1, object => 1, html => 1,                        button => 1, marquee => 1, object => 1, html => 1,
5515                       }->{$_->[1]}) {                       }->{$_->[1]}) {
5516                  !!!cp ('t352');
5517                last INSCOPE;                last INSCOPE;
5518              }              }
5519            } # INSCOPE            } # INSCOPE
# Line 5019  sub _tree_construction_main ($) { Line 5527  sub _tree_construction_main ($) {
5527          ## has a p element in scope          ## has a p element in scope
5528          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5529            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5530                !!!cp ('t353');
5531              !!!back-token;              !!!back-token;
5532              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5533              redo B;              redo B;
# Line 5026  sub _tree_construction_main ($) { Line 5535  sub _tree_construction_main ($) {
5535                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5536                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5537                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5538                !!!cp ('t354');
5539              last INSCOPE;              last INSCOPE;
5540            }            }
5541          } # INSCOPE          } # INSCOPE
# Line 5037  sub _tree_construction_main ($) { Line 5547  sub _tree_construction_main ($) {
5547            ## Step 2            ## Step 2
5548            if ($node->[1] eq 'li') {            if ($node->[1] eq 'li') {
5549              if ($i != -1) {              if ($i != -1) {
5550                  !!!cp ('t355');
5551                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5552                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5553                } else {
5554                  !!!cp ('t356');
5555              }              }
5556              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5557              last LI;              last LI;
5558              } else {
5559                !!!cp ('t357');
5560            }            }
5561                        
5562            ## Step 3            ## Step 3
# Line 5050  sub _tree_construction_main ($) { Line 5565  sub _tree_construction_main ($) {
5565                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5566                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5567                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5568                !!!cp ('t358');
5569              last LI;              last LI;
5570            }            }
5571                        
5572              !!!cp ('t359');
5573            ## Step 4            ## Step 4
5574            $i--;            $i--;
5575            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 5066  sub _tree_construction_main ($) { Line 5583  sub _tree_construction_main ($) {
5583          ## has a p element in scope          ## has a p element in scope
5584          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5585            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5586                !!!cp ('t360');
5587              !!!back-token;              !!!back-token;
5588              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5589              redo B;              redo B;
# Line 5073  sub _tree_construction_main ($) { Line 5591  sub _tree_construction_main ($) {
5591                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5592                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5593                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5594                !!!cp ('t361');
5595              last INSCOPE;              last INSCOPE;
5596            }            }
5597          } # INSCOPE          } # INSCOPE
# Line 5084  sub _tree_construction_main ($) { Line 5603  sub _tree_construction_main ($) {
5603            ## Step 2            ## Step 2
5604            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {
5605              if ($i != -1) {              if ($i != -1) {
5606                  !!!cp ('t362');
5607                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
5608                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
5609                } else {
5610                  !!!cp ('t363');
5611              }              }
5612              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
5613              last LI;              last LI;
5614              } else {
5615                !!!cp ('t364');
5616            }            }
5617                        
5618            ## Step 3            ## Step 3
# Line 5097  sub _tree_construction_main ($) { Line 5621  sub _tree_construction_main ($) {
5621                ($special_category->{$node->[1]} or                ($special_category->{$node->[1]} or
5622                 $scoping_category->{$node->[1]}) and                 $scoping_category->{$node->[1]}) and
5623                $node->[1] ne 'address' and $node->[1] ne 'div') {                $node->[1] ne 'address' and $node->[1] ne 'div') {
5624                !!!cp ('t365');
5625              last LI;              last LI;
5626            }            }
5627                        
5628              !!!cp ('t366');
5629            ## Step 4            ## Step 4
5630            $i--;            $i--;
5631            $node = $self->{open_elements}->[$i];            $node = $self->{open_elements}->[$i];
# Line 5113  sub _tree_construction_main ($) { Line 5639  sub _tree_construction_main ($) {
5639          ## has a p element in scope          ## has a p element in scope
5640          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5641            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5642                !!!cp ('t367');
5643              !!!back-token;              !!!back-token;
5644              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5645              redo B;              redo B;
# Line 5120  sub _tree_construction_main ($) { Line 5647  sub _tree_construction_main ($) {
5647                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5648                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5649                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5650                !!!cp ('t368');
5651              last INSCOPE;              last INSCOPE;
5652            }            }
5653          } # INSCOPE          } # INSCOPE
# Line 5130  sub _tree_construction_main ($) { Line 5658  sub _tree_construction_main ($) {
5658                        
5659          !!!next-token;          !!!next-token;
5660          redo B;          redo B;
       } elsif ({  
                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
                }->{$token->{tag_name}}) {  
         ## has a p element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => END_TAG_TOKEN, tag_name => 'p'};  
             redo B;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>  
         ## has an element in scope  
         #my $i;  
         #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
         #  my $node = $self->{open_elements}->[$_];  
         #  if ({  
         #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
         #      }->{$node->[1]}) {  
         #    $i = $_;  
         #    last INSCOPE;  
         #  } elsif ({  
         #            table => 1, caption => 1, td => 1, th => 1,  
         #            button => 1, marquee => 1, object => 1, html => 1,  
         #           }->{$node->[1]}) {  
         #    last INSCOPE;  
         #  }  
         #} # INSCOPE  
         #    
         #if (defined $i) {  
         #  !!! parse-error (type => 'in hn:hn');  
         #  splice @{$self->{open_elements}}, $i;  
         #}  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         !!!next-token;  
         redo B;  
5661        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
5662          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
5663            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
5664            if ($node->[1] eq 'a') {            if ($node->[1] eq 'a') {
5665                !!!cp ('t371');
5666              !!!parse-error (type => 'in a:a');              !!!parse-error (type => 'in a:a');
5667                            
5668              !!!back-token;              !!!back-token;
# Line 5187  sub _tree_construction_main ($) { Line 5671  sub _tree_construction_main ($) {
5671                            
5672              AFE2: for (reverse 0..$#$active_formatting_elements) {              AFE2: for (reverse 0..$#$active_formatting_elements) {
5673                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {                if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
5674                    !!!cp ('t372');
5675                  splice @$active_formatting_elements, $_, 1;                  splice @$active_formatting_elements, $_, 1;
5676                  last AFE2;                  last AFE2;
5677                }                }
5678              } # AFE2              } # AFE2
5679              OE: for (reverse 0..$#{$self->{open_elements}}) {              OE: for (reverse 0..$#{$self->{open_elements}}) {
5680                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {                if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {
5681                    !!!cp ('t373');
5682                  splice @{$self->{open_elements}}, $_, 1;                  splice @{$self->{open_elements}}, $_, 1;
5683                  last OE;                  last OE;
5684                }                }
5685              } # OE              } # OE
5686              last AFE;              last AFE;
5687            } elsif ($node->[0] eq '#marker') {            } elsif ($node->[0] eq '#marker') {
5688                !!!cp ('t374');
5689              last AFE;              last AFE;
5690            }            }
5691          } # AFE          } # AFE
# Line 5215  sub _tree_construction_main ($) { Line 5702  sub _tree_construction_main ($) {
5702                  s => 1, small => 1, strile => 1,                  s => 1, small => 1, strile => 1,
5703                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
5704                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5705            !!!cp ('t375');
5706          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5707                    
5708          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5229  sub _tree_construction_main ($) { Line 5717  sub _tree_construction_main ($) {
5717          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5718            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5719            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
5720                !!!cp ('t376');
5721              !!!parse-error (type => 'in nobr:nobr');              !!!parse-error (type => 'in nobr:nobr');
5722              !!!back-token;              !!!back-token;
5723              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};
# Line 5237  sub _tree_construction_main ($) { Line 5726  sub _tree_construction_main ($) {
5726                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5727                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5728                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5729                !!!cp ('t377');
5730              last INSCOPE;              last INSCOPE;
5731            }            }
5732          } # INSCOPE          } # INSCOPE
# Line 5251  sub _tree_construction_main ($) { Line 5741  sub _tree_construction_main ($) {
5741          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5742            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
5743            if ($node->[1] eq 'button') {            if ($node->[1] eq 'button') {
5744                !!!cp ('t378');
5745              !!!parse-error (type => 'in button:button');              !!!parse-error (type => 'in button:button');
5746              !!!back-token;              !!!back-token;
5747              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button'};
# Line 5259  sub _tree_construction_main ($) { Line 5750  sub _tree_construction_main ($) {
5750                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5751                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5752                     }->{$node->[1]}) {                     }->{$node->[1]}) {
5753                !!!cp ('t379');
5754              last INSCOPE;              last INSCOPE;
5755            }            }
5756          } # INSCOPE          } # INSCOPE
# Line 5266  sub _tree_construction_main ($) { Line 5758  sub _tree_construction_main ($) {
5758          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5759                        
5760          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5761    
5762            ## TODO: associate with $self->{form_element} if defined
5763    
5764          push @$active_formatting_elements, ['#marker', ''];          push @$active_formatting_elements, ['#marker', ''];
5765    
5766          !!!next-token;          !!!next-token;
5767          redo B;          redo B;
5768        } elsif ($token->{tag_name} eq 'marquee' or        } elsif ($token->{tag_name} eq 'marquee' or
5769                 $token->{tag_name} eq 'object') {                 $token->{tag_name} eq 'object') {
5770            !!!cp ('t380');
5771          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5772                    
5773          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5280  sub _tree_construction_main ($) { Line 5776  sub _tree_construction_main ($) {
5776          !!!next-token;          !!!next-token;
5777          redo B;          redo B;
5778        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
5779            !!!cp ('t381');
5780          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5781          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5782          redo B;          redo B;
# Line 5287  sub _tree_construction_main ($) { Line 5784  sub _tree_construction_main ($) {
5784          ## has a p element in scope          ## has a p element in scope
5785          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5786            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5787                !!!cp ('t382');
5788              !!!back-token;              !!!back-token;
5789              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5790              redo B;              redo B;
# Line 5294  sub _tree_construction_main ($) { Line 5792  sub _tree_construction_main ($) {
5792                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5793                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5794                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5795                !!!cp ('t383');
5796              last INSCOPE;              last INSCOPE;
5797            }            }
5798          } # INSCOPE          } # INSCOPE
# Line 5310  sub _tree_construction_main ($) { Line 5809  sub _tree_construction_main ($) {
5809                  image => 1,                  image => 1,
5810                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5811          if ($token->{tag_name} eq 'image') {          if ($token->{tag_name} eq 'image') {
5812              !!!cp ('t384');
5813            !!!parse-error (type => 'image');            !!!parse-error (type => 'image');
5814            $token->{tag_name} = 'img';            $token->{tag_name} = 'img';
5815            } else {
5816              !!!cp ('t385');
5817          }          }
5818    
5819          ## NOTE: There is an "as if <br>" code clone.          ## NOTE: There is an "as if <br>" code clone.
# Line 5326  sub _tree_construction_main ($) { Line 5828  sub _tree_construction_main ($) {
5828          ## has a p element in scope          ## has a p element in scope
5829          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
5830            if ($_->[1] eq 'p') {            if ($_->[1] eq 'p') {
5831                !!!cp ('t386');
5832              !!!back-token;              !!!back-token;
5833              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p'};
5834              redo B;              redo B;
# Line 5333  sub _tree_construction_main ($) { Line 5836  sub _tree_construction_main ($) {
5836                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
5837                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
5838                     }->{$_->[1]}) {                     }->{$_->[1]}) {
5839                !!!cp ('t387');
5840              last INSCOPE;              last INSCOPE;
5841            }            }
5842          } # INSCOPE          } # INSCOPE
# Line 5343  sub _tree_construction_main ($) { Line 5847  sub _tree_construction_main ($) {
5847          !!!next-token;          !!!next-token;
5848          redo B;          redo B;
5849        } elsif ($token->{tag_name} eq 'input') {        } elsif ($token->{tag_name} eq 'input') {
5850            !!!cp ('t388');
5851          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5852                    
5853          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5355  sub _tree_construction_main ($) { Line 5860  sub _tree_construction_main ($) {
5860          !!!parse-error (type => 'isindex');          !!!parse-error (type => 'isindex');
5861                    
5862          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
5863              !!!cp ('t389');
5864            ## Ignore the token            ## Ignore the token
5865            !!!next-token;            !!!next-token;
5866            redo B;            redo B;
# Line 5374  sub _tree_construction_main ($) { Line 5880  sub _tree_construction_main ($) {
5880                          {type => START_TAG_TOKEN, tag_name => 'label'},                          {type => START_TAG_TOKEN, tag_name => 'label'},
5881                         );                         );
5882            if ($prompt_attr) {            if ($prompt_attr) {
5883                !!!cp ('t390');
5884              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};
5885            } else {            } else {
5886                !!!cp ('t391');
5887              push @tokens, {type => CHARACTER_TOKEN,              push @tokens, {type => CHARACTER_TOKEN,
5888                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
5889              ## TODO: make this configurable              ## TODO: make this configurable
# Line 5407  sub _tree_construction_main ($) { Line 5915  sub _tree_construction_main ($) {
5915          if ($token->{type} == CHARACTER_TOKEN) {          if ($token->{type} == CHARACTER_TOKEN) {
5916            $token->{data} =~ s/^\x0A//;            $token->{data} =~ s/^\x0A//;
5917            unless (length $token->{data}) {            unless (length $token->{data}) {
5918                !!!cp ('t392');
5919              !!!next-token;              !!!next-token;
5920              } else {
5921                !!!cp ('t393');
5922            }            }
5923            } else {
5924              !!!cp ('t394');
5925          }          }
5926          while ($token->{type} == CHARACTER_TOKEN) {          while ($token->{type} == CHARACTER_TOKEN) {
5927              !!!cp ('t395');
5928            $text .= $token->{data};            $text .= $token->{data};
5929            !!!next-token;            !!!next-token;
5930          }          }
5931          if (length $text) {          if (length $text) {
5932              !!!cp ('t396');
5933            $el->manakai_append_text ($text);            $el->manakai_append_text ($text);
5934          }          }
5935                    
# Line 5422  sub _tree_construction_main ($) { Line 5937  sub _tree_construction_main ($) {
5937                    
5938          if ($token->{type} == END_TAG_TOKEN and          if ($token->{type} == END_TAG_TOKEN and
5939              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
5940              !!!cp ('t397');
5941            ## Ignore the token            ## Ignore the token
5942          } else {          } else {
5943              !!!cp ('t398');
5944            !!!parse-error (type => 'in RCDATA:#'.$token->{type});            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
5945          }          }
5946          !!!next-token;          !!!next-token;
# Line 5434  sub _tree_construction_main ($) { Line 5951  sub _tree_construction_main ($) {
5951                  noframes => 1,                  noframes => 1,
5952                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
5953                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5954            !!!cp ('t399');
5955          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
5956          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
5957          redo B;          redo B;
5958        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
5959            !!!cp ('t400');
5960          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5961                    
5962          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
5963    
5964            ## TODO: associate with $self->{form_element} if defined
5965                    
5966          $self->{insertion_mode} = IN_SELECT_IM;          $self->{insertion_mode} = IN_SELECT_IM;
5967          !!!next-token;          !!!next-token;
# Line 5451  sub _tree_construction_main ($) { Line 5972  sub _tree_construction_main ($) {
5972                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
5973                  thead => 1, tr => 1,                  thead => 1, tr => 1,
5974                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
5975            !!!cp ('t401');
5976          !!!parse-error (type => 'in body:'.$token->{tag_name});          !!!parse-error (type => 'in body:'.$token->{tag_name});
5977          ## Ignore the token          ## Ignore the token
5978          !!!next-token;          !!!next-token;
# Line 5458  sub _tree_construction_main ($) { Line 5980  sub _tree_construction_main ($) {
5980                    
5981          ## ISSUE: An issue on HTML5 new elements in the spec.          ## ISSUE: An issue on HTML5 new elements in the spec.
5982        } else {        } else {
5983            !!!cp ('t402');
5984          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
5985                    
5986          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 5475  sub _tree_construction_main ($) { Line 5998  sub _tree_construction_main ($) {
5998                         th => 1, tr => 1, body => 1, html => 1,                         th => 1, tr => 1, body => 1, html => 1,
5999                       tbody => 1, tfoot => 1, thead => 1,                       tbody => 1, tfoot => 1, thead => 1,
6000                      }->{$_->[1]}) {                      }->{$_->[1]}) {
6001                  !!!cp ('t403');
6002                !!!parse-error (type => 'not closed:'.$_->[1]);                !!!parse-error (type => 'not closed:'.$_->[1]);
6003                } else {
6004                  !!!cp ('t404');
6005              }              }
6006            }            }
6007    
# Line 5483  sub _tree_construction_main ($) { Line 6009  sub _tree_construction_main ($) {
6009            !!!next-token;            !!!next-token;
6010            redo B;            redo B;
6011          } else {          } else {
6012              !!!cp ('t405');
6013            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6014            ## Ignore the token            ## Ignore the token
6015            !!!next-token;            !!!next-token;
# Line 5492  sub _tree_construction_main ($) { Line 6019  sub _tree_construction_main ($) {
6019          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') {
6020            ## ISSUE: There is an issue in the spec.            ## ISSUE: There is an issue in the spec.
6021            if ($self->{open_elements}->[-1]->[1] ne 'body') {            if ($self->{open_elements}->[-1]->[1] ne 'body') {
6022                !!!cp ('t406');
6023              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);
6024              } else {
6025                !!!cp ('t407');
6026            }            }
6027            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6028            ## reprocess            ## reprocess
6029            redo B;            redo B;
6030          } else {          } else {
6031              !!!cp ('t408');
6032            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6033            ## Ignore the token            ## Ignore the token
6034            !!!next-token;            !!!next-token;
# Line 5525  sub _tree_construction_main ($) { Line 6056  sub _tree_construction_main ($) {
6056                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6057                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6058                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6059                  !!!cp ('t409');
6060                !!!back-token;                !!!back-token;
6061                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6062                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6063                redo B;                redo B;
6064              }              }
6065                
6066                !!!cp ('t410');
6067              $i = $_;              $i = $_;
6068              last INSCOPE unless $token->{tag_name} eq 'p';              last INSCOPE unless $token->{tag_name} eq 'p';
6069            } elsif ({            } elsif ({
6070                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6071                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6072                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6073                !!!cp ('t411');
6074              last INSCOPE;              last INSCOPE;
6075            }            }
6076          } # INSCOPE          } # INSCOPE
6077                    
6078          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6079            if (defined $i) {            if (defined $i) {
6080                !!!cp ('t412');
6081              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6082            } else {            } else {
6083                !!!cp ('t413');
6084              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6085            }            }
6086          }          }
6087                    
6088          if (defined $i) {          if (defined $i) {
6089              !!!cp ('t414');
6090            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
6091          } elsif ($token->{tag_name} eq 'p') {          } elsif ($token->{tag_name} eq 'p') {
6092              !!!cp ('t415');
6093            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
6094            my $el;            my $el;
6095            !!!create-element ($el, 'p');            !!!create-element ($el, 'p');
6096            $insert->($el);            $insert->($el);
6097            } else {
6098              !!!cp ('t416');
6099          }          }
6100          $clear_up_to_marker->()          $clear_up_to_marker->()
6101            if {            if {
# Line 5570  sub _tree_construction_main ($) { Line 6111  sub _tree_construction_main ($) {
6111              ## generate implied end tags              ## generate implied end tags
6112              if ({              if ({
6113                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
6114    
6115                     ## NOTE: The following elements never appear here, maybe.
6116                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6117                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot => 1, thead => 1,
6118                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6119                  !!!cp ('t417');
6120                !!!back-token;                !!!back-token;
6121                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6122                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6123                redo B;                redo B;
6124              }              }
6125                
6126                !!!cp ('t418');
6127              last INSCOPE;              last INSCOPE;
6128            } elsif ({            } elsif ({
6129                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6130                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6131                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6132                !!!cp ('t419');
6133              last INSCOPE;              last INSCOPE;
6134            }            }
6135          } # INSCOPE          } # INSCOPE
6136                    
6137          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {
6138              !!!cp ('t420');
6139            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
6140          } else {          } else {
6141              !!!cp ('t421');
6142            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6143          }          }
6144    
# Line 5612  sub _tree_construction_main ($) { Line 6161  sub _tree_construction_main ($) {
6161                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6162                   tbody => 1, tfoot=> 1, thead => 1,                   tbody => 1, tfoot=> 1, thead => 1,
6163                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6164                  !!!cp ('t422');
6165                !!!back-token;                !!!back-token;
6166                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6167                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
6168                redo B;                redo B;
6169              }              }
6170    
6171                !!!cp ('t423');
6172              $i = $_;              $i = $_;
6173              last INSCOPE;              last INSCOPE;
6174            } elsif ({            } elsif ({
6175                      table => 1, caption => 1, td => 1, th => 1,                      table => 1, caption => 1, td => 1, th => 1,
6176                      button => 1, marquee => 1, object => 1, html => 1,                      button => 1, marquee => 1, object => 1, html => 1,
6177                     }->{$node->[1]}) {                     }->{$node->[1]}) {
6178                !!!cp ('t424');
6179              last INSCOPE;              last INSCOPE;
6180            }            }
6181          } # INSCOPE          } # INSCOPE
6182                    
6183          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
6184              !!!cp ('t425');
6185            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6186            } else {
6187              !!!cp ('t426');
6188          }          }
6189                    
6190          splice @{$self->{open_elements}}, $i if defined $i;          splice @{$self->{open_elements}}, $i if defined $i;
# Line 5640  sub _tree_construction_main ($) { Line 6196  sub _tree_construction_main ($) {
6196                  nobr => 1, s => 1, small => 1, strile => 1,                  nobr => 1, s => 1, small => 1, strile => 1,
6197                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
6198                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6199            !!!cp ('t427');
6200          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
6201          redo B;          redo B;
6202        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
6203            !!!cp ('t428');
6204          !!!parse-error (type => 'unmatched end tag:br');          !!!parse-error (type => 'unmatched end tag:br');
6205    
6206          ## As if <br>          ## As if <br>
# Line 5667  sub _tree_construction_main ($) { Line 6225  sub _tree_construction_main ($) {
6225                  table => 1, textarea => 1, wbr => 1,                  table => 1, textarea => 1, wbr => 1,
6226                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
6227                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6228            !!!cp ('t429');
6229          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6230          ## Ignore the token          ## Ignore the token
6231          !!!next-token;          !!!next-token;
# Line 5689  sub _tree_construction_main ($) { Line 6248  sub _tree_construction_main ($) {
6248                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
6249                   tbody => 1, tfoot => 1, thead => 1,                   tbody => 1, tfoot => 1, thead => 1,
6250                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
6251                  !!!cp ('t430');
6252                  ## ISSUE: Can this case be reached?
6253                !!!back-token;                !!!back-token;
6254                $token = {type => END_TAG_TOKEN,                $token = {type => END_TAG_TOKEN,
6255                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                          tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
# Line 5697  sub _tree_construction_main ($) { Line 6258  sub _tree_construction_main ($) {
6258                    
6259              ## Step 2              ## Step 2
6260              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {
6261                  !!!cp ('t431');
6262                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
6263                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
6264                } else {
6265                  !!!cp ('t432');
6266              }              }
6267                            
6268              ## Step 3              ## Step 3
# Line 5712  sub _tree_construction_main ($) { Line 6276  sub _tree_construction_main ($) {
6276                  #not $phrasing_category->{$node->[1]} and                  #not $phrasing_category->{$node->[1]} and
6277                  ($special_category->{$node->[1]} or                  ($special_category->{$node->[1]} or
6278                   $scoping_category->{$node->[1]})) {                   $scoping_category->{$node->[1]})) {
6279                  !!!cp ('t433');
6280                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
6281                ## Ignore the token                ## Ignore the token
6282                !!!next-token;                !!!next-token;
6283                last S2;                last S2;
6284              }              }
6285    
6286                !!!cp ('t434');
6287            }            }
6288                        
6289            ## Step 4            ## Step 4
# Line 5732  sub _tree_construction_main ($) { Line 6299  sub _tree_construction_main ($) {
6299      redo B;      redo B;
6300    } # B    } # B
6301    
   ## NOTE: The "trailing end" phase in HTML5 is split into  
   ## two insertion modes: "after html body" and "after html frameset".  
   ## NOTE: States in the main stage is preserved while  
   ## the parser stays in the trailing end phase. # MUST  
   
6302    ## Stop parsing # MUST    ## Stop parsing # MUST
6303        
6304    ## TODO: script stuffs    ## TODO: script stuffs
# Line 5778  sub set_inner_html ($$$) { Line 6340  sub set_inner_html ($$$) {
6340      my $p = $class->new;      my $p = $class->new;
6341      $p->{document} = $doc;      $p->{document} = $doc;
6342    
6343      ## Step 9 # MUST      ## Step 8 # MUST
6344      my $i = 0;      my $i = 0;
6345      my $line = 1;      my $line = 1;
6346      my $column = 0;      my $column = 0;
# Line 5795  sub set_inner_html ($$$) { Line 6357  sub set_inner_html ($$$) {
6357        if ($self->{next_char} == 0x000A) { # LF        if ($self->{next_char} == 0x000A) { # LF
6358          $line++;          $line++;
6359          $column = 0;          $column = 0;
6360            !!!cp ('i1');
6361        } elsif ($self->{next_char} == 0x000D) { # CR        } elsif ($self->{next_char} == 0x000D) { # CR
6362          $i++ if substr ($$s, $i, 1) eq "\x0A";          $i++ if substr ($$s, $i, 1) eq "\x0A";
6363          $self->{next_char} = 0x000A; # LF # MUST          $self->{next_char} = 0x000A; # LF # MUST
6364          $line++;          $line++;
6365          $column = 0;          $column = 0;
6366            !!!cp ('i2');
6367        } elsif ($self->{next_char} > 0x10FFFF) {        } elsif ($self->{next_char} > 0x10FFFF) {
6368          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6369            !!!cp ('i3');
6370        } elsif ($self->{next_char} == 0x0000) { # NULL        } elsif ($self->{next_char} == 0x0000) { # NULL
6371            !!!cp ('i4');
6372          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
6373          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
6374        }        }
# Line 5841  sub set_inner_html ($$$) { Line 6407  sub set_inner_html ($$$) {
6407    
6408      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
6409    
6410      ## Step 4      ## Step 3
6411      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
6412        ('http://www.w3.org/1999/xhtml', [undef, 'html']);        ('http://www.w3.org/1999/xhtml', [undef, 'html']);
6413    
6414      ## Step 5 # MUST      ## Step 4 # MUST
6415      $doc->append_child ($root);      $doc->append_child ($root);
6416    
6417      ## Step 6 # MUST      ## Step 5 # MUST
6418      push @{$p->{open_elements}}, [$root, 'html'];      push @{$p->{open_elements}}, [$root, 'html'];
6419    
6420      undef $p->{head_element};      undef $p->{head_element};
6421    
6422      ## Step 7 # MUST      ## Step 6 # MUST
6423      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;
6424    
6425      ## Step 8 # MUST      ## Step 7 # MUST
6426      my $anode = $node;      my $anode = $node;
6427      AN: while (defined $anode) {      AN: while (defined $anode) {
6428        if ($anode->node_type == 1) {        if ($anode->node_type == 1) {
6429          my $nsuri = $anode->namespace_uri;          my $nsuri = $anode->namespace_uri;
6430          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {          if (defined $nsuri and $nsuri eq 'http://www.w3.org/1999/xhtml') {
6431            if ($anode->manakai_local_name eq 'form') {            if ($anode->manakai_local_name eq 'form') {
6432                !!!cp ('i5');
6433              $p->{form_element} = $anode;              $p->{form_element} = $anode;
6434              last AN;              last AN;
6435            }            }
# Line 5871  sub set_inner_html ($$$) { Line 6438  sub set_inner_html ($$$) {
6438        $anode = $anode->parent_node;        $anode = $anode->parent_node;
6439      } # AN      } # AN
6440            
6441      ## Step 3 # MUST      ## Step 9 # MUST
     ## Step 10 # MUST  
6442      {      {
6443        my $self = $p;        my $self = $p;
6444        !!!next-token;        !!!next-token;
6445      }      }
6446      $p->_tree_construction_main;      $p->_tree_construction_main;
6447    
6448      ## Step 11 # MUST      ## Step 10 # MUST
6449      my @cn = @{$node->child_nodes};      my @cn = @{$node->child_nodes};
6450      for (@cn) {      for (@cn) {
6451        $node->remove_child ($_);        $node->remove_child ($_);
6452      }      }
6453      ## ISSUE: mutation events? read-only?      ## ISSUE: mutation events? read-only?
6454    
6455      ## Step 12 # MUST      ## Step 11 # MUST
6456      @cn = @{$root->child_nodes};      @cn = @{$root->child_nodes};
6457      for (@cn) {      for (@cn) {
6458        $this_doc->adopt_node ($_);        $this_doc->adopt_node ($_);

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24