/[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.27 by wakaba, Sun Jun 24 14:24:21 2007 UTC revision 1.35 by wakaba, Mon Jul 16 03:21:04 2007 UTC
# Line 7  our $VERSION=do{my @r=(q$Revision$=~/\d+ Line 7  our $VERSION=do{my @r=(q$Revision$=~/\d+
7  ## doc.write ('');  ## doc.write ('');
8  ## alert (doc.compatMode);  ## alert (doc.compatMode);
9    
10    ## ISSUE: HTML5 revision 967 says that the encoding layer MUST NOT
11    ## strip BOM and the HTML layer MUST ignore it.  Whether we can do it
12    ## is not yet clear.
13    ## "{U+FEFF}..." in UTF-16BE/UTF-16LE is three or four characters?
14    ## "{U+FEFF}..." in GB18030?
15    
16  my $permitted_slash_tag_name = {  my $permitted_slash_tag_name = {
17    base => 1,    base => 1,
18    link => 1,    link => 1,
# Line 327  sub _get_next_token ($) { Line 333  sub _get_next_token ($) {
333        if ($self->{content_model_flag} eq 'RCDATA' or        if ($self->{content_model_flag} eq 'RCDATA' or
334            $self->{content_model_flag} eq 'CDATA') {            $self->{content_model_flag} eq 'CDATA') {
335          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
336              ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>
337            my @next_char;            my @next_char;
338            TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {            TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {
339              push @next_char, $self->{next_input_character};              push @next_char, $self->{next_input_character};
# Line 418  sub _get_next_token ($) { Line 425  sub _get_next_token ($) {
425          redo A;          redo A;
426        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
427          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
428              $self->{current_token}->{first_start_tag}
429                  = not defined $self->{last_emitted_start_tag_name};
430            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
431          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
432            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 443  sub _get_next_token ($) { Line 452  sub _get_next_token ($) {
452        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
453          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
454          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
455              $self->{current_token}->{first_start_tag}
456                  = not defined $self->{last_emitted_start_tag_name};
457            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
458          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
459            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 489  sub _get_next_token ($) { Line 500  sub _get_next_token ($) {
500          redo A;          redo A;
501        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
502          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
503              $self->{current_token}->{first_start_tag}
504                  = not defined $self->{last_emitted_start_tag_name};
505            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
506          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
507            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 527  sub _get_next_token ($) { Line 540  sub _get_next_token ($) {
540        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
541          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
542          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
543              $self->{current_token}->{first_start_tag}
544                  = not defined $self->{last_emitted_start_tag_name};
545            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
546          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
547            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 578  sub _get_next_token ($) { Line 593  sub _get_next_token ($) {
593        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
594          $before_leave->();          $before_leave->();
595          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
596              $self->{current_token}->{first_start_tag}
597                  = not defined $self->{last_emitted_start_tag_name};
598            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
599          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
600            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 617  sub _get_next_token ($) { Line 634  sub _get_next_token ($) {
634          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
635          $before_leave->();          $before_leave->();
636          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
637              $self->{current_token}->{first_start_tag}
638                  = not defined $self->{last_emitted_start_tag_name};
639            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
640          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
641            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 653  sub _get_next_token ($) { Line 672  sub _get_next_token ($) {
672          redo A;          redo A;
673        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
674          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
675              $self->{current_token}->{first_start_tag}
676                  = not defined $self->{last_emitted_start_tag_name};
677            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
678          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
679            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 684  sub _get_next_token ($) { Line 705  sub _get_next_token ($) {
705            #            #
706          } else {          } else {
707            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
708              ## TODO: Different error type for <aa / bb> than <aa/>
709          }          }
710          $self->{state} = 'before attribute name';          $self->{state} = 'before attribute name';
711          # next-input-character is already done          # next-input-character is already done
# Line 691  sub _get_next_token ($) { Line 713  sub _get_next_token ($) {
713        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
714          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
715          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
716              $self->{current_token}->{first_start_tag}
717                  = not defined $self->{last_emitted_start_tag_name};
718            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
719          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
720            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 736  sub _get_next_token ($) { Line 760  sub _get_next_token ($) {
760          redo A;          redo A;
761        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
762          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
763              $self->{current_token}->{first_start_tag}
764                  = not defined $self->{last_emitted_start_tag_name};
765            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
766          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
767            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 754  sub _get_next_token ($) { Line 780  sub _get_next_token ($) {
780        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
781          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
782          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
783              $self->{current_token}->{first_start_tag}
784                  = not defined $self->{last_emitted_start_tag_name};
785            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
786          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
787            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 788  sub _get_next_token ($) { Line 816  sub _get_next_token ($) {
816        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
817          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
818          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
819              $self->{current_token}->{first_start_tag}
820                  = not defined $self->{last_emitted_start_tag_name};
821            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
822          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
823            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 822  sub _get_next_token ($) { Line 852  sub _get_next_token ($) {
852        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
853          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
854          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
855              $self->{current_token}->{first_start_tag}
856                  = not defined $self->{last_emitted_start_tag_name};
857            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
858          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
859            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 859  sub _get_next_token ($) { Line 891  sub _get_next_token ($) {
891          redo A;          redo A;
892        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
893          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
894              $self->{current_token}->{first_start_tag}
895                  = not defined $self->{last_emitted_start_tag_name};
896            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
897          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
898            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 877  sub _get_next_token ($) { Line 911  sub _get_next_token ($) {
911        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
912          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
913          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
914              $self->{current_token}->{first_start_tag}
915                  = not defined $self->{last_emitted_start_tag_name};
916            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
917          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
918            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model_flag} = 'PCDATA'; # MUST
# Line 990  sub _get_next_token ($) { Line 1026  sub _get_next_token ($) {
1026          }          }
1027        }        }
1028    
1029        !!!parse-error (type => 'bogus comment open');        !!!parse-error (type => 'bogus comment');
1030        $self->{next_input_character} = shift @next_char;        $self->{next_input_character} = shift @next_char;
1031        !!!back-next-input-character (@next_char);        !!!back-next-input-character (@next_char);
1032        $self->{state} = 'bogus comment';        $self->{state} = 'bogus comment';
# Line 1049  sub _get_next_token ($) { Line 1085  sub _get_next_token ($) {
1085          redo A;          redo A;
1086        } else {        } else {
1087          $self->{current_token}->{data} # comment          $self->{current_token}->{data} # comment
1088              .= chr ($self->{next_input_character});              .= '-' . chr ($self->{next_input_character});
1089          $self->{state} = 'comment';          $self->{state} = 'comment';
1090          !!!next-input-character;          !!!next-input-character;
1091          redo A;          redo A;
# Line 1459  sub _get_next_token ($) { Line 1495  sub _get_next_token ($) {
1495    
1496          redo A;          redo A;
1497        } else {        } else {
1498          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after SYSTEM');
1499          $self->{state} = 'bogus DOCTYPE';          $self->{state} = 'bogus DOCTYPE';
1500          !!!next-input-character;          !!!next-input-character;
1501          redo A;          redo A;
# Line 1627  sub _tokenize_attempt_to_consume_an_enti Line 1663  sub _tokenize_attempt_to_consume_an_enti
1663            !!!parse-error (type => 'CR character reference');            !!!parse-error (type => 'CR character reference');
1664            $code = 0x000A;            $code = 0x000A;
1665          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
1666            !!!parse-error (type => sprintf 'c1 entity:U+%04X', $code);            !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
1667            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
1668          }          }
1669    
# Line 1662  sub _tokenize_attempt_to_consume_an_enti Line 1698  sub _tokenize_attempt_to_consume_an_enti
1698          !!!parse-error (type => 'CR character reference');          !!!parse-error (type => 'CR character reference');
1699          $code = 0x000A;          $code = 0x000A;
1700        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
1701          !!!parse-error (type => sprintf 'c1 entity:U+%04X', $code);          !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
1702          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
1703        }        }
1704                
# Line 1716  sub _tokenize_attempt_to_consume_an_enti Line 1752  sub _tokenize_attempt_to_consume_an_enti
1752      if ($match > 0) {      if ($match > 0) {
1753        return {type => 'character', data => $value};        return {type => 'character', data => $value};
1754      } elsif ($match < 0) {      } elsif ($match < 0) {
1755        !!!parse-error (type => 'refc');        !!!parse-error (type => 'no refc');
1756        return {type => 'character', data => $value};        return {type => 'character', data => $value};
1757      } else {      } else {
1758        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
# Line 1982  sub _tree_construction_root_element ($) Line 2018  sub _tree_construction_root_element ($)
2018        my $root_element; !!!create-element ($root_element, 'html');        my $root_element; !!!create-element ($root_element, 'html');
2019        $self->{document}->append_child ($root_element);        $self->{document}->append_child ($root_element);
2020        push @{$self->{open_elements}}, [$root_element, 'html'];        push @{$self->{open_elements}}, [$root_element, 'html'];
       #$phase = 'main';  
2021        ## reprocess        ## reprocess
2022        #redo B;        #redo B;
2023        return;        return; ## Go to the main phase.
2024    } # B    } # B
2025  } # _tree_construction_root_element  } # _tree_construction_root_element
2026    
# Line 2001  sub _reset_insertion_mode ($) { Line 2036  sub _reset_insertion_mode ($) {
2036            
2037      ## Step 3      ## Step 3
2038      S3: {      S3: {
2039        $last = 1 if $self->{open_elements}->[0]->[0] eq $node->[0];        ## ISSUE: Oops! "If node is the first node in the stack of open
2040        if (defined $self->{inner_html_node}) {        ## elements, then set last to true. If the context element of the
2041          if ($self->{inner_html_node}->[1] eq 'td' or        ## HTML fragment parsing algorithm is neither a td element nor a
2042              $self->{inner_html_node}->[1] eq 'th') {        ## th element, then set node to the context element. (fragment case)":
2043            #        ## The second "if" is in the scope of the first "if"!?
2044          } else {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
2045            $node = $self->{inner_html_node};          $last = 1;
2046            if (defined $self->{inner_html_node}) {
2047              if ($self->{inner_html_node}->[1] eq 'td' or
2048                  $self->{inner_html_node}->[1] eq 'th') {
2049                #
2050              } else {
2051                $node = $self->{inner_html_node};
2052              }
2053          }          }
2054        }        }
2055            
# Line 2054  sub _reset_insertion_mode ($) { Line 2096  sub _reset_insertion_mode ($) {
2096  sub _tree_construction_main ($) {  sub _tree_construction_main ($) {
2097    my $self = shift;    my $self = shift;
2098    
2099    my $phase = 'main';    my $previous_insertion_mode;
2100    
2101    my $active_formatting_elements = [];    my $active_formatting_elements = [];
2102    
# Line 2455  sub _tree_construction_main ($) { Line 2497  sub _tree_construction_main ($) {
2497          $parse_rcdata->('CDATA', $insert);          $parse_rcdata->('CDATA', $insert);
2498          return;          return;
2499        } elsif ({        } elsif ({
2500                  base => 1, link => 1, meta => 1,                  base => 1, link => 1,
2501                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
2502          ## 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
2503          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2504          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
2505          !!!next-token;          !!!next-token;
2506          ## TODO: Extracting |charset| from |meta|.          return;
2507          } elsif ($token->{tag_name} eq 'meta') {
2508            ## NOTE: This is an "as if in head" code clone, only "-t" differs
2509            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2510            pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
2511    
2512            unless ($self->{confident}) {
2513              my $charset;
2514              if ($token->{attributes}->{charset}) { ## TODO: And if supported
2515                $charset = $token->{attributes}->{charset}->{value};
2516              }
2517              if ($token->{attributes}->{'http-equiv'}) {
2518                ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.
2519                if ($token->{attributes}->{'http-equiv'}->{value}
2520                    =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
2521                        [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
2522                        ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
2523                  $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
2524                } ## TODO: And if supported
2525              }
2526              ## TODO: Change the encoding
2527            }
2528    
2529            !!!next-token;
2530          return;          return;
2531        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
2532          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
2533          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
2534          $parse_rcdata->('RCDATA', $insert);          $parse_rcdata->('RCDATA', sub {
2535              if (defined $self->{head_element}) {
2536                $self->{head_element}->append_child ($_[0]);
2537              } else {
2538                $insert->($_[0]);
2539              }
2540            });
2541          return;          return;
2542        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
2543          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 2569  sub _tree_construction_main ($) { Line 2640  sub _tree_construction_main ($) {
2640              if ($i != -1) {              if ($i != -1) {
2641                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
2642                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
               ## TODO: test  
2643              }              }
2644              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2645              last LI;              last LI;
# Line 2617  sub _tree_construction_main ($) { Line 2687  sub _tree_construction_main ($) {
2687              if ($i != -1) {              if ($i != -1) {
2688                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
2689                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
               ## TODO: test  
2690              }              }
2691              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2692              last LI;              last LI;
# Line 2761  sub _tree_construction_main ($) { Line 2830  sub _tree_construction_main ($) {
2830          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2831            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
2832            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
2833                !!!parse-error (type => 'not closed:nobr');
2834              !!!back-token;              !!!back-token;
2835              $token = {type => 'end tag', tag_name => 'nobr'};              $token = {type => 'end tag', tag_name => 'nobr'};
2836              return;              return;
# Line 2844  sub _tree_construction_main ($) { Line 2914  sub _tree_construction_main ($) {
2914            !!!parse-error (type => 'image');            !!!parse-error (type => 'image');
2915            $token->{tag_name} = 'img';            $token->{tag_name} = 'img';
2916          }          }
2917            
2918            ## NOTE: There is an "as if <br>" code clone.
2919          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2920                    
2921          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 3002  sub _tree_construction_main ($) { Line 3073  sub _tree_construction_main ($) {
3073              unless ({              unless ({
3074                         dd => 1, dt => 1, li => 1, p => 1, td => 1,                         dd => 1, dt => 1, li => 1, p => 1, td => 1,
3075                         th => 1, tr => 1, body => 1, html => 1,                         th => 1, tr => 1, body => 1, html => 1,
3076                         tbody => 1, tfoot => 1, thead => 1,
3077                      }->{$_->[1]}) {                      }->{$_->[1]}) {
3078                !!!parse-error (type => 'not closed:'.$_->[1]);                !!!parse-error (type => 'not closed:'.$_->[1]);
3079              }              }
# Line 3051  sub _tree_construction_main ($) { Line 3123  sub _tree_construction_main ($) {
3123                   li => ($token->{tag_name} ne 'li'),                   li => ($token->{tag_name} ne 'li'),
3124                   p => ($token->{tag_name} ne 'p'),                   p => ($token->{tag_name} ne 'p'),
3125                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3126                     tbody => 1, tfoot=> 1, thead => 1,
3127                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3128                !!!back-token;                !!!back-token;
3129                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3068  sub _tree_construction_main ($) { Line 3141  sub _tree_construction_main ($) {
3141          } # INSCOPE          } # INSCOPE
3142                    
3143          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3144            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            if (defined $i) {
3145                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3146              } else {
3147                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3148              }
3149          }          }
3150                    
3151          splice @{$self->{open_elements}}, $i if defined $i;          if (defined $i) {
3152              splice @{$self->{open_elements}}, $i;
3153            } elsif ($token->{tag_name} eq 'p') {
3154              ## As if <p>, then reprocess the current token
3155              my $el;
3156              !!!create-element ($el, 'p');
3157              $insert->($el);
3158            }
3159          $clear_up_to_marker->()          $clear_up_to_marker->()
3160            if {            if {
3161              button => 1, marquee => 1, object => 1,              button => 1, marquee => 1, object => 1,
# Line 3087  sub _tree_construction_main ($) { Line 3171  sub _tree_construction_main ($) {
3171              if ({              if ({
3172                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3173                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3174                     tbody => 1, tfoot=> 1, thead => 1,
3175                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3176                !!!back-token;                !!!back-token;
3177                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3125  sub _tree_construction_main ($) { Line 3210  sub _tree_construction_main ($) {
3210              if ({              if ({
3211                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3212                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3213                     tbody => 1, tfoot=> 1, thead => 1,
3214                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3215                !!!back-token;                !!!back-token;
3216                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3155  sub _tree_construction_main ($) { Line 3241  sub _tree_construction_main ($) {
3241                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
3242                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
3243          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
3244  ## TODO: <http://html5.org/tools/web-apps-tracker?from=883&to=884>          return;
3245          } elsif ($token->{tag_name} eq 'br') {
3246            !!!parse-error (type => 'unmatched end tag:br');
3247    
3248            ## As if <br>
3249            $reconstruct_active_formatting_elements->($insert_to_current);
3250            
3251            my $el;
3252            !!!create-element ($el, 'br');
3253            $insert->($el);
3254            
3255            ## Ignore the token.
3256            !!!next-token;
3257          return;          return;
3258        } elsif ({        } elsif ({
3259                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
3260                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
3261                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
3262                  thead => 1, tr => 1,                  thead => 1, tr => 1,
3263                  area => 1, basefont => 1, bgsound => 1, br => 1,                  area => 1, basefont => 1, bgsound => 1,
3264                  embed => 1, hr => 1, iframe => 1, image => 1,                  embed => 1, hr => 1, iframe => 1, image => 1,
3265                  img => 1, input => 1, isindex => 1, noembed => 1,                  img => 1, input => 1, isindex => 1, noembed => 1,
3266                  noframes => 1, param => 1, select => 1, spacer => 1,                  noframes => 1, param => 1, select => 1, spacer => 1,
# Line 3189  sub _tree_construction_main ($) { Line 3287  sub _tree_construction_main ($) {
3287              if ({              if ({
3288                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3289                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3290                     tbody => 1, tfoot=> 1, thead => 1,
3291                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3292                !!!back-token;                !!!back-token;
3293                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3232  sub _tree_construction_main ($) { Line 3331  sub _tree_construction_main ($) {
3331    }; # $in_body    }; # $in_body
3332    
3333    B: {    B: {
3334      if ($phase eq 'main') {      if ($self->{insertion_mode} ne 'trailing end') {
3335        if ($token->{type} eq 'DOCTYPE') {        if ($token->{type} eq 'DOCTYPE') {
3336          !!!parse-error (type => 'in html:#DOCTYPE');          !!!parse-error (type => 'in html:#DOCTYPE');
3337          ## Ignore the token          ## Ignore the token
# Line 3241  sub _tree_construction_main ($) { Line 3340  sub _tree_construction_main ($) {
3340          redo B;          redo B;
3341        } elsif ($token->{type} eq 'start tag' and        } elsif ($token->{type} eq 'start tag' and
3342                 $token->{tag_name} eq 'html') {                 $token->{tag_name} eq 'html') {
3343          ## TODO: unless it is the first start tag token, parse-error  ## ISSUE: "aa<html>" is not a parse error.
3344    ## ISSUE: "<html>" in fragment is not a parse error.
3345            unless ($token->{first_start_tag}) {
3346              !!!parse-error (type => 'not first start tag');
3347            }
3348          my $top_el = $self->{open_elements}->[0]->[0];          my $top_el = $self->{open_elements}->[0]->[0];
3349          for my $attr_name (keys %{$token->{attributes}}) {          for my $attr_name (keys %{$token->{attributes}}) {
3350            unless ($top_el->has_attribute_ns (undef, $attr_name)) {            unless ($top_el->has_attribute_ns (undef, $attr_name)) {
# Line 3256  sub _tree_construction_main ($) { Line 3359  sub _tree_construction_main ($) {
3359          ## Generate implied end tags          ## Generate implied end tags
3360          if ({          if ({
3361               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,
3362                 tbody => 1, tfoot=> 1, thead => 1,
3363              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
3364            !!!back-token;            !!!back-token;
3365            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};
# Line 3315  sub _tree_construction_main ($) { Line 3419  sub _tree_construction_main ($) {
3419              }              }
3420              redo B;              redo B;
3421            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3422              if ({head => 1, body => 1, html => 1}->{$token->{tag_name}}) {              if ({
3423                     head => 1, body => 1, html => 1,
3424                     p => 1, br => 1,
3425                    }->{$token->{tag_name}}) {
3426                ## As if <head>                ## As if <head>
3427                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3428                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3353  sub _tree_construction_main ($) { Line 3460  sub _tree_construction_main ($) {
3460            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3461              if ({base => ($self->{insertion_mode} eq 'in head' or              if ({base => ($self->{insertion_mode} eq 'in head' or
3462                            $self->{insertion_mode} eq 'after head'),                            $self->{insertion_mode} eq 'after head'),
3463                   link => 1, meta => 1}->{$token->{tag_name}}) {                   link => 1}->{$token->{tag_name}}) {
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} eq 'after head') {                if ($self->{insertion_mode} eq 'after head') {
3466                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
# Line 3361  sub _tree_construction_main ($) { Line 3468  sub _tree_construction_main ($) {
3468                }                }
3469                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
3470                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3471                  pop @{$self->{open_elements}}
3472                      if $self->{insertion_mode} eq 'after head';
3473                  !!!next-token;
3474                  redo B;
3475                } elsif ($token->{tag_name} eq 'meta') {
3476                  ## NOTE: There is a "as if in head" code clone.
3477                  if ($self->{insertion_mode} eq 'after head') {
3478                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3479                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3480                  }
3481                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3482                  pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3483    
3484                  unless ($self->{confident}) {
3485                    my $charset;
3486                    if ($token->{attributes}->{charset}) { ## TODO: And if supported
3487                      $charset = $token->{attributes}->{charset}->{value};
3488                    }
3489                    if ($token->{attributes}->{'http-equiv'}) {
3490                      ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.
3491                      if ($token->{attributes}->{'http-equiv'}->{value}
3492                          =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
3493                              [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
3494                              ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
3495                        $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
3496                      } ## TODO: And if supported
3497                    }
3498                    ## TODO: Change the encoding
3499                  }
3500    
3501                ## TODO: Extracting |charset| from |meta|.                ## TODO: Extracting |charset| from |meta|.
3502                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3503                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
# Line 3373  sub _tree_construction_main ($) { Line 3510  sub _tree_construction_main ($) {
3510                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3511                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3512                }                }
3513                $parse_rcdata->('RCDATA', $insert_to_current);                my $parent = defined $self->{head_element} ? $self->{head_element}
3514                      : $self->{open_elements}->[-1]->[0];
3515                  $parse_rcdata->('RCDATA', sub { $parent->append_child ($_[0]) });
3516                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3517                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
3518                redo B;                redo B;
# Line 3397  sub _tree_construction_main ($) { Line 3536  sub _tree_construction_main ($) {
3536                  !!!next-token;                  !!!next-token;
3537                  redo B;                  redo B;
3538                } elsif ($self->{insertion_mode} eq 'in head noscript') {                } elsif ($self->{insertion_mode} eq 'in head noscript') {
3539                  !!!parse-error (type => 'noscript in noscript');                  !!!parse-error (type => 'in noscript:noscript');
3540                  ## Ignore the token                  ## Ignore the token
3541                  redo B;                  redo B;
3542                } else {                } else {
# Line 3449  sub _tree_construction_main ($) { Line 3588  sub _tree_construction_main ($) {
3588                !!!next-token;                !!!next-token;
3589                redo B;                redo B;
3590              } elsif ($self->{insertion_mode} eq 'in head' and              } elsif ($self->{insertion_mode} eq 'in head' and
3591                       ($token->{tag_name} eq 'body' or                       {
3592                        $token->{tag_name} eq 'html')) {                        body => 1, html => 1,
3593                          p => 1, br => 1,
3594                         }->{$token->{tag_name}}) {
3595                  #
3596                } elsif ($self->{insertion_mode} eq 'in head noscript' and
3597                         {
3598                          p => 1, br => 1,
3599                         }->{$token->{tag_name}}) {
3600                #                #
3601              } elsif ($self->{insertion_mode} ne 'after head') {              } elsif ($self->{insertion_mode} ne 'after head') {
3602                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
# Line 3634  sub _tree_construction_main ($) { Line 3780  sub _tree_construction_main ($) {
3780                if ({                if ({
3781                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3782                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3783                       tbody => 1, tfoot=> 1, thead => 1,
3784                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3785                  !!!back-token; # <table>                  !!!back-token; # <table>
3786                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 3682  sub _tree_construction_main ($) { Line 3829  sub _tree_construction_main ($) {
3829                if ({                if ({
3830                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3831                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3832                       tbody => 1, tfoot=> 1, thead => 1,
3833                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3834                  !!!back-token;                  !!!back-token;
3835                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 3765  sub _tree_construction_main ($) { Line 3913  sub _tree_construction_main ($) {
3913                if ({                if ({
3914                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3915                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3916                       tbody => 1, tfoot=> 1, thead => 1,
3917                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3918                  !!!back-token; # <?>                  !!!back-token; # <?>
3919                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => 'end tag', tag_name => 'caption'};
# Line 3815  sub _tree_construction_main ($) { Line 3964  sub _tree_construction_main ($) {
3964                if ({                if ({
3965                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3966                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3967                       tbody => 1, tfoot=> 1, thead => 1,
3968                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3969                  !!!back-token;                  !!!back-token;
3970                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 3862  sub _tree_construction_main ($) { Line 4012  sub _tree_construction_main ($) {
4012                if ({                if ({
4013                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4014                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4015                       tbody => 1, tfoot=> 1, thead => 1,
4016                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4017                  !!!back-token; # </table>                  !!!back-token; # </table>
4018                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => 'end tag', tag_name => 'caption'};
# Line 4127  sub _tree_construction_main ($) { Line 4278  sub _tree_construction_main ($) {
4278                if ({                if ({
4279                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4280                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4281                       tbody => 1, tfoot=> 1, thead => 1,
4282                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4283                  !!!back-token; # <table>                  !!!back-token; # <table>
4284                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 4395  sub _tree_construction_main ($) { Line 4547  sub _tree_construction_main ($) {
4547                if ({                if ({
4548                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4549                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4550                       tbody => 1, tfoot=> 1, thead => 1,
4551                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4552                  !!!back-token; # <table>                  !!!back-token; # <table>
4553                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 4636  sub _tree_construction_main ($) { Line 4789  sub _tree_construction_main ($) {
4789                     td => ($token->{tag_name} eq 'th'),                     td => ($token->{tag_name} eq 'th'),
4790                     th => ($token->{tag_name} eq 'td'),                     th => ($token->{tag_name} eq 'td'),
4791                     tr => 1,                     tr => 1,
4792                       tbody => 1, tfoot=> 1, thead => 1,
4793                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4794                  !!!back-token;                  !!!back-token;
4795                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 4887  sub _tree_construction_main ($) { Line 5041  sub _tree_construction_main ($) {
5041          } elsif ($self->{insertion_mode} eq 'after body') {          } elsif ($self->{insertion_mode} eq 'after body') {
5042            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
5043              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5044                  my $data = $1;
5045                ## As if in body                ## As if in body
5046                $reconstruct_active_formatting_elements->($insert_to_current);                $reconstruct_active_formatting_elements->($insert_to_current);
5047                                
5048                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5049    
5050                unless (length $token->{data}) {                unless (length $token->{data}) {
5051                  !!!next-token;                  !!!next-token;
# Line 4916  sub _tree_construction_main ($) { Line 5071  sub _tree_construction_main ($) {
5071                  !!!next-token;                  !!!next-token;
5072                  redo B;                  redo B;
5073                } else {                } else {
5074                  $phase = 'trailing end';                  $previous_insertion_mode = $self->{insertion_mode};
5075                    $self->{insertion_mode} = 'trailing end';
5076                  !!!next-token;                  !!!next-token;
5077                  redo B;                  redo B;
5078                }                }
# Line 4933  sub _tree_construction_main ($) { Line 5089  sub _tree_construction_main ($) {
5089          } elsif ($self->{insertion_mode} eq 'in frameset') {          } elsif ($self->{insertion_mode} eq 'in frameset') {
5090            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
5091              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5092                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5093    
5094                unless (length $token->{data}) {                unless (length $token->{data}) {
5095                  !!!next-token;                  !!!next-token;
# Line 4988  sub _tree_construction_main ($) { Line 5144  sub _tree_construction_main ($) {
5144            }            }
5145                        
5146            if (defined $token->{tag_name}) {            if (defined $token->{tag_name}) {
5147              !!!parse-error (type => 'in frameset:'.$token->{tag_name});              !!!parse-error (type => 'in frameset:'.($token->{type} eq 'end tag' ? '/' : '').$token->{tag_name});
5148            } else {            } else {
5149              !!!parse-error (type => 'in frameset:#'.$token->{type});              !!!parse-error (type => 'in frameset:#'.$token->{type});
5150            }            }
# Line 4998  sub _tree_construction_main ($) { Line 5154  sub _tree_construction_main ($) {
5154          } elsif ($self->{insertion_mode} eq 'after frameset') {          } elsif ($self->{insertion_mode} eq 'after frameset') {
5155            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
5156              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5157                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5158    
5159                unless (length $token->{data}) {                unless (length $token->{data}) {
5160                  !!!next-token;                  !!!next-token;
# Line 5006  sub _tree_construction_main ($) { Line 5162  sub _tree_construction_main ($) {
5162                }                }
5163              }              }
5164    
5165              #              if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
5166                  !!!parse-error (type => 'after frameset:#character');
5167    
5168                  ## Ignore the token.
5169                  if (length $token->{data}) {
5170                    ## reprocess the rest of characters
5171                  } else {
5172                    !!!next-token;
5173                  }
5174                  redo B;
5175                }
5176            } elsif ($token->{type} eq 'comment') {            } elsif ($token->{type} eq 'comment') {
5177              my $comment = $self->{document}->create_comment ($token->{data});              my $comment = $self->{document}->create_comment ($token->{data});
5178              $self->{open_elements}->[-1]->[0]->append_child ($comment);              $self->{open_elements}->[-1]->[0]->append_child ($comment);
# Line 5021  sub _tree_construction_main ($) { Line 5187  sub _tree_construction_main ($) {
5187              }              }
5188            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
5189              if ($token->{tag_name} eq 'html') {              if ($token->{tag_name} eq 'html') {
5190                $phase = 'trailing end';                $previous_insertion_mode = $self->{insertion_mode};
5191                  $self->{insertion_mode} = 'trailing end';
5192                !!!next-token;                !!!next-token;
5193                redo B;                redo B;
5194              } else {              } else {
5195                #                #
5196              }              }
5197            } else {            } else {
5198              #              die "$0: $token->{type}: Unknown token type";
5199            }            }
5200                        
5201            if (defined $token->{tag_name}) {            !!!parse-error (type => 'after frameset:'.($token->{tag_name} eq 'end tag' ? '/' : '').$token->{tag_name});
             !!!parse-error (type => 'after frameset:'.$token->{tag_name});  
           } else {  
             !!!parse-error (type => 'after frameset:#'.$token->{type});  
           }  
5202            ## Ignore the token            ## Ignore the token
5203            !!!next-token;            !!!next-token;
5204            redo B;            redo B;
# Line 5045  sub _tree_construction_main ($) { Line 5208  sub _tree_construction_main ($) {
5208            die "$0: $self->{insertion_mode}: Unknown insertion mode";            die "$0: $self->{insertion_mode}: Unknown insertion mode";
5209          }          }
5210        }        }
5211      } elsif ($phase eq 'trailing end') {      } elsif ($self->{insertion_mode} eq 'trailing end') {
5212        ## states in the main stage is preserved yet # MUST        ## states in the main stage is preserved yet # MUST
5213                
5214        if ($token->{type} eq 'DOCTYPE') {        if ($token->{type} eq 'DOCTYPE') {
# Line 5065  sub _tree_construction_main ($) { Line 5228  sub _tree_construction_main ($) {
5228            ## NOTE: The insertion mode in the main phase            ## NOTE: The insertion mode in the main phase
5229            ## just before the phase has been changed to the trailing            ## just before the phase has been changed to the trailing
5230            ## end phase is either "after body" or "after frameset".            ## end phase is either "after body" or "after frameset".
5231            $reconstruct_active_formatting_elements->($insert_to_current)            $reconstruct_active_formatting_elements->($insert_to_current);
             if $phase eq 'main';  
5232                        
5233            $self->{open_elements}->[-1]->[0]->manakai_append_text ($data);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($data);
5234                        
# Line 5077  sub _tree_construction_main ($) { Line 5239  sub _tree_construction_main ($) {
5239          }          }
5240    
5241          !!!parse-error (type => 'after html:#character');          !!!parse-error (type => 'after html:#character');
5242          $phase = 'main';          $self->{insertion_mode} = $previous_insertion_mode;
5243          ## reprocess          ## reprocess
5244          redo B;          redo B;
5245        } elsif ($token->{type} eq 'start tag' or        } elsif ($token->{type} eq 'start tag' or
5246                 $token->{type} eq 'end tag') {                 $token->{type} eq 'end tag') {
5247          !!!parse-error (type => 'after html:'.$token->{tag_name});          !!!parse-error (type => 'after html:'.($token->{type} eq 'end tag' ? '/' : '').$token->{tag_name});
5248          $phase = 'main';          $self->{insertion_mode} = $previous_insertion_mode;
5249          ## reprocess          ## reprocess
5250          redo B;          redo B;
5251        } elsif ($token->{type} eq 'end-of-file') {        } elsif ($token->{type} eq 'end-of-file') {

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.35

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24