/[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.25 by wakaba, Sun Jun 24 05:12:11 2007 UTC revision 1.39 by wakaba, Sat Jul 21 04:55:20 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 247  sub _get_next_token ($) { Line 253  sub _get_next_token ($) {
253      } elsif ($self->{state} eq 'entity data') {      } elsif ($self->{state} eq 'entity data') {
254        ## (cannot happen in CDATA state)        ## (cannot happen in CDATA state)
255                
256        my $token = $self->_tokenize_attempt_to_consume_an_entity;        my $token = $self->_tokenize_attempt_to_consume_an_entity (0);
257    
258        $self->{state} = 'data';        $self->{state} = 'data';
259        # next-input-character is already done        # next-input-character is already done
# 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 553  sub _get_next_token ($) { Line 568  sub _get_next_token ($) {
568        my $before_leave = sub {        my $before_leave = sub {
569          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
570              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
571            !!!parse-error (type => 'dupulicate attribute');            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name});
572            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
573          } else {          } else {
574            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}
# 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 899  sub _get_next_token ($) { Line 935  sub _get_next_token ($) {
935          redo A;          redo A;
936        }        }
937      } elsif ($self->{state} eq 'entity in attribute value') {      } elsif ($self->{state} eq 'entity in attribute value') {
938        my $token = $self->_tokenize_attempt_to_consume_an_entity;        my $token = $self->_tokenize_attempt_to_consume_an_entity (1);
939    
940        unless (defined $token) {        unless (defined $token) {
941          $self->{current_attribute}->{value} .= '&';          $self->{current_attribute}->{value} .= '&';
# 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 1409  sub _get_next_token ($) { Line 1445  sub _get_next_token ($) {
1445          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1446    
1447          $self->{state} = 'data';          $self->{state} = 'data';
1448          ## recomsume          ## reconsume
1449    
1450          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1451          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
# Line 1452  sub _get_next_token ($) { Line 1488  sub _get_next_token ($) {
1488          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1489    
1490          $self->{state} = 'data';          $self->{state} = 'data';
1491          ## recomsume          ## reconsume
1492    
1493          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1494          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
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 1527  sub _get_next_token ($) { Line 1563  sub _get_next_token ($) {
1563          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1564    
1565          $self->{state} = 'data';          $self->{state} = 'data';
1566          ## recomsume          ## reconsume
1567    
1568          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1569          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
# Line 1570  sub _get_next_token ($) { Line 1606  sub _get_next_token ($) {
1606    die "$0: _get_next_token: unexpected case";    die "$0: _get_next_token: unexpected case";
1607  } # _get_next_token  } # _get_next_token
1608    
1609  sub _tokenize_attempt_to_consume_an_entity ($) {  sub _tokenize_attempt_to_consume_an_entity ($$) {
1610    my $self = shift;    my ($self, $in_attr) = @_;
1611    
1612    if ({    if ({
1613         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,         0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
# Line 1584  sub _tokenize_attempt_to_consume_an_enti Line 1620  sub _tokenize_attempt_to_consume_an_enti
1620      !!!next-input-character;      !!!next-input-character;
1621      if ($self->{next_input_character} == 0x0078 or # x      if ($self->{next_input_character} == 0x0078 or # x
1622          $self->{next_input_character} == 0x0058) { # X          $self->{next_input_character} == 0x0058) { # X
1623        my $num;        my $code;
1624        X: {        X: {
1625          my $x_char = $self->{next_input_character};          my $x_char = $self->{next_input_character};
1626          !!!next-input-character;          !!!next-input-character;
1627          if (0x0030 <= $self->{next_input_character} and          if (0x0030 <= $self->{next_input_character} and
1628              $self->{next_input_character} <= 0x0039) { # 0..9              $self->{next_input_character} <= 0x0039) { # 0..9
1629            $num ||= 0;            $code ||= 0;
1630            $num *= 0x10;            $code *= 0x10;
1631            $num += $self->{next_input_character} - 0x0030;            $code += $self->{next_input_character} - 0x0030;
1632            redo X;            redo X;
1633          } elsif (0x0061 <= $self->{next_input_character} and          } elsif (0x0061 <= $self->{next_input_character} and
1634                   $self->{next_input_character} <= 0x0066) { # a..f                   $self->{next_input_character} <= 0x0066) { # a..f
1635            ## ISSUE: the spec says U+0078, which is apparently incorrect            $code ||= 0;
1636            $num ||= 0;            $code *= 0x10;
1637            $num *= 0x10;            $code += $self->{next_input_character} - 0x0060 + 9;
           $num += $self->{next_input_character} - 0x0060 + 9;  
1638            redo X;            redo X;
1639          } elsif (0x0041 <= $self->{next_input_character} and          } elsif (0x0041 <= $self->{next_input_character} and
1640                   $self->{next_input_character} <= 0x0046) { # A..F                   $self->{next_input_character} <= 0x0046) { # A..F
1641            ## ISSUE: the spec says U+0058, which is apparently incorrect            $code ||= 0;
1642            $num ||= 0;            $code *= 0x10;
1643            $num *= 0x10;            $code += $self->{next_input_character} - 0x0040 + 9;
           $num += $self->{next_input_character} - 0x0040 + 9;  
1644            redo X;            redo X;
1645          } elsif (not defined $num) { # no hexadecimal digit          } elsif (not defined $code) { # no hexadecimal digit
1646            !!!parse-error (type => 'bare hcro');            !!!parse-error (type => 'bare hcro');
1647              !!!back-next-input-character ($x_char, $self->{next_input_character});
1648            $self->{next_input_character} = 0x0023; # #            $self->{next_input_character} = 0x0023; # #
           !!!back-next-input-character ($x_char);  
1649            return undef;            return undef;
1650          } elsif ($self->{next_input_character} == 0x003B) { # ;          } elsif ($self->{next_input_character} == 0x003B) { # ;
1651            !!!next-input-character;            !!!next-input-character;
# Line 1619  sub _tokenize_attempt_to_consume_an_enti Line 1653  sub _tokenize_attempt_to_consume_an_enti
1653            !!!parse-error (type => 'no refc');            !!!parse-error (type => 'no refc');
1654          }          }
1655    
1656          ## TODO: check the definition for |a valid Unicode character|.          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
1657          ## <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-December/thread.html#8189>            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
1658          if ($num > 1114111 or $num == 0) {            $code = 0xFFFD;
1659            $num = 0xFFFD; # REPLACEMENT CHARACTER          } elsif ($code > 0x10FFFF) {
1660            ## ISSUE: Why this is not an error?            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
1661          } elsif (0x80 <= $num and $num <= 0x9F) {            $code = 0xFFFD;
1662            !!!parse-error (type => sprintf 'c1 entity:U+%04X', $num);          } elsif ($code == 0x000D) {
1663            $num = $c1_entity_char->{$num};            !!!parse-error (type => 'CR character reference');
1664              $code = 0x000A;
1665            } elsif (0x80 <= $code and $code <= 0x9F) {
1666              !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
1667              $code = $c1_entity_char->{$code};
1668          }          }
1669    
1670          return {type => 'character', data => chr $num};          return {type => 'character', data => chr $code};
1671        } # X        } # X
1672      } elsif (0x0030 <= $self->{next_input_character} and      } elsif (0x0030 <= $self->{next_input_character} and
1673               $self->{next_input_character} <= 0x0039) { # 0..9               $self->{next_input_character} <= 0x0039) { # 0..9
# Line 1650  sub _tokenize_attempt_to_consume_an_enti Line 1688  sub _tokenize_attempt_to_consume_an_enti
1688          !!!parse-error (type => 'no refc');          !!!parse-error (type => 'no refc');
1689        }        }
1690    
1691        ## TODO: check the definition for |a valid Unicode character|.        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
1692        if ($code > 1114111 or $code == 0) {          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
1693          $code = 0xFFFD; # REPLACEMENT CHARACTER          $code = 0xFFFD;
1694          ## ISSUE: Why this is not an error?        } elsif ($code > 0x10FFFF) {
1695            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
1696            $code = 0xFFFD;
1697          } elsif ($code == 0x000D) {
1698            !!!parse-error (type => 'CR character reference');
1699            $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 1674  sub _tokenize_attempt_to_consume_an_enti Line 1717  sub _tokenize_attempt_to_consume_an_enti
1717      !!!next-input-character;      !!!next-input-character;
1718    
1719      my $value = $entity_name;      my $value = $entity_name;
1720      my $match;      my $match = 0;
1721      require Whatpm::_NamedEntityList;      require Whatpm::_NamedEntityList;
1722      our $EntityChar;      our $EntityChar;
1723    
# Line 1689  sub _tokenize_attempt_to_consume_an_enti Line 1732  sub _tokenize_attempt_to_consume_an_enti
1732              $self->{next_input_character} == 0x003B)) { # ;              $self->{next_input_character} == 0x003B)) { # ;
1733        $entity_name .= chr $self->{next_input_character};        $entity_name .= chr $self->{next_input_character};
1734        if (defined $EntityChar->{$entity_name}) {        if (defined $EntityChar->{$entity_name}) {
         $value = $EntityChar->{$entity_name};  
1735          if ($self->{next_input_character} == 0x003B) { # ;          if ($self->{next_input_character} == 0x003B) { # ;
1736              $value = $EntityChar->{$entity_name};
1737            $match = 1;            $match = 1;
1738            !!!next-input-character;            !!!next-input-character;
1739            last;            last;
1740          } else {          } else {
1741              $value = $EntityChar->{$entity_name};
1742            $match = -1;            $match = -1;
1743              !!!next-input-character;
1744          }          }
1745        } else {        } else {
1746          $value .= chr $self->{next_input_character};          $value .= chr $self->{next_input_character};
1747            $match *= 2;
1748            !!!next-input-character;
1749        }        }
       !!!next-input-character;  
1750      }      }
1751            
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};        if ($in_attr and $match < -1) {
1757            return {type => 'character', data => '&'.$entity_name};
1758          } else {
1759            return {type => 'character', data => $value};
1760          }
1761      } else {      } else {
1762        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
1763        ## NOTE: No characters are consumed in the spec.        ## NOTE: No characters are consumed in the spec.
1764        !!!back-token ({type => 'character', data => $value});        return {type => 'character', data => '&'.$value};
       return undef;  
1765      }      }
1766    } else {    } else {
1767      ## no characters are consumed      ## no characters are consumed
# Line 1907  sub _tree_construction_initial ($) { Line 1956  sub _tree_construction_initial ($) {
1956      } elsif ($token->{type} eq 'character') {      } elsif ($token->{type} eq 'character') {
1957        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
1958          ## Ignore the token          ## Ignore the token
1959    
1960          unless (length $token->{data}) {          unless (length $token->{data}) {
1961            ## Stay in the phase            ## Stay in the phase
1962            !!!next-token;            !!!next-token;
# Line 1949  sub _tree_construction_root_element ($) Line 1999  sub _tree_construction_root_element ($)
1999          !!!next-token;          !!!next-token;
2000          redo B;          redo B;
2001        } elsif ($token->{type} eq 'character') {        } elsif ($token->{type} eq 'character') {
2002          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
2003            $self->{document}->manakai_append_text ($1);            ## Ignore the token.
2004            ## ISSUE: DOM3 Core does not allow Document > Text  
2005            unless (length $token->{data}) {            unless (length $token->{data}) {
2006              ## Stay in the phase              ## Stay in the phase
2007              !!!next-token;              !!!next-token;
# Line 1972  sub _tree_construction_root_element ($) Line 2022  sub _tree_construction_root_element ($)
2022        my $root_element; !!!create-element ($root_element, 'html');        my $root_element; !!!create-element ($root_element, 'html');
2023        $self->{document}->append_child ($root_element);        $self->{document}->append_child ($root_element);
2024        push @{$self->{open_elements}}, [$root_element, 'html'];        push @{$self->{open_elements}}, [$root_element, 'html'];
       #$phase = 'main';  
2025        ## reprocess        ## reprocess
2026        #redo B;        #redo B;
2027        return;        return; ## Go to the main phase.
2028    } # B    } # B
2029  } # _tree_construction_root_element  } # _tree_construction_root_element
2030    
# Line 1991  sub _reset_insertion_mode ($) { Line 2040  sub _reset_insertion_mode ($) {
2040            
2041      ## Step 3      ## Step 3
2042      S3: {      S3: {
2043        $last = 1 if $self->{open_elements}->[0]->[0] eq $node->[0];        ## ISSUE: Oops! "If node is the first node in the stack of open
2044        if (defined $self->{inner_html_node}) {        ## elements, then set last to true. If the context element of the
2045          if ($self->{inner_html_node}->[1] eq 'td' or        ## HTML fragment parsing algorithm is neither a td element nor a
2046              $self->{inner_html_node}->[1] eq 'th') {        ## th element, then set node to the context element. (fragment case)":
2047            #        ## The second "if" is in the scope of the first "if"!?
2048          } else {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
2049            $node = $self->{inner_html_node};          $last = 1;
2050            if (defined $self->{inner_html_node}) {
2051              if ($self->{inner_html_node}->[1] eq 'td' or
2052                  $self->{inner_html_node}->[1] eq 'th') {
2053                #
2054              } else {
2055                $node = $self->{inner_html_node};
2056              }
2057          }          }
2058        }        }
2059            
# Line 2044  sub _reset_insertion_mode ($) { Line 2100  sub _reset_insertion_mode ($) {
2100  sub _tree_construction_main ($) {  sub _tree_construction_main ($) {
2101    my $self = shift;    my $self = shift;
2102    
2103    my $phase = 'main';    my $previous_insertion_mode;
2104    
2105    my $active_formatting_elements = [];    my $active_formatting_elements = [];
2106    
# Line 2445  sub _tree_construction_main ($) { Line 2501  sub _tree_construction_main ($) {
2501          $parse_rcdata->('CDATA', $insert);          $parse_rcdata->('CDATA', $insert);
2502          return;          return;
2503        } elsif ({        } elsif ({
2504                  base => 1, link => 1, meta => 1,                  base => 1, link => 1,
2505                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
2506          ## 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
2507          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2508          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
2509          !!!next-token;          !!!next-token;
2510          return;          return;
2511          } elsif ($token->{tag_name} eq 'meta') {
2512            ## NOTE: This is an "as if in head" code clone, only "-t" differs
2513            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2514            pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
2515    
2516            unless ($self->{confident}) {
2517              my $charset;
2518              if ($token->{attributes}->{charset}) { ## TODO: And if supported
2519                $charset = $token->{attributes}->{charset}->{value};
2520              }
2521              if ($token->{attributes}->{'http-equiv'}) {
2522                ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.
2523                if ($token->{attributes}->{'http-equiv'}->{value}
2524                    =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
2525                        [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
2526                        ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
2527                  $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
2528                } ## TODO: And if supported
2529              }
2530              ## TODO: Change the encoding
2531            }
2532    
2533            !!!next-token;
2534            return;
2535        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
2536          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
2537          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
2538          $parse_rcdata->('RCDATA', $insert);          $parse_rcdata->('RCDATA', sub {
2539              if (defined $self->{head_element}) {
2540                $self->{head_element}->append_child ($_[0]);
2541              } else {
2542                $insert->($_[0]);
2543              }
2544            });
2545          return;          return;
2546        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
2547          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 2558  sub _tree_construction_main ($) { Line 2644  sub _tree_construction_main ($) {
2644              if ($i != -1) {              if ($i != -1) {
2645                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
2646                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
               ## TODO: test  
2647              }              }
2648              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2649              last LI;              last LI;
# Line 2606  sub _tree_construction_main ($) { Line 2691  sub _tree_construction_main ($) {
2691              if ($i != -1) {              if ($i != -1) {
2692                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
2693                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
               ## TODO: test  
2694              }              }
2695              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2696              last LI;              last LI;
# Line 2750  sub _tree_construction_main ($) { Line 2834  sub _tree_construction_main ($) {
2834          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2835            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
2836            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
2837                !!!parse-error (type => 'not closed:nobr');
2838              !!!back-token;              !!!back-token;
2839              $token = {type => 'end tag', tag_name => 'nobr'};              $token = {type => 'end tag', tag_name => 'nobr'};
2840              return;              return;
# Line 2833  sub _tree_construction_main ($) { Line 2918  sub _tree_construction_main ($) {
2918            !!!parse-error (type => 'image');            !!!parse-error (type => 'image');
2919            $token->{tag_name} = 'img';            $token->{tag_name} = 'img';
2920          }          }
2921            
2922            ## NOTE: There is an "as if <br>" code clone.
2923          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2924                    
2925          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 2991  sub _tree_construction_main ($) { Line 3077  sub _tree_construction_main ($) {
3077              unless ({              unless ({
3078                         dd => 1, dt => 1, li => 1, p => 1, td => 1,                         dd => 1, dt => 1, li => 1, p => 1, td => 1,
3079                         th => 1, tr => 1, body => 1, html => 1,                         th => 1, tr => 1, body => 1, html => 1,
3080                         tbody => 1, tfoot => 1, thead => 1,
3081                      }->{$_->[1]}) {                      }->{$_->[1]}) {
3082                !!!parse-error (type => 'not closed:'.$_->[1]);                !!!parse-error (type => 'not closed:'.$_->[1]);
3083              }              }
# Line 3040  sub _tree_construction_main ($) { Line 3127  sub _tree_construction_main ($) {
3127                   li => ($token->{tag_name} ne 'li'),                   li => ($token->{tag_name} ne 'li'),
3128                   p => ($token->{tag_name} ne 'p'),                   p => ($token->{tag_name} ne 'p'),
3129                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3130                     tbody => 1, tfoot=> 1, thead => 1,
3131                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3132                !!!back-token;                !!!back-token;
3133                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3057  sub _tree_construction_main ($) { Line 3145  sub _tree_construction_main ($) {
3145          } # INSCOPE          } # INSCOPE
3146                    
3147          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3148            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            if (defined $i) {
3149                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3150              } else {
3151                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3152              }
3153          }          }
3154                    
3155          splice @{$self->{open_elements}}, $i if defined $i;          if (defined $i) {
3156              splice @{$self->{open_elements}}, $i;
3157            } elsif ($token->{tag_name} eq 'p') {
3158              ## As if <p>, then reprocess the current token
3159              my $el;
3160              !!!create-element ($el, 'p');
3161              $insert->($el);
3162            }
3163          $clear_up_to_marker->()          $clear_up_to_marker->()
3164            if {            if {
3165              button => 1, marquee => 1, object => 1,              button => 1, marquee => 1, object => 1,
# Line 3076  sub _tree_construction_main ($) { Line 3175  sub _tree_construction_main ($) {
3175              if ({              if ({
3176                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3177                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3178                     tbody => 1, tfoot=> 1, thead => 1,
3179                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3180                !!!back-token;                !!!back-token;
3181                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3114  sub _tree_construction_main ($) { Line 3214  sub _tree_construction_main ($) {
3214              if ({              if ({
3215                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3216                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3217                     tbody => 1, tfoot=> 1, thead => 1,
3218                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3219                !!!back-token;                !!!back-token;
3220                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3144  sub _tree_construction_main ($) { Line 3245  sub _tree_construction_main ($) {
3245                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
3246                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
3247          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
3248  ## TODO: <http://html5.org/tools/web-apps-tracker?from=883&to=884>          return;
3249          } elsif ($token->{tag_name} eq 'br') {
3250            !!!parse-error (type => 'unmatched end tag:br');
3251    
3252            ## As if <br>
3253            $reconstruct_active_formatting_elements->($insert_to_current);
3254            
3255            my $el;
3256            !!!create-element ($el, 'br');
3257            $insert->($el);
3258            
3259            ## Ignore the token.
3260            !!!next-token;
3261          return;          return;
3262        } elsif ({        } elsif ({
3263                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
3264                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
3265                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
3266                  thead => 1, tr => 1,                  thead => 1, tr => 1,
3267                  area => 1, basefont => 1, bgsound => 1, br => 1,                  area => 1, basefont => 1, bgsound => 1,
3268                  embed => 1, hr => 1, iframe => 1, image => 1,                  embed => 1, hr => 1, iframe => 1, image => 1,
3269                  img => 1, input => 1, isindex => 1, noembed => 1,                  img => 1, input => 1, isindex => 1, noembed => 1,
3270                  noframes => 1, param => 1, select => 1, spacer => 1,                  noframes => 1, param => 1, select => 1, spacer => 1,
# Line 3178  sub _tree_construction_main ($) { Line 3291  sub _tree_construction_main ($) {
3291              if ({              if ({
3292                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3293                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3294                     tbody => 1, tfoot=> 1, thead => 1,
3295                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3296                !!!back-token;                !!!back-token;
3297                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3221  sub _tree_construction_main ($) { Line 3335  sub _tree_construction_main ($) {
3335    }; # $in_body    }; # $in_body
3336    
3337    B: {    B: {
3338      if ($phase eq 'main') {      if ($token->{type} eq 'DOCTYPE') {
3339        if ($token->{type} eq 'DOCTYPE') {        !!!parse-error (type => 'DOCTYPE in the middle');
3340          !!!parse-error (type => 'in html:#DOCTYPE');        ## Ignore the token
3341          ## Ignore the token        ## Stay in the phase
3342          ## Stay in the phase        !!!next-token;
3343          !!!next-token;        redo B;
3344          redo B;      } elsif ($token->{type} eq 'end-of-file') {
3345        } elsif ($token->{type} eq 'start tag' and        if ($token->{insertion_mode} ne 'trailing end') {
                $token->{tag_name} eq 'html') {  
         ## TODO: unless it is the first start tag token, parse-error  
         my $top_el = $self->{open_elements}->[0]->[0];  
         for my $attr_name (keys %{$token->{attributes}}) {  
           unless ($top_el->has_attribute_ns (undef, $attr_name)) {  
             $top_el->set_attribute_ns  
               (undef, [undef, $attr_name],  
                $token->{attributes}->{$attr_name}->{value});  
           }  
         }  
         !!!next-token;  
         redo B;  
       } elsif ($token->{type} eq 'end-of-file') {  
3346          ## Generate implied end tags          ## Generate implied end tags
3347          if ({          if ({
3348               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,
3349                 tbody => 1, tfoot=> 1, thead => 1,
3350              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
3351            !!!back-token;            !!!back-token;
3352            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};
# Line 3260  sub _tree_construction_main ($) { Line 3362  sub _tree_construction_main ($) {
3362            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3363          }          }
3364    
         ## Stop parsing  
         last B;  
   
3365          ## ISSUE: There is an issue in the spec.          ## ISSUE: There is an issue in the spec.
3366          }
3367    
3368          ## Stop parsing
3369          last B;
3370        } elsif ($token->{type} eq 'start tag' and
3371                 $token->{tag_name} eq 'html') {
3372          if ($self->{insertion_mode} eq 'trailing end') {
3373            ## Turn into the main phase
3374            !!!parse-error (type => 'after html:html');
3375            $self->{insertion_mode} = $previous_insertion_mode;
3376          }
3377    
3378    ## ISSUE: "aa<html>" is not a parse error.
3379    ## ISSUE: "<html>" in fragment is not a parse error.
3380          unless ($token->{first_start_tag}) {
3381            !!!parse-error (type => 'not first start tag');
3382          }
3383          my $top_el = $self->{open_elements}->[0]->[0];
3384          for my $attr_name (keys %{$token->{attributes}}) {
3385            unless ($top_el->has_attribute_ns (undef, $attr_name)) {
3386              $top_el->set_attribute_ns
3387                (undef, [undef, $attr_name],
3388                 $token->{attributes}->{$attr_name}->{value});
3389            }
3390          }
3391          !!!next-token;
3392          redo B;
3393        } elsif ($token->{type} eq 'comment') {
3394          my $comment = $self->{document}->create_comment ($token->{data});
3395          if ($self->{insertion_mode} eq 'trailing end') {
3396            $self->{document}->append_child ($comment);
3397          } elsif ($self->{insertion_mode} eq 'after body') {
3398            $self->{open_elements}->[0]->[0]->append_child ($comment);
3399        } else {        } else {
3400          if ($self->{insertion_mode} eq 'before head') {          $self->{open_elements}->[-1]->[0]->append_child ($comment);
3401          }
3402          !!!next-token;
3403          redo B;
3404        } elsif ($self->{insertion_mode} eq 'before head') {
3405            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3406              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3407                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
# Line 3281  sub _tree_construction_main ($) { Line 3417  sub _tree_construction_main ($) {
3417              $self->{insertion_mode} = 'in head';              $self->{insertion_mode} = 'in head';
3418              ## reprocess              ## reprocess
3419              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
3420            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3421              my $attr = $token->{tag_name} eq 'head' ? $token->{attributes} : {};              my $attr = $token->{tag_name} eq 'head' ? $token->{attributes} : {};
3422              !!!create-element ($self->{head_element}, 'head', $attr);              !!!create-element ($self->{head_element}, 'head', $attr);
# Line 3304  sub _tree_construction_main ($) { Line 3435  sub _tree_construction_main ($) {
3435              }              }
3436              redo B;              redo B;
3437            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3438              if ({head => 1, body => 1, html => 1}->{$token->{tag_name}}) {              if ({
3439                     head => 1, body => 1, html => 1,
3440                     p => 1, br => 1,
3441                    }->{$token->{tag_name}}) {
3442                ## As if <head>                ## As if <head>
3443                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3444                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3334  sub _tree_construction_main ($) { Line 3468  sub _tree_construction_main ($) {
3468              }              }
3469                            
3470              #              #
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
3471            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3472              if ({base => ($self->{insertion_mode} eq 'in head' or              if ({base => ($self->{insertion_mode} eq 'in head' or
3473                            $self->{insertion_mode} eq 'after head'),                            $self->{insertion_mode} eq 'after head'),
3474                   link => 1, meta => 1}->{$token->{tag_name}}) {                   link => 1}->{$token->{tag_name}}) {
3475                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
3476                if ($self->{insertion_mode} eq 'after head') {                if ($self->{insertion_mode} eq 'after head') {
3477                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
# Line 3354  sub _tree_construction_main ($) { Line 3483  sub _tree_construction_main ($) {
3483                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
3484                !!!next-token;                !!!next-token;
3485                redo B;                redo B;
3486                } elsif ($token->{tag_name} eq 'meta') {
3487                  ## NOTE: There is a "as if in head" code clone.
3488                  if ($self->{insertion_mode} eq 'after head') {
3489                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3490                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3491                  }
3492                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3493                  pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3494    
3495                  unless ($self->{confident}) {
3496                    my $charset;
3497                    if ($token->{attributes}->{charset}) { ## TODO: And if supported
3498                      $charset = $token->{attributes}->{charset}->{value};
3499                    }
3500                    if ($token->{attributes}->{'http-equiv'}) {
3501                      ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.
3502                      if ($token->{attributes}->{'http-equiv'}->{value}
3503                          =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
3504                              [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
3505                              ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
3506                        $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
3507                      } ## TODO: And if supported
3508                    }
3509                    ## TODO: Change the encoding
3510                  }
3511    
3512                  ## TODO: Extracting |charset| from |meta|.
3513                  pop @{$self->{open_elements}}
3514                      if $self->{insertion_mode} eq 'after head';
3515                  !!!next-token;
3516                  redo B;
3517              } elsif ($token->{tag_name} eq 'title' and              } elsif ($token->{tag_name} eq 'title' and
3518                       $self->{insertion_mode} eq 'in head') {                       $self->{insertion_mode} eq 'in head') {
3519                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 3361  sub _tree_construction_main ($) { Line 3521  sub _tree_construction_main ($) {
3521                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3522                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3523                }                }
3524                $parse_rcdata->('RCDATA', $insert_to_current);                my $parent = defined $self->{head_element} ? $self->{head_element}
3525                      : $self->{open_elements}->[-1]->[0];
3526                  $parse_rcdata->('RCDATA', sub { $parent->append_child ($_[0]) });
3527                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3528                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
3529                redo B;                redo B;
# Line 3385  sub _tree_construction_main ($) { Line 3547  sub _tree_construction_main ($) {
3547                  !!!next-token;                  !!!next-token;
3548                  redo B;                  redo B;
3549                } elsif ($self->{insertion_mode} eq 'in head noscript') {                } elsif ($self->{insertion_mode} eq 'in head noscript') {
3550                  !!!parse-error (type => 'noscript in noscript');                  !!!parse-error (type => 'in noscript:noscript');
3551                  ## Ignore the token                  ## Ignore the token
3552                  redo B;                  redo B;
3553                } else {                } else {
# Line 3437  sub _tree_construction_main ($) { Line 3599  sub _tree_construction_main ($) {
3599                !!!next-token;                !!!next-token;
3600                redo B;                redo B;
3601              } elsif ($self->{insertion_mode} eq 'in head' and              } elsif ($self->{insertion_mode} eq 'in head' and
3602                       ($token->{tag_name} eq 'body' or                       {
3603                        $token->{tag_name} eq 'html')) {                        body => 1, html => 1,
3604                          p => 1, br => 1,
3605                         }->{$token->{tag_name}}) {
3606                  #
3607                } elsif ($self->{insertion_mode} eq 'in head noscript' and
3608                         {
3609                          p => 1, br => 1,
3610                         }->{$token->{tag_name}}) {
3611                #                #
3612              } elsif ($self->{insertion_mode} ne 'after head') {              } elsif ($self->{insertion_mode} ne 'after head') {
3613                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
# Line 3477  sub _tree_construction_main ($) { Line 3646  sub _tree_construction_main ($) {
3646    
3647              !!!next-token;              !!!next-token;
3648              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## NOTE: There is a code clone of "comment in body".  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
3649            } else {            } else {
3650              $in_body->($insert_to_current);              $in_body->($insert_to_current);
3651              redo B;              redo B;
# Line 3546  sub _tree_construction_main ($) { Line 3709  sub _tree_construction_main ($) {
3709                            
3710              !!!next-token;              !!!next-token;
3711              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
3712            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3713              if ({              if ({
3714                   caption => 1,                   caption => 1,
# Line 3622  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 3670  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 3715  sub _tree_construction_main ($) { Line 3875  sub _tree_construction_main ($) {
3875    
3876              !!!next-token;              !!!next-token;
3877              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## NOTE: This is a code clone of "comment in body".  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
3878            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3879              if ({              if ({
3880                   caption => 1, col => 1, colgroup => 1, tbody => 1,                   caption => 1, col => 1, colgroup => 1, tbody => 1,
# Line 3753  sub _tree_construction_main ($) { Line 3907  sub _tree_construction_main ($) {
3907                if ({                if ({
3908                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3909                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3910                       tbody => 1, tfoot=> 1, thead => 1,
3911                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3912                  !!!back-token; # <?>                  !!!back-token; # <?>
3913                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => 'end tag', tag_name => 'caption'};
# Line 3803  sub _tree_construction_main ($) { Line 3958  sub _tree_construction_main ($) {
3958                if ({                if ({
3959                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3960                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3961                       tbody => 1, tfoot=> 1, thead => 1,
3962                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3963                  !!!back-token;                  !!!back-token;
3964                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 3850  sub _tree_construction_main ($) { Line 4006  sub _tree_construction_main ($) {
4006                if ({                if ({
4007                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4008                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4009                       tbody => 1, tfoot=> 1, thead => 1,
4010                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4011                  !!!back-token; # </table>                  !!!back-token; # </table>
4012                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => 'end tag', tag_name => 'caption'};
# Line 3899  sub _tree_construction_main ($) { Line 4056  sub _tree_construction_main ($) {
4056              }              }
4057                            
4058              #              #
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4059            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4060              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
4061                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4009  sub _tree_construction_main ($) { Line 4161  sub _tree_construction_main ($) {
4161                            
4162              !!!next-token;              !!!next-token;
4163              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## Copied from 'in table'  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4164            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4165              if ({              if ({
4166                   tr => 1,                   tr => 1,
# Line 4115  sub _tree_construction_main ($) { Line 4261  sub _tree_construction_main ($) {
4261                if ({                if ({
4262                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4263                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4264                       tbody => 1, tfoot=> 1, thead => 1,
4265                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4266                  !!!back-token; # <table>                  !!!back-token; # <table>
4267                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 4293  sub _tree_construction_main ($) { Line 4440  sub _tree_construction_main ($) {
4440                            
4441              !!!next-token;              !!!next-token;
4442              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## Copied from 'in table'  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4443            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4444              if ($token->{tag_name} eq 'th' or              if ($token->{tag_name} eq 'th' or
4445                  $token->{tag_name} eq 'td') {                  $token->{tag_name} eq 'td') {
# Line 4383  sub _tree_construction_main ($) { Line 4524  sub _tree_construction_main ($) {
4524                if ({                if ({
4525                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4526                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4527                       tbody => 1, tfoot=> 1, thead => 1,
4528                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4529                  !!!back-token; # <table>                  !!!back-token; # <table>
4530                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 4557  sub _tree_construction_main ($) { Line 4699  sub _tree_construction_main ($) {
4699    
4700              !!!next-token;              !!!next-token;
4701              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## NOTE: This is a code clone of "comment in body".  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4702            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4703              if ({              if ({
4704                   caption => 1, col => 1, colgroup => 1,                   caption => 1, col => 1, colgroup => 1,
# Line 4624  sub _tree_construction_main ($) { Line 4760  sub _tree_construction_main ($) {
4760                     td => ($token->{tag_name} eq 'th'),                     td => ($token->{tag_name} eq 'th'),
4761                     th => ($token->{tag_name} eq 'td'),                     th => ($token->{tag_name} eq 'td'),
4762                     tr => 1,                     tr => 1,
4763                       tbody => 1, tfoot=> 1, thead => 1,
4764                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4765                  !!!back-token;                  !!!back-token;
4766                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 4698  sub _tree_construction_main ($) { Line 4835  sub _tree_construction_main ($) {
4835              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4836              !!!next-token;              !!!next-token;
4837              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4838            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4839              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
4840                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
# Line 4875  sub _tree_construction_main ($) { Line 5007  sub _tree_construction_main ($) {
5007          } elsif ($self->{insertion_mode} eq 'after body') {          } elsif ($self->{insertion_mode} eq 'after body') {
5008            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
5009              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5010                  my $data = $1;
5011                ## As if in body                ## As if in body
5012                $reconstruct_active_formatting_elements->($insert_to_current);                $reconstruct_active_formatting_elements->($insert_to_current);
5013                                
5014                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5015    
5016                unless (length $token->{data}) {                unless (length $token->{data}) {
5017                  !!!next-token;                  !!!next-token;
# Line 4887  sub _tree_construction_main ($) { Line 5020  sub _tree_construction_main ($) {
5020              }              }
5021                            
5022              #              #
5023              !!!parse-error (type => 'after body:#'.$token->{type});              !!!parse-error (type => 'after body:#character');
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[0]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
5024            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
5025              !!!parse-error (type => 'after body:'.$token->{tag_name});              !!!parse-error (type => 'after body:'.$token->{tag_name});
5026              #              #
# Line 4904  sub _tree_construction_main ($) { Line 5032  sub _tree_construction_main ($) {
5032                  !!!next-token;                  !!!next-token;
5033                  redo B;                  redo B;
5034                } else {                } else {
5035                  $phase = 'trailing end';                  $previous_insertion_mode = $self->{insertion_mode};
5036                    $self->{insertion_mode} = 'trailing end';
5037                  !!!next-token;                  !!!next-token;
5038                  redo B;                  redo B;
5039                }                }
# Line 4912  sub _tree_construction_main ($) { Line 5041  sub _tree_construction_main ($) {
5041                !!!parse-error (type => 'after body:/'.$token->{tag_name});                !!!parse-error (type => 'after body:/'.$token->{tag_name});
5042              }              }
5043            } else {            } else {
5044              !!!parse-error (type => 'after body:#'.$token->{type});              die "$0: $token->{type}: Unknown token type";
5045            }            }
5046    
5047            $self->{insertion_mode} = 'in body';            $self->{insertion_mode} = 'in body';
5048            ## reprocess            ## reprocess
5049            redo B;            redo B;
5050          } elsif ($self->{insertion_mode} eq 'in frameset') {      } elsif ($self->{insertion_mode} eq 'in frameset') {
5051            if ($token->{type} eq 'character') {        if ($token->{type} eq 'character') {
5052              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5053                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
   
               unless (length $token->{data}) {  
                 !!!next-token;  
                 redo B;  
               }  
             }  
5054    
5055              #            unless (length $token->{data}) {
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
5056              !!!next-token;              !!!next-token;
5057              redo B;              redo B;
           } elsif ($token->{type} eq 'start tag') {  
             if ($token->{tag_name} eq 'frameset') {  
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'frame') {  
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               pop @{$self->{open_elements}};  
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'noframes') {  
               $in_body->($insert_to_current);  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'frameset') {  
               if ($self->{open_elements}->[-1]->[1] eq 'html' and  
                   @{$self->{open_elements}} == 1) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
               } else {  
                 pop @{$self->{open_elements}};  
                 !!!next-token;  
               }  
                 
               ## if not inner_html and  
               if ($self->{open_elements}->[-1]->[1] ne 'frameset') {  
                 $self->{insertion_mode} = 'after frameset';  
               }  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
5058            }            }
5059                      }
5060            if (defined $token->{tag_name}) {  
5061              !!!parse-error (type => 'in frameset:'.$token->{tag_name});          !!!parse-error (type => 'in frameset:#character');
5062            ## Ignore the token
5063            !!!next-token;
5064            redo B;
5065          } elsif ($token->{type} eq 'start tag') {
5066            if ($token->{tag_name} eq 'frameset') {
5067              !!!insert-element ($token->{tag_name}, $token->{attributes});
5068              !!!next-token;
5069              redo B;
5070            } elsif ($token->{tag_name} eq 'frame') {
5071              !!!insert-element ($token->{tag_name}, $token->{attributes});
5072              pop @{$self->{open_elements}};
5073              !!!next-token;
5074              redo B;
5075            } elsif ($token->{tag_name} eq 'noframes') {
5076              $in_body->($insert_to_current);
5077              redo B;
5078            } else {
5079              !!!parse-error (type => 'in frameset:'.$token->{tag_name});
5080              ## Ignore the token
5081              !!!next-token;
5082              redo B;
5083            }
5084          } elsif ($token->{type} eq 'end tag') {
5085            if ($token->{tag_name} eq 'frameset') {
5086              if ($self->{open_elements}->[-1]->[1] eq 'html' and
5087                  @{$self->{open_elements}} == 1) {
5088                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5089                ## Ignore the token
5090                !!!next-token;
5091            } else {            } else {
5092              !!!parse-error (type => 'in frameset:#'.$token->{type});              pop @{$self->{open_elements}};
5093                !!!next-token;
5094              }
5095    
5096              if (not defined $self->{inner_html_node} and
5097                  $self->{open_elements}->[-1]->[1] ne 'frameset') {
5098                $self->{insertion_mode} = 'after frameset';
5099            }            }
5100              redo B;
5101            } else {
5102              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
5103            ## Ignore the token            ## Ignore the token
5104            !!!next-token;            !!!next-token;
5105            redo B;            redo B;
5106          } elsif ($self->{insertion_mode} eq 'after frameset') {          }
5107            if ($token->{type} eq 'character') {        } else {
5108            die "$0: $token->{type}: Unknown token type";
5109          }
5110        } elsif ($self->{insertion_mode} eq 'after frameset') {
5111          if ($token->{type} eq 'character') {
5112              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5113                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5114    
5115                unless (length $token->{data}) {                unless (length $token->{data}) {
5116                  !!!next-token;                  !!!next-token;
# Line 4994  sub _tree_construction_main ($) { Line 5118  sub _tree_construction_main ($) {
5118                }                }
5119              }              }
5120    
5121              #              if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
5122            } elsif ($token->{type} eq 'comment') {                !!!parse-error (type => 'after frameset:#character');
5123              my $comment = $self->{document}->create_comment ($token->{data});  
5124              $self->{open_elements}->[-1]->[0]->append_child ($comment);                ## Ignore the token.
5125              !!!next-token;                if (length $token->{data}) {
5126              redo B;                  ## reprocess the rest of characters
5127            } elsif ($token->{type} eq 'start tag') {                } else {
5128              if ($token->{tag_name} eq 'noframes') {                  !!!next-token;
5129                $in_body->($insert_to_current);                }
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'html') {  
               $phase = 'trailing end';  
               !!!next-token;  
5130                redo B;                redo B;
             } else {  
               #  
5131              }              }
5132            } else {  
5133              #          die qq[$0: Character "$token->{data}"];
5134            }        } elsif ($token->{type} eq 'start tag') {
5135                      if ($token->{tag_name} eq 'noframes') {
5136            if (defined $token->{tag_name}) {            $in_body->($insert_to_current);
5137              !!!parse-error (type => 'after frameset:'.$token->{tag_name});            redo B;
5138            } else {          } else {
5139              !!!parse-error (type => 'after frameset:#'.$token->{type});            !!!parse-error (type => 'after frameset:'.$token->{tag_name});
           }  
5140            ## Ignore the token            ## Ignore the token
5141            !!!next-token;            !!!next-token;
5142            redo B;            redo B;
5143            }
5144            ## ISSUE: An issue in spec there        } elsif ($token->{type} eq 'end tag') {
5145            if ($token->{tag_name} eq 'html') {
5146              $previous_insertion_mode = $self->{insertion_mode};
5147              $self->{insertion_mode} = 'trailing end';
5148              !!!next-token;
5149              redo B;
5150          } else {          } else {
5151            die "$0: $self->{insertion_mode}: Unknown insertion mode";            !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
5152              ## Ignore the token
5153              !!!next-token;
5154              redo B;
5155          }          }
5156          } else {
5157            die "$0: $token->{type}: Unknown token type";
5158        }        }
5159      } elsif ($phase eq 'trailing end') {  
5160          ## ISSUE: An issue in spec here
5161        } elsif ($self->{insertion_mode} eq 'trailing end') {
5162        ## states in the main stage is preserved yet # MUST        ## states in the main stage is preserved yet # MUST
5163                
5164        if ($token->{type} eq 'DOCTYPE') {        if ($token->{type} eq 'character') {
         !!!parse-error (type => 'after html:#DOCTYPE');  
         ## Ignore the token  
         !!!next-token;  
         redo B;  
       } elsif ($token->{type} eq 'comment') {  
         my $comment = $self->{document}->create_comment ($token->{data});  
         $self->{document}->append_child ($comment);  
         !!!next-token;  
         redo B;  
       } elsif ($token->{type} eq 'character') {  
5165          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5166            my $data = $1;            my $data = $1;
5167            ## As if in the main phase.            ## As if in the main phase.
5168            ## NOTE: The insertion mode in the main phase            ## NOTE: The insertion mode in the main phase
5169            ## just before the phase has been changed to the trailing            ## just before the phase has been changed to the trailing
5170            ## end phase is either "after body" or "after frameset".            ## end phase is either "after body" or "after frameset".
5171            $reconstruct_active_formatting_elements->($insert_to_current)            $reconstruct_active_formatting_elements->($insert_to_current);
             if $phase eq 'main';  
5172                        
5173            $self->{open_elements}->[-1]->[0]->manakai_append_text ($data);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($data);
5174                        
# Line 5065  sub _tree_construction_main ($) { Line 5179  sub _tree_construction_main ($) {
5179          }          }
5180    
5181          !!!parse-error (type => 'after html:#character');          !!!parse-error (type => 'after html:#character');
5182          $phase = 'main';          $self->{insertion_mode} = $previous_insertion_mode;
5183          ## reprocess          ## reprocess
5184          redo B;          redo B;
5185        } elsif ($token->{type} eq 'start tag' or        } elsif ($token->{type} eq 'start tag') {
                $token->{type} eq 'end tag') {  
5186          !!!parse-error (type => 'after html:'.$token->{tag_name});          !!!parse-error (type => 'after html:'.$token->{tag_name});
5187          $phase = 'main';          $self->{insertion_mode} = $previous_insertion_mode;
5188            ## reprocess
5189            redo B;
5190          } elsif ($token->{type} eq 'end tag') {
5191            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5192            $self->{insertion_mode} = $previous_insertion_mode;
5193          ## reprocess          ## reprocess
5194          redo B;          redo B;
       } elsif ($token->{type} eq 'end-of-file') {  
         ## Stop parsing  
         last B;  
5195        } else {        } else {
5196          die "$0: $token->{type}: Unknown token";          die "$0: $token->{type}: Unknown token";
5197        }        }
5198        } else {
5199          die "$0: $self->{insertion_mode}: Unknown insertion mode";
5200      }      }
5201    } # B    } # B
5202    
# Line 5279  sub get_inner_html ($$$) { Line 5396  sub get_inner_html ($$$) {
5396            
5397      my $nt = $child->node_type;      my $nt = $child->node_type;
5398      if ($nt == 1) { # Element      if ($nt == 1) { # Element
5399        my $tag_name = lc $child->tag_name; ## ISSUE: Definition of "lowercase"        my $tag_name = $child->tag_name; ## TODO: manakai_tag_name
5400        $s .= '<' . $tag_name;        $s .= '<' . $tag_name;
5401          ## NOTE: Non-HTML case:
5402        ## ISSUE: Non-html elements        ## <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/11191>
5403    
5404        my @attrs = @{$child->attributes}; # sort order MUST be stable        my @attrs = @{$child->attributes}; # sort order MUST be stable
5405        for my $attr (@attrs) { # order is implementation dependent        for my $attr (@attrs) { # order is implementation dependent
5406          my $attr_name = lc $attr->name; ## ISSUE: Definition of "lowercase"          my $attr_name = $attr->name; ## TODO: manakai_name
5407          $s .= ' ' . $attr_name . '="';          $s .= ' ' . $attr_name . '="';
5408          my $attr_value = $attr->value;          my $attr_value = $attr->value;
5409          ## escape          ## escape
# Line 5310  sub get_inner_html ($$$) { Line 5427  sub get_inner_html ($$$) {
5427        if (not $in_cdata and {        if (not $in_cdata and {
5428          style => 1, script => 1, xmp => 1, iframe => 1,          style => 1, script => 1, xmp => 1, iframe => 1,
5429          noembed => 1, noframes => 1, noscript => 1,          noembed => 1, noframes => 1, noscript => 1,
5430            plaintext => 1,
5431        }->{$tag_name}) {        }->{$tag_name}) {
5432          unshift @node, 'cdata-out';          unshift @node, 'cdata-out';
5433          $in_cdata = 1;          $in_cdata = 1;

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.39

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24