/[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.22 by wakaba, Sat Jun 23 14:55:45 2007 UTC revision 1.42 by wakaba, Sat Jul 21 06:59:16 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 144  sub new ($) { Line 150  sub new ($) {
150    return $self;    return $self;
151  } # new  } # new
152    
153    sub CM_ENTITY () { 0b001 } # & markup in data
154    sub CM_LIMITED_MARKUP () { 0b010 } # < markup in data (limited)
155    sub CM_FULL_MARKUP () { 0b100 } # < markup in data (any)
156    
157    sub PLAINTEXT_CONTENT_MODEL () { 0 }
158    sub CDATA_CONTENT_MODEL () { CM_LIMITED_MARKUP }
159    sub RCDATA_CONTENT_MODEL () { CM_ENTITY | CM_LIMITED_MARKUP }
160    sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP }
161    
162  ## Implementations MUST act as if state machine in the spec  ## Implementations MUST act as if state machine in the spec
163    
164  sub _initialize_tokenizer ($) {  sub _initialize_tokenizer ($) {
165    my $self = shift;    my $self = shift;
166    $self->{state} = 'data'; # MUST    $self->{state} = 'data'; # MUST
167    $self->{content_model_flag} = 'PCDATA'; # be    $self->{content_model} = PCDATA_CONTENT_MODEL; # be
168    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE    undef $self->{current_token}; # start tag, end tag, comment, or DOCTYPE
169    undef $self->{current_attribute};    undef $self->{current_attribute};
170    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
# Line 188  sub _get_next_token ($) { Line 203  sub _get_next_token ($) {
203    A: {    A: {
204      if ($self->{state} eq 'data') {      if ($self->{state} eq 'data') {
205        if ($self->{next_input_character} == 0x0026) { # &        if ($self->{next_input_character} == 0x0026) { # &
206          if ($self->{content_model_flag} eq 'PCDATA' or          if ($self->{content_model} & CM_ENTITY) { # PCDATA | RCDATA
             $self->{content_model_flag} eq 'RCDATA') {  
207            $self->{state} = 'entity data';            $self->{state} = 'entity data';
208            !!!next-input-character;            !!!next-input-character;
209            redo A;            redo A;
# Line 197  sub _get_next_token ($) { Line 211  sub _get_next_token ($) {
211            #            #
212          }          }
213        } elsif ($self->{next_input_character} == 0x002D) { # -        } elsif ($self->{next_input_character} == 0x002D) { # -
214          if ($self->{content_model_flag} eq 'RCDATA' or          if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
             $self->{content_model_flag} eq 'CDATA') {  
215            unless ($self->{escape}) {            unless ($self->{escape}) {
216              if ($self->{prev_input_character}->[0] == 0x002D and # -              if ($self->{prev_input_character}->[0] == 0x002D and # -
217                  $self->{prev_input_character}->[1] == 0x0021 and # !                  $self->{prev_input_character}->[1] == 0x0021 and # !
# Line 210  sub _get_next_token ($) { Line 223  sub _get_next_token ($) {
223                    
224          #          #
225        } elsif ($self->{next_input_character} == 0x003C) { # <        } elsif ($self->{next_input_character} == 0x003C) { # <
226          if ($self->{content_model_flag} eq 'PCDATA' or          if ($self->{content_model} & CM_FULL_MARKUP or # PCDATA
227              (($self->{content_model_flag} eq 'CDATA' or              (($self->{content_model} & CM_LIMITED_MARKUP) and # CDATA | RCDATA
               $self->{content_model_flag} eq 'RCDATA') and  
228               not $self->{escape})) {               not $self->{escape})) {
229            $self->{state} = 'tag open';            $self->{state} = 'tag open';
230            !!!next-input-character;            !!!next-input-character;
# Line 222  sub _get_next_token ($) { Line 234  sub _get_next_token ($) {
234          }          }
235        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
236          if ($self->{escape} and          if ($self->{escape} and
237              ($self->{content_model_flag} eq 'RCDATA' or              ($self->{content_model} & CM_LIMITED_MARKUP)) { # RCDATA | CDATA
              $self->{content_model_flag} eq 'CDATA')) {  
238            if ($self->{prev_input_character}->[0] == 0x002D and # -            if ($self->{prev_input_character}->[0] == 0x002D and # -
239                $self->{prev_input_character}->[1] == 0x002D) { # -                $self->{prev_input_character}->[1] == 0x002D) { # -
240              delete $self->{escape};              delete $self->{escape};
# Line 247  sub _get_next_token ($) { Line 258  sub _get_next_token ($) {
258      } elsif ($self->{state} eq 'entity data') {      } elsif ($self->{state} eq 'entity data') {
259        ## (cannot happen in CDATA state)        ## (cannot happen in CDATA state)
260                
261        my $token = $self->_tokenize_attempt_to_consume_an_entity;        my $token = $self->_tokenize_attempt_to_consume_an_entity (0);
262    
263        $self->{state} = 'data';        $self->{state} = 'data';
264        # next-input-character is already done        # next-input-character is already done
# Line 260  sub _get_next_token ($) { Line 271  sub _get_next_token ($) {
271    
272        redo A;        redo A;
273      } elsif ($self->{state} eq 'tag open') {      } elsif ($self->{state} eq 'tag open') {
274        if ($self->{content_model_flag} eq 'RCDATA' or        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
           $self->{content_model_flag} eq 'CDATA') {  
275          if ($self->{next_input_character} == 0x002F) { # /          if ($self->{next_input_character} == 0x002F) { # /
276            !!!next-input-character;            !!!next-input-character;
277            $self->{state} = 'close tag open';            $self->{state} = 'close tag open';
# Line 274  sub _get_next_token ($) { Line 284  sub _get_next_token ($) {
284    
285            redo A;            redo A;
286          }          }
287        } elsif ($self->{content_model_flag} eq 'PCDATA') {        } elsif ($self->{content_model} & CM_FULL_MARKUP) { # PCDATA
288          if ($self->{next_input_character} == 0x0021) { # !          if ($self->{next_input_character} == 0x0021) { # !
289            $self->{state} = 'markup declaration open';            $self->{state} = 'markup declaration open';
290            !!!next-input-character;            !!!next-input-character;
# Line 321  sub _get_next_token ($) { Line 331  sub _get_next_token ($) {
331            redo A;            redo A;
332          }          }
333        } else {        } else {
334          die "$0: $self->{content_model_flag}: Unknown content model flag";          die "$0: $self->{content_model} in tag open";
335        }        }
336      } elsif ($self->{state} eq 'close tag open') {      } elsif ($self->{state} eq 'close tag open') {
337        if ($self->{content_model_flag} eq 'RCDATA' or        if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA
338            $self->{content_model_flag} eq 'CDATA') {          if (defined $self->{last_emitted_start_tag_name}) {
339          my @next_char;            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>
340          TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {            my @next_char;
341              TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {
342                push @next_char, $self->{next_input_character};
343                my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);
344                my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;
345                if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) {
346                  !!!next-input-character;
347                  next TAGNAME;
348                } else {
349                  $self->{next_input_character} = shift @next_char; # reconsume
350                  !!!back-next-input-character (@next_char);
351                  $self->{state} = 'data';
352    
353                  !!!emit ({type => 'character', data => '</'});
354      
355                  redo A;
356                }
357              }
358            push @next_char, $self->{next_input_character};            push @next_char, $self->{next_input_character};
359            my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);        
360            my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;            unless ($self->{next_input_character} == 0x0009 or # HT
361            if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) {                    $self->{next_input_character} == 0x000A or # LF
362              !!!next-input-character;                    $self->{next_input_character} == 0x000B or # VT
363              next TAGNAME;                    $self->{next_input_character} == 0x000C or # FF
364            } else {                    $self->{next_input_character} == 0x0020 or # SP
365                      $self->{next_input_character} == 0x003E or # >
366                      $self->{next_input_character} == 0x002F or # /
367                      $self->{next_input_character} == -1) {
368              $self->{next_input_character} = shift @next_char; # reconsume              $self->{next_input_character} = shift @next_char; # reconsume
369              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
370              $self->{state} = 'data';              $self->{state} = 'data';
   
371              !!!emit ({type => 'character', data => '</'});              !!!emit ({type => 'character', data => '</'});
   
372              redo A;              redo A;
373              } else {
374                $self->{next_input_character} = shift @next_char;
375                !!!back-next-input-character (@next_char);
376                # and consume...
377            }            }
378          }          } else {
379          push @next_char, $self->{next_input_character};            ## No start tag token has ever been emitted
380                  # 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);  
381            $self->{state} = 'data';            $self->{state} = 'data';
   
382            !!!emit ({type => 'character', data => '</'});            !!!emit ({type => 'character', data => '</'});
   
383            redo A;            redo A;
         } else {  
           $self->{next_input_character} = shift @next_char;  
           !!!back-next-input-character (@next_char);  
           # and consume...  
384          }          }
385        }        }
386                
# Line 412  sub _get_next_token ($) { Line 428  sub _get_next_token ($) {
428          redo A;          redo A;
429        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
430          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
431              $self->{current_token}->{first_start_tag}
432                  = not defined $self->{last_emitted_start_tag_name};
433            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
434          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
435            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
436            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
437              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
438            }            }
# Line 425  sub _get_next_token ($) { Line 443  sub _get_next_token ($) {
443          !!!next-input-character;          !!!next-input-character;
444    
445          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
446    
447          redo A;          redo A;
448        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 438  sub _get_next_token ($) { Line 455  sub _get_next_token ($) {
455        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
456          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
457          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
458              $self->{current_token}->{first_start_tag}
459                  = not defined $self->{last_emitted_start_tag_name};
460            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
461          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
462            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
463            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
464              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
465            }            }
# Line 451  sub _get_next_token ($) { Line 470  sub _get_next_token ($) {
470          # reconsume          # reconsume
471    
472          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
473    
474          redo A;          redo A;
475        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_input_character} == 0x002F) { # /
# Line 485  sub _get_next_token ($) { Line 503  sub _get_next_token ($) {
503          redo A;          redo A;
504        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
505          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
506              $self->{current_token}->{first_start_tag}
507                  = not defined $self->{last_emitted_start_tag_name};
508            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
509          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
510            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
511            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
512              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
513            }            }
# Line 498  sub _get_next_token ($) { Line 518  sub _get_next_token ($) {
518          !!!next-input-character;          !!!next-input-character;
519    
520          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
521    
522          redo A;          redo A;
523        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 524  sub _get_next_token ($) { Line 543  sub _get_next_token ($) {
543        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
544          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
545          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
546              $self->{current_token}->{first_start_tag}
547                  = not defined $self->{last_emitted_start_tag_name};
548            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
549          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
550            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
551            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
552              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
553            }            }
# Line 537  sub _get_next_token ($) { Line 558  sub _get_next_token ($) {
558          # reconsume          # reconsume
559    
560          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
561    
562          redo A;          redo A;
563        } else {        } else {
# Line 551  sub _get_next_token ($) { Line 571  sub _get_next_token ($) {
571        my $before_leave = sub {        my $before_leave = sub {
572          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
573              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
574            !!!parse-error (type => 'dupulicate attribute');            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name});
575            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
576          } else {          } else {
577            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}            $self->{current_token}->{attributes}->{$self->{current_attribute}->{name}}
# Line 576  sub _get_next_token ($) { Line 596  sub _get_next_token ($) {
596        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
597          $before_leave->();          $before_leave->();
598          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
599              $self->{current_token}->{first_start_tag}
600                  = not defined $self->{last_emitted_start_tag_name};
601            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
602          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
603            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
604            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
605              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
606            }            }
# Line 589  sub _get_next_token ($) { Line 611  sub _get_next_token ($) {
611          !!!next-input-character;          !!!next-input-character;
612    
613          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
614    
615          redo A;          redo A;
616        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 616  sub _get_next_token ($) { Line 637  sub _get_next_token ($) {
637          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
638          $before_leave->();          $before_leave->();
639          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
640              $self->{current_token}->{first_start_tag}
641                  = not defined $self->{last_emitted_start_tag_name};
642            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
643          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
644            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
645            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
646              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
647            }            }
# Line 629  sub _get_next_token ($) { Line 652  sub _get_next_token ($) {
652          # reconsume          # reconsume
653    
654          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
655    
656          redo A;          redo A;
657        } else {        } else {
# Line 653  sub _get_next_token ($) { Line 675  sub _get_next_token ($) {
675          redo A;          redo A;
676        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
677          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
678              $self->{current_token}->{first_start_tag}
679                  = not defined $self->{last_emitted_start_tag_name};
680            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
681          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
682            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
683            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
684              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
685            }            }
# Line 666  sub _get_next_token ($) { Line 690  sub _get_next_token ($) {
690          !!!next-input-character;          !!!next-input-character;
691    
692          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
693    
694          redo A;          redo A;
695        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 685  sub _get_next_token ($) { Line 708  sub _get_next_token ($) {
708            #            #
709          } else {          } else {
710            !!!parse-error (type => 'nestc');            !!!parse-error (type => 'nestc');
711              ## TODO: Different error type for <aa / bb> than <aa/>
712          }          }
713          $self->{state} = 'before attribute name';          $self->{state} = 'before attribute name';
714          # next-input-character is already done          # next-input-character is already done
# Line 692  sub _get_next_token ($) { Line 716  sub _get_next_token ($) {
716        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
717          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
718          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
719              $self->{current_token}->{first_start_tag}
720                  = not defined $self->{last_emitted_start_tag_name};
721            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
722          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
723            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
724            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
725              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
726            }            }
# Line 705  sub _get_next_token ($) { Line 731  sub _get_next_token ($) {
731          # reconsume          # reconsume
732    
733          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
734    
735          redo A;          redo A;
736        } else {        } else {
# Line 738  sub _get_next_token ($) { Line 763  sub _get_next_token ($) {
763          redo A;          redo A;
764        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
765          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
766              $self->{current_token}->{first_start_tag}
767                  = not defined $self->{last_emitted_start_tag_name};
768            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
769          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
770            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
771            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
772              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
773            }            }
# Line 751  sub _get_next_token ($) { Line 778  sub _get_next_token ($) {
778          !!!next-input-character;          !!!next-input-character;
779    
780          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
781    
782          redo A;          redo A;
783        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
784          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
785          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
786              $self->{current_token}->{first_start_tag}
787                  = not defined $self->{last_emitted_start_tag_name};
788            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
789          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
790            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
791            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
792              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
793            }            }
# Line 770  sub _get_next_token ($) { Line 798  sub _get_next_token ($) {
798          ## reconsume          ## reconsume
799    
800          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
801    
802          redo A;          redo A;
803        } else {        } else {
# Line 792  sub _get_next_token ($) { Line 819  sub _get_next_token ($) {
819        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
820          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
821          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
822              $self->{current_token}->{first_start_tag}
823                  = not defined $self->{last_emitted_start_tag_name};
824            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
825          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
826            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
827            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
828              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
829            }            }
# Line 805  sub _get_next_token ($) { Line 834  sub _get_next_token ($) {
834          ## reconsume          ## reconsume
835    
836          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
837    
838          redo A;          redo A;
839        } else {        } else {
# Line 827  sub _get_next_token ($) { Line 855  sub _get_next_token ($) {
855        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
856          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
857          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
858              $self->{current_token}->{first_start_tag}
859                  = not defined $self->{last_emitted_start_tag_name};
860            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
861          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
862            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
863            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
864              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
865            }            }
# Line 840  sub _get_next_token ($) { Line 870  sub _get_next_token ($) {
870          ## reconsume          ## reconsume
871    
872          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
873    
874          redo A;          redo A;
875        } else {        } else {
# Line 865  sub _get_next_token ($) { Line 894  sub _get_next_token ($) {
894          redo A;          redo A;
895        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
896          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
897              $self->{current_token}->{first_start_tag}
898                  = not defined $self->{last_emitted_start_tag_name};
899            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
900          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
901            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
902            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
903              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
904            }            }
# Line 878  sub _get_next_token ($) { Line 909  sub _get_next_token ($) {
909          !!!next-input-character;          !!!next-input-character;
910    
911          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
912    
913          redo A;          redo A;
914        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
915          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
916          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
917              $self->{current_token}->{first_start_tag}
918                  = not defined $self->{last_emitted_start_tag_name};
919            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
920          } elsif ($self->{current_token}->{type} eq 'end tag') {          } elsif ($self->{current_token}->{type} eq 'end tag') {
921            $self->{content_model_flag} = 'PCDATA'; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
922            if ($self->{current_token}->{attributes}) {            if ($self->{current_token}->{attributes}) {
923              !!!parse-error (type => 'end tag attribute');              !!!parse-error (type => 'end tag attribute');
924            }            }
# Line 897  sub _get_next_token ($) { Line 929  sub _get_next_token ($) {
929          ## reconsume          ## reconsume
930    
931          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
932    
933          redo A;          redo A;
934        } else {        } else {
# Line 907  sub _get_next_token ($) { Line 938  sub _get_next_token ($) {
938          redo A;          redo A;
939        }        }
940      } elsif ($self->{state} eq 'entity in attribute value') {      } elsif ($self->{state} eq 'entity in attribute value') {
941        my $token = $self->_tokenize_attempt_to_consume_an_entity;        my $token = $self->_tokenize_attempt_to_consume_an_entity (1);
942    
943        unless (defined $token) {        unless (defined $token) {
944          $self->{current_attribute}->{value} .= '&';          $self->{current_attribute}->{value} .= '&';
# Line 956  sub _get_next_token ($) { Line 987  sub _get_next_token ($) {
987          push @next_char, $self->{next_input_character};          push @next_char, $self->{next_input_character};
988          if ($self->{next_input_character} == 0x002D) { # -          if ($self->{next_input_character} == 0x002D) { # -
989            $self->{current_token} = {type => 'comment', data => ''};            $self->{current_token} = {type => 'comment', data => ''};
990            $self->{state} = 'comment';            $self->{state} = 'comment start';
991            !!!next-input-character;            !!!next-input-character;
992            redo A;            redo A;
993          }          }
# Line 998  sub _get_next_token ($) { Line 1029  sub _get_next_token ($) {
1029          }          }
1030        }        }
1031    
1032        !!!parse-error (type => 'bogus comment open');        !!!parse-error (type => 'bogus comment');
1033        $self->{next_input_character} = shift @next_char;        $self->{next_input_character} = shift @next_char;
1034        !!!back-next-input-character (@next_char);        !!!back-next-input-character (@next_char);
1035        $self->{state} = 'bogus comment';        $self->{state} = 'bogus comment';
# Line 1006  sub _get_next_token ($) { Line 1037  sub _get_next_token ($) {
1037                
1038        ## ISSUE: typos in spec: chacacters, is is a parse error        ## ISSUE: typos in spec: chacacters, is is a parse error
1039        ## 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?
1040        } elsif ($self->{state} eq 'comment start') {
1041          if ($self->{next_input_character} == 0x002D) { # -
1042            $self->{state} = 'comment start dash';
1043            !!!next-input-character;
1044            redo A;
1045          } elsif ($self->{next_input_character} == 0x003E) { # >
1046            !!!parse-error (type => 'bogus comment');
1047            $self->{state} = 'data';
1048            !!!next-input-character;
1049    
1050            !!!emit ($self->{current_token}); # comment
1051    
1052            redo A;
1053          } elsif ($self->{next_input_character} == -1) {
1054            !!!parse-error (type => 'unclosed comment');
1055            $self->{state} = 'data';
1056            ## reconsume
1057    
1058            !!!emit ($self->{current_token}); # comment
1059    
1060            redo A;
1061          } else {
1062            $self->{current_token}->{data} # comment
1063                .= chr ($self->{next_input_character});
1064            $self->{state} = 'comment';
1065            !!!next-input-character;
1066            redo A;
1067          }
1068        } elsif ($self->{state} eq 'comment start dash') {
1069          if ($self->{next_input_character} == 0x002D) { # -
1070            $self->{state} = 'comment end';
1071            !!!next-input-character;
1072            redo A;
1073          } elsif ($self->{next_input_character} == 0x003E) { # >
1074            !!!parse-error (type => 'bogus comment');
1075            $self->{state} = 'data';
1076            !!!next-input-character;
1077    
1078            !!!emit ($self->{current_token}); # comment
1079    
1080            redo A;
1081          } elsif ($self->{next_input_character} == -1) {
1082            !!!parse-error (type => 'unclosed comment');
1083            $self->{state} = 'data';
1084            ## reconsume
1085    
1086            !!!emit ($self->{current_token}); # comment
1087    
1088            redo A;
1089          } else {
1090            $self->{current_token}->{data} # comment
1091                .= '-' . chr ($self->{next_input_character});
1092            $self->{state} = 'comment';
1093            !!!next-input-character;
1094            redo A;
1095          }
1096      } elsif ($self->{state} eq 'comment') {      } elsif ($self->{state} eq 'comment') {
1097        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1098          $self->{state} = 'comment dash';          $self->{state} = 'comment end dash';
1099          !!!next-input-character;          !!!next-input-character;
1100          redo A;          redo A;
1101        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1017  sub _get_next_token ($) { Line 1104  sub _get_next_token ($) {
1104          ## reconsume          ## reconsume
1105    
1106          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1107    
1108          redo A;          redo A;
1109        } else {        } else {
# Line 1026  sub _get_next_token ($) { Line 1112  sub _get_next_token ($) {
1112          !!!next-input-character;          !!!next-input-character;
1113          redo A;          redo A;
1114        }        }
1115      } elsif ($self->{state} eq 'comment dash') {      } elsif ($self->{state} eq 'comment end dash') {
1116        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1117          $self->{state} = 'comment end';          $self->{state} = 'comment end';
1118          !!!next-input-character;          !!!next-input-character;
# Line 1037  sub _get_next_token ($) { Line 1123  sub _get_next_token ($) {
1123          ## reconsume          ## reconsume
1124    
1125          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1126    
1127          redo A;          redo A;
1128        } else {        } else {
# Line 1052  sub _get_next_token ($) { Line 1137  sub _get_next_token ($) {
1137          !!!next-input-character;          !!!next-input-character;
1138    
1139          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1140    
1141          redo A;          redo A;
1142        } elsif ($self->{next_input_character} == 0x002D) { # -        } elsif ($self->{next_input_character} == 0x002D) { # -
# Line 1067  sub _get_next_token ($) { Line 1151  sub _get_next_token ($) {
1151          ## reconsume          ## reconsume
1152    
1153          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1154    
1155          redo A;          redo A;
1156        } else {        } else {
# Line 1142  sub _get_next_token ($) { Line 1225  sub _get_next_token ($) {
1225          !!!next-input-character;          !!!next-input-character;
1226    
1227          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1228    
1229          redo A;          redo A;
1230        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1152  sub _get_next_token ($) { Line 1234  sub _get_next_token ($) {
1234    
1235          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1236          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1237    
1238          redo A;          redo A;
1239        } else {        } else {
# Line 1176  sub _get_next_token ($) { Line 1257  sub _get_next_token ($) {
1257          !!!next-input-character;          !!!next-input-character;
1258    
1259          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1260    
1261          redo A;          redo A;
1262        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1186  sub _get_next_token ($) { Line 1266  sub _get_next_token ($) {
1266    
1267          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1268          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1269    
1270          redo A;          redo A;
1271        } elsif ($self->{next_input_character} == 0x0050 or # P        } elsif ($self->{next_input_character} == 0x0050 or # P
# Line 1278  sub _get_next_token ($) { Line 1357  sub _get_next_token ($) {
1357    
1358          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1359          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1360    
1361          redo A;          redo A;
1362        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1289  sub _get_next_token ($) { Line 1367  sub _get_next_token ($) {
1367    
1368          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1369          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1370    
1371          redo A;          redo A;
1372        } else {        } else {
# Line 1311  sub _get_next_token ($) { Line 1388  sub _get_next_token ($) {
1388    
1389          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1390          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1391    
1392          redo A;          redo A;
1393        } else {        } else {
# Line 1334  sub _get_next_token ($) { Line 1410  sub _get_next_token ($) {
1410    
1411          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1412          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1413    
1414          redo A;          redo A;
1415        } else {        } else {
# Line 1367  sub _get_next_token ($) { Line 1442  sub _get_next_token ($) {
1442          !!!next-input-character;          !!!next-input-character;
1443    
1444          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1445    
1446          redo A;          redo A;
1447        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1448          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1449    
1450          $self->{state} = 'data';          $self->{state} = 'data';
1451          ## recomsume          ## reconsume
1452    
1453          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1454          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1455    
1456          redo A;          redo A;
1457        } else {        } else {
# Line 1412  sub _get_next_token ($) { Line 1485  sub _get_next_token ($) {
1485    
1486          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1487          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1488    
1489          redo A;          redo A;
1490        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1491          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1492    
1493          $self->{state} = 'data';          $self->{state} = 'data';
1494          ## recomsume          ## reconsume
1495    
1496          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1497          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1498    
1499          redo A;          redo A;
1500        } else {        } else {
1501          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after SYSTEM');
1502          $self->{state} = 'bogus DOCTYPE';          $self->{state} = 'bogus DOCTYPE';
1503          !!!next-input-character;          !!!next-input-character;
1504          redo A;          redo A;
# Line 1445  sub _get_next_token ($) { Line 1516  sub _get_next_token ($) {
1516    
1517          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1518          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1519    
1520          redo A;          redo A;
1521        } else {        } else {
# Line 1468  sub _get_next_token ($) { Line 1538  sub _get_next_token ($) {
1538    
1539          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1540          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1541    
1542          redo A;          redo A;
1543        } else {        } else {
# Line 1491  sub _get_next_token ($) { Line 1560  sub _get_next_token ($) {
1560          !!!next-input-character;          !!!next-input-character;
1561    
1562          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1563    
1564          redo A;          redo A;
1565        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1566          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
1567    
1568          $self->{state} = 'data';          $self->{state} = 'data';
1569          ## recomsume          ## reconsume
1570    
1571          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1572          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1573    
1574          redo A;          redo A;
1575        } else {        } else {
# Line 1518  sub _get_next_token ($) { Line 1585  sub _get_next_token ($) {
1585    
1586          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1587          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1588    
1589          redo A;          redo A;
1590        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1528  sub _get_next_token ($) { Line 1594  sub _get_next_token ($) {
1594    
1595          delete $self->{current_token}->{correct};          delete $self->{current_token}->{correct};
1596          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1597    
1598          redo A;          redo A;
1599        } else {        } else {
# Line 1544  sub _get_next_token ($) { Line 1609  sub _get_next_token ($) {
1609    die "$0: _get_next_token: unexpected case";    die "$0: _get_next_token: unexpected case";
1610  } # _get_next_token  } # _get_next_token
1611    
1612  sub _tokenize_attempt_to_consume_an_entity ($) {  sub _tokenize_attempt_to_consume_an_entity ($$) {
1613    my $self = shift;    my ($self, $in_attr) = @_;
1614    
1615    if ({    if ({
1616         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 1623  sub _tokenize_attempt_to_consume_an_enti
1623      !!!next-input-character;      !!!next-input-character;
1624      if ($self->{next_input_character} == 0x0078 or # x      if ($self->{next_input_character} == 0x0078 or # x
1625          $self->{next_input_character} == 0x0058) { # X          $self->{next_input_character} == 0x0058) { # X
1626        my $num;        my $code;
1627        X: {        X: {
1628          my $x_char = $self->{next_input_character};          my $x_char = $self->{next_input_character};
1629          !!!next-input-character;          !!!next-input-character;
1630          if (0x0030 <= $self->{next_input_character} and          if (0x0030 <= $self->{next_input_character} and
1631              $self->{next_input_character} <= 0x0039) { # 0..9              $self->{next_input_character} <= 0x0039) { # 0..9
1632            $num ||= 0;            $code ||= 0;
1633            $num *= 0x10;            $code *= 0x10;
1634            $num += $self->{next_input_character} - 0x0030;            $code += $self->{next_input_character} - 0x0030;
1635            redo X;            redo X;
1636          } elsif (0x0061 <= $self->{next_input_character} and          } elsif (0x0061 <= $self->{next_input_character} and
1637                   $self->{next_input_character} <= 0x0066) { # a..f                   $self->{next_input_character} <= 0x0066) { # a..f
1638            ## ISSUE: the spec says U+0078, which is apparently incorrect            $code ||= 0;
1639            $num ||= 0;            $code *= 0x10;
1640            $num *= 0x10;            $code += $self->{next_input_character} - 0x0060 + 9;
           $num += $self->{next_input_character} - 0x0060 + 9;  
1641            redo X;            redo X;
1642          } elsif (0x0041 <= $self->{next_input_character} and          } elsif (0x0041 <= $self->{next_input_character} and
1643                   $self->{next_input_character} <= 0x0046) { # A..F                   $self->{next_input_character} <= 0x0046) { # A..F
1644            ## ISSUE: the spec says U+0058, which is apparently incorrect            $code ||= 0;
1645            $num ||= 0;            $code *= 0x10;
1646            $num *= 0x10;            $code += $self->{next_input_character} - 0x0040 + 9;
           $num += $self->{next_input_character} - 0x0040 + 9;  
1647            redo X;            redo X;
1648          } elsif (not defined $num) { # no hexadecimal digit          } elsif (not defined $code) { # no hexadecimal digit
1649            !!!parse-error (type => 'bare hcro');            !!!parse-error (type => 'bare hcro');
1650              !!!back-next-input-character ($x_char, $self->{next_input_character});
1651            $self->{next_input_character} = 0x0023; # #            $self->{next_input_character} = 0x0023; # #
           !!!back-next-input-character ($x_char);  
1652            return undef;            return undef;
1653          } elsif ($self->{next_input_character} == 0x003B) { # ;          } elsif ($self->{next_input_character} == 0x003B) { # ;
1654            !!!next-input-character;            !!!next-input-character;
# Line 1593  sub _tokenize_attempt_to_consume_an_enti Line 1656  sub _tokenize_attempt_to_consume_an_enti
1656            !!!parse-error (type => 'no refc');            !!!parse-error (type => 'no refc');
1657          }          }
1658    
1659          ## TODO: check the definition for |a valid Unicode character|.          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
1660          ## <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-December/thread.html#8189>            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
1661          if ($num > 1114111 or $num == 0) {            $code = 0xFFFD;
1662            $num = 0xFFFD; # REPLACEMENT CHARACTER          } elsif ($code > 0x10FFFF) {
1663            ## ISSUE: Why this is not an error?            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
1664          } elsif (0x80 <= $num and $num <= 0x9F) {            $code = 0xFFFD;
1665            !!!parse-error (type => sprintf 'c1 entity:U+%04X', $num);          } elsif ($code == 0x000D) {
1666            $num = $c1_entity_char->{$num};            !!!parse-error (type => 'CR character reference');
1667              $code = 0x000A;
1668            } elsif (0x80 <= $code and $code <= 0x9F) {
1669              !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
1670              $code = $c1_entity_char->{$code};
1671          }          }
1672    
1673          return {type => 'character', data => chr $num};          return {type => 'character', data => chr $code};
1674        } # X        } # X
1675      } elsif (0x0030 <= $self->{next_input_character} and      } elsif (0x0030 <= $self->{next_input_character} and
1676               $self->{next_input_character} <= 0x0039) { # 0..9               $self->{next_input_character} <= 0x0039) { # 0..9
# Line 1624  sub _tokenize_attempt_to_consume_an_enti Line 1691  sub _tokenize_attempt_to_consume_an_enti
1691          !!!parse-error (type => 'no refc');          !!!parse-error (type => 'no refc');
1692        }        }
1693    
1694        ## TODO: check the definition for |a valid Unicode character|.        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
1695        if ($code > 1114111 or $code == 0) {          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
1696          $code = 0xFFFD; # REPLACEMENT CHARACTER          $code = 0xFFFD;
1697          ## ISSUE: Why this is not an error?        } elsif ($code > 0x10FFFF) {
1698            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
1699            $code = 0xFFFD;
1700          } elsif ($code == 0x000D) {
1701            !!!parse-error (type => 'CR character reference');
1702            $code = 0x000A;
1703        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
1704          !!!parse-error (type => sprintf 'c1 entity:U+%04X', $code);          !!!parse-error (type => sprintf 'C1 character reference:U+%04X', $code);
1705          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
1706        }        }
1707                
# Line 1648  sub _tokenize_attempt_to_consume_an_enti Line 1720  sub _tokenize_attempt_to_consume_an_enti
1720      !!!next-input-character;      !!!next-input-character;
1721    
1722      my $value = $entity_name;      my $value = $entity_name;
1723      my $match;      my $match = 0;
1724      require Whatpm::_NamedEntityList;      require Whatpm::_NamedEntityList;
1725      our $EntityChar;      our $EntityChar;
1726    
# Line 1663  sub _tokenize_attempt_to_consume_an_enti Line 1735  sub _tokenize_attempt_to_consume_an_enti
1735              $self->{next_input_character} == 0x003B)) { # ;              $self->{next_input_character} == 0x003B)) { # ;
1736        $entity_name .= chr $self->{next_input_character};        $entity_name .= chr $self->{next_input_character};
1737        if (defined $EntityChar->{$entity_name}) {        if (defined $EntityChar->{$entity_name}) {
         $value = $EntityChar->{$entity_name};  
1738          if ($self->{next_input_character} == 0x003B) { # ;          if ($self->{next_input_character} == 0x003B) { # ;
1739              $value = $EntityChar->{$entity_name};
1740            $match = 1;            $match = 1;
1741            !!!next-input-character;            !!!next-input-character;
1742            last;            last;
1743          } else {          } else {
1744              $value = $EntityChar->{$entity_name};
1745            $match = -1;            $match = -1;
1746              !!!next-input-character;
1747          }          }
1748        } else {        } else {
1749          $value .= chr $self->{next_input_character};          $value .= chr $self->{next_input_character};
1750            $match *= 2;
1751            !!!next-input-character;
1752        }        }
       !!!next-input-character;  
1753      }      }
1754            
1755      if ($match > 0) {      if ($match > 0) {
1756        return {type => 'character', data => $value};        return {type => 'character', data => $value};
1757      } elsif ($match < 0) {      } elsif ($match < 0) {
1758        !!!parse-error (type => 'refc');        !!!parse-error (type => 'no refc');
1759        return {type => 'character', data => $value};        if ($in_attr and $match < -1) {
1760            return {type => 'character', data => '&'.$entity_name};
1761          } else {
1762            return {type => 'character', data => $value};
1763          }
1764      } else {      } else {
1765        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
1766        ## NOTE: No characters are consumed in the spec.        ## NOTE: No characters are consumed in the spec.
1767        !!!back-token ({type => 'character', data => $value});        return {type => 'character', data => '&'.$value};
       return undef;  
1768      }      }
1769    } else {    } else {
1770      ## no characters are consumed      ## no characters are consumed
# Line 1881  sub _tree_construction_initial ($) { Line 1959  sub _tree_construction_initial ($) {
1959      } elsif ($token->{type} eq 'character') {      } elsif ($token->{type} eq 'character') {
1960        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
1961          ## Ignore the token          ## Ignore the token
1962    
1963          unless (length $token->{data}) {          unless (length $token->{data}) {
1964            ## Stay in the phase            ## Stay in the phase
1965            !!!next-token;            !!!next-token;
# Line 1923  sub _tree_construction_root_element ($) Line 2002  sub _tree_construction_root_element ($)
2002          !!!next-token;          !!!next-token;
2003          redo B;          redo B;
2004        } elsif ($token->{type} eq 'character') {        } elsif ($token->{type} eq 'character') {
2005          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
2006            $self->{document}->manakai_append_text ($1);            ## Ignore the token.
2007            ## ISSUE: DOM3 Core does not allow Document > Text  
2008            unless (length $token->{data}) {            unless (length $token->{data}) {
2009              ## Stay in the phase              ## Stay in the phase
2010              !!!next-token;              !!!next-token;
# Line 1946  sub _tree_construction_root_element ($) Line 2025  sub _tree_construction_root_element ($)
2025        my $root_element; !!!create-element ($root_element, 'html');        my $root_element; !!!create-element ($root_element, 'html');
2026        $self->{document}->append_child ($root_element);        $self->{document}->append_child ($root_element);
2027        push @{$self->{open_elements}}, [$root_element, 'html'];        push @{$self->{open_elements}}, [$root_element, 'html'];
       #$phase = 'main';  
2028        ## reprocess        ## reprocess
2029        #redo B;        #redo B;
2030        return;        return; ## Go to the main phase.
2031    } # B    } # B
2032  } # _tree_construction_root_element  } # _tree_construction_root_element
2033    
# Line 1965  sub _reset_insertion_mode ($) { Line 2043  sub _reset_insertion_mode ($) {
2043            
2044      ## Step 3      ## Step 3
2045      S3: {      S3: {
2046        $last = 1 if $self->{open_elements}->[0]->[0] eq $node->[0];        ## ISSUE: Oops! "If node is the first node in the stack of open
2047        if (defined $self->{inner_html_node}) {        ## elements, then set last to true. If the context element of the
2048          if ($self->{inner_html_node}->[1] eq 'td' or        ## HTML fragment parsing algorithm is neither a td element nor a
2049              $self->{inner_html_node}->[1] eq 'th') {        ## th element, then set node to the context element. (fragment case)":
2050            #        ## The second "if" is in the scope of the first "if"!?
2051          } else {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
2052            $node = $self->{inner_html_node};          $last = 1;
2053            if (defined $self->{inner_html_node}) {
2054              if ($self->{inner_html_node}->[1] eq 'td' or
2055                  $self->{inner_html_node}->[1] eq 'th') {
2056                #
2057              } else {
2058                $node = $self->{inner_html_node};
2059              }
2060          }          }
2061        }        }
2062            
# Line 2018  sub _reset_insertion_mode ($) { Line 2103  sub _reset_insertion_mode ($) {
2103  sub _tree_construction_main ($) {  sub _tree_construction_main ($) {
2104    my $self = shift;    my $self = shift;
2105    
2106    my $phase = 'main';    my $previous_insertion_mode;
2107    
2108    my $active_formatting_elements = [];    my $active_formatting_elements = [];
2109    
# Line 2102  sub _tree_construction_main ($) { Line 2187  sub _tree_construction_main ($) {
2187      }      }
2188    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2189    
2190    my $style_start_tag = sub {    my $parse_rcdata = sub ($$) {
2191      my $style_el; !!!create-element ($style_el, 'style', $token->{attributes});      my ($content_model_flag, $insert) = @_;
2192      ## $self->{insertion_mode} eq 'in head' and ... (always true)  
2193      (($self->{insertion_mode} eq 'in head' and defined $self->{head_element})      ## Step 1
2194       ? $self->{head_element} : $self->{open_elements}->[-1]->[0])      my $start_tag_name = $token->{tag_name};
2195        ->append_child ($style_el);      my $el;
2196      $self->{content_model_flag} = 'CDATA';      !!!create-element ($el, $start_tag_name, $token->{attributes});
2197    
2198        ## Step 2
2199        $insert->($el); # /context node/->append_child ($el)
2200    
2201        ## Step 3
2202        $self->{content_model} = $content_model_flag; # CDATA or RCDATA
2203      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
2204                  
2205        ## Step 4
2206      my $text = '';      my $text = '';
2207      !!!next-token;      !!!next-token;
2208      while ($token->{type} eq 'character') {      while ($token->{type} eq 'character') { # or until stop tokenizing
2209        $text .= $token->{data};        $text .= $token->{data};
2210        !!!next-token;        !!!next-token;
2211      } # stop if non-character token or tokenizer stops tokenising      }
2212    
2213        ## Step 5
2214      if (length $text) {      if (length $text) {
2215        $style_el->manakai_append_text ($text);        my $text = $self->{document}->create_text_node ($text);
2216          $el->append_child ($text);
2217      }      }
2218        
2219      $self->{content_model_flag} = 'PCDATA';      ## Step 6
2220                      $self->{content_model} = PCDATA_CONTENT_MODEL;
2221      if ($token->{type} eq 'end tag' and $token->{tag_name} eq 'style') {  
2222        ## Step 7
2223        if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) {
2224        ## Ignore the token        ## Ignore the token
2225      } else {      } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2226        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in CDATA:#'.$token->{type});
2227        ## ISSUE: And ignore?      } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2228          !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2229        } else {
2230          die "$0: $content_model_flag in parse_rcdata";
2231      }      }
2232      !!!next-token;      !!!next-token;
2233    }; # $style_start_tag    }; # $parse_rcdata
2234    
2235    my $script_start_tag = sub {    my $script_start_tag = sub ($) {
2236        my $insert = $_[0];
2237      my $script_el;      my $script_el;
2238      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2239      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
2240    
2241      $self->{content_model_flag} = 'CDATA';      $self->{content_model} = CDATA_CONTENT_MODEL;
2242      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
2243            
2244      my $text = '';      my $text = '';
# Line 2150  sub _tree_construction_main ($) { Line 2251  sub _tree_construction_main ($) {
2251        $script_el->manakai_append_text ($text);        $script_el->manakai_append_text ($text);
2252      }      }
2253                                
2254      $self->{content_model_flag} = 'PCDATA';      $self->{content_model} = PCDATA_CONTENT_MODEL;
2255    
2256      if ($token->{type} eq 'end tag' and      if ($token->{type} eq 'end tag' and
2257          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
# Line 2166  sub _tree_construction_main ($) { Line 2267  sub _tree_construction_main ($) {
2267      } else {      } else {
2268        ## TODO: $old_insertion_point = current insertion point        ## TODO: $old_insertion_point = current insertion point
2269        ## TODO: insertion point = just before the next input character        ## TODO: insertion point = just before the next input character
2270          
2271        (($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);  
2272                
2273        ## TODO: insertion point = $old_insertion_point (might be "undefined")        ## TODO: insertion point = $old_insertion_point (might be "undefined")
2274                
# Line 2362  sub _tree_construction_main ($) { Line 2462  sub _tree_construction_main ($) {
2462    }; # $formatting_end_tag    }; # $formatting_end_tag
2463    
2464    my $insert_to_current = sub {    my $insert_to_current = sub {
2465      $self->{open_elements}->[-1]->[0]->append_child (shift);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
2466    }; # $insert_to_current    }; # $insert_to_current
2467    
2468    my $insert_to_foster = sub {    my $insert_to_foster = sub {
# Line 2400  sub _tree_construction_main ($) { Line 2500  sub _tree_construction_main ($) {
2500      my $insert = shift;      my $insert = shift;
2501      if ($token->{type} eq 'start tag') {      if ($token->{type} eq 'start tag') {
2502        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
2503          $script_start_tag->();          ## NOTE: This is an "as if in head" code clone
2504            $script_start_tag->($insert);
2505          return;          return;
2506        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
2507          $style_start_tag->();          ## NOTE: This is an "as if in head" code clone
2508            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
2509          return;          return;
2510        } elsif ({        } elsif ({
2511                  base => 1, link => 1, meta => 1,                  base => 1, link => 1,
2512                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
2513          !!!parse-error (type => 'in body:'.$token->{tag_name});          ## NOTE: This is an "as if in head" code clone, only "-t" differs
2514          ## NOTE: This is an "as if in head" code clone          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2515          my $el;          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
2516          !!!create-element ($el, $token->{tag_name}, $token->{attributes});          !!!next-token;
2517          if (defined $self->{head_element}) {          return;
2518            $self->{head_element}->append_child ($el);        } elsif ($token->{tag_name} eq 'meta') {
2519          } else {          ## NOTE: This is an "as if in head" code clone, only "-t" differs
2520            $insert->($el);          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2521            pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
2522    
2523            unless ($self->{confident}) {
2524              my $charset;
2525              if ($token->{attributes}->{charset}) { ## TODO: And if supported
2526                $charset = $token->{attributes}->{charset}->{value};
2527              }
2528              if ($token->{attributes}->{'http-equiv'}) {
2529                ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.
2530                if ($token->{attributes}->{'http-equiv'}->{value}
2531                    =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
2532                        [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
2533                        ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
2534                  $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
2535                } ## TODO: And if supported
2536              }
2537              ## TODO: Change the encoding
2538          }          }
2539            
2540          !!!next-token;          !!!next-token;
2541          return;          return;
2542        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
2543          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
2544          ## NOTE: There is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
2545          my $title_el;          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {
2546          !!!create-element ($title_el, 'title', $token->{attributes});            if (defined $self->{head_element}) {
2547          (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])              $self->{head_element}->append_child ($_[0]);
2548            ->append_child ($title_el);            } else {
2549          $self->{content_model_flag} = 'RCDATA';              $insert->($_[0]);
2550          delete $self->{escape}; # MUST            }
2551                    });
         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;  
2552          return;          return;
2553        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
2554          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 2552  sub _tree_construction_main ($) { Line 2651  sub _tree_construction_main ($) {
2651              if ($i != -1) {              if ($i != -1) {
2652                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
2653                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
               ## TODO: test  
2654              }              }
2655              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2656              last LI;              last LI;
# Line 2600  sub _tree_construction_main ($) { Line 2698  sub _tree_construction_main ($) {
2698              if ($i != -1) {              if ($i != -1) {
2699                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'end tag missing:'.
2700                                $self->{open_elements}->[-1]->[1]);                                $self->{open_elements}->[-1]->[1]);
               ## TODO: test  
2701              }              }
2702              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2703              last LI;              last LI;
# Line 2641  sub _tree_construction_main ($) { Line 2738  sub _tree_construction_main ($) {
2738                        
2739          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2740                        
2741          $self->{content_model_flag} = 'PLAINTEXT';          $self->{content_model} = PLAINTEXT_CONTENT_MODEL;
2742                        
2743          !!!next-token;          !!!next-token;
2744          return;          return;
# Line 2663  sub _tree_construction_main ($) { Line 2760  sub _tree_construction_main ($) {
2760            }            }
2761          } # INSCOPE          } # INSCOPE
2762                        
2763            ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>
2764          ## has an element in scope          ## has an element in scope
2765          my $i;          #my $i;
2766          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2767            my $node = $self->{open_elements}->[$_];          #  my $node = $self->{open_elements}->[$_];
2768            if ({          #  if ({
2769                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,          #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
2770                }->{$node->[1]}) {          #      }->{$node->[1]}) {
2771              $i = $_;          #    $i = $_;
2772              last INSCOPE;          #    last INSCOPE;
2773            } elsif ({          #  } elsif ({
2774                      table => 1, caption => 1, td => 1, th => 1,          #            table => 1, caption => 1, td => 1, th => 1,
2775                      button => 1, marquee => 1, object => 1, html => 1,          #            button => 1, marquee => 1, object => 1, html => 1,
2776                     }->{$node->[1]}) {          #           }->{$node->[1]}) {
2777              last INSCOPE;          #    last INSCOPE;
2778            }          #  }
2779          } # INSCOPE          #} # INSCOPE
2780                      #  
2781          if (defined $i) {          #if (defined $i) {
2782            !!!parse-error (type => 'in hn:hn');          #  !!! parse-error (type => 'in hn:hn');
2783            splice @{$self->{open_elements}}, $i;          #  splice @{$self->{open_elements}}, $i;
2784          }          #}
2785                        
2786          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2787                        
# Line 2743  sub _tree_construction_main ($) { Line 2841  sub _tree_construction_main ($) {
2841          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2842            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
2843            if ($node->[1] eq 'nobr') {            if ($node->[1] eq 'nobr') {
2844                !!!parse-error (type => 'not closed:nobr');
2845              !!!back-token;              !!!back-token;
2846              $token = {type => 'end tag', tag_name => 'nobr'};              $token = {type => 'end tag', tag_name => 'nobr'};
2847              return;              return;
# Line 2794  sub _tree_construction_main ($) { Line 2893  sub _tree_construction_main ($) {
2893          return;          return;
2894        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
2895          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2896                    $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           
         $self->{content_model_flag} = 'CDATA';  
         delete $self->{escape}; # MUST  
           
         !!!next-token;  
2897          return;          return;
2898        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
2899          ## has a p element in scope          ## has a p element in scope
# Line 2832  sub _tree_construction_main ($) { Line 2925  sub _tree_construction_main ($) {
2925            !!!parse-error (type => 'image');            !!!parse-error (type => 'image');
2926            $token->{tag_name} = 'img';            $token->{tag_name} = 'img';
2927          }          }
2928            
2929            ## NOTE: There is an "as if <br>" code clone.
2930          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2931                    
2932          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
# Line 2909  sub _tree_construction_main ($) { Line 3003  sub _tree_construction_main ($) {
3003            !!!back-token (@tokens);            !!!back-token (@tokens);
3004            return;            return;
3005          }          }
3006        } 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}}) {  
3007          my $tag_name = $token->{tag_name};          my $tag_name = $token->{tag_name};
3008          my $el;          my $el;
3009          !!!create-element ($el, $token->{tag_name}, $token->{attributes});          !!!create-element ($el, $token->{tag_name}, $token->{attributes});
3010                    
3011          if ($token->{tag_name} eq 'textarea') {          ## TODO: $self->{form_element} if defined
3012            ## TODO: $self->{form_element} if defined          $self->{content_model} = RCDATA_CONTENT_MODEL;
           $self->{content_model_flag} = 'RCDATA';  
         } else {  
           $self->{content_model_flag} = 'CDATA';  
         }  
3013          delete $self->{escape}; # MUST          delete $self->{escape}; # MUST
3014                    
3015          $insert->($el);          $insert->($el);
3016                    
3017          my $text = '';          my $text = '';
3018          if ($token->{tag_name} eq 'textarea') {          !!!next-token;
3019            !!!next-token;          if ($token->{type} eq 'character') {
3020            if ($token->{type} eq 'character') {            $token->{data} =~ s/^\x0A//;
3021              $token->{data} =~ s/^\x0A//;            unless (length $token->{data}) {
3022              unless (length $token->{data}) {              !!!next-token;
               !!!next-token;  
             }  
3023            }            }
         } else {  
           !!!next-token;  
3024          }          }
3025          while ($token->{type} eq 'character') {          while ($token->{type} eq 'character') {
3026            $text .= $token->{data};            $text .= $token->{data};
# Line 2950  sub _tree_construction_main ($) { Line 3030  sub _tree_construction_main ($) {
3030            $el->manakai_append_text ($text);            $el->manakai_append_text ($text);
3031          }          }
3032                    
3033          $self->{content_model_flag} = 'PCDATA';          $self->{content_model} = PCDATA_CONTENT_MODEL;
3034                    
3035          if ($token->{type} eq 'end tag' and          if ($token->{type} eq 'end tag' and
3036              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
3037            ## Ignore the token            ## Ignore the token
3038          } else {          } else {
3039            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?  
3040          }          }
3041          !!!next-token;          !!!next-token;
3042          return;          return;
3043          } elsif ({
3044                    iframe => 1,
3045                    noembed => 1,
3046                    noframes => 1,
3047                    noscript => 0, ## TODO: 1 if scripting is enabled
3048                   }->{$token->{tag_name}}) {
3049            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
3050            return;
3051        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
3052          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
3053                    
# Line 3001  sub _tree_construction_main ($) { Line 3084  sub _tree_construction_main ($) {
3084              unless ({              unless ({
3085                         dd => 1, dt => 1, li => 1, p => 1, td => 1,                         dd => 1, dt => 1, li => 1, p => 1, td => 1,
3086                         th => 1, tr => 1, body => 1, html => 1,                         th => 1, tr => 1, body => 1, html => 1,
3087                         tbody => 1, tfoot => 1, thead => 1,
3088                      }->{$_->[1]}) {                      }->{$_->[1]}) {
3089                !!!parse-error (type => 'not closed:'.$_->[1]);                !!!parse-error (type => 'not closed:'.$_->[1]);
3090              }              }
# Line 3050  sub _tree_construction_main ($) { Line 3134  sub _tree_construction_main ($) {
3134                   li => ($token->{tag_name} ne 'li'),                   li => ($token->{tag_name} ne 'li'),
3135                   p => ($token->{tag_name} ne 'p'),                   p => ($token->{tag_name} ne 'p'),
3136                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3137                     tbody => 1, tfoot=> 1, thead => 1,
3138                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3139                !!!back-token;                !!!back-token;
3140                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3067  sub _tree_construction_main ($) { Line 3152  sub _tree_construction_main ($) {
3152          } # INSCOPE          } # INSCOPE
3153                    
3154          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {          if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3155            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            if (defined $i) {
3156                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3157              } else {
3158                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3159              }
3160          }          }
3161                    
3162          splice @{$self->{open_elements}}, $i if defined $i;          if (defined $i) {
3163              splice @{$self->{open_elements}}, $i;
3164            } elsif ($token->{tag_name} eq 'p') {
3165              ## As if <p>, then reprocess the current token
3166              my $el;
3167              !!!create-element ($el, 'p');
3168              $insert->($el);
3169            }
3170          $clear_up_to_marker->()          $clear_up_to_marker->()
3171            if {            if {
3172              button => 1, marquee => 1, object => 1,              button => 1, marquee => 1, object => 1,
# Line 3086  sub _tree_construction_main ($) { Line 3182  sub _tree_construction_main ($) {
3182              if ({              if ({
3183                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3184                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3185                     tbody => 1, tfoot=> 1, thead => 1,
3186                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3187                !!!back-token;                !!!back-token;
3188                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3124  sub _tree_construction_main ($) { Line 3221  sub _tree_construction_main ($) {
3221              if ({              if ({
3222                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3223                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3224                     tbody => 1, tfoot=> 1, thead => 1,
3225                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3226                !!!back-token;                !!!back-token;
3227                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3154  sub _tree_construction_main ($) { Line 3252  sub _tree_construction_main ($) {
3252                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
3253                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
3254          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
3255  ## TODO: <http://html5.org/tools/web-apps-tracker?from=883&to=884>          return;
3256          } elsif ($token->{tag_name} eq 'br') {
3257            !!!parse-error (type => 'unmatched end tag:br');
3258    
3259            ## As if <br>
3260            $reconstruct_active_formatting_elements->($insert_to_current);
3261            
3262            my $el;
3263            !!!create-element ($el, 'br');
3264            $insert->($el);
3265            
3266            ## Ignore the token.
3267            !!!next-token;
3268          return;          return;
3269        } elsif ({        } elsif ({
3270                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
3271                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
3272                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
3273                  thead => 1, tr => 1,                  thead => 1, tr => 1,
3274                  area => 1, basefont => 1, bgsound => 1, br => 1,                  area => 1, basefont => 1, bgsound => 1,
3275                  embed => 1, hr => 1, iframe => 1, image => 1,                  embed => 1, hr => 1, iframe => 1, image => 1,
3276                  img => 1, input => 1, isindex => 1, noembed => 1,                  img => 1, input => 1, isindex => 1, noembed => 1,
3277                  noframes => 1, param => 1, select => 1, spacer => 1,                  noframes => 1, param => 1, select => 1, spacer => 1,
# Line 3188  sub _tree_construction_main ($) { Line 3298  sub _tree_construction_main ($) {
3298              if ({              if ({
3299                   dd => 1, dt => 1, li => 1, p => 1,                   dd => 1, dt => 1, li => 1, p => 1,
3300                   td => 1, th => 1, tr => 1,                   td => 1, th => 1, tr => 1,
3301                     tbody => 1, tfoot=> 1, thead => 1,
3302                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3303                !!!back-token;                !!!back-token;
3304                $token = {type => 'end tag',                $token = {type => 'end tag',
# Line 3211  sub _tree_construction_main ($) { Line 3322  sub _tree_construction_main ($) {
3322                  #not $phrasing_category->{$node->[1]} and                  #not $phrasing_category->{$node->[1]} and
3323                  ($special_category->{$node->[1]} or                  ($special_category->{$node->[1]} or
3324                   $scoping_category->{$node->[1]})) {                   $scoping_category->{$node->[1]})) {
3325                !!!parse-error (type => 'not closed:'.$node->[1]);                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3326                ## Ignore the token                ## Ignore the token
3327                !!!next-token;                !!!next-token;
3328                last S2;                last S2;
# Line 3231  sub _tree_construction_main ($) { Line 3342  sub _tree_construction_main ($) {
3342    }; # $in_body    }; # $in_body
3343    
3344    B: {    B: {
3345      if ($phase eq 'main') {      if ($token->{type} eq 'DOCTYPE') {
3346        if ($token->{type} eq 'DOCTYPE') {        !!!parse-error (type => 'DOCTYPE in the middle');
3347          !!!parse-error (type => 'in html:#DOCTYPE');        ## Ignore the token
3348          ## Ignore the token        ## Stay in the phase
3349          ## Stay in the phase        !!!next-token;
3350          !!!next-token;        redo B;
3351          redo B;      } elsif ($token->{type} eq 'end-of-file') {
3352        } elsif ($token->{type} eq 'start tag' and        if ($token->{insertion_mode} ne 'trailing end') {
                $token->{tag_name} eq 'html') {  
         ## TODO: unless it is the first start tag token, parse-error  
         my $top_el = $self->{open_elements}->[0]->[0];  
         for my $attr_name (keys %{$token->{attributes}}) {  
           unless ($top_el->has_attribute_ns (undef, $attr_name)) {  
             $top_el->set_attribute_ns  
               (undef, [undef, $attr_name],  
                $token->{attributes}->{$attr_name}->{value});  
           }  
         }  
         !!!next-token;  
         redo B;  
       } elsif ($token->{type} eq 'end-of-file') {  
3353          ## Generate implied end tags          ## Generate implied end tags
3354          if ({          if ({
3355               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,
3356                 tbody => 1, tfoot=> 1, thead => 1,
3357              }->{$self->{open_elements}->[-1]->[1]}) {              }->{$self->{open_elements}->[-1]->[1]}) {
3358            !!!back-token;            !!!back-token;
3359            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};            $token = {type => 'end tag', tag_name => $self->{open_elements}->[-1]->[1]};
# Line 3270  sub _tree_construction_main ($) { Line 3369  sub _tree_construction_main ($) {
3369            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);            !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3370          }          }
3371    
         ## Stop parsing  
         last B;  
   
3372          ## ISSUE: There is an issue in the spec.          ## ISSUE: There is an issue in the spec.
3373          }
3374    
3375          ## Stop parsing
3376          last B;
3377        } elsif ($token->{type} eq 'start tag' and
3378                 $token->{tag_name} eq 'html') {
3379          if ($self->{insertion_mode} eq 'trailing end') {
3380            ## Turn into the main phase
3381            !!!parse-error (type => 'after html:html');
3382            $self->{insertion_mode} = $previous_insertion_mode;
3383          }
3384    
3385    ## ISSUE: "aa<html>" is not a parse error.
3386    ## ISSUE: "<html>" in fragment is not a parse error.
3387          unless ($token->{first_start_tag}) {
3388            !!!parse-error (type => 'not first start tag');
3389          }
3390          my $top_el = $self->{open_elements}->[0]->[0];
3391          for my $attr_name (keys %{$token->{attributes}}) {
3392            unless ($top_el->has_attribute_ns (undef, $attr_name)) {
3393              $top_el->set_attribute_ns
3394                (undef, [undef, $attr_name],
3395                 $token->{attributes}->{$attr_name}->{value});
3396            }
3397          }
3398          !!!next-token;
3399          redo B;
3400        } elsif ($token->{type} eq 'comment') {
3401          my $comment = $self->{document}->create_comment ($token->{data});
3402          if ($self->{insertion_mode} eq 'trailing end') {
3403            $self->{document}->append_child ($comment);
3404          } elsif ($self->{insertion_mode} eq 'after body') {
3405            $self->{open_elements}->[0]->[0]->append_child ($comment);
3406        } else {        } else {
3407          if ($self->{insertion_mode} eq 'before head') {          $self->{open_elements}->[-1]->[0]->append_child ($comment);
3408          }
3409          !!!next-token;
3410          redo B;
3411        } elsif ($self->{insertion_mode} eq 'before head') {
3412            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3413              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3414                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
# Line 3291  sub _tree_construction_main ($) { Line 3424  sub _tree_construction_main ($) {
3424              $self->{insertion_mode} = 'in head';              $self->{insertion_mode} = 'in head';
3425              ## reprocess              ## reprocess
3426              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
3427            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3428              my $attr = $token->{tag_name} eq 'head' ? $token->{attributes} : {};              my $attr = $token->{tag_name} eq 'head' ? $token->{attributes} : {};
3429              !!!create-element ($self->{head_element}, 'head', $attr);              !!!create-element ($self->{head_element}, 'head', $attr);
# Line 3314  sub _tree_construction_main ($) { Line 3442  sub _tree_construction_main ($) {
3442              }              }
3443              redo B;              redo B;
3444            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3445              if ({head => 1, body => 1, html => 1}->{$token->{tag_name}}) {              if ({
3446                     head => 1, body => 1, html => 1,
3447                     p => 1, br => 1,
3448                    }->{$token->{tag_name}}) {
3449                ## As if <head>                ## As if <head>
3450                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3451                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3331  sub _tree_construction_main ($) { Line 3462  sub _tree_construction_main ($) {
3462            } else {            } else {
3463              die "$0: $token->{type}: Unknown type";              die "$0: $token->{type}: Unknown type";
3464            }            }
3465          } elsif ($self->{insertion_mode} eq 'in head') {          } elsif ($self->{insertion_mode} eq 'in head' or
3466                     $self->{insertion_mode} eq 'in head noscript' or
3467                     $self->{insertion_mode} eq 'after head') {
3468            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3469              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3470                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
# Line 3342  sub _tree_construction_main ($) { Line 3475  sub _tree_construction_main ($) {
3475              }              }
3476                            
3477              #              #
           } 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;  
3478            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3479              if ($token->{tag_name} eq 'title') {              if ({base => ($self->{insertion_mode} eq 'in head' or
3480                ## NOTE: There is an "as if in head" code clone                            $self->{insertion_mode} eq 'after head'),
3481                my $title_el;                   link => 1}->{$token->{tag_name}}) {
3482                !!!create-element ($title_el, 'title', $token->{attributes});                ## NOTE: There is a "as if in head" code clone.
3483                (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])                if ($self->{insertion_mode} eq 'after head') {
3484                  ->append_child ($title_el);                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3485                $self->{content_model_flag} = 'RCDATA';                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3486                delete $self->{escape}; # MUST                }
3487                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3488                my $text = '';                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3489                  pop @{$self->{open_elements}}
3490                      if $self->{insertion_mode} eq 'after head';
3491                !!!next-token;                !!!next-token;
3492                while ($token->{type} eq 'character') {                redo B;
3493                  $text .= $token->{data};              } elsif ($token->{tag_name} eq 'meta') {
3494                  !!!next-token;                ## NOTE: There is a "as if in head" code clone.
3495                  if ($self->{insertion_mode} eq 'after head') {
3496                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3497                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3498                }                }
3499                if (length $text) {                !!!insert-element ($token->{tag_name}, $token->{attributes});
3500                  $title_el->manakai_append_text ($text);                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3501    
3502                  unless ($self->{confident}) {
3503                    my $charset;
3504                    if ($token->{attributes}->{charset}) { ## TODO: And if supported
3505                      $charset = $token->{attributes}->{charset}->{value};
3506                    }
3507                    if ($token->{attributes}->{'http-equiv'}) {
3508                      ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.
3509                      if ($token->{attributes}->{'http-equiv'}->{value}
3510                          =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
3511                              [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
3512                              ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
3513                        $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
3514                      } ## TODO: And if supported
3515                    }
3516                    ## TODO: Change the encoding
3517                }                }
3518                  
3519                $self->{content_model_flag} = 'PCDATA';                ## TODO: Extracting |charset| from |meta|.
3520                                pop @{$self->{open_elements}}
3521                if ($token->{type} eq 'end tag' and                    if $self->{insertion_mode} eq 'after head';
3522                    $token->{tag_name} eq 'title') {                !!!next-token;
3523                  redo B;
3524                } elsif ($token->{tag_name} eq 'title' and
3525                         $self->{insertion_mode} eq 'in head') {
3526                  ## NOTE: There is a "as if in head" code clone.
3527                  if ($self->{insertion_mode} eq 'after head') {
3528                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3529                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3530                  }
3531                  my $parent = defined $self->{head_element} ? $self->{head_element}
3532                      : $self->{open_elements}->[-1]->[0];
3533                  $parse_rcdata->(RCDATA_CONTENT_MODEL,
3534                                  sub { $parent->append_child ($_[0]) });
3535                  pop @{$self->{open_elements}}
3536                      if $self->{insertion_mode} eq 'after head';
3537                  redo B;
3538                } elsif ($token->{tag_name} eq 'style') {
3539                  ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
3540                  ## insertion mode 'in head')
3541                  ## NOTE: There is a "as if in head" code clone.
3542                  if ($self->{insertion_mode} eq 'after head') {
3543                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3544                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3545                  }
3546                  $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
3547                  pop @{$self->{open_elements}}
3548                      if $self->{insertion_mode} eq 'after head';
3549                  redo B;
3550                } elsif ($token->{tag_name} eq 'noscript') {
3551                  if ($self->{insertion_mode} eq 'in head') {
3552                    ## NOTE: and scripting is disalbed
3553                    !!!insert-element ($token->{tag_name}, $token->{attributes});
3554                    $self->{insertion_mode} = 'in head noscript';
3555                    !!!next-token;
3556                    redo B;
3557                  } elsif ($self->{insertion_mode} eq 'in head noscript') {
3558                    !!!parse-error (type => 'in noscript:noscript');
3559                  ## Ignore the token                  ## Ignore the token
3560                    !!!next-token;
3561                    redo B;
3562                } else {                } else {
3563                  !!!parse-error (type => 'in RCDATA:#'.$token->{type});                  #
                 ## ISSUE: And ignore?  
3564                }                }
3565                } elsif ($token->{tag_name} eq 'head' and
3566                         $self->{insertion_mode} ne 'after head') {
3567                  !!!parse-error (type => 'in head:head'); # or in head noscript
3568                  ## Ignore the token
3569                !!!next-token;                !!!next-token;
3570                redo B;                redo B;
3571              } elsif ($token->{tag_name} eq 'style') {              } elsif ($self->{insertion_mode} ne 'in head noscript' and
3572                $style_start_tag->();                       $token->{tag_name} eq 'script') {
3573                redo B;                if ($self->{insertion_mode} eq 'after head') {
3574              } elsif ($token->{tag_name} eq 'script') {                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3575                $script_start_tag->();                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3576                  }
3577                  ## NOTE: There is a "as if in head" code clone.
3578                  $script_start_tag->($insert_to_current);
3579                  pop @{$self->{open_elements}}
3580                      if $self->{insertion_mode} eq 'after head';
3581                redo B;                redo B;
3582              } elsif ({base => 1, link => 1, meta => 1}->{$token->{tag_name}}) {              } elsif ($self->{insertion_mode} eq 'after head' and
3583                ## NOTE: There are "as if in head" code clones                       $token->{tag_name} eq 'body') {
3584                my $el;                !!!insert-element ('body', $token->{attributes});
3585                !!!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);  
   
3586                !!!next-token;                !!!next-token;
3587                redo B;                redo B;
3588              } elsif ($token->{tag_name} eq 'head') {              } elsif ($self->{insertion_mode} eq 'after head' and
3589                !!!parse-error (type => 'in head:head');                       $token->{tag_name} eq 'frameset') {
3590                ## Ignore the token                !!!insert-element ('frameset', $token->{attributes});
3591                  $self->{insertion_mode} = 'in frameset';
3592                !!!next-token;                !!!next-token;
3593                redo B;                redo B;
3594              } else {              } else {
3595                #                #
3596              }              }
3597            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3598              if ($token->{tag_name} eq 'head') {              if ($self->{insertion_mode} eq 'in head' and
3599                if ($self->{open_elements}->[-1]->[1] eq 'head') {                  $token->{tag_name} eq 'head') {
3600                  pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
               } else {  
                 !!!parse-error (type => 'unmatched end tag:head');  
               }  
3601                $self->{insertion_mode} = 'after head';                $self->{insertion_mode} = 'after head';
3602                !!!next-token;                !!!next-token;
3603                redo B;                redo B;
3604              } elsif ($token->{tag_name} eq 'body' or              } elsif ($self->{insertion_mode} eq 'in head noscript' and
3605                       $token->{tag_name} eq 'html') {                  $token->{tag_name} eq 'noscript') {
3606                  pop @{$self->{open_elements}};
3607                  $self->{insertion_mode} = 'in head';
3608                  !!!next-token;
3609                  redo B;
3610                } elsif ($self->{insertion_mode} eq 'in head' and
3611                         {
3612                          body => 1, html => 1,
3613                          p => 1, br => 1,
3614                         }->{$token->{tag_name}}) {
3615                #                #
3616              } else {              } elsif ($self->{insertion_mode} eq 'in head noscript' and
3617                         {
3618                          p => 1, br => 1,
3619                         }->{$token->{tag_name}}) {
3620                  #
3621                } elsif ($self->{insertion_mode} ne 'after head') {
3622                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3623                ## Ignore the token                ## Ignore the token
3624                !!!next-token;                !!!next-token;
3625                redo B;                redo B;
3626                } else {
3627                  #
3628              }              }
3629            } else {            } else {
3630              #              #
3631            }            }
3632    
3633            if ($self->{open_elements}->[-1]->[1] eq 'head') {            ## As if </head> or </noscript> or <body>
3634              ## As if </head>            if ($self->{insertion_mode} eq 'in head') {
3635                pop @{$self->{open_elements}};
3636                $self->{insertion_mode} = 'after head';
3637              } elsif ($self->{insertion_mode} eq 'in head noscript') {
3638              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
3639                !!!parse-error (type => 'in noscript:'.(defined $token->{tag_name} ? ($token->{type} eq 'end tag' ? '/' : '') . $token->{tag_name} : '#' . $token->{type}));
3640                $self->{insertion_mode} = 'in head';
3641              } else { # 'after head'
3642                !!!insert-element ('body');
3643                $self->{insertion_mode} = 'in body';
3644            }            }
           $self->{insertion_mode} = 'after head';  
3645            ## reprocess            ## reprocess
3646            redo B;            redo B;
3647    
3648            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3649          } elsif ($self->{insertion_mode} eq 'after head') {          } elsif ($self->{insertion_mode} eq 'in body' or
3650                     $self->{insertion_mode} eq 'in caption') {
3651            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3652              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              ## NOTE: There is a code clone of "character in body".
3653                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);              $reconstruct_active_formatting_elements->($insert_to_current);
               unless (length $token->{data}) {  
                 !!!next-token;  
                 redo B;  
               }  
             }  
3654                            
3655              #              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
3656            } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
3657              !!!next-token;              !!!next-token;
3658              redo B;              redo B;
3659            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3660              if ($token->{tag_name} eq 'body') {              if ({
3661                !!!insert-element ('body', $token->{attributes});                   caption => 1, col => 1, colgroup => 1, tbody => 1,
3662                $self->{insertion_mode} = 'in body';                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,
3663                !!!next-token;                  }->{$token->{tag_name}} and
3664                    $self->{insertion_mode} eq 'in caption') {
3665                  !!!parse-error (type => 'not closed:caption');
3666    
3667                  ## As if </caption>
3668                  ## have a table element in table scope
3669                  my $i;
3670                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3671                    my $node = $self->{open_elements}->[$_];
3672                    if ($node->[1] eq 'caption') {
3673                      $i = $_;
3674                      last INSCOPE;
3675                    } elsif ({
3676                              table => 1, html => 1,
3677                             }->{$node->[1]}) {
3678                      last INSCOPE;
3679                    }
3680                  } # INSCOPE
3681                  unless (defined $i) {
3682                    !!!parse-error (type => 'unmatched end tag:caption');
3683                    ## Ignore the token
3684                    !!!next-token;
3685                    redo B;
3686                  }
3687                  
3688                  ## generate implied end tags
3689                  if ({
3690                       dd => 1, dt => 1, li => 1, p => 1,
3691                       td => 1, th => 1, tr => 1,
3692                       tbody => 1, tfoot=> 1, thead => 1,
3693                      }->{$self->{open_elements}->[-1]->[1]}) {
3694                    !!!back-token; # <?>
3695                    $token = {type => 'end tag', tag_name => 'caption'};
3696                    !!!back-token;
3697                    $token = {type => 'end tag',
3698                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3699                    redo B;
3700                  }
3701    
3702                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3703                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3704                  }
3705    
3706                  splice @{$self->{open_elements}}, $i;
3707    
3708                  $clear_up_to_marker->();
3709    
3710                  $self->{insertion_mode} = 'in table';
3711    
3712                  ## reprocess
3713                redo B;                redo B;
3714              } elsif ($token->{tag_name} eq 'frameset') {              } else {
3715                !!!insert-element ('frameset', $token->{attributes});                #
3716                $self->{insertion_mode} = 'in frameset';              }
3717              } elsif ($token->{type} eq 'end tag') {
3718                if ($token->{tag_name} eq 'caption' and
3719                    $self->{insertion_mode} eq 'in caption') {
3720                  ## have a table element in table scope
3721                  my $i;
3722                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3723                    my $node = $self->{open_elements}->[$_];
3724                    if ($node->[1] eq $token->{tag_name}) {
3725                      $i = $_;
3726                      last INSCOPE;
3727                    } elsif ({
3728                              table => 1, html => 1,
3729                             }->{$node->[1]}) {
3730                      last INSCOPE;
3731                    }
3732                  } # INSCOPE
3733                  unless (defined $i) {
3734                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3735                    ## Ignore the token
3736                    !!!next-token;
3737                    redo B;
3738                  }
3739                  
3740                  ## generate implied end tags
3741                  if ({
3742                       dd => 1, dt => 1, li => 1, p => 1,
3743                       td => 1, th => 1, tr => 1,
3744                       tbody => 1, tfoot=> 1, thead => 1,
3745                      }->{$self->{open_elements}->[-1]->[1]}) {
3746                    !!!back-token;
3747                    $token = {type => 'end tag',
3748                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3749                    redo B;
3750                  }
3751    
3752                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3753                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3754                  }
3755    
3756                  splice @{$self->{open_elements}}, $i;
3757    
3758                  $clear_up_to_marker->();
3759    
3760                  $self->{insertion_mode} = 'in table';
3761    
3762                !!!next-token;                !!!next-token;
3763                redo B;                redo B;
3764              } elsif ({              } elsif ($token->{tag_name} eq 'table' and
3765                        base => 1, link => 1, meta => 1,                       $self->{insertion_mode} eq 'in caption') {
3766                        script => 1, style => 1, title => 1,                !!!parse-error (type => 'not closed:caption');
3767                       }->{$token->{tag_name}}) {  
3768                !!!parse-error (type => 'after head:'.$token->{tag_name});                ## As if </caption>
3769                $self->{insertion_mode} = 'in head';                ## have a table element in table scope
3770                  my $i;
3771                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3772                    my $node = $self->{open_elements}->[$_];
3773                    if ($node->[1] eq 'caption') {
3774                      $i = $_;
3775                      last INSCOPE;
3776                    } elsif ({
3777                              table => 1, html => 1,
3778                             }->{$node->[1]}) {
3779                      last INSCOPE;
3780                    }
3781                  } # INSCOPE
3782                  unless (defined $i) {
3783                    !!!parse-error (type => 'unmatched end tag:caption');
3784                    ## Ignore the token
3785                    !!!next-token;
3786                    redo B;
3787                  }
3788                  
3789                  ## generate implied end tags
3790                  if ({
3791                       dd => 1, dt => 1, li => 1, p => 1,
3792                       td => 1, th => 1, tr => 1,
3793                       tbody => 1, tfoot=> 1, thead => 1,
3794                      }->{$self->{open_elements}->[-1]->[1]}) {
3795                    !!!back-token; # </table>
3796                    $token = {type => 'end tag', tag_name => 'caption'};
3797                    !!!back-token;
3798                    $token = {type => 'end tag',
3799                              tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3800                    redo B;
3801                  }
3802    
3803                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3804                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3805                  }
3806    
3807                  splice @{$self->{open_elements}}, $i;
3808    
3809                  $clear_up_to_marker->();
3810    
3811                  $self->{insertion_mode} = 'in table';
3812    
3813                ## reprocess                ## reprocess
3814                redo B;                redo B;
3815                } elsif ({
3816                          body => 1, col => 1, colgroup => 1,
3817                          html => 1, tbody => 1, td => 1, tfoot => 1,
3818                          th => 1, thead => 1, tr => 1,
3819                         }->{$token->{tag_name}} and
3820                         $self->{insertion_mode} eq 'in caption') {
3821                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3822                  ## Ignore the token
3823                  !!!next-token;
3824                  redo B;
3825              } else {              } else {
3826                #                #
3827              }              }
3828            } else {            } else {
3829              #              #
3830            }            }
             
           ## As if <body>  
           !!!insert-element ('body');  
           $self->{insertion_mode} = 'in body';  
           ## reprocess  
           redo B;  
         } elsif ($self->{insertion_mode} eq 'in body') {  
           if ($token->{type} eq 'character') {  
             ## NOTE: There is a code clone of "character in body".  
             $reconstruct_active_formatting_elements->($insert_to_current);  
               
             $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});  
3831    
3832              !!!next-token;            $in_body->($insert_to_current);
3833              redo B;            redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## NOTE: There is a code clone of "comment in body".  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
           } else {  
             $in_body->($insert_to_current);  
             redo B;  
           }  
3834          } elsif ($self->{insertion_mode} eq 'in table') {          } elsif ($self->{insertion_mode} eq 'in table') {
3835            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3836              ## NOTE: There are "character in table" code clones.              ## NOTE: There are "character in table" code clones.
# Line 3558  sub _tree_construction_main ($) { Line 3890  sub _tree_construction_main ($) {
3890                            
3891              !!!next-token;              !!!next-token;
3892              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
3893            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3894              if ({              if ({
3895                   caption => 1,                   caption => 1,
# Line 3634  sub _tree_construction_main ($) { Line 3961  sub _tree_construction_main ($) {
3961                if ({                if ({
3962                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3963                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3964                       tbody => 1, tfoot=> 1, thead => 1,
3965                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3966                  !!!back-token; # <table>                  !!!back-token; # <table>
3967                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 3682  sub _tree_construction_main ($) { Line 4010  sub _tree_construction_main ($) {
4010                if ({                if ({
4011                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4012                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4013                       tbody => 1, tfoot=> 1, thead => 1,
4014                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4015                  !!!back-token;                  !!!back-token;
4016                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 3718  sub _tree_construction_main ($) { Line 4047  sub _tree_construction_main ($) {
4047            !!!parse-error (type => 'in table:'.$token->{tag_name});            !!!parse-error (type => 'in table:'.$token->{tag_name});
4048            $in_body->($insert_to_foster);            $in_body->($insert_to_foster);
4049            redo B;            redo B;
         } elsif ($self->{insertion_mode} eq 'in caption') {  
           if ($token->{type} eq 'character') {  
             ## NOTE: This is a code clone of "character in body".  
             $reconstruct_active_formatting_elements->($insert_to_current);  
               
             $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});  
   
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'comment') {  
             ## NOTE: This is a code clone of "comment in body".  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ({  
                  caption => 1, col => 1, colgroup => 1, tbody => 1,  
                  td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,  
                 }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'not closed:caption');  
   
               ## As if </caption>  
               ## have a table element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'caption') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:caption');  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
                 
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!back-token; # <?>  
                 $token = {type => 'end tag', tag_name => 'caption'};  
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne 'caption') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in table';  
   
               ## reprocess  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'caption') {  
               ## have a table element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq $token->{tag_name}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
                 
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne 'caption') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in table';  
   
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'table') {  
               !!!parse-error (type => 'not closed:caption');  
   
               ## As if </caption>  
               ## have a table element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'caption') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:caption');  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
                 
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!back-token; # </table>  
                 $token = {type => 'end tag', tag_name => 'caption'};  
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
   
               if ($self->{open_elements}->[-1]->[1] ne 'caption') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in table';  
   
               ## reprocess  
               redo B;  
             } elsif ({  
                       body => 1, col => 1, colgroup => 1,  
                       html => 1, tbody => 1, td => 1, tfoot => 1,  
                       th => 1, thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
           }  
                 
           $in_body->($insert_to_current);  
           redo B;  
4050          } elsif ($self->{insertion_mode} eq 'in column group') {          } elsif ($self->{insertion_mode} eq 'in column group') {
4051            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
4052              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
# Line 3911  sub _tree_construction_main ($) { Line 4058  sub _tree_construction_main ($) {
4058              }              }
4059                            
4060              #              #
           } 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;  
4061            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4062              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
4063                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes});
# Line 4021  sub _tree_construction_main ($) { Line 4163  sub _tree_construction_main ($) {
4163                            
4164              !!!next-token;              !!!next-token;
4165              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## Copied from 'in table'  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4166            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4167              if ({              if ({
4168                   tr => 1,                   tr => 1,
# Line 4127  sub _tree_construction_main ($) { Line 4263  sub _tree_construction_main ($) {
4263                if ({                if ({
4264                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4265                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4266                       tbody => 1, tfoot=> 1, thead => 1,
4267                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4268                  !!!back-token; # <table>                  !!!back-token; # <table>
4269                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 4305  sub _tree_construction_main ($) { Line 4442  sub _tree_construction_main ($) {
4442                            
4443              !!!next-token;              !!!next-token;
4444              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## Copied from 'in table'  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4445            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4446              if ($token->{tag_name} eq 'th' or              if ($token->{tag_name} eq 'th' or
4447                  $token->{tag_name} eq 'td') {                  $token->{tag_name} eq 'td') {
# Line 4395  sub _tree_construction_main ($) { Line 4526  sub _tree_construction_main ($) {
4526                if ({                if ({
4527                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
4528                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4529                       tbody => 1, tfoot=> 1, thead => 1,
4530                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4531                  !!!back-token; # <table>                  !!!back-token; # <table>
4532                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'table'};
# Line 4569  sub _tree_construction_main ($) { Line 4701  sub _tree_construction_main ($) {
4701    
4702              !!!next-token;              !!!next-token;
4703              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             ## NOTE: This is a code clone of "comment in body".  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4704            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4705              if ({              if ({
4706                   caption => 1, col => 1, colgroup => 1,                   caption => 1, col => 1, colgroup => 1,
# Line 4636  sub _tree_construction_main ($) { Line 4762  sub _tree_construction_main ($) {
4762                     td => ($token->{tag_name} eq 'th'),                     td => ($token->{tag_name} eq 'th'),
4763                     th => ($token->{tag_name} eq 'td'),                     th => ($token->{tag_name} eq 'td'),
4764                     tr => 1,                     tr => 1,
4765                       tbody => 1, tfoot=> 1, thead => 1,
4766                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
4767                  !!!back-token;                  !!!back-token;
4768                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 4710  sub _tree_construction_main ($) { Line 4837  sub _tree_construction_main ($) {
4837              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4838              !!!next-token;              !!!next-token;
4839              redo B;              redo B;
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
4840            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
4841              if ($token->{tag_name} eq 'option') {              if ($token->{tag_name} eq 'option') {
4842                if ($self->{open_elements}->[-1]->[1] eq 'option') {                if ($self->{open_elements}->[-1]->[1] eq 'option') {
# Line 4887  sub _tree_construction_main ($) { Line 5009  sub _tree_construction_main ($) {
5009          } elsif ($self->{insertion_mode} eq 'after body') {          } elsif ($self->{insertion_mode} eq 'after body') {
5010            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
5011              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5012                  my $data = $1;
5013                ## As if in body                ## As if in body
5014                $reconstruct_active_formatting_elements->($insert_to_current);                $reconstruct_active_formatting_elements->($insert_to_current);
5015                                
5016                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5017    
5018                unless (length $token->{data}) {                unless (length $token->{data}) {
5019                  !!!next-token;                  !!!next-token;
# Line 4899  sub _tree_construction_main ($) { Line 5022  sub _tree_construction_main ($) {
5022              }              }
5023                            
5024              #              #
5025              !!!parse-error (type => 'after body:#'.$token->{type});              !!!parse-error (type => 'after body:#character');
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[0]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
5026            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
5027              !!!parse-error (type => 'after body:'.$token->{tag_name});              !!!parse-error (type => 'after body:'.$token->{tag_name});
5028              #              #
# Line 4916  sub _tree_construction_main ($) { Line 5034  sub _tree_construction_main ($) {
5034                  !!!next-token;                  !!!next-token;
5035                  redo B;                  redo B;
5036                } else {                } else {
5037                  $phase = 'trailing end';                  $previous_insertion_mode = $self->{insertion_mode};
5038                    $self->{insertion_mode} = 'trailing end';
5039                  !!!next-token;                  !!!next-token;
5040                  redo B;                  redo B;
5041                }                }
# Line 4924  sub _tree_construction_main ($) { Line 5043  sub _tree_construction_main ($) {
5043                !!!parse-error (type => 'after body:/'.$token->{tag_name});                !!!parse-error (type => 'after body:/'.$token->{tag_name});
5044              }              }
5045            } else {            } else {
5046              !!!parse-error (type => 'after body:#'.$token->{type});              die "$0: $token->{type}: Unknown token type";
5047            }            }
5048    
5049            $self->{insertion_mode} = 'in body';            $self->{insertion_mode} = 'in body';
5050            ## reprocess            ## reprocess
5051            redo B;            redo B;
5052          } elsif ($self->{insertion_mode} eq 'in frameset') {      } elsif ($self->{insertion_mode} eq 'in frameset') {
5053            if ($token->{type} eq 'character') {        if ($token->{type} eq 'character') {
5054              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5055                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
   
               unless (length $token->{data}) {  
                 !!!next-token;  
                 redo B;  
               }  
             }  
5056    
5057              #            unless (length $token->{data}) {
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
5058              !!!next-token;              !!!next-token;
5059              redo B;              redo B;
           } elsif ($token->{type} eq 'start tag') {  
             if ($token->{tag_name} eq 'frameset') {  
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'frame') {  
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               pop @{$self->{open_elements}};  
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'noframes') {  
               $in_body->($insert_to_current);  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'frameset') {  
               if ($self->{open_elements}->[-1]->[1] eq 'html' and  
                   @{$self->{open_elements}} == 1) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
               } else {  
                 pop @{$self->{open_elements}};  
                 !!!next-token;  
               }  
                 
               ## if not inner_html and  
               if ($self->{open_elements}->[-1]->[1] ne 'frameset') {  
                 $self->{insertion_mode} = 'after frameset';  
               }  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
5060            }            }
5061                      }
5062            if (defined $token->{tag_name}) {  
5063              !!!parse-error (type => 'in frameset:'.$token->{tag_name});          !!!parse-error (type => 'in frameset:#character');
5064            ## Ignore the token
5065            !!!next-token;
5066            redo B;
5067          } elsif ($token->{type} eq 'start tag') {
5068            if ($token->{tag_name} eq 'frameset') {
5069              !!!insert-element ($token->{tag_name}, $token->{attributes});
5070              !!!next-token;
5071              redo B;
5072            } elsif ($token->{tag_name} eq 'frame') {
5073              !!!insert-element ($token->{tag_name}, $token->{attributes});
5074              pop @{$self->{open_elements}};
5075              !!!next-token;
5076              redo B;
5077            } elsif ($token->{tag_name} eq 'noframes') {
5078              $in_body->($insert_to_current);
5079              redo B;
5080            } else {
5081              !!!parse-error (type => 'in frameset:'.$token->{tag_name});
5082              ## Ignore the token
5083              !!!next-token;
5084              redo B;
5085            }
5086          } elsif ($token->{type} eq 'end tag') {
5087            if ($token->{tag_name} eq 'frameset') {
5088              if ($self->{open_elements}->[-1]->[1] eq 'html' and
5089                  @{$self->{open_elements}} == 1) {
5090                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5091                ## Ignore the token
5092                !!!next-token;
5093            } else {            } else {
5094              !!!parse-error (type => 'in frameset:#'.$token->{type});              pop @{$self->{open_elements}};
5095                !!!next-token;
5096              }
5097    
5098              if (not defined $self->{inner_html_node} and
5099                  $self->{open_elements}->[-1]->[1] ne 'frameset') {
5100                $self->{insertion_mode} = 'after frameset';
5101            }            }
5102              redo B;
5103            } else {
5104              !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
5105            ## Ignore the token            ## Ignore the token
5106            !!!next-token;            !!!next-token;
5107            redo B;            redo B;
5108          } elsif ($self->{insertion_mode} eq 'after frameset') {          }
5109            if ($token->{type} eq 'character') {        } else {
5110            die "$0: $token->{type}: Unknown token type";
5111          }
5112        } elsif ($self->{insertion_mode} eq 'after frameset') {
5113          if ($token->{type} eq 'character') {
5114              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5115                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
5116    
5117                unless (length $token->{data}) {                unless (length $token->{data}) {
5118                  !!!next-token;                  !!!next-token;
# Line 5006  sub _tree_construction_main ($) { Line 5120  sub _tree_construction_main ($) {
5120                }                }
5121              }              }
5122    
5123              #              if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
5124            } elsif ($token->{type} eq 'comment') {                !!!parse-error (type => 'after frameset:#character');
5125              my $comment = $self->{document}->create_comment ($token->{data});  
5126              $self->{open_elements}->[-1]->[0]->append_child ($comment);                ## Ignore the token.
5127              !!!next-token;                if (length $token->{data}) {
5128              redo B;                  ## reprocess the rest of characters
5129            } elsif ($token->{type} eq 'start tag') {                } else {
5130              if ($token->{tag_name} eq 'noframes') {                  !!!next-token;
5131                $in_body->($insert_to_current);                }
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'html') {  
               $phase = 'trailing end';  
               !!!next-token;  
5132                redo B;                redo B;
             } else {  
               #  
5133              }              }
5134            } else {  
5135              #          die qq[$0: Character "$token->{data}"];
5136            }        } elsif ($token->{type} eq 'start tag') {
5137                      if ($token->{tag_name} eq 'noframes') {
5138            if (defined $token->{tag_name}) {            $in_body->($insert_to_current);
5139              !!!parse-error (type => 'after frameset:'.$token->{tag_name});            redo B;
5140            } else {          } else {
5141              !!!parse-error (type => 'after frameset:#'.$token->{type});            !!!parse-error (type => 'after frameset:'.$token->{tag_name});
           }  
5142            ## Ignore the token            ## Ignore the token
5143            !!!next-token;            !!!next-token;
5144            redo B;            redo B;
5145            }
5146            ## ISSUE: An issue in spec there        } elsif ($token->{type} eq 'end tag') {
5147            if ($token->{tag_name} eq 'html') {
5148              $previous_insertion_mode = $self->{insertion_mode};
5149              $self->{insertion_mode} = 'trailing end';
5150              !!!next-token;
5151              redo B;
5152          } else {          } else {
5153            die "$0: $self->{insertion_mode}: Unknown insertion mode";            !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
5154              ## Ignore the token
5155              !!!next-token;
5156              redo B;
5157          }          }
5158          } else {
5159            die "$0: $token->{type}: Unknown token type";
5160        }        }
5161      } elsif ($phase eq 'trailing end') {  
5162          ## ISSUE: An issue in spec here
5163        } elsif ($self->{insertion_mode} eq 'trailing end') {
5164        ## states in the main stage is preserved yet # MUST        ## states in the main stage is preserved yet # MUST
5165                
5166        if ($token->{type} eq 'DOCTYPE') {        if ($token->{type} eq 'character') {
         !!!parse-error (type => 'after html:#DOCTYPE');  
         ## Ignore the token  
         !!!next-token;  
         redo B;  
       } elsif ($token->{type} eq 'comment') {  
         my $comment = $self->{document}->create_comment ($token->{data});  
         $self->{document}->append_child ($comment);  
         !!!next-token;  
         redo B;  
       } elsif ($token->{type} eq 'character') {  
5167          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
5168            my $data = $1;            my $data = $1;
5169            ## As if in the main phase.            ## As if in the main phase.
5170            ## NOTE: The insertion mode in the main phase            ## NOTE: The insertion mode in the main phase
5171            ## just before the phase has been changed to the trailing            ## just before the phase has been changed to the trailing
5172            ## end phase is either "after body" or "after frameset".            ## end phase is either "after body" or "after frameset".
5173            $reconstruct_active_formatting_elements->($insert_to_current)            $reconstruct_active_formatting_elements->($insert_to_current);
             if $phase eq 'main';  
5174                        
5175            $self->{open_elements}->[-1]->[0]->manakai_append_text ($data);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($data);
5176                        
# Line 5077  sub _tree_construction_main ($) { Line 5181  sub _tree_construction_main ($) {
5181          }          }
5182    
5183          !!!parse-error (type => 'after html:#character');          !!!parse-error (type => 'after html:#character');
5184          $phase = 'main';          $self->{insertion_mode} = $previous_insertion_mode;
5185          ## reprocess          ## reprocess
5186          redo B;          redo B;
5187        } elsif ($token->{type} eq 'start tag' or        } elsif ($token->{type} eq 'start tag') {
                $token->{type} eq 'end tag') {  
5188          !!!parse-error (type => 'after html:'.$token->{tag_name});          !!!parse-error (type => 'after html:'.$token->{tag_name});
5189          $phase = 'main';          $self->{insertion_mode} = $previous_insertion_mode;
5190            ## reprocess
5191            redo B;
5192          } elsif ($token->{type} eq 'end tag') {
5193            !!!parse-error (type => 'after html:/'.$token->{tag_name});
5194            $self->{insertion_mode} = $previous_insertion_mode;
5195          ## reprocess          ## reprocess
5196          redo B;          redo B;
       } elsif ($token->{type} eq 'end-of-file') {  
         ## Stop parsing  
         last B;  
5197        } else {        } else {
5198          die "$0: $token->{type}: Unknown token";          die "$0: $token->{type}: Unknown token";
5199        }        }
5200        } else {
5201          die "$0: $self->{insertion_mode}: Unknown insertion mode";
5202      }      }
5203    } # B    } # B
5204    
# Line 5179  sub set_inner_html ($$$) { Line 5286  sub set_inner_html ($$$) {
5286    
5287      ## Step 2      ## Step 2
5288      my $node_ln = $node->local_name;      my $node_ln = $node->local_name;
5289      $p->{content_model_flag} = {      $p->{content_model} = {
5290        title => 'RCDATA',        title => RCDATA_CONTENT_MODEL,
5291        textarea => 'RCDATA',        textarea => RCDATA_CONTENT_MODEL,
5292        style => 'CDATA',        style => CDATA_CONTENT_MODEL,
5293        script => 'CDATA',        script => CDATA_CONTENT_MODEL,
5294        xmp => 'CDATA',        xmp => CDATA_CONTENT_MODEL,
5295        iframe => 'CDATA',        iframe => CDATA_CONTENT_MODEL,
5296        noembed => 'CDATA',        noembed => CDATA_CONTENT_MODEL,
5297        noframes => 'CDATA',        noframes => CDATA_CONTENT_MODEL,
5298        noscript => 'CDATA',        noscript => CDATA_CONTENT_MODEL,
5299        plaintext => 'PLAINTEXT',        plaintext => PLAINTEXT_CONTENT_MODEL,
5300      }->{$node_ln} || 'PCDATA';      }->{$node_ln};
5301         ## ISSUE: What is "the name of the element"? local name?      $p->{content_model} = PCDATA_CONTENT_MODEL
5302            unless defined $p->{content_model};
5303            ## ISSUE: What is "the name of the element"? local name?
5304    
5305      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
5306    
# Line 5291  sub get_inner_html ($$$) { Line 5400  sub get_inner_html ($$$) {
5400            
5401      my $nt = $child->node_type;      my $nt = $child->node_type;
5402      if ($nt == 1) { # Element      if ($nt == 1) { # Element
5403        my $tag_name = lc $child->tag_name; ## ISSUE: Definition of "lowercase"        my $tag_name = $child->tag_name; ## TODO: manakai_tag_name
5404        $s .= '<' . $tag_name;        $s .= '<' . $tag_name;
5405          ## NOTE: Non-HTML case:
5406        ## ISSUE: Non-html elements        ## <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/11191>
5407    
5408        my @attrs = @{$child->attributes}; # sort order MUST be stable        my @attrs = @{$child->attributes}; # sort order MUST be stable
5409        for my $attr (@attrs) { # order is implementation dependent        for my $attr (@attrs) { # order is implementation dependent
5410          my $attr_name = lc $attr->name; ## ISSUE: Definition of "lowercase"          my $attr_name = $attr->name; ## TODO: manakai_name
5411          $s .= ' ' . $attr_name . '="';          $s .= ' ' . $attr_name . '="';
5412          my $attr_value = $attr->value;          my $attr_value = $attr->value;
5413          ## escape          ## escape
# Line 5317  sub get_inner_html ($$$) { Line 5426  sub get_inner_html ($$$) {
5426          spacer => 1, wbr => 1,          spacer => 1, wbr => 1,
5427        }->{$tag_name};        }->{$tag_name};
5428    
5429          $s .= "\x0A" if $tag_name eq 'pre' or $tag_name eq 'textarea';
5430    
5431        if (not $in_cdata and {        if (not $in_cdata and {
5432          style => 1, script => 1, xmp => 1, iframe => 1,          style => 1, script => 1, xmp => 1, iframe => 1,
5433          noembed => 1, noframes => 1, noscript => 1,          noembed => 1, noframes => 1, noscript => 1,
5434            plaintext => 1,
5435        }->{$tag_name}) {        }->{$tag_name}) {
5436          unshift @node, 'cdata-out';          unshift @node, 'cdata-out';
5437          $in_cdata = 1;          $in_cdata = 1;

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.42

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24