/[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.20 by wakaba, Sat Jun 23 14:25:05 2007 UTC revision 1.34 by wakaba, Mon Jul 16 01:52:27 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 326  sub _get_next_token ($) { Line 332  sub _get_next_token ($) {
332      } elsif ($self->{state} eq 'close tag open') {      } elsif ($self->{state} eq 'close tag open') {
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          my @next_char;          if (defined $self->{last_emitted_start_tag_name}) {
336          TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>
337              my @next_char;
338              TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {
339                push @next_char, $self->{next_input_character};
340                my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);
341                my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;
342                if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) {
343                  !!!next-input-character;
344                  next TAGNAME;
345                } else {
346                  $self->{next_input_character} = shift @next_char; # reconsume
347                  !!!back-next-input-character (@next_char);
348                  $self->{state} = 'data';
349    
350                  !!!emit ({type => 'character', data => '</'});
351      
352                  redo A;
353                }
354              }
355            push @next_char, $self->{next_input_character};            push @next_char, $self->{next_input_character};
356            my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);        
357            my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;            unless ($self->{next_input_character} == 0x0009 or # HT
358            if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) {                    $self->{next_input_character} == 0x000A or # LF
359              !!!next-input-character;                    $self->{next_input_character} == 0x000B or # VT
360              next TAGNAME;                    $self->{next_input_character} == 0x000C or # FF
361            } else {                    $self->{next_input_character} == 0x0020 or # SP
362                      $self->{next_input_character} == 0x003E or # >
363                      $self->{next_input_character} == 0x002F or # /
364                      $self->{next_input_character} == -1) {
365              $self->{next_input_character} = shift @next_char; # reconsume              $self->{next_input_character} = shift @next_char; # reconsume
366              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
367              $self->{state} = 'data';              $self->{state} = 'data';
   
368              !!!emit ({type => 'character', data => '</'});              !!!emit ({type => 'character', data => '</'});
   
369              redo A;              redo A;
370              } else {
371                $self->{next_input_character} = shift @next_char;
372                !!!back-next-input-character (@next_char);
373                # and consume...
374            }            }
375          }          } else {
376          push @next_char, $self->{next_input_character};            ## No start tag token has ever been emitted
377                  # next-input-character is already done
         unless ($self->{next_input_character} == 0x0009 or # HT  
                 $self->{next_input_character} == 0x000A or # LF  
                 $self->{next_input_character} == 0x000B or # VT  
                 $self->{next_input_character} == 0x000C or # FF  
                 $self->{next_input_character} == 0x0020 or # SP  
                 $self->{next_input_character} == 0x003E or # >  
                 $self->{next_input_character} == 0x002F or # /  
                 $self->{next_input_character} == -1) {  
           $self->{next_input_character} = shift @next_char; # reconsume  
           !!!back-next-input-character (@next_char);  
378            $self->{state} = 'data';            $self->{state} = 'data';
   
379            !!!emit ({type => 'character', data => '</'});            !!!emit ({type => 'character', data => '</'});
   
380            redo A;            redo A;
         } else {  
           $self->{next_input_character} = shift @next_char;  
           !!!back-next-input-character (@next_char);  
           # and consume...  
381          }          }
382        }        }
383                
# Line 412  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 425  sub _get_next_token ($) { Line 440  sub _get_next_token ($) {
440          !!!next-input-character;          !!!next-input-character;
441    
442          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
443    
444          redo A;          redo A;
445        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 438  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 451  sub _get_next_token ($) { Line 467  sub _get_next_token ($) {
467          # reconsume          # reconsume
468    
469          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
470    
471          redo A;          redo A;
472        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_input_character} == 0x002F) { # /
# Line 485  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 498  sub _get_next_token ($) { Line 515  sub _get_next_token ($) {
515          !!!next-input-character;          !!!next-input-character;
516    
517          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
518    
519          redo A;          redo A;
520        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 524  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 537  sub _get_next_token ($) { Line 555  sub _get_next_token ($) {
555          # reconsume          # reconsume
556    
557          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
558    
559          redo A;          redo A;
560        } else {        } else {
# Line 576  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 589  sub _get_next_token ($) { Line 608  sub _get_next_token ($) {
608          !!!next-input-character;          !!!next-input-character;
609    
610          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
611    
612          redo A;          redo A;
613        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 616  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 629  sub _get_next_token ($) { Line 649  sub _get_next_token ($) {
649          # reconsume          # reconsume
650    
651          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
652    
653          redo A;          redo A;
654        } else {        } else {
# 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 666  sub _get_next_token ($) { Line 687  sub _get_next_token ($) {
687          !!!next-input-character;          !!!next-input-character;
688    
689          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
690    
691          redo A;          redo A;
692        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 685  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 692  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 705  sub _get_next_token ($) { Line 728  sub _get_next_token ($) {
728          # reconsume          # reconsume
729    
730          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
731    
732          redo A;          redo A;
733        } else {        } else {
# Line 738  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 751  sub _get_next_token ($) { Line 775  sub _get_next_token ($) {
775          !!!next-input-character;          !!!next-input-character;
776    
777          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
778    
779          redo A;          redo A;
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 770  sub _get_next_token ($) { Line 795  sub _get_next_token ($) {
795          ## reconsume          ## reconsume
796    
797          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
798    
799          redo A;          redo A;
800        } else {        } else {
# Line 792  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 805  sub _get_next_token ($) { Line 831  sub _get_next_token ($) {
831          ## reconsume          ## reconsume
832    
833          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
834    
835          redo A;          redo A;
836        } else {        } else {
# Line 827  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 840  sub _get_next_token ($) { Line 867  sub _get_next_token ($) {
867          ## reconsume          ## reconsume
868    
869          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
870    
871          redo A;          redo A;
872        } else {        } else {
# Line 865  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 878  sub _get_next_token ($) { Line 906  sub _get_next_token ($) {
906          !!!next-input-character;          !!!next-input-character;
907    
908          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
909    
910          redo A;          redo A;
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 897  sub _get_next_token ($) { Line 926  sub _get_next_token ($) {
926          ## reconsume          ## reconsume
927    
928          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
929    
930          redo A;          redo A;
931        } else {        } else {
# Line 907  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 956  sub _get_next_token ($) { Line 984  sub _get_next_token ($) {
984          push @next_char, $self->{next_input_character};          push @next_char, $self->{next_input_character};
985          if ($self->{next_input_character} == 0x002D) { # -          if ($self->{next_input_character} == 0x002D) { # -
986            $self->{current_token} = {type => 'comment', data => ''};            $self->{current_token} = {type => 'comment', data => ''};
987            $self->{state} = 'comment';            $self->{state} = 'comment start';
988            !!!next-input-character;            !!!next-input-character;
989            redo A;            redo A;
990          }          }
# Line 998  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 1006  sub _get_next_token ($) { Line 1034  sub _get_next_token ($) {
1034                
1035        ## ISSUE: typos in spec: chacacters, is is a parse error        ## ISSUE: typos in spec: chacacters, is is a parse error
1036        ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it?        ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it?
1037        } elsif ($self->{state} eq 'comment start') {
1038          if ($self->{next_input_character} == 0x002D) { # -
1039            $self->{state} = 'comment start dash';
1040            !!!next-input-character;
1041            redo A;
1042          } elsif ($self->{next_input_character} == 0x003E) { # >
1043            !!!parse-error (type => 'bogus comment');
1044            $self->{state} = 'data';
1045            !!!next-input-character;
1046    
1047            !!!emit ($self->{current_token}); # comment
1048    
1049            redo A;
1050          } elsif ($self->{next_input_character} == -1) {
1051            !!!parse-error (type => 'unclosed comment');
1052            $self->{state} = 'data';
1053            ## reconsume
1054    
1055            !!!emit ($self->{current_token}); # comment
1056    
1057            redo A;
1058          } else {
1059            $self->{current_token}->{data} # comment
1060                .= chr ($self->{next_input_character});
1061            $self->{state} = 'comment';
1062            !!!next-input-character;
1063            redo A;
1064          }
1065        } elsif ($self->{state} eq 'comment start dash') {
1066          if ($self->{next_input_character} == 0x002D) { # -
1067            $self->{state} = 'comment end';
1068            !!!next-input-character;
1069            redo A;
1070          } elsif ($self->{next_input_character} == 0x003E) { # >
1071            !!!parse-error (type => 'bogus comment');
1072            $self->{state} = 'data';
1073            !!!next-input-character;
1074    
1075            !!!emit ($self->{current_token}); # comment
1076    
1077            redo A;
1078          } elsif ($self->{next_input_character} == -1) {
1079            !!!parse-error (type => 'unclosed comment');
1080            $self->{state} = 'data';
1081            ## reconsume
1082    
1083            !!!emit ($self->{current_token}); # comment
1084    
1085            redo A;
1086          } else {
1087            $self->{current_token}->{data} # comment
1088                .= '-' . chr ($self->{next_input_character});
1089            $self->{state} = 'comment';
1090            !!!next-input-character;
1091            redo A;
1092          }
1093      } elsif ($self->{state} eq 'comment') {      } elsif ($self->{state} eq 'comment') {
1094        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1095          $self->{state} = 'comment dash';          $self->{state} = 'comment end dash';
1096          !!!next-input-character;          !!!next-input-character;
1097          redo A;          redo A;
1098        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1017  sub _get_next_token ($) { Line 1101  sub _get_next_token ($) {
1101          ## reconsume          ## reconsume
1102    
1103          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1104    
1105          redo A;          redo A;
1106        } else {        } else {
# Line 1026  sub _get_next_token ($) { Line 1109  sub _get_next_token ($) {
1109          !!!next-input-character;          !!!next-input-character;
1110          redo A;          redo A;
1111        }        }
1112      } elsif ($self->{state} eq 'comment dash') {      } elsif ($self->{state} eq 'comment end dash') {
1113        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1114          $self->{state} = 'comment end';          $self->{state} = 'comment end';
1115          !!!next-input-character;          !!!next-input-character;
# Line 1037  sub _get_next_token ($) { Line 1120  sub _get_next_token ($) {
1120          ## reconsume          ## reconsume
1121    
1122          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1123    
1124          redo A;          redo A;
1125        } else {        } else {
# Line 1052  sub _get_next_token ($) { Line 1134  sub _get_next_token ($) {
1134          !!!next-input-character;          !!!next-input-character;
1135    
1136          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1137    
1138          redo A;          redo A;
1139        } elsif ($self->{next_input_character} == 0x002D) { # -        } elsif ($self->{next_input_character} == 0x002D) { # -
# Line 1067  sub _get_next_token ($) { Line 1148  sub _get_next_token ($) {
1148          ## reconsume          ## reconsume
1149    
1150          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1151    
1152          redo A;          redo A;
1153        } else {        } else {
# Line 1142  sub _get_next_token ($) { Line 1222  sub _get_next_token ($) {
1222          !!!next-input-character;          !!!next-input-character;
1223    
1224          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1225    
1226          redo A;          redo A;
1227        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1152  sub _get_next_token ($) { Line 1231  sub _get_next_token ($) {
1231    
1232          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1233          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1234    
1235          redo A;          redo A;
1236        } else {        } else {
# Line 1176  sub _get_next_token ($) { Line 1254  sub _get_next_token ($) {
1254          !!!next-input-character;          !!!next-input-character;
1255    
1256          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1257    
1258          redo A;          redo A;
1259        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1186  sub _get_next_token ($) { Line 1263  sub _get_next_token ($) {
1263    
1264          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1265          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1266    
1267          redo A;          redo A;
1268        } elsif ($self->{next_input_character} == 0x0050 or # P        } elsif ($self->{next_input_character} == 0x0050 or # P
# Line 1278  sub _get_next_token ($) { Line 1354  sub _get_next_token ($) {
1354    
1355          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1356          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1357    
1358          redo A;          redo A;
1359        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1289  sub _get_next_token ($) { Line 1364  sub _get_next_token ($) {
1364    
1365          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1366          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1367    
1368          redo A;          redo A;
1369        } else {        } else {
# Line 1311  sub _get_next_token ($) { Line 1385  sub _get_next_token ($) {
1385    
1386          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1387          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1388    
1389          redo A;          redo A;
1390        } else {        } else {
# Line 1334  sub _get_next_token ($) { Line 1407  sub _get_next_token ($) {
1407    
1408          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1409          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1410    
1411          redo A;          redo A;
1412        } else {        } else {
# Line 1367  sub _get_next_token ($) { Line 1439  sub _get_next_token ($) {
1439          !!!next-input-character;          !!!next-input-character;
1440    
1441          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1442    
1443          redo A;          redo A;
1444        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
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
         undef $self->{current_token};  
1452    
1453          redo A;          redo A;
1454        } else {        } else {
# Line 1412  sub _get_next_token ($) { Line 1482  sub _get_next_token ($) {
1482    
1483          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1484          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1485    
1486          redo A;          redo A;
1487        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
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
         undef $self->{current_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 1445  sub _get_next_token ($) { Line 1513  sub _get_next_token ($) {
1513    
1514          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1515          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1516    
1517          redo A;          redo A;
1518        } else {        } else {
# Line 1468  sub _get_next_token ($) { Line 1535  sub _get_next_token ($) {
1535    
1536          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1537          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1538    
1539          redo A;          redo A;
1540        } else {        } else {
# Line 1491  sub _get_next_token ($) { Line 1557  sub _get_next_token ($) {
1557          !!!next-input-character;          !!!next-input-character;
1558    
1559          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1560    
1561          redo A;          redo A;
1562        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
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
         undef $self->{current_token};  
1570    
1571          redo A;          redo A;
1572        } else {        } else {
# Line 1518  sub _get_next_token ($) { Line 1582  sub _get_next_token ($) {
1582    
1583          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1584          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1585    
1586          redo A;          redo A;
1587        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1528  sub _get_next_token ($) { Line 1591  sub _get_next_token ($) {
1591    
1592          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1593          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1594    
1595          redo A;          redo A;
1596        } else {        } else {
# Line 1544  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 1558  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            $self->{next_input_character} = 0x0023; # #            $self->{next_input_character} = 0x0023; # #
1648            !!!back-next-input-character ($x_char);            !!!back-next-input-character ($x_char);
# Line 1593  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 1624  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 1663  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 {          } elsif (not $in_attr) {
1741              $value = $EntityChar->{$entity_name};
1742            $match = -1;            $match = -1;
1743            } else {
1744              $value .= chr $self->{next_input_character};
1745          }          }
1746        } else {        } else {
1747          $value .= chr $self->{next_input_character};          $value .= chr $self->{next_input_character};
# Line 1680  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');
1759        ## NOTE: No characters are consumed in the spec.        ## NOTE: No characters are consumed in the spec.
1760        !!!back-token ({type => 'character', data => $value});        return {type => 'character', data => '&'.$value};
       return undef;  
1761      }      }
1762    } else {    } else {
1763      ## no characters are consumed      ## no characters are consumed
# Line 1881  sub _tree_construction_initial ($) { Line 1952  sub _tree_construction_initial ($) {
1952      } elsif ($token->{type} eq 'character') {      } elsif ($token->{type} eq 'character') {
1953        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
1954          ## Ignore the token          ## Ignore the token
1955    
1956          unless (length $token->{data}) {          unless (length $token->{data}) {
1957            ## Stay in the phase            ## Stay in the phase
1958            !!!next-token;            !!!next-token;
# Line 1923  sub _tree_construction_root_element ($) Line 1995  sub _tree_construction_root_element ($)
1995          !!!next-token;          !!!next-token;
1996          redo B;          redo B;
1997        } elsif ($token->{type} eq 'character') {        } elsif ($token->{type} eq 'character') {
1998          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
1999            $self->{document}->manakai_append_text ($1);            ## Ignore the token.
2000            ## ISSUE: DOM3 Core does not allow Document > Text  
2001            unless (length $token->{data}) {            unless (length $token->{data}) {
2002              ## Stay in the phase              ## Stay in the phase
2003              !!!next-token;              !!!next-token;
# Line 1965  sub _reset_insertion_mode ($) { Line 2037  sub _reset_insertion_mode ($) {
2037            
2038      ## Step 3      ## Step 3
2039      S3: {      S3: {
2040        $last = 1 if $self->{open_elements}->[0]->[0] eq $node->[0];        ## ISSUE: Oops! "If node is the first node in the stack of open
2041        if (defined $self->{inner_html_node}) {        ## elements, then set last to true. If the context element of the
2042          if ($self->{inner_html_node}->[1] eq 'td' or        ## HTML fragment parsing algorithm is neither a td element nor a
2043              $self->{inner_html_node}->[1] eq 'th') {        ## th element, then set node to the context element. (fragment case)":
2044            #        ## The second "if" is in the scope of the first "if"!?
2045          } else {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
2046            $node = $self->{inner_html_node};          $last = 1;
2047            if (defined $self->{inner_html_node}) {
2048              if ($self->{inner_html_node}->[1] eq 'td' or
2049                  $self->{inner_html_node}->[1] eq 'th') {
2050                #
2051              } else {
2052                $node = $self->{inner_html_node};
2053              }
2054          }          }
2055        }        }
2056            
# Line 2102  sub _tree_construction_main ($) { Line 2181  sub _tree_construction_main ($) {
2181      }      }
2182    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2183    
2184    my $style_start_tag = sub {    my $parse_rcdata = sub ($$) {
2185      my $style_el; !!!create-element ($style_el, 'style', $token->{attributes});      my ($content_model_flag, $insert) = @_;
2186      ## $self->{insertion_mode} eq 'in head' and ... (always true)  
2187      (($self->{insertion_mode} eq 'in head' and defined $self->{head_element})      ## Step 1
2188       ? $self->{head_element} : $self->{open_elements}->[-1]->[0])      my $start_tag_name = $token->{tag_name};
2189        ->append_child ($style_el);      my $el;
2190      $self->{content_model_flag} = 'CDATA';      !!!create-element ($el, $start_tag_name, $token->{attributes});
2191    
2192        ## Step 2
2193        $insert->($el); # /context node/->append_child ($el)
2194    
2195        ## Step 3
2196        $self->{content_model_flag} = $content_model_flag; # CDATA or RCDATA
2197      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
2198                  
2199        ## Step 4
2200      my $text = '';      my $text = '';
2201      !!!next-token;      !!!next-token;
2202      while ($token->{type} eq 'character') {      while ($token->{type} eq 'character') { # or until stop tokenizing
2203        $text .= $token->{data};        $text .= $token->{data};
2204        !!!next-token;        !!!next-token;
2205      } # stop if non-character token or tokenizer stops tokenising      }
2206    
2207        ## Step 5
2208      if (length $text) {      if (length $text) {
2209        $style_el->manakai_append_text ($text);        my $text = $self->{document}->create_text_node ($text);
2210          $el->append_child ($text);
2211      }      }
2212        
2213        ## Step 6
2214      $self->{content_model_flag} = 'PCDATA';      $self->{content_model_flag} = 'PCDATA';
2215                  
2216      if ($token->{type} eq 'end tag' and $token->{tag_name} eq 'style') {      ## Step 7
2217        if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) {
2218        ## Ignore the token        ## Ignore the token
2219      } else {      } else {
2220        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in '.$content_model_flag.':#'.$token->{type});
       ## ISSUE: And ignore?  
2221      }      }
2222      !!!next-token;      !!!next-token;
2223    }; # $style_start_tag    }; # $parse_rcdata
2224    
2225    my $script_start_tag = sub {    my $script_start_tag = sub ($) {
2226        my $insert = $_[0];
2227      my $script_el;      my $script_el;
2228      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2229      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
# Line 2166  sub _tree_construction_main ($) { Line 2257  sub _tree_construction_main ($) {
2257      } else {      } else {
2258        ## TODO: $old_insertion_point = current insertion point        ## TODO: $old_insertion_point = current insertion point
2259        ## TODO: insertion point = just before the next input character        ## TODO: insertion point = just before the next input character
2260          
2261        (($self->{insertion_mode} eq 'in head' and defined $self->{head_element})        $insert->($script_el);
        ? $self->{head_element} : $self->{open_elements}->[-1]->[0])->append_child ($script_el);  
2262                
2263        ## TODO: insertion point = $old_insertion_point (might be "undefined")        ## TODO: insertion point = $old_insertion_point (might be "undefined")
2264                
# Line 2362  sub _tree_construction_main ($) { Line 2452  sub _tree_construction_main ($) {
2452    }; # $formatting_end_tag    }; # $formatting_end_tag
2453    
2454    my $insert_to_current = sub {    my $insert_to_current = sub {
2455      $self->{open_elements}->[-1]->[0]->append_child (shift);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
2456    }; # $insert_to_current    }; # $insert_to_current
2457    
2458    my $insert_to_foster = sub {    my $insert_to_foster = sub {
# Line 2400  sub _tree_construction_main ($) { Line 2490  sub _tree_construction_main ($) {
2490      my $insert = shift;      my $insert = shift;
2491      if ($token->{type} eq 'start tag') {      if ($token->{type} eq 'start tag') {
2492        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
2493          $script_start_tag->();          ## NOTE: This is an "as if in head" code clone
2494            $script_start_tag->($insert);
2495          return;          return;
2496        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
2497          $style_start_tag->();          ## NOTE: This is an "as if in head" code clone
2498            $parse_rcdata->('CDATA', $insert);
2499          return;          return;
2500        } elsif ({        } elsif ({
2501                  base => 1, link => 1, meta => 1,                  base => 1, link => 1, meta => 1,
2502                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
2503          !!!parse-error (type => 'in body:'.$token->{tag_name});          ## NOTE: This is an "as if in head" code clone, only "-t" differs
2504          ## NOTE: This is an "as if in head" code clone          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2505          my $el;          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
2506          !!!create-element ($el, $token->{tag_name}, $token->{attributes});          !!!next-token;
2507          if (defined $self->{head_element}) {          ## TODO: Extracting |charset| from |meta|.
2508            $self->{head_element}->append_child ($el);          return;
2509          } else {        } elsif ($token->{tag_name} eq 'meta') {
2510            $insert->($el);          ## NOTE: This is an "as if in head" code clone, only "-t" differs
2511            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2512            pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
2513    
2514            unless ($self->{confident}) {
2515              my $charset;
2516              if ($token->{attributes}->{charset}) { ## TODO: And if supported
2517                $charset = $token->{attributes}->{charset}->{value};
2518              }
2519              if ($token->{attributes}->{'http-equiv'}) {
2520                if ($token->{attributes}->{'http-equiv'}->{value}
2521                    =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
2522                        [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
2523                        ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
2524                  $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
2525                } ## TODO: And if supported
2526              }
2527              ## TODO: Change the encoding
2528          }          }
2529            
2530          !!!next-token;          !!!next-token;
2531            ## TODO: Extracting |charset| from |meta|.
2532          return;          return;
2533        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
2534          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
2535          ## NOTE: There is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
2536          my $title_el;          $parse_rcdata->('RCDATA', sub {
2537          !!!create-element ($title_el, 'title', $token->{attributes});            if (defined $self->{head_element}) {
2538          (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])              $self->{head_element}->append_child ($_[0]);
2539            ->append_child ($title_el);            } else {
2540          $self->{content_model_flag} = 'RCDATA';              $insert->($_[0]);
2541          delete $self->{escape}; # MUST            }
2542                    });
         my $text = '';  
         !!!next-token;  
         while ($token->{type} eq 'character') {  
           $text .= $token->{data};  
           !!!next-token;  
         }  
         if (length $text) {  
           $title_el->manakai_append_text ($text);  
         }  
           
         $self->{content_model_flag} = 'PCDATA';  
           
         if ($token->{type} eq 'end tag' and  
             $token->{tag_name} eq 'title') {  
           ## Ignore the token  
         } else {  
           !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
           ## ISSUE: And ignore?  
         }  
         !!!next-token;  
2543          return;          return;
2544        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
2545          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 2552  sub _tree_construction_main ($) { Line 2642  sub _tree_construction_main ($) {
2642              if ($i != -1) {              if ($i != -1) {
2643                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
2644                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
               ## TODO: test  
2645              }              }
2646              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2647              last LI;              last LI;
# Line 2600  sub _tree_construction_main ($) { Line 2689  sub _tree_construction_main ($) {
2689              if ($i != -1) {              if ($i != -1) {
2690                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
2691                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
               ## TODO: test  
2692              }              }
2693              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2694              last LI;              last LI;
# Line 2663  sub _tree_construction_main ($) { Line 2751  sub _tree_construction_main ($) {
2751            }            }
2752          } # INSCOPE          } # INSCOPE
2753                        
2754            ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>
2755          ## has an element in scope          ## has an element in scope
2756          my $i;          #my $i;
2757          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2758            my $node = $self->{open_elements}->[$_];          #  my $node = $self->{open_elements}->[$_];
2759            if ({          #  if ({
2760                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,          #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
2761                }->{$node->[1]}) {          #      }->{$node->[1]}) {
2762              $i = $_;          #    $i = $_;
2763              last INSCOPE;          #    last INSCOPE;
2764            } elsif ({          #  } elsif ({
2765                      table => 1, caption => 1, td => 1, th => 1,          #            table => 1, caption => 1, td => 1, th => 1,
2766                      button => 1, marquee => 1, object => 1, html => 1,          #            button => 1, marquee => 1, object => 1, html => 1,
2767                     }->{$node->[1]}) {          #           }->{$node->[1]}) {
2768              last INSCOPE;          #    last INSCOPE;
2769            }          #  }
2770          } # INSCOPE          #} # INSCOPE
2771                      #  
2772          if (defined $i) {          #if (defined $i) {
2773            !!!parse-error (type => 'in hn:hn');          #  !!! parse-error (type => 'in hn:hn');
2774            splice @{$self->{open_elements}}, $i;          #  splice @{$self->{open_elements}}, $i;
2775          }          #}
2776                        
2777          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2778                        
# Line 2743  sub _tree_construction_main ($) { Line 2832  sub _tree_construction_main ($) {
2832          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2833            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
2834            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
2835                !!!parse-error (type => 'not closed:nobr');
2836              !!!back-token;              !!!back-token;
2837              $token = {type => 'end tag', tag_name => 'nobr'};              $token = {type => 'end tag', tag_name => 'nobr'};
2838              return;              return;
# Line 2794  sub _tree_construction_main ($) { Line 2884  sub _tree_construction_main ($) {
2884          return;          return;
2885        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
2886          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2887                    $parse_rcdata->('CDATA', $insert);
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           
         $self->{content_model_flag} = 'CDATA';  
         delete $self->{escape}; # MUST  
           
         !!!next-token;  
2888          return;          return;
2889        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
2890          ## has a p element in scope          ## has a p element in scope
# Line 2832  sub _tree_construction_main ($) { Line 2916  sub _tree_construction_main ($) {
2916            !!!parse-error (type => 'image');            !!!parse-error (type => 'image');
2917            $token->{tag_name} = 'img';            $token->{tag_name} = 'img';
2918          }          }
2919            
2920            ## NOTE: There is an "as if <br>" code clone.
2921          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2922                    
2923          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 2878  sub _tree_construction_main ($) { Line 2963  sub _tree_construction_main ($) {
2963            return;            return;
2964          } else {          } else {
2965            my $at = $token->{attributes};            my $at = $token->{attributes};
2966              my $form_attrs;
2967              $form_attrs->{action} = $at->{action} if $at->{action};
2968              my $prompt_attr = $at->{prompt};
2969            $at->{name} = {name => 'name', value => 'isindex'};            $at->{name} = {name => 'name', value => 'isindex'};
2970              delete $at->{action};
2971              delete $at->{prompt};
2972            my @tokens = (            my @tokens = (
2973                          {type => 'start tag', tag_name => 'form'},                          {type => 'start tag', tag_name => 'form',
2974                             attributes => $form_attrs},
2975                          {type => 'start tag', tag_name => 'hr'},                          {type => 'start tag', tag_name => 'hr'},
2976                          {type => 'start tag', tag_name => 'p'},                          {type => 'start tag', tag_name => 'p'},
2977                          {type => 'start tag', tag_name => 'label'},                          {type => 'start tag', tag_name => 'label'},
2978                          {type => 'character',                         );
2979                           data => 'This is a searchable index. Insert your search keywords here: '}, # SHOULD            if ($prompt_attr) {
2980                          ## TODO: make this configurable              push @tokens, {type => 'character', data => $prompt_attr->{value}};
2981              } else {
2982                push @tokens, {type => 'character',
2983                               data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
2984                ## TODO: make this configurable
2985              }
2986              push @tokens,
2987                          {type => 'start tag', tag_name => 'input', attributes => $at},                          {type => 'start tag', tag_name => 'input', attributes => $at},
2988                          #{type => 'character', data => ''}, # SHOULD                          #{type => 'character', data => ''}, # SHOULD
2989                          {type => 'end tag', tag_name => 'label'},                          {type => 'end tag', tag_name => 'label'},
2990                          {type => 'end tag', tag_name => 'p'},                          {type => 'end tag', tag_name => 'p'},
2991                          {type => 'start tag', tag_name => 'hr'},                          {type => 'start tag', tag_name => 'hr'},
2992                          {type => 'end tag', tag_name => 'form'},                          {type => 'end tag', tag_name => 'form'};
                        );  
2993            $token = shift @tokens;            $token = shift @tokens;
2994            !!!back-token (@tokens);            !!!back-token (@tokens);
2995            return;            return;
2996          }          }
2997        } elsif ({        } elsif ($token->{tag_name} eq 'textarea') {
                 textarea => 1,  
                 iframe => 1,  
                 noembed => 1,  
                 noframes => 1,  
                 noscript => 0, ## TODO: 1 if scripting is enabled  
                }->{$token->{tag_name}}) {  
2998          my $tag_name = $token->{tag_name};          my $tag_name = $token->{tag_name};
2999          my $el;          my $el;
3000          !!!create-element ($el, $token->{tag_name}, $token->{attributes});          !!!create-element ($el, $token->{tag_name}, $token->{attributes});
3001                    
3002          if ($token->{tag_name} eq 'textarea') {          ## TODO: $self->{form_element} if defined
3003            ## TODO: $self->{form_element} if defined          $self->{content_model_flag} = 'RCDATA';
           $self->{content_model_flag} = 'RCDATA';  
         } else {  
           $self->{content_model_flag} = 'CDATA';  
         }  
3004          delete $self->{escape}; # MUST          delete $self->{escape}; # MUST
3005                    
3006          $insert->($el);          $insert->($el);
3007                    
3008          my $text = '';          my $text = '';
3009          if ($token->{tag_name} eq 'textarea') {          !!!next-token;
3010            !!!next-token;          if ($token->{type} eq 'character') {
3011            if ($token->{type} eq 'character') {            $token->{data} =~ s/^\x0A//;
3012              $token->{data} =~ s/^\x0A//;            unless (length $token->{data}) {
3013              unless (length $token->{data}) {              !!!next-token;
               !!!next-token;  
             }  
3014            }            }
         } else {  
           !!!next-token;  
3015          }          }
3016          while ($token->{type} eq 'character') {          while ($token->{type} eq 'character') {
3017            $text .= $token->{data};            $text .= $token->{data};
# Line 2945  sub _tree_construction_main ($) { Line 3027  sub _tree_construction_main ($) {
3027              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
3028            ## Ignore the token            ## Ignore the token
3029          } else {          } else {
3030            if ($token->{tag_name} eq 'textarea') {            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
             !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
           } else {  
             !!!parse-error (type => 'in CDATA:#'.$token->{type});  
           }  
           ## ISSUE: And ignore?  
3031          }          }
3032          !!!next-token;          !!!next-token;
3033          return;          return;
3034          } elsif ({
3035                    iframe => 1,
3036                    noembed => 1,
3037                    noframes => 1,
3038                    noscript => 0, ## TODO: 1 if scripting is enabled
3039                   }->{$token->{tag_name}}) {
3040            $parse_rcdata->('CDATA', $insert);
3041            return;
3042        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
3043          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
3044                    
# Line 2990  sub _tree_construction_main ($) { Line 3075  sub _tree_construction_main ($) {
3075              unless ({              unless ({
3076                         dd => 1, dt => 1, li => 1, p => 1, td => 1,                         dd => 1, dt => 1, li => 1, p => 1, td => 1,
3077                         th => 1, tr => 1, body => 1, html => 1,                         th => 1, tr => 1, body => 1, html => 1,
3078                         tbody => 1, tfoot => 1, thead => 1,
3079                      }->{$_->[1]}) {                      }->{$_->[1]}) {
3080                !!!parse-error (type => 'not closed:'.$_->[1]);                !!!parse-error (type => 'not closed:'.$_->[1]);
3081              }              }
# Line 3039  sub _tree_construction_main ($) { Line 3125  sub _tree_construction_main ($) {
3125                   li => ($token->{tag_name} ne 'li'),                   li => ($token->{tag_name} ne 'li'),
3126                   p => ($token->{tag_name} ne 'p'),                   p => ($token->{tag_name} ne 'p'),
3127                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3128                     tbody => 1, tfoot=> 1, thead => 1,
3129                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3130                !!!back-token;                !!!back-token;
3131                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3056  sub _tree_construction_main ($) { Line 3143  sub _tree_construction_main ($) {
3143          } # INSCOPE          } # INSCOPE
3144                    
3145          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3146            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            if (defined $i) {
3147                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3148              } else {
3149                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3150              }
3151          }          }
3152                    
3153          splice @{$self->{open_elements}}, $i if defined $i;          if (defined $i) {
3154              splice @{$self->{open_elements}}, $i;
3155            } elsif ($token->{tag_name} eq 'p') {
3156              ## As if <p>, then reprocess the current token
3157              my $el;
3158              !!!create-element ($el, 'p');
3159              $insert->($el);
3160            }
3161          $clear_up_to_marker->()          $clear_up_to_marker->()
3162            if {            if {
3163              button => 1, marquee => 1, object => 1,              button => 1, marquee => 1, object => 1,
# Line 3075  sub _tree_construction_main ($) { Line 3173  sub _tree_construction_main ($) {
3173              if ({              if ({
3174                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3175                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3176                     tbody => 1, tfoot=> 1, thead => 1,
3177                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3178                !!!back-token;                !!!back-token;
3179                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3113  sub _tree_construction_main ($) { Line 3212  sub _tree_construction_main ($) {
3212              if ({              if ({
3213                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3214                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3215                     tbody => 1, tfoot=> 1, thead => 1,
3216                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3217                !!!back-token;                !!!back-token;
3218                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3143  sub _tree_construction_main ($) { Line 3243  sub _tree_construction_main ($) {
3243                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
3244                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
3245          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
3246  ## TODO: <http://html5.org/tools/web-apps-tracker?from=883&to=884>          return;
3247          } elsif ($token->{tag_name} eq 'br') {
3248            !!!parse-error (type => 'unmatched end tag:br');
3249    
3250            ## As if <br>
3251            $reconstruct_active_formatting_elements->($insert_to_current);
3252            
3253            my $el;
3254            !!!create-element ($el, 'br');
3255            $insert->($el);
3256            
3257            ## Ignore the token.
3258            !!!next-token;
3259          return;          return;
3260        } elsif ({        } elsif ({
3261                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
3262                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
3263                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
3264                  thead => 1, tr => 1,                  thead => 1, tr => 1,
3265                  area => 1, basefont => 1, bgsound => 1, br => 1,                  area => 1, basefont => 1, bgsound => 1,
3266                  embed => 1, hr => 1, iframe => 1, image => 1,                  embed => 1, hr => 1, iframe => 1, image => 1,
3267                  img => 1, input => 1, isindex => 1, noembed => 1,                  img => 1, input => 1, isindex => 1, noembed => 1,
3268                  noframes => 1, param => 1, select => 1, spacer => 1,                  noframes => 1, param => 1, select => 1, spacer => 1,
# Line 3177  sub _tree_construction_main ($) { Line 3289  sub _tree_construction_main ($) {
3289              if ({              if ({
3290                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3291                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3292                     tbody => 1, tfoot=> 1, thead => 1,
3293                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3294                !!!back-token;                !!!back-token;
3295                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3200  sub _tree_construction_main ($) { Line 3313  sub _tree_construction_main ($) {
3313                  #not $phrasing_category->{$node->[1]} and                  #not $phrasing_category->{$node->[1]} and
3314                  ($special_category->{$node->[1]} or                  ($special_category->{$node->[1]} or
3315                   $scoping_category->{$node->[1]})) {                   $scoping_category->{$node->[1]})) {
3316                !!!parse-error (type => 'not closed:'.$node->[1]);                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3317                ## Ignore the token                ## Ignore the token
3318                !!!next-token;                !!!next-token;
3319                last S2;                last S2;
# Line 3229  sub _tree_construction_main ($) { Line 3342  sub _tree_construction_main ($) {
3342          redo B;          redo B;
3343        } elsif ($token->{type} eq 'start tag' and        } elsif ($token->{type} eq 'start tag' and
3344                 $token->{tag_name} eq 'html') {                 $token->{tag_name} eq 'html') {
3345          ## TODO: unless it is the first start tag token, parse-error  ## ISSUE: "aa<html>" is not a parse error.
3346    ## ISSUE: "<html>" in fragment is not a parse error.
3347            unless ($token->{first_start_tag}) {
3348              !!!parse-error (type => 'not first start tag');
3349            }
3350          my $top_el = $self->{open_elements}->[0]->[0];          my $top_el = $self->{open_elements}->[0]->[0];
3351          for my $attr_name (keys %{$token->{attributes}}) {          for my $attr_name (keys %{$token->{attributes}}) {
3352            unless ($top_el->has_attribute_ns (undef, $attr_name)) {            unless ($top_el->has_attribute_ns (undef, $attr_name)) {
# Line 3244  sub _tree_construction_main ($) { Line 3361  sub _tree_construction_main ($) {
3361          ## Generate implied end tags          ## Generate implied end tags
3362          if ({          if ({
3363               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,
3364                 tbody => 1, tfoot=> 1, thead => 1,
3365              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
3366            !!!back-token;            !!!back-token;
3367            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};
# Line 3303  sub _tree_construction_main ($) { Line 3421  sub _tree_construction_main ($) {
3421              }              }
3422              redo B;              redo B;
3423            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3424              if ($token->{tag_name} eq 'html') {              if ({
3425                     head => 1, body => 1, html => 1,
3426                     p => 1, br => 1,
3427                    }->{$token->{tag_name}}) {
3428                ## As if <head>                ## As if <head>
3429                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3430                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3313  sub _tree_construction_main ($) { Line 3434  sub _tree_construction_main ($) {
3434                redo B;                redo B;
3435              } else {              } else {
3436                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3437                ## Ignore the token                ## Ignore the token ## ISSUE: An issue in the spec.
3438                !!!next-token;                !!!next-token;
3439                redo B;                redo B;
3440              }              }
3441            } else {            } else {
3442              die "$0: $token->{type}: Unknown type";              die "$0: $token->{type}: Unknown type";
3443            }            }
3444          } elsif ($self->{insertion_mode} eq 'in head') {          } elsif ($self->{insertion_mode} eq 'in head' or
3445                     $self->{insertion_mode} eq 'in head noscript' or
3446                     $self->{insertion_mode} eq 'after head') {
3447            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3448              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3449                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
# Line 3337  sub _tree_construction_main ($) { Line 3460  sub _tree_construction_main ($) {
3460              !!!next-token;              !!!next-token;
3461              redo B;              redo B;
3462            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3463              if ($token->{tag_name} eq 'title') {              if ({base => ($self->{insertion_mode} eq 'in head' or
3464                ## NOTE: There is an "as if in head" code clone                            $self->{insertion_mode} eq 'after head'),
3465                my $title_el;                   link => 1}->{$token->{tag_name}}) {
3466                !!!create-element ($title_el, 'title', $token->{attributes});                ## NOTE: There is a "as if in head" code clone.
3467                (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])                if ($self->{insertion_mode} eq 'after head') {
3468                  ->append_child ($title_el);                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3469                $self->{content_model_flag} = 'RCDATA';                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3470                delete $self->{escape}; # MUST                }
3471                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3472                my $text = '';                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3473                  ## TODO: Extracting |charset| from |meta|.
3474                  pop @{$self->{open_elements}}
3475                      if $self->{insertion_mode} eq 'after head';
3476                !!!next-token;                !!!next-token;
3477                while ($token->{type} eq 'character') {                redo B;
3478                  $text .= $token->{data};              } elsif ($token->{tag_name} eq 'meta') {
3479                  !!!next-token;                ## NOTE: There is a "as if in head" code clone.
3480                  if ($self->{insertion_mode} eq 'after head') {
3481                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3482                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3483                }                }
3484                if (length $text) {                !!!insert-element ($token->{tag_name}, $token->{attributes});
3485                  $title_el->manakai_append_text ($text);                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3486    
3487                  unless ($self->{confident}) {
3488                    my $charset;
3489                    if ($token->{attributes}->{charset}) { ## TODO: And if supported
3490                      $charset = $token->{attributes}->{charset}->{value};
3491                    }
3492                    if ($token->{attributes}->{'http-equiv'}) {
3493                      if ($token->{attributes}->{'http-equiv'}->{value}
3494                          =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
3495                              [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
3496                              ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
3497                        $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
3498                      } ## TODO: And if supported
3499                    }
3500                    ## TODO: Change the encoding
3501                }                }
3502                  
3503                $self->{content_model_flag} = 'PCDATA';                ## TODO: Extracting |charset| from |meta|.
3504                                pop @{$self->{open_elements}}
3505                if ($token->{type} eq 'end tag' and                    if $self->{insertion_mode} eq 'after head';
3506                    $token->{tag_name} eq 'title') {                !!!next-token;
3507                  redo B;
3508                } elsif ($token->{tag_name} eq 'title' and
3509                         $self->{insertion_mode} eq 'in head') {
3510                  ## NOTE: There is a "as if in head" code clone.
3511                  if ($self->{insertion_mode} eq 'after head') {
3512                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3513                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3514                  }
3515                  my $parent = defined $self->{head_element} ? $self->{head_element}
3516                      : $self->{open_elements}->[-1]->[0];
3517                  $parse_rcdata->('RCDATA', sub { $parent->append_child ($_[0]) });
3518                  pop @{$self->{open_elements}}
3519                      if $self->{insertion_mode} eq 'after head';
3520                  redo B;
3521                } elsif ($token->{tag_name} eq 'style') {
3522                  ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
3523                  ## insertion mode 'in head')
3524                  ## NOTE: There is a "as if in head" code clone.
3525                  if ($self->{insertion_mode} eq 'after head') {
3526                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3527                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3528                  }
3529                  $parse_rcdata->('CDATA', $insert_to_current);
3530                  pop @{$self->{open_elements}}
3531                      if $self->{insertion_mode} eq 'after head';
3532                  redo B;
3533                } elsif ($token->{tag_name} eq 'noscript') {
3534                  if ($self->{insertion_mode} eq 'in head') {
3535                    ## NOTE: and scripting is disalbed
3536                    !!!insert-element ($token->{tag_name}, $token->{attributes});
3537                    $self->{insertion_mode} = 'in head noscript';
3538                    !!!next-token;
3539                    redo B;
3540                  } elsif ($self->{insertion_mode} eq 'in head noscript') {
3541                    !!!parse-error (type => 'in noscript:noscript');
3542                  ## Ignore the token                  ## Ignore the token
3543                    redo B;
3544                } else {                } else {
3545                  !!!parse-error (type => 'in RCDATA:#'.$token->{type});                  #
                 ## ISSUE: And ignore?  
3546                }                }
3547                } elsif ($token->{tag_name} eq 'head' and
3548                         $self->{insertion_mode} ne 'after head') {
3549                  !!!parse-error (type => 'in head:head'); # or in head noscript
3550                  ## Ignore the token
3551                !!!next-token;                !!!next-token;
3552                redo B;                redo B;
3553              } elsif ($token->{tag_name} eq 'style') {              } elsif ($self->{insertion_mode} ne 'in head noscript' and
3554                $style_start_tag->();                       $token->{tag_name} eq 'script') {
3555                redo B;                if ($self->{insertion_mode} eq 'after head') {
3556              } elsif ($token->{tag_name} eq 'script') {                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3557                $script_start_tag->();                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3558                  }
3559                  ## NOTE: There is a "as if in head" code clone.
3560                  $script_start_tag->($insert_to_current);
3561                  pop @{$self->{open_elements}}
3562                      if $self->{insertion_mode} eq 'after head';
3563                redo B;                redo B;
3564              } elsif ({base => 1, link => 1, meta => 1}->{$token->{tag_name}}) {              } elsif ($self->{insertion_mode} eq 'after head' and
3565                ## NOTE: There are "as if in head" code clones                       $token->{tag_name} eq 'body') {
3566                my $el;                !!!insert-element ('body', $token->{attributes});
3567                !!!create-element ($el, $token->{tag_name}, $token->{attributes});                $self->{insertion_mode} = 'in body';
               (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])  
                 ->append_child ($el);  
   
3568                !!!next-token;                !!!next-token;
3569                redo B;                redo B;
3570              } elsif ($token->{tag_name} eq 'head') {              } elsif ($self->{insertion_mode} eq 'after head' and
3571                !!!parse-error (type => 'in head:head');                       $token->{tag_name} eq 'frameset') {
3572                ## Ignore the token                !!!insert-element ('frameset', $token->{attributes});
3573                  $self->{insertion_mode} = 'in frameset';
3574                !!!next-token;                !!!next-token;
3575                redo B;                redo B;
3576              } else {              } else {
3577                #                #
3578              }              }
3579            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3580              if ($token->{tag_name} eq 'head') {              if ($self->{insertion_mode} eq 'in head' and
3581                if ($self->{open_elements}->[-1]->[1] eq 'head') {                  $token->{tag_name} eq 'head') {
3582                  pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
               } else {  
                 !!!parse-error (type => 'unmatched end tag:head');  
               }  
3583                $self->{insertion_mode} = 'after head';                $self->{insertion_mode} = 'after head';
3584                !!!next-token;                !!!next-token;
3585                redo B;                redo B;
3586              } elsif ($token->{tag_name} eq 'html') {              } elsif ($self->{insertion_mode} eq 'in head noscript' and
3587                    $token->{tag_name} eq 'noscript') {
3588                  pop @{$self->{open_elements}};
3589                  $self->{insertion_mode} = 'in head';
3590                  !!!next-token;
3591                  redo B;
3592                } elsif ($self->{insertion_mode} eq 'in head' and
3593                         {
3594                          body => 1, html => 1,
3595                          p => 1, br => 1,
3596                         }->{$token->{tag_name}}) {
3597                #                #
3598              } else {              } elsif ($self->{insertion_mode} eq 'in head noscript' and
3599                         {
3600                          p => 1, br => 1,
3601                         }->{$token->{tag_name}}) {
3602                  #
3603                } elsif ($self->{insertion_mode} ne 'after head') {
3604                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3605                ## Ignore the token                ## Ignore the token
3606                !!!next-token;                !!!next-token;
3607                redo B;                redo B;
3608                } else {
3609                  #
3610              }              }
3611            } else {            } else {
3612              #              #
3613            }            }
3614    
3615            if ($self->{open_elements}->[-1]->[1] eq 'head') {            ## As if </head> or </noscript> or <body>
3616              ## As if </head>            if ($self->{insertion_mode} eq 'in head') {
3617                pop @{$self->{open_elements}};
3618                $self->{insertion_mode} = 'after head';
3619              } elsif ($self->{insertion_mode} eq 'in head noscript') {
3620              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
3621                !!!parse-error (type => 'in noscript:'.(defined $token->{tag_name} ? ($token->{type} eq 'end tag' ? '/' : '') . $token->{tag_name} : '#' . $token->{type}));
3622                $self->{insertion_mode} = 'in head';
3623              } else { # 'after head'
3624                !!!insert-element ('body');
3625                $self->{insertion_mode} = 'in body';
3626            }            }
           $self->{insertion_mode} = 'after head';  
3627            ## reprocess            ## reprocess
3628            redo B;            redo B;
3629    
3630            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
         } elsif ($self->{insertion_mode} eq 'after head') {  
           if ($token->{type} eq 'character') {  
             if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {  
               $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);  
               unless (length $token->{data}) {  
                 !!!next-token;  
                 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;  
           } elsif ($token->{type} eq 'start tag') {  
             if ($token->{tag_name} eq 'body') {  
               !!!insert-element ('body', $token->{attributes});  
               $self->{insertion_mode} = 'in body';  
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'frameset') {  
               !!!insert-element ('frameset', $token->{attributes});  
               $self->{insertion_mode} = 'in frameset';  
               !!!next-token;  
               redo B;  
             } elsif ({  
                       base => 1, link => 1, meta => 1,  
                       script => 1, style => 1, title => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'after head:'.$token->{tag_name});  
               $self->{insertion_mode} = 'in head';  
               ## reprocess  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
           }  
             
           ## As if <body>  
           !!!insert-element ('body');  
           $self->{insertion_mode} = 'in body';  
           ## reprocess  
           redo B;  
3631          } elsif ($self->{insertion_mode} eq 'in body') {          } elsif ($self->{insertion_mode} eq 'in body') {
3632            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3633              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
# Line 3622  sub _tree_construction_main ($) { Line 3782  sub _tree_construction_main ($) {
3782                if ({                if ({
3783                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3784                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3785                       tbody => 1, tfoot=> 1, thead => 1,
3786                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3787                  !!!back-token; # <table>                  !!!back-token; # <table>
3788                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 3670  sub _tree_construction_main ($) { Line 3831  sub _tree_construction_main ($) {
3831                if ({                if ({
3832                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3833                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3834                       tbody => 1, tfoot=> 1, thead => 1,
3835                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3836                  !!!back-token;                  !!!back-token;
3837                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 3753  sub _tree_construction_main ($) { Line 3915  sub _tree_construction_main ($) {
3915                if ({                if ({
3916                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3917                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3918                       tbody => 1, tfoot=> 1, thead => 1,
3919                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3920                  !!!back-token; # <?>                  !!!back-token; # <?>
3921                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => 'end tag', tag_name => 'caption'};
# Line 3803  sub _tree_construction_main ($) { Line 3966  sub _tree_construction_main ($) {
3966                if ({                if ({
3967                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3968                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3969                       tbody => 1, tfoot=> 1, thead => 1,
3970                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3971                  !!!back-token;                  !!!back-token;
3972                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 3850  sub _tree_construction_main ($) { Line 4014  sub _tree_construction_main ($) {
4014                if ({                if ({
4015                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4016                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4017                       tbody => 1, tfoot=> 1, thead => 1,
4018                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4019                  !!!back-token; # </table>                  !!!back-token; # </table>
4020                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => 'end tag', tag_name => 'caption'};
# Line 4115  sub _tree_construction_main ($) { Line 4280  sub _tree_construction_main ($) {
4280                if ({                if ({
4281                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4282                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4283                       tbody => 1, tfoot=> 1, thead => 1,
4284                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4285                  !!!back-token; # <table>                  !!!back-token; # <table>
4286                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 4383  sub _tree_construction_main ($) { Line 4549  sub _tree_construction_main ($) {
4549                if ({                if ({
4550                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4551                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4552                       tbody => 1, tfoot=> 1, thead => 1,
4553                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4554                  !!!back-token; # <table>                  !!!back-token; # <table>
4555                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 4624  sub _tree_construction_main ($) { Line 4791  sub _tree_construction_main ($) {
4791                     td => ($token->{tag_name} eq 'th'),                     td => ($token->{tag_name} eq 'th'),
4792                     th => ($token->{tag_name} eq 'td'),                     th => ($token->{tag_name} eq 'td'),
4793                     tr => 1,                     tr => 1,
4794                       tbody => 1, tfoot=> 1, thead => 1,
4795                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4796                  !!!back-token;                  !!!back-token;
4797                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 4976  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 5020  sub _tree_construction_main ($) { Line 5188  sub _tree_construction_main ($) {
5188            }            }
5189                        
5190            if (defined $token->{tag_name}) {            if (defined $token->{tag_name}) {
5191              !!!parse-error (type => 'after frameset:'.$token->{tag_name});              !!!parse-error (type => 'after frameset:'.($token->{tag_name} eq 'end tag' ? '/' : '').$token->{tag_name});
5192            } else {            } else {
5193              !!!parse-error (type => 'after frameset:#'.$token->{type});              !!!parse-error (type => 'after frameset:#'.$token->{type});
5194            }            }
# Line 5070  sub _tree_construction_main ($) { Line 5238  sub _tree_construction_main ($) {
5238          redo B;          redo B;
5239        } elsif ($token->{type} eq 'start tag' or        } elsif ($token->{type} eq 'start tag' or
5240                 $token->{type} eq 'end tag') {                 $token->{type} eq 'end tag') {
5241          !!!parse-error (type => 'after html:'.$token->{tag_name});          !!!parse-error (type => 'after html:'.($token->{type} eq 'end tag' ? '/' : '').$token->{tag_name});
5242          $phase = 'main';          $phase = 'main';
5243          ## reprocess          ## reprocess
5244          redo B;          redo B;
# Line 5279  sub get_inner_html ($$$) { Line 5447  sub get_inner_html ($$$) {
5447            
5448      my $nt = $child->node_type;      my $nt = $child->node_type;
5449      if ($nt == 1) { # Element      if ($nt == 1) { # Element
5450        my $tag_name = lc $child->tag_name; ## ISSUE: Definition of "lowercase"        my $tag_name = $child->tag_name; ## TODO: manakai_tag_name
5451        $s .= '<' . $tag_name;        $s .= '<' . $tag_name;
5452          ## NOTE: Non-HTML case:
5453        ## ISSUE: Non-html elements        ## <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/11191>
5454    
5455        my @attrs = @{$child->attributes}; # sort order MUST be stable        my @attrs = @{$child->attributes}; # sort order MUST be stable
5456        for my $attr (@attrs) { # order is implementation dependent        for my $attr (@attrs) { # order is implementation dependent
5457          my $attr_name = lc $attr->name; ## ISSUE: Definition of "lowercase"          my $attr_name = $attr->name; ## TODO: manakai_name
5458          $s .= ' ' . $attr_name . '="';          $s .= ' ' . $attr_name . '="';
5459          my $attr_value = $attr->value;          my $attr_value = $attr->value;
5460          ## escape          ## escape
# Line 5305  sub get_inner_html ($$$) { Line 5473  sub get_inner_html ($$$) {
5473          spacer => 1, wbr => 1,          spacer => 1, wbr => 1,
5474        }->{$tag_name};        }->{$tag_name};
5475    
5476          $s .= "\x0A" if $tag_name eq 'pre' or $tag_name eq 'textarea';
5477    
5478        if (not $in_cdata and {        if (not $in_cdata and {
5479          style => 1, script => 1, xmp => 1, iframe => 1,          style => 1, script => 1, xmp => 1, iframe => 1,
5480          noembed => 1, noframes => 1, noscript => 1,          noembed => 1, noframes => 1, noscript => 1,
5481            plaintext => 1,
5482        }->{$tag_name}) {        }->{$tag_name}) {
5483          unshift @node, 'cdata-out';          unshift @node, 'cdata-out';
5484          $in_cdata = 1;          $in_cdata = 1;

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.34

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24