/[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.36 by wakaba, Mon Jul 16 04:51:22 2007 UTC revision 1.53 by wakaba, Sat Jul 21 12:37:57 2007 UTC
# Line 150  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 194  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 203  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 216  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 228  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 266  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 280  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 327  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
           $self->{content_model_flag} eq 'CDATA') {  
338          if (defined $self->{last_emitted_start_tag_name}) {          if (defined $self->{last_emitted_start_tag_name}) {
339            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>            ## NOTE: <http://krijnhoetmer.nl/irc-logs/whatwg/20070626#l-564>
340            my @next_char;            my @next_char;
# Line 429  sub _get_next_token ($) { Line 432  sub _get_next_token ($) {
432                = not defined $self->{last_emitted_start_tag_name};                = 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 456  sub _get_next_token ($) { Line 459  sub _get_next_token ($) {
459                = not defined $self->{last_emitted_start_tag_name};                = 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 504  sub _get_next_token ($) { Line 507  sub _get_next_token ($) {
507                = not defined $self->{last_emitted_start_tag_name};                = 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 544  sub _get_next_token ($) { Line 547  sub _get_next_token ($) {
547                = not defined $self->{last_emitted_start_tag_name};                = 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 568  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 597  sub _get_next_token ($) { Line 600  sub _get_next_token ($) {
600                = not defined $self->{last_emitted_start_tag_name};                = 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 638  sub _get_next_token ($) { Line 641  sub _get_next_token ($) {
641                = not defined $self->{last_emitted_start_tag_name};                = 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 676  sub _get_next_token ($) { Line 679  sub _get_next_token ($) {
679                = not defined $self->{last_emitted_start_tag_name};                = 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 717  sub _get_next_token ($) { Line 720  sub _get_next_token ($) {
720                = not defined $self->{last_emitted_start_tag_name};                = 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 764  sub _get_next_token ($) { Line 767  sub _get_next_token ($) {
767                = not defined $self->{last_emitted_start_tag_name};                = 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 784  sub _get_next_token ($) { Line 787  sub _get_next_token ($) {
787                = not defined $self->{last_emitted_start_tag_name};                = 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 820  sub _get_next_token ($) { Line 823  sub _get_next_token ($) {
823                = not defined $self->{last_emitted_start_tag_name};                = 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 856  sub _get_next_token ($) { Line 859  sub _get_next_token ($) {
859                = not defined $self->{last_emitted_start_tag_name};                = 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 895  sub _get_next_token ($) { Line 898  sub _get_next_token ($) {
898                = not defined $self->{last_emitted_start_tag_name};                = 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 915  sub _get_next_token ($) { Line 918  sub _get_next_token ($) {
918                = not defined $self->{last_emitted_start_tag_name};                = 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 1644  sub _tokenize_attempt_to_consume_an_enti Line 1647  sub _tokenize_attempt_to_consume_an_enti
1647            redo X;            redo X;
1648          } elsif (not defined $code) { # 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 1717  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 1737  sub _tokenize_attempt_to_consume_an_enti Line 1740  sub _tokenize_attempt_to_consume_an_enti
1740            $match = 1;            $match = 1;
1741            !!!next-input-character;            !!!next-input-character;
1742            last;            last;
1743          } elsif (not $in_attr) {          } else {
1744            $value = $EntityChar->{$entity_name};            $value = $EntityChar->{$entity_name};
1745            $match = -1;            $match = -1;
1746          } else {            !!!next-input-character;
           $value .= chr $self->{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 => 'no 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.
# Line 2060  sub _reset_insertion_mode ($) { Line 2067  sub _reset_insertion_mode ($) {
2067                        th => 'in cell',                        th => 'in cell',
2068                        tr => 'in row',                        tr => 'in row',
2069                        tbody => 'in table body',                        tbody => 'in table body',
2070                        thead => 'in table head',                        thead => 'in table body',
2071                        tfoot => 'in table foot',                        tfoot => 'in table body',
2072                        caption => 'in caption',                        caption => 'in caption',
2073                        colgroup => 'in column group',                        colgroup => 'in column group',
2074                        table => 'in table',                        table => 'in table',
# Line 2096  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    
   my $previous_insertion_mode;  
   
2106    my $active_formatting_elements = [];    my $active_formatting_elements = [];
2107    
2108    my $reconstruct_active_formatting_elements = sub { # MUST    my $reconstruct_active_formatting_elements = sub { # MUST
# Line 2192  sub _tree_construction_main ($) { Line 2197  sub _tree_construction_main ($) {
2197      $insert->($el); # /context node/->append_child ($el)      $insert->($el); # /context node/->append_child ($el)
2198    
2199      ## Step 3      ## Step 3
2200      $self->{content_model_flag} = $content_model_flag; # CDATA or RCDATA      $self->{content_model} = $content_model_flag; # CDATA or RCDATA
2201      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
2202    
2203      ## Step 4      ## Step 4
# Line 2210  sub _tree_construction_main ($) { Line 2215  sub _tree_construction_main ($) {
2215      }      }
2216    
2217      ## Step 6      ## Step 6
2218      $self->{content_model_flag} = 'PCDATA';      $self->{content_model} = PCDATA_CONTENT_MODEL;
2219    
2220      ## Step 7      ## Step 7
2221      if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) {      if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) {
2222        ## Ignore the token        ## Ignore the token
2223        } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2224          !!!parse-error (type => 'in CDATA:#'.$token->{type});
2225        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2226          !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2227      } else {      } else {
2228        !!!parse-error (type => 'in '.$content_model_flag.':#'.$token->{type});        die "$0: $content_model_flag in parse_rcdata";
2229      }      }
2230      !!!next-token;      !!!next-token;
2231    }; # $parse_rcdata    }; # $parse_rcdata
# Line 2227  sub _tree_construction_main ($) { Line 2236  sub _tree_construction_main ($) {
2236      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2237      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
2238    
2239      $self->{content_model_flag} = 'CDATA';      $self->{content_model} = CDATA_CONTENT_MODEL;
2240      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
2241            
2242      my $text = '';      my $text = '';
# Line 2240  sub _tree_construction_main ($) { Line 2249  sub _tree_construction_main ($) {
2249        $script_el->manakai_append_text ($text);        $script_el->manakai_append_text ($text);
2250      }      }
2251                                
2252      $self->{content_model_flag} = 'PCDATA';      $self->{content_model} = PCDATA_CONTENT_MODEL;
2253    
2254      if ($token->{type} eq 'end tag' and      if ($token->{type} eq 'end tag' and
2255          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
# Line 2485  sub _tree_construction_main ($) { Line 2494  sub _tree_construction_main ($) {
2494                         }                         }
2495    }; # $insert_to_foster    }; # $insert_to_foster
2496    
2497    my $in_body = sub {    my $insert;
     my $insert = shift;  
     if ($token->{type} eq 'start tag') {  
       if ($token->{tag_name} eq 'script') {  
         ## NOTE: This is an "as if in head" code clone  
         $script_start_tag->($insert);  
         return;  
       } elsif ($token->{tag_name} eq 'style') {  
         ## NOTE: This is an "as if in head" code clone  
         $parse_rcdata->('CDATA', $insert);  
         return;  
       } elsif ({  
                 base => 1, link => 1,  
                }->{$token->{tag_name}}) {  
         ## NOTE: This is an "as if in head" code clone, only "-t" differs  
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.  
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'meta') {  
         ## NOTE: This is an "as if in head" code clone, only "-t" differs  
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.  
   
         unless ($self->{confident}) {  
           my $charset;  
           if ($token->{attributes}->{charset}) { ## TODO: And if supported  
             $charset = $token->{attributes}->{charset}->{value};  
           }  
           if ($token->{attributes}->{'http-equiv'}) {  
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
             if ($token->{attributes}->{'http-equiv'}->{value}  
                 =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=  
                     [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|  
                     ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {  
               $charset = defined $1 ? $1 : defined $2 ? $2 : $3;  
             } ## TODO: And if supported  
           }  
           ## TODO: Change the encoding  
         }  
   
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'title') {  
         !!!parse-error (type => 'in body:title');  
         ## NOTE: This is an "as if in head" code clone  
         $parse_rcdata->('RCDATA', sub {  
           if (defined $self->{head_element}) {  
             $self->{head_element}->append_child ($_[0]);  
           } else {  
             $insert->($_[0]);  
           }  
         });  
         return;  
       } elsif ($token->{tag_name} eq 'body') {  
         !!!parse-error (type => 'in body:body');  
                 
         if (@{$self->{open_elements}} == 1 or  
             $self->{open_elements}->[1]->[1] ne 'body') {  
           ## Ignore the token  
         } else {  
           my $body_el = $self->{open_elements}->[1]->[0];  
           for my $attr_name (keys %{$token->{attributes}}) {  
             unless ($body_el->has_attribute_ns (undef, $attr_name)) {  
               $body_el->set_attribute_ns  
                 (undef, [undef, $attr_name],  
                  $token->{attributes}->{$attr_name}->{value});  
             }  
           }  
         }  
         !!!next-token;  
         return;  
       } elsif ({  
                 address => 1, blockquote => 1, center => 1, dir => 1,  
                 div => 1, dl => 1, fieldset => 1, listing => 1,  
                 menu => 1, ol => 1, p => 1, ul => 1,  
                 pre => 1,  
                }->{$token->{tag_name}}) {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         if ($token->{tag_name} eq 'pre') {  
           !!!next-token;  
           if ($token->{type} eq 'character') {  
             $token->{data} =~ s/^\x0A//;  
             unless (length $token->{data}) {  
               !!!next-token;  
             }  
           }  
         } else {  
           !!!next-token;  
         }  
         return;  
       } elsif ($token->{tag_name} eq 'form') {  
         if (defined $self->{form_element}) {  
           !!!parse-error (type => 'in form:form');  
           ## Ignore the token  
           !!!next-token;  
           return;  
         } else {  
           ## has a p element in scope  
           INSCOPE: for (reverse @{$self->{open_elements}}) {  
             if ($_->[1] eq 'p') {  
               !!!back-token;  
               $token = {type => 'end tag', tag_name => 'p'};  
               return;  
             } elsif ({  
                       table => 1, caption => 1, td => 1, th => 1,  
                       button => 1, marquee => 1, object => 1, html => 1,  
                      }->{$_->[1]}) {  
               last INSCOPE;  
             }  
           } # INSCOPE  
               
           !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           $self->{form_element} = $self->{open_elements}->[-1]->[0];  
           !!!next-token;  
           return;  
         }  
       } elsif ($token->{tag_name} eq 'li') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## Step 1  
         my $i = -1;  
         my $node = $self->{open_elements}->[$i];  
         LI: {  
           ## Step 2  
           if ($node->[1] eq 'li') {  
             if ($i != -1) {  
               !!!parse-error (type => 'end tag missing:'.  
                               $self->{open_elements}->[-1]->[1]);  
             }  
             splice @{$self->{open_elements}}, $i;  
             last LI;  
           }  
             
           ## Step 3  
           if (not $formatting_category->{$node->[1]} and  
               #not $phrasing_category->{$node->[1]} and  
               ($special_category->{$node->[1]} or  
                $scoping_category->{$node->[1]}) and  
               $node->[1] ne 'address' and $node->[1] ne 'div') {  
             last LI;  
           }  
             
           ## Step 4  
           $i--;  
           $node = $self->{open_elements}->[$i];  
           redo LI;  
         } # LI  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'dd' or $token->{tag_name} eq 'dt') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## Step 1  
         my $i = -1;  
         my $node = $self->{open_elements}->[$i];  
         LI: {  
           ## Step 2  
           if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {  
             if ($i != -1) {  
               !!!parse-error (type => 'end tag missing:'.  
                               $self->{open_elements}->[-1]->[1]);  
             }  
             splice @{$self->{open_elements}}, $i;  
             last LI;  
           }  
             
           ## Step 3  
           if (not $formatting_category->{$node->[1]} and  
               #not $phrasing_category->{$node->[1]} and  
               ($special_category->{$node->[1]} or  
                $scoping_category->{$node->[1]}) and  
               $node->[1] ne 'address' and $node->[1] ne 'div') {  
             last LI;  
           }  
             
           ## Step 4  
           $i--;  
           $node = $self->{open_elements}->[$i];  
           redo LI;  
         } # LI  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'plaintext') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         $self->{content_model_flag} = 'PLAINTEXT';  
             
         !!!next-token;  
         return;  
       } elsif ({  
                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
                }->{$token->{tag_name}}) {  
         ## has a p element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>  
         ## has an element in scope  
         #my $i;  
         #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
         #  my $node = $self->{open_elements}->[$_];  
         #  if ({  
         #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
         #      }->{$node->[1]}) {  
         #    $i = $_;  
         #    last INSCOPE;  
         #  } elsif ({  
         #            table => 1, caption => 1, td => 1, th => 1,  
         #            button => 1, marquee => 1, object => 1, html => 1,  
         #           }->{$node->[1]}) {  
         #    last INSCOPE;  
         #  }  
         #} # INSCOPE  
         #    
         #if (defined $i) {  
         #  !!! parse-error (type => 'in hn:hn');  
         #  splice @{$self->{open_elements}}, $i;  
         #}  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'a') {  
         AFE: for my $i (reverse 0..$#$active_formatting_elements) {  
           my $node = $active_formatting_elements->[$i];  
           if ($node->[1] eq 'a') {  
             !!!parse-error (type => 'in a:a');  
               
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'a'};  
             $formatting_end_tag->($token->{tag_name});  
               
             AFE2: for (reverse 0..$#$active_formatting_elements) {  
               if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {  
                 splice @$active_formatting_elements, $_, 1;  
                 last AFE2;  
               }  
             } # AFE2  
             OE: for (reverse 0..$#{$self->{open_elements}}) {  
               if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {  
                 splice @{$self->{open_elements}}, $_, 1;  
                 last OE;  
               }  
             } # OE  
             last AFE;  
           } elsif ($node->[0] eq '#marker') {  
             last AFE;  
           }  
         } # AFE  
             
         $reconstruct_active_formatting_elements->($insert_to_current);  
   
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, $self->{open_elements}->[-1];  
   
         !!!next-token;  
         return;  
       } elsif ({  
                 b => 1, big => 1, em => 1, font => 1, i => 1,  
                 s => 1, small => 1, strile => 1,  
                 strong => 1, tt => 1, u => 1,  
                }->{$token->{tag_name}}) {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, $self->{open_elements}->[-1];  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'nobr') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
   
         ## has a |nobr| element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'nobr') {  
             !!!parse-error (type => 'not closed:nobr');  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'nobr'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, $self->{open_elements}->[-1];  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'button') {  
         ## has a button element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq 'button') {  
             !!!parse-error (type => 'in button:button');  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'button'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         $reconstruct_active_formatting_elements->($insert_to_current);  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, ['#marker', ''];  
   
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'marquee' or  
                $token->{tag_name} eq 'object') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         push @$active_formatting_elements, ['#marker', ''];  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'xmp') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
         $parse_rcdata->('CDATA', $insert);  
         return;  
       } elsif ($token->{tag_name} eq 'table') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
             
         $self->{insertion_mode} = 'in table';  
             
         !!!next-token;  
         return;  
       } elsif ({  
                 area => 1, basefont => 1, bgsound => 1, br => 1,  
                 embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,  
                 image => 1,  
                }->{$token->{tag_name}}) {  
         if ($token->{tag_name} eq 'image') {  
           !!!parse-error (type => 'image');  
           $token->{tag_name} = 'img';  
         }  
   
         ## NOTE: There is an "as if <br>" code clone.  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}};  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'hr') {  
         ## has a p element in scope  
         INSCOPE: for (reverse @{$self->{open_elements}}) {  
           if ($_->[1] eq 'p') {  
             !!!back-token;  
             $token = {type => 'end tag', tag_name => 'p'};  
             return;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
             
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         pop @{$self->{open_elements}};  
             
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'input') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
         ## TODO: associate with $self->{form_element} if defined  
         pop @{$self->{open_elements}};  
           
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'isindex') {  
         !!!parse-error (type => 'isindex');  
           
         if (defined $self->{form_element}) {  
           ## Ignore the token  
           !!!next-token;  
           return;  
         } else {  
           my $at = $token->{attributes};  
           my $form_attrs;  
           $form_attrs->{action} = $at->{action} if $at->{action};  
           my $prompt_attr = $at->{prompt};  
           $at->{name} = {name => 'name', value => 'isindex'};  
           delete $at->{action};  
           delete $at->{prompt};  
           my @tokens = (  
                         {type => 'start tag', tag_name => 'form',  
                          attributes => $form_attrs},  
                         {type => 'start tag', tag_name => 'hr'},  
                         {type => 'start tag', tag_name => 'p'},  
                         {type => 'start tag', tag_name => 'label'},  
                        );  
           if ($prompt_attr) {  
             push @tokens, {type => 'character', data => $prompt_attr->{value}};  
           } else {  
             push @tokens, {type => 'character',  
                            data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD  
             ## TODO: make this configurable  
           }  
           push @tokens,  
                         {type => 'start tag', tag_name => 'input', attributes => $at},  
                         #{type => 'character', data => ''}, # SHOULD  
                         {type => 'end tag', tag_name => 'label'},  
                         {type => 'end tag', tag_name => 'p'},  
                         {type => 'start tag', tag_name => 'hr'},  
                         {type => 'end tag', tag_name => 'form'};  
           $token = shift @tokens;  
           !!!back-token (@tokens);  
           return;  
         }  
       } elsif ($token->{tag_name} eq 'textarea') {  
         my $tag_name = $token->{tag_name};  
         my $el;  
         !!!create-element ($el, $token->{tag_name}, $token->{attributes});  
           
         ## TODO: $self->{form_element} if defined  
         $self->{content_model_flag} = 'RCDATA';  
         delete $self->{escape}; # MUST  
           
         $insert->($el);  
           
         my $text = '';  
         !!!next-token;  
         if ($token->{type} eq 'character') {  
           $token->{data} =~ s/^\x0A//;  
           unless (length $token->{data}) {  
             !!!next-token;  
           }  
         }  
         while ($token->{type} eq 'character') {  
           $text .= $token->{data};  
           !!!next-token;  
         }  
         if (length $text) {  
           $el->manakai_append_text ($text);  
         }  
           
         $self->{content_model_flag} = 'PCDATA';  
           
         if ($token->{type} eq 'end tag' and  
             $token->{tag_name} eq $tag_name) {  
           ## Ignore the token  
         } else {  
           !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
         }  
         !!!next-token;  
         return;  
       } elsif ({  
                 iframe => 1,  
                 noembed => 1,  
                 noframes => 1,  
                 noscript => 0, ## TODO: 1 if scripting is enabled  
                }->{$token->{tag_name}}) {  
         $parse_rcdata->('CDATA', $insert);  
         return;  
       } elsif ($token->{tag_name} eq 'select') {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           
         $self->{insertion_mode} = 'in select';  
         !!!next-token;  
         return;  
       } elsif ({  
                 caption => 1, col => 1, colgroup => 1, frame => 1,  
                 frameset => 1, head => 1, option => 1, optgroup => 1,  
                 tbody => 1, td => 1, tfoot => 1, th => 1,  
                 thead => 1, tr => 1,  
                }->{$token->{tag_name}}) {  
         !!!parse-error (type => 'in body:'.$token->{tag_name});  
         ## Ignore the token  
         !!!next-token;  
         return;  
           
         ## ISSUE: An issue on HTML5 new elements in the spec.  
       } else {  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           
         !!!next-token;  
         return;  
       }  
     } elsif ($token->{type} eq 'end tag') {  
       if ($token->{tag_name} eq 'body') {  
         if (@{$self->{open_elements}} > 1 and  
             $self->{open_elements}->[1]->[1] eq 'body') {  
           for (@{$self->{open_elements}}) {  
             unless ({  
                        dd => 1, dt => 1, li => 1, p => 1, td => 1,  
                        th => 1, tr => 1, body => 1, html => 1,  
                      tbody => 1, tfoot => 1, thead => 1,  
                     }->{$_->[1]}) {  
               !!!parse-error (type => 'not closed:'.$_->[1]);  
             }  
           }  
   
           $self->{insertion_mode} = 'after body';  
           !!!next-token;  
           return;  
         } else {  
           !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
           ## Ignore the token  
           !!!next-token;  
           return;  
         }  
       } elsif ($token->{tag_name} eq 'html') {  
         if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {  
           ## ISSUE: There is an issue in the spec.  
           if ($self->{open_elements}->[-1]->[1] ne 'body') {  
             !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);  
           }  
           $self->{insertion_mode} = 'after body';  
           ## reprocess  
           return;  
         } else {  
           !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
           ## Ignore the token  
           !!!next-token;  
           return;  
         }  
       } elsif ({  
                 address => 1, blockquote => 1, center => 1, dir => 1,  
                 div => 1, dl => 1, fieldset => 1, listing => 1,  
                 menu => 1, ol => 1, pre => 1, ul => 1,  
                 p => 1,  
                 dd => 1, dt => 1, li => 1,  
                 button => 1, marquee => 1, object => 1,  
                }->{$token->{tag_name}}) {  
         ## has an element in scope  
         my $i;  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq $token->{tag_name}) {  
             ## generate implied end tags  
             if ({  
                  dd => ($token->{tag_name} ne 'dd'),  
                  dt => ($token->{tag_name} ne 'dt'),  
                  li => ($token->{tag_name} ne 'li'),  
                  p => ($token->{tag_name} ne 'p'),  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => 'end tag',  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               return;  
             }  
             $i = $_;  
             last INSCOPE unless $token->{tag_name} eq 'p';  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
           
         if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {  
           if (defined $i) {  
             !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
           } else {  
             !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
           }  
         }  
           
         if (defined $i) {  
           splice @{$self->{open_elements}}, $i;  
         } elsif ($token->{tag_name} eq 'p') {  
           ## As if <p>, then reprocess the current token  
           my $el;  
           !!!create-element ($el, 'p');  
           $insert->($el);  
         }  
         $clear_up_to_marker->()  
           if {  
             button => 1, marquee => 1, object => 1,  
           }->{$token->{tag_name}};  
         !!!next-token;  
         return;  
       } elsif ($token->{tag_name} eq 'form') {  
         ## has an element in scope  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ($node->[1] eq $token->{tag_name}) {  
             ## generate implied end tags  
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => 'end tag',  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               return;  
             }  
             last INSCOPE;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
           
         if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {  
           pop @{$self->{open_elements}};  
         } else {  
           !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
         }  
   
         undef $self->{form_element};  
         !!!next-token;  
         return;  
       } elsif ({  
                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
                }->{$token->{tag_name}}) {  
         ## has an element in scope  
         my $i;  
         INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
           my $node = $self->{open_elements}->[$_];  
           if ({  
                h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
               }->{$node->[1]}) {  
             ## generate implied end tags  
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => 'end tag',  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               return;  
             }  
             $i = $_;  
             last INSCOPE;  
           } elsif ({  
                     table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
             last INSCOPE;  
           }  
         } # INSCOPE  
           
         if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {  
           !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
         }  
           
         splice @{$self->{open_elements}}, $i if defined $i;  
         !!!next-token;  
         return;  
       } elsif ({  
                 a => 1,  
                 b => 1, big => 1, em => 1, font => 1, i => 1,  
                 nobr => 1, s => 1, small => 1, strile => 1,  
                 strong => 1, tt => 1, u => 1,  
                }->{$token->{tag_name}}) {  
         $formatting_end_tag->($token->{tag_name});  
         return;  
       } elsif ($token->{tag_name} eq 'br') {  
         !!!parse-error (type => 'unmatched end tag:br');  
   
         ## As if <br>  
         $reconstruct_active_formatting_elements->($insert_to_current);  
           
         my $el;  
         !!!create-element ($el, 'br');  
         $insert->($el);  
           
         ## Ignore the token.  
         !!!next-token;  
         return;  
       } elsif ({  
                 caption => 1, col => 1, colgroup => 1, frame => 1,  
                 frameset => 1, head => 1, option => 1, optgroup => 1,  
                 tbody => 1, td => 1, tfoot => 1, th => 1,  
                 thead => 1, tr => 1,  
                 area => 1, basefont => 1, bgsound => 1,  
                 embed => 1, hr => 1, iframe => 1, image => 1,  
                 img => 1, input => 1, isindex => 1, noembed => 1,  
                 noframes => 1, param => 1, select => 1, spacer => 1,  
                 table => 1, textarea => 1, wbr => 1,  
                 noscript => 0, ## TODO: if scripting is enabled  
                }->{$token->{tag_name}}) {  
         !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
         ## Ignore the token  
         !!!next-token;  
         return;  
           
         ## ISSUE: Issue on HTML5 new elements in spec  
           
       } else {  
         ## Step 1  
         my $node_i = -1;  
         my $node = $self->{open_elements}->[$node_i];  
   
         ## Step 2  
         S2: {  
           if ($node->[1] eq $token->{tag_name}) {  
             ## Step 1  
             ## generate implied end tags  
             if ({  
                  dd => 1, dt => 1, li => 1, p => 1,  
                  td => 1, th => 1, tr => 1,  
                  tbody => 1, tfoot=> 1, thead => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               !!!back-token;  
               $token = {type => 'end tag',  
                         tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
               return;  
             }  
           
             ## Step 2  
             if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {  
               !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
             }  
               
             ## Step 3  
             splice @{$self->{open_elements}}, $node_i;  
   
             !!!next-token;  
             last S2;  
           } else {  
             ## Step 3  
             if (not $formatting_category->{$node->[1]} and  
                 #not $phrasing_category->{$node->[1]} and  
                 ($special_category->{$node->[1]} or  
                  $scoping_category->{$node->[1]})) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               last S2;  
             }  
           }  
             
           ## Step 4  
           $node_i--;  
           $node = $self->{open_elements}->[$node_i];  
             
           ## Step 5;  
           redo S2;  
         } # S2  
         return;  
       }  
     }  
   }; # $in_body  
2498    
2499    B: {    B: {
2500      if ($token->{type} eq 'DOCTYPE') {      if ($token->{type} eq 'DOCTYPE') {
# Line 3338  sub _tree_construction_main ($) { Line 2504  sub _tree_construction_main ($) {
2504        !!!next-token;        !!!next-token;
2505        redo B;        redo B;
2506      } elsif ($token->{type} eq 'end-of-file') {      } elsif ($token->{type} eq 'end-of-file') {
2507        if ($token->{insertion_mode} ne 'trailing end') {        if ($self->{insertion_mode} eq 'after html body' or
2508              $self->{insertion_mode} eq 'after html frameset') {
2509            #
2510          } else {
2511          ## Generate implied end tags          ## Generate implied end tags
2512          if ({          if ({
2513               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,
# Line 3365  sub _tree_construction_main ($) { Line 2534  sub _tree_construction_main ($) {
2534        last B;        last B;
2535      } elsif ($token->{type} eq 'start tag' and      } elsif ($token->{type} eq 'start tag' and
2536               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
2537        if ($self->{insertion_mode} eq 'trailing end') {        if ($self->{insertion_mode} eq 'after html body') {
2538            ## Turn into the main phase
2539            !!!parse-error (type => 'after html:html');
2540            $self->{insertion_mode} = 'after body';
2541          } elsif ($self->{insertion_mode} eq 'after html frameset') {
2542          ## Turn into the main phase          ## Turn into the main phase
2543          !!!parse-error (type => 'after html:html');          !!!parse-error (type => 'after html:html');
2544          $self->{insertion_mode} = $previous_insertion_mode;          $self->{insertion_mode} = 'after frameset';
2545        }        }
2546    
2547  ## ISSUE: "aa<html>" is not a parse error.  ## ISSUE: "aa<html>" is not a parse error.
# Line 3388  sub _tree_construction_main ($) { Line 2561  sub _tree_construction_main ($) {
2561        redo B;        redo B;
2562      } elsif ($token->{type} eq 'comment') {      } elsif ($token->{type} eq 'comment') {
2563        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
2564        if ($self->{insertion_mode} eq 'trailing end') {        if ($self->{insertion_mode} eq 'after html body' or
2565              $self->{insertion_mode} eq 'after html frameset') {
2566          $self->{document}->append_child ($comment);          $self->{document}->append_child ($comment);
2567        } elsif ($self->{insertion_mode} eq 'after body') {        } elsif ($self->{insertion_mode} eq 'after body') {
2568          $self->{open_elements}->[0]->[0]->append_child ($comment);          $self->{open_elements}->[0]->[0]->append_child ($comment);
# Line 3397  sub _tree_construction_main ($) { Line 2571  sub _tree_construction_main ($) {
2571        }        }
2572        !!!next-token;        !!!next-token;
2573        redo B;        redo B;
2574      } elsif ($self->{insertion_mode} eq 'before head') {      } elsif ($self->{insertion_mode} eq 'in head' or
2575            if ($token->{type} eq 'character') {               $self->{insertion_mode} eq 'in head noscript' or
2576              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {               $self->{insertion_mode} eq 'after head' or
2577                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);               $self->{insertion_mode} eq 'before head') {
2578                unless (length $token->{data}) {        if ($token->{type} eq 'character') {
2579                  !!!next-token;          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
2580                  redo B;            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
2581                }            unless (length $token->{data}) {
2582              }              !!!next-token;
2583              ## As if <head>              redo B;
2584              !!!create-element ($self->{head_element}, 'head');            }
2585              $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});          }
2586              push @{$self->{open_elements}}, [$self->{head_element}, 'head'];  
2587              $self->{insertion_mode} = 'in head';          if ($self->{insertion_mode} eq 'before head') {
2588              ## As if <head>
2589              !!!create-element ($self->{head_element}, 'head');
2590              $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2591              push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2592    
2593              ## Reprocess in the "in head" insertion mode...
2594              pop @{$self->{open_elements}};
2595    
2596              ## Reprocess in the "after head" insertion mode...
2597            } elsif ($self->{insertion_mode} eq 'in head noscript') {
2598              ## As if </noscript>
2599              pop @{$self->{open_elements}};
2600              !!!parse-error (type => 'in noscript:#character');
2601              
2602              ## Reprocess in the "in head" insertion mode...
2603              ## As if </head>
2604              pop @{$self->{open_elements}};
2605    
2606              ## Reprocess in the "after head" insertion mode...
2607            } elsif ($self->{insertion_mode} eq 'in head') {
2608              pop @{$self->{open_elements}};
2609    
2610              ## Reprocess in the "after head" insertion mode...
2611            }
2612    
2613                ## "after head" insertion mode
2614                ## As if <body>
2615                !!!insert-element ('body');
2616                $self->{insertion_mode} = 'in body';
2617              ## reprocess              ## reprocess
2618              redo B;              redo B;
2619            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
             my $attr = $token->{tag_name} eq 'head' ? $token->{attributes} : {};  
             !!!create-element ($self->{head_element}, 'head', $attr);  
             $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});  
             push @{$self->{open_elements}}, [$self->{head_element}, 'head'];  
             $self->{insertion_mode} = 'in head';  
2620              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
2621                !!!next-token;                if ($self->{insertion_mode} eq 'before head') {
2622              #} elsif ({                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});
2623              #          base => 1, link => 1, meta => 1,                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2624              #          script => 1, style => 1, title => 1,                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];
2625              #         }->{$token->{tag_name}}) {                  $self->{insertion_mode} = 'in head';
2626              #  ## reprocess                  !!!next-token;
2627              } else {                  redo B;
2628                ## reprocess                } elsif ($self->{insertion_mode} ne 'after head') {
2629              }                  !!!parse-error (type => 'in head:head'); # or in head noscript
2630              redo B;                  ## Ignore the token
2631            } elsif ($token->{type} eq 'end tag') {                  !!!next-token;
2632              if ({                  redo B;
2633                   head => 1, body => 1, html => 1,                } else {
2634                   p => 1, br => 1,                  #
2635                  }->{$token->{tag_name}}) {                }
2636                } elsif ($self->{insertion_mode} eq 'before head') {
2637                ## As if <head>                ## As if <head>
2638                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
2639                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2640                push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2641    
2642                $self->{insertion_mode} = 'in head';                $self->{insertion_mode} = 'in head';
2643                ## reprocess                ## Reprocess in the "in head" insertion mode...
               redo B;  
             } else {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token ## ISSUE: An issue in the spec.  
               !!!next-token;  
               redo B;  
2644              }              }
2645            } else {  
2646              die "$0: $token->{type}: Unknown type";              if ($token->{tag_name} eq 'base') {
2647            }                if ($self->{insertion_mode} eq 'in head noscript') {
2648          } elsif ($self->{insertion_mode} eq 'in head' or                  ## As if </noscript>
2649                   $self->{insertion_mode} eq 'in head noscript' or                  pop @{$self->{open_elements}};
2650                   $self->{insertion_mode} eq 'after head') {                  !!!parse-error (type => 'in noscript:base');
2651            if ($token->{type} eq 'character') {                
2652              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {                  $self->{insertion_mode} = 'in head';
2653                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                  ## Reprocess in the "in head" insertion mode...
               unless (length $token->{data}) {  
                 !!!next-token;  
                 redo B;  
2654                }                }
2655              }  
2656                              ## NOTE: There is a "as if in head" code clone.
2657              #                if ($self->{insertion_mode} eq 'after head') {
2658            } elsif ($token->{type} eq 'start tag') {                  !!!parse-error (type => 'after head:'.$token->{tag_name});
2659              if ({base => ($self->{insertion_mode} eq 'in head' or                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2660                            $self->{insertion_mode} eq 'after head'),                }
2661                   link => 1}->{$token->{tag_name}}) {                !!!insert-element ($token->{tag_name}, $token->{attributes});
2662                  pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
2663                  pop @{$self->{open_elements}}
2664                      if $self->{insertion_mode} eq 'after head';
2665                  !!!next-token;
2666                  redo B;
2667                } elsif ($token->{tag_name} eq 'link') {
2668                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
2669                if ($self->{insertion_mode} eq 'after head') {                if ($self->{insertion_mode} eq 'after head') {
2670                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
# Line 3510  sub _tree_construction_main ($) { Line 2707  sub _tree_construction_main ($) {
2707                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
2708                !!!next-token;                !!!next-token;
2709                redo B;                redo B;
2710              } elsif ($token->{tag_name} eq 'title' and              } elsif ($token->{tag_name} eq 'title') {
2711                       $self->{insertion_mode} eq 'in head') {                if ($self->{insertion_mode} eq 'in head noscript') {
2712                ## NOTE: There is a "as if in head" code clone.                  ## As if </noscript>
2713                if ($self->{insertion_mode} eq 'after head') {                  pop @{$self->{open_elements}};
2714                    !!!parse-error (type => 'in noscript:title');
2715                  
2716                    $self->{insertion_mode} = 'in head';
2717                    ## Reprocess in the "in head" insertion mode...
2718                  } elsif ($self->{insertion_mode} eq 'after head') {
2719                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
2720                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2721                }                }
2722    
2723                  ## NOTE: There is a "as if in head" code clone.
2724                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
2725                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
2726                $parse_rcdata->('RCDATA', sub { $parent->append_child ($_[0]) });                $parse_rcdata->(RCDATA_CONTENT_MODEL,
2727                                  sub { $parent->append_child ($_[0]) });
2728                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
2729                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
2730                redo B;                redo B;
# Line 3531  sub _tree_construction_main ($) { Line 2736  sub _tree_construction_main ($) {
2736                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
2737                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2738                }                }
2739                $parse_rcdata->('CDATA', $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
2740                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
2741                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
2742                redo B;                redo B;
# Line 3545  sub _tree_construction_main ($) { Line 2750  sub _tree_construction_main ($) {
2750                } elsif ($self->{insertion_mode} eq 'in head noscript') {                } elsif ($self->{insertion_mode} eq 'in head noscript') {
2751                  !!!parse-error (type => 'in noscript:noscript');                  !!!parse-error (type => 'in noscript:noscript');
2752                  ## Ignore the token                  ## Ignore the token
2753                    !!!next-token;
2754                  redo B;                  redo B;
2755                } else {                } else {
2756                  #                  #
2757                }                }
2758              } elsif ($token->{tag_name} eq 'head' and              } elsif ($token->{tag_name} eq 'script') {
2759                       $self->{insertion_mode} ne 'after head') {                if ($self->{insertion_mode} eq 'in head noscript') {
2760                !!!parse-error (type => 'in head:head'); # or in head noscript                  ## As if </noscript>
2761                ## Ignore the token                  pop @{$self->{open_elements}};
2762                !!!next-token;                  !!!parse-error (type => 'in noscript:script');
2763                redo B;                
2764              } elsif ($self->{insertion_mode} ne 'in head noscript' and                  $self->{insertion_mode} = 'in head';
2765                       $token->{tag_name} eq 'script') {                  ## Reprocess in the "in head" insertion mode...
2766                if ($self->{insertion_mode} eq 'after head') {                } elsif ($self->{insertion_mode} eq 'after head') {
2767                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
2768                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2769                }                }
2770    
2771                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
2772                $script_start_tag->($insert_to_current);                $script_start_tag->($insert_to_current);
2773                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
2774                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
2775                redo B;                redo B;
2776              } elsif ($self->{insertion_mode} eq 'after head' and              } elsif ($token->{tag_name} eq 'body' or
                      $token->{tag_name} eq 'body') {  
               !!!insert-element ('body', $token->{attributes});  
               $self->{insertion_mode} = 'in body';  
               !!!next-token;  
               redo B;  
             } elsif ($self->{insertion_mode} eq 'after head' and  
2777                       $token->{tag_name} eq 'frameset') {                       $token->{tag_name} eq 'frameset') {
2778                !!!insert-element ('frameset', $token->{attributes});                if ($self->{insertion_mode} eq 'in head noscript') {
2779                $self->{insertion_mode} = 'in frameset';                  ## As if </noscript>
2780                    pop @{$self->{open_elements}};
2781                    !!!parse-error (type => 'in noscript:'.$token->{tag_name});
2782                    
2783                    ## Reprocess in the "in head" insertion mode...
2784                    ## As if </head>
2785                    pop @{$self->{open_elements}};
2786                    
2787                    ## Reprocess in the "after head" insertion mode...
2788                  } elsif ($self->{insertion_mode} eq 'in head') {
2789                    pop @{$self->{open_elements}};
2790                    
2791                    ## Reprocess in the "after head" insertion mode...
2792                  }
2793    
2794                  ## "after head" insertion mode
2795                  !!!insert-element ($token->{tag_name}, $token->{attributes});
2796                  $self->{insertion_mode} = 'in '.$token->{tag_name};
2797                !!!next-token;                !!!next-token;
2798                redo B;                redo B;
2799              } else {              } else {
2800                #                #
2801              }              }
2802            } elsif ($token->{type} eq 'end tag') {  
2803              if ($self->{insertion_mode} eq 'in head' and              if ($self->{insertion_mode} eq 'in head noscript') {
2804                  $token->{tag_name} eq 'head') {                ## As if </noscript>
2805                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
2806                $self->{insertion_mode} = 'after head';                !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
2807                !!!next-token;                
2808                redo B;                ## Reprocess in the "in head" insertion mode...
2809              } elsif ($self->{insertion_mode} eq 'in head noscript' and                ## As if </head>
                 $token->{tag_name} eq 'noscript') {  
2810                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
2811                $self->{insertion_mode} = 'in head';  
2812                !!!next-token;                ## Reprocess in the "after head" insertion mode...
2813                redo B;              } elsif ($self->{insertion_mode} eq 'in head') {
2814              } elsif ($self->{insertion_mode} eq 'in head' and                ## As if </head>
2815                       {                pop @{$self->{open_elements}};
2816                        body => 1, html => 1,  
2817                        p => 1, br => 1,                ## Reprocess in the "after head" insertion mode...
                      }->{$token->{tag_name}}) {  
               #  
             } elsif ($self->{insertion_mode} eq 'in head noscript' and  
                      {  
                       p => 1, br => 1,  
                      }->{$token->{tag_name}}) {  
               #  
             } elsif ($self->{insertion_mode} ne 'after head') {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               redo B;  
             } else {  
               #  
2818              }              }
           } else {  
             #  
           }  
2819    
2820            ## As if </head> or </noscript> or <body>              ## "after head" insertion mode
2821            if ($self->{insertion_mode} eq 'in head') {              ## As if <body>
             pop @{$self->{open_elements}};  
             $self->{insertion_mode} = 'after head';  
           } elsif ($self->{insertion_mode} eq 'in head noscript') {  
             pop @{$self->{open_elements}};  
             !!!parse-error (type => 'in noscript:'.(defined $token->{tag_name} ? ($token->{type} eq 'end tag' ? '/' : '') . $token->{tag_name} : '#' . $token->{type}));  
             $self->{insertion_mode} = 'in head';  
           } else { # 'after head'  
2822              !!!insert-element ('body');              !!!insert-element ('body');
2823              $self->{insertion_mode} = 'in body';              $self->{insertion_mode} = 'in body';
2824            }              ## reprocess
           ## reprocess  
           redo B;  
   
           ## ISSUE: An issue in the spec.  
         } 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});  
   
             !!!next-token;  
             redo B;  
           } else {  
             $in_body->($insert_to_current);  
2825              redo B;              redo B;
2826            }            } elsif ($token->{type} eq 'end tag') {
2827          } elsif ($self->{insertion_mode} eq 'in table') {              if ($token->{tag_name} eq 'head') {
2828            if ($token->{type} eq 'character') {                if ($self->{insertion_mode} eq 'before head') {
2829              ## NOTE: There are "character in table" code clones.                  ## As if <head>
2830              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {                  !!!create-element ($self->{head_element}, 'head');
2831                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2832                                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
2833                unless (length $token->{data}) {  
2834                    ## Reprocess in the "in head" insertion mode...
2835                    pop @{$self->{open_elements}};
2836                    $self->{insertion_mode} = 'after head';
2837                    !!!next-token;
2838                    redo B;
2839                  } elsif ($self->{insertion_mode} eq 'in head noscript') {
2840                    ## As if </noscript>
2841                    pop @{$self->{open_elements}};
2842                    !!!parse-error (type => 'in noscript:script');
2843                    
2844                    ## Reprocess in the "in head" insertion mode...
2845                    pop @{$self->{open_elements}};
2846                    $self->{insertion_mode} = 'after head';
2847                    !!!next-token;
2848                    redo B;
2849                  } elsif ($self->{insertion_mode} eq 'in head') {
2850                    pop @{$self->{open_elements}};
2851                    $self->{insertion_mode} = 'after head';
2852                  !!!next-token;                  !!!next-token;
2853                  redo B;                  redo B;
               }  
             }  
   
             !!!parse-error (type => 'in table:#character');  
   
             ## As if in body, but insert into foster parent element  
             ## ISSUE: Spec says that "whenever a node would be inserted  
             ## into the current node" while characters might not be  
             ## result in a new Text node.  
             $reconstruct_active_formatting_elements->($insert_to_foster);  
               
             if ({  
                  table => 1, tbody => 1, tfoot => 1,  
                  thead => 1, tr => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
               # MUST  
               my $foster_parent_element;  
               my $next_sibling;  
               my $prev_sibling;  
               OE: for (reverse 0..$#{$self->{open_elements}}) {  
                 if ($self->{open_elements}->[$_]->[1] eq 'table') {  
                   my $parent = $self->{open_elements}->[$_]->[0]->parent_node;  
                   if (defined $parent and $parent->node_type == 1) {  
                     $foster_parent_element = $parent;  
                     $next_sibling = $self->{open_elements}->[$_]->[0];  
                     $prev_sibling = $next_sibling->previous_sibling;  
                   } else {  
                     $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];  
                     $prev_sibling = $foster_parent_element->last_child;  
                   }  
                   last OE;  
                 }  
               } # OE  
               $foster_parent_element = $self->{open_elements}->[0]->[0] and  
               $prev_sibling = $foster_parent_element->last_child  
                 unless defined $foster_parent_element;  
               if (defined $prev_sibling and  
                   $prev_sibling->node_type == 3) {  
                 $prev_sibling->manakai_append_text ($token->{data});  
2854                } else {                } else {
2855                  $foster_parent_element->insert_before                  #
                   ($self->{document}->create_text_node ($token->{data}),  
                    $next_sibling);  
2856                }                }
2857              } else {              } elsif ($token->{tag_name} eq 'noscript') {
2858                $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});                if ($self->{insertion_mode} eq 'in head noscript') {
             }  
               
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ({  
                  caption => 1,  
                  colgroup => 1,  
                  tbody => 1, tfoot => 1, thead => 1,  
                 }->{$token->{tag_name}}) {  
               ## Clear back to table context  
               while ($self->{open_elements}->[-1]->[1] ne 'table' and  
                      $self->{open_elements}->[-1]->[1] ne 'html') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
2859                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
2860                    $self->{insertion_mode} = 'in head';
2861                    !!!next-token;
2862                    redo B;
2863                  } elsif ($self->{insertion_mode} eq 'before head') {
2864                    !!!parse-error (type => 'unmatched end tag:noscript');
2865                    ## Ignore the token ## ISSUE: An issue in the spec.
2866                    !!!next-token;
2867                    redo B;
2868                  } else {
2869                    #
2870                }                }
   
               push @$active_formatting_elements, ['#marker', '']  
                 if $token->{tag_name} eq 'caption';  
   
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               $self->{insertion_mode} = {  
                                  caption => 'in caption',  
                                  colgroup => 'in column group',  
                                  tbody => 'in table body',  
                                  tfoot => 'in table body',  
                                  thead => 'in table body',  
                                 }->{$token->{tag_name}};  
               !!!next-token;  
               redo B;  
2871              } elsif ({              } elsif ({
2872                        col => 1,                        body => 1, html => 1,
                       td => 1, th => 1, tr => 1,  
2873                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
2874                ## Clear back to table context                if ($self->{insertion_mode} eq 'before head') {
2875                while ($self->{open_elements}->[-1]->[1] ne 'table' and                  ## As if <head>
2876                       $self->{open_elements}->[-1]->[1] ne 'html') {                  !!!create-element ($self->{head_element}, 'head');
2877                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2878                  pop @{$self->{open_elements}};                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
               }  
   
               !!!insert-element ($token->{tag_name} eq 'col' ? 'colgroup' : 'tbody');  
               $self->{insertion_mode} = $token->{tag_name} eq 'col'  
                 ? 'in column group' : 'in table body';  
               ## reprocess  
               redo B;  
             } elsif ($token->{tag_name} eq 'table') {  
               ## NOTE: There are code clones for this "table in table"  
               !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
2879    
2880                ## As if </table>                  $self->{insertion_mode} = 'in head';
2881                ## have a table element in table scope                  ## Reprocess in the "in head" insertion mode...
2882                my $i;                } elsif ($self->{insertion_mode} eq 'in head noscript') {
2883                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
2884                  my $node = $self->{open_elements}->[$_];                  ## Ignore the token
                 if ($node->[1] eq 'table') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:table');  
                 ## Ignore tokens </table><table>  
2885                  !!!next-token;                  !!!next-token;
2886                  redo B;                  redo B;
2887                }                }
2888                                
2889                ## generate implied end tags                #
2890                if ({              } elsif ({
2891                     dd => 1, dt => 1, li => 1, p => 1,                        p => 1, br => 1,
2892                     td => 1, th => 1, tr => 1,                       }->{$token->{tag_name}}) {
2893                     tbody => 1, tfoot=> 1, thead => 1,                if ($self->{insertion_mode} eq 'before head') {
2894                    }->{$self->{open_elements}->[-1]->[1]}) {                  ## As if <head>
2895                  !!!back-token; # <table>                  !!!create-element ($self->{head_element}, 'head');
2896                  $token = {type => 'end tag', tag_name => 'table'};                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2897                  !!!back-token;                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
                 redo B;  
               }  
2898    
2899                if ($self->{open_elements}->[-1]->[1] ne 'table') {                  $self->{insertion_mode} = 'in head';
2900                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  ## Reprocess in the "in head" insertion mode...
2901                }                }
2902    
               splice @{$self->{open_elements}}, $i;  
   
               $self->_reset_insertion_mode;  
   
               ## reprocess  
               redo B;  
             } else {  
2903                #                #
2904              }              } else {
2905            } elsif ($token->{type} eq 'end tag') {                if ($self->{insertion_mode} ne 'after head') {
             if ($token->{tag_name} eq 'table') {  
               ## 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) {  
2906                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
2907                  ## Ignore the token                  ## Ignore the token
2908                  !!!next-token;                  !!!next-token;
2909                  redo B;                  redo B;
2910                  } else {
2911                    #
2912                }                }
2913                              }
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                    tbody => 1, tfoot=> 1, thead => 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 'table') {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
2914    
2915                splice @{$self->{open_elements}}, $i;              if ($self->{insertion_mode} eq 'in head noscript') {
2916                  ## As if </noscript>
2917                  pop @{$self->{open_elements}};
2918                  !!!parse-error (type => 'in noscript:/'.$token->{tag_name});
2919                  
2920                  ## Reprocess in the "in head" insertion mode...
2921                  ## As if </head>
2922                  pop @{$self->{open_elements}};
2923    
2924                $self->_reset_insertion_mode;                ## Reprocess in the "after head" insertion mode...
2925                } elsif ($self->{insertion_mode} eq 'in head') {
2926                  ## As if </head>
2927                  pop @{$self->{open_elements}};
2928    
2929                !!!next-token;                ## Reprocess in the "after head" insertion mode...
2930                redo B;              } elsif ($self->{insertion_mode} eq 'before head') {
             } elsif ({  
                       body => 1, caption => 1, col => 1, colgroup => 1,  
                       html => 1, tbody => 1, td => 1, tfoot => 1, th => 1,  
                       thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
2931                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
2932                ## Ignore the token                ## Ignore the token ## ISSUE: An issue in the spec.
2933                !!!next-token;                !!!next-token;
2934                redo B;                redo B;
             } else {  
               #  
2935              }              }
2936    
2937                ## "after head" insertion mode
2938                ## As if <body>
2939                !!!insert-element ('body');
2940                $self->{insertion_mode} = 'in body';
2941                ## reprocess
2942                redo B;
2943            } else {            } else {
2944              #              die "$0: $token->{type}: Unknown token type";
2945            }            }
2946    
2947            !!!parse-error (type => 'in table:'.$token->{tag_name});            ## ISSUE: An issue in the spec.
2948            $in_body->($insert_to_foster);      } elsif ($self->{insertion_mode} eq 'in body' or
2949            redo B;               $self->{insertion_mode} eq 'in cell' or
2950          } elsif ($self->{insertion_mode} eq 'in caption') {               $self->{insertion_mode} eq 'in caption') {
2951            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
2952              ## NOTE: This is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
2953              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
2954                            
2955              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
# Line 3876  sub _tree_construction_main ($) { Line 2961  sub _tree_construction_main ($) {
2961                   caption => 1, col => 1, colgroup => 1, tbody => 1,                   caption => 1, col => 1, colgroup => 1, tbody => 1,
2962                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,
2963                  }->{$token->{tag_name}}) {                  }->{$token->{tag_name}}) {
2964                !!!parse-error (type => 'not closed:caption');                if ($self->{insertion_mode} eq 'in cell') {
2965                    ## have an element in table scope
2966                ## As if </caption>                  my $tn;
2967                ## have a table element in table scope                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2968                my $i;                    my $node = $self->{open_elements}->[$_];
2969                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {
2970                  my $node = $self->{open_elements}->[$_];                      $tn = $node->[1];
2971                  if ($node->[1] eq 'caption') {                      last INSCOPE;
2972                    $i = $_;                    } elsif ({
2973                    last INSCOPE;                              table => 1, html => 1,
2974                  } elsif ({                             }->{$node->[1]}) {
2975                            table => 1, html => 1,                      last INSCOPE;
2976                           }->{$node->[1]}) {                    }
2977                    last INSCOPE;                  } # INSCOPE
2978                  }                    unless (defined $tn) {
2979                } # INSCOPE                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
2980                unless (defined $i) {                      ## Ignore the token
2981                  !!!parse-error (type => 'unmatched end tag:caption');                      !!!next-token;
2982                  ## Ignore the token                      redo B;
2983                  !!!next-token;                    }
2984                  redo B;                  
2985                }                  ## Close the cell
                 
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                    tbody => 1, tfoot=> 1, thead => 1,  
                   }->{$self->{open_elements}->[-1]->[1]}) {  
2986                  !!!back-token; # <?>                  !!!back-token; # <?>
2987                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => 'end tag', tag_name => $tn};
                 !!!back-token;  
                 $token = {type => 'end tag',  
                           tag_name => $self->{open_elements}->[-1]->[1]}; # MUST  
2988                  redo B;                  redo B;
2989                }                } elsif ($self->{insertion_mode} eq 'in caption') {
2990                    !!!parse-error (type => 'not closed:caption');
2991                    
2992                    ## As if </caption>
2993                    ## have a table element in table scope
2994                    my $i;
2995                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2996                      my $node = $self->{open_elements}->[$_];
2997                      if ($node->[1] eq 'caption') {
2998                        $i = $_;
2999                        last INSCOPE;
3000                      } elsif ({
3001                                table => 1, html => 1,
3002                               }->{$node->[1]}) {
3003                        last INSCOPE;
3004                      }
3005                    } # INSCOPE
3006                      unless (defined $i) {
3007                        !!!parse-error (type => 'unmatched end tag:caption');
3008                        ## Ignore the token
3009                        !!!next-token;
3010                        redo B;
3011                      }
3012                    
3013                    ## generate implied end tags
3014                    if ({
3015                         dd => 1, dt => 1, li => 1, p => 1,
3016                         td => 1, th => 1, tr => 1,
3017                         tbody => 1, tfoot=> 1, thead => 1,
3018                        }->{$self->{open_elements}->[-1]->[1]}) {
3019                      !!!back-token; # <?>
3020                      $token = {type => 'end tag', tag_name => 'caption'};
3021                      !!!back-token;
3022                      $token = {type => 'end tag',
3023                                tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3024                      redo B;
3025                    }
3026    
3027                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3028                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3029                    }
3030                    
3031                    splice @{$self->{open_elements}}, $i;
3032                    
3033                    $clear_up_to_marker->();
3034                    
3035                    $self->{insertion_mode} = 'in table';
3036                    
3037                    ## reprocess
3038                    redo B;
3039                  } else {
3040                    #
3041                }                }
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in table';  
   
               ## reprocess  
               redo B;  
3042              } else {              } else {
3043                #                #
3044              }              }
3045            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3046              if ($token->{tag_name} eq 'caption') {              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {
3047                ## have a table element in table scope                if ($self->{insertion_mode} eq 'in cell') {
3048                    ## have an element in table scope
3049                    my $i;
3050                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3051                      my $node = $self->{open_elements}->[$_];
3052                      if ($node->[1] eq $token->{tag_name}) {
3053                        $i = $_;
3054                        last INSCOPE;
3055                      } elsif ({
3056                                table => 1, html => 1,
3057                               }->{$node->[1]}) {
3058                        last INSCOPE;
3059                      }
3060                    } # INSCOPE
3061                      unless (defined $i) {
3062                        !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3063                        ## Ignore the token
3064                        !!!next-token;
3065                        redo B;
3066                      }
3067                    
3068                    ## generate implied end tags
3069                    if ({
3070                         dd => 1, dt => 1, li => 1, p => 1,
3071                         td => ($token->{tag_name} eq 'th'),
3072                         th => ($token->{tag_name} eq 'td'),
3073                         tr => 1,
3074                         tbody => 1, tfoot=> 1, thead => 1,
3075                        }->{$self->{open_elements}->[-1]->[1]}) {
3076                      !!!back-token;
3077                      $token = {type => 'end tag',
3078                                tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3079                      redo B;
3080                    }
3081                    
3082                    if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
3083                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3084                    }
3085                    
3086                    splice @{$self->{open_elements}}, $i;
3087                    
3088                    $clear_up_to_marker->();
3089                    
3090                    $self->{insertion_mode} = 'in row';
3091                    
3092                    !!!next-token;
3093                    redo B;
3094                  } elsif ($self->{insertion_mode} eq 'in caption') {
3095                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3096                    ## Ignore the token
3097                    !!!next-token;
3098                    redo B;
3099                  } else {
3100                    #
3101                  }
3102                } elsif ($token->{tag_name} eq 'caption') {
3103                  if ($self->{insertion_mode} eq 'in caption') {
3104                    ## have a table element in table scope
3105                    my $i;
3106                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3107                      my $node = $self->{open_elements}->[$_];
3108                      if ($node->[1] eq $token->{tag_name}) {
3109                        $i = $_;
3110                        last INSCOPE;
3111                      } elsif ({
3112                                table => 1, html => 1,
3113                               }->{$node->[1]}) {
3114                        last INSCOPE;
3115                      }
3116                    } # INSCOPE
3117                      unless (defined $i) {
3118                        !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3119                        ## Ignore the token
3120                        !!!next-token;
3121                        redo B;
3122                      }
3123                    
3124                    ## generate implied end tags
3125                    if ({
3126                         dd => 1, dt => 1, li => 1, p => 1,
3127                         td => 1, th => 1, tr => 1,
3128                         tbody => 1, tfoot=> 1, thead => 1,
3129                        }->{$self->{open_elements}->[-1]->[1]}) {
3130                      !!!back-token;
3131                      $token = {type => 'end tag',
3132                                tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3133                      redo B;
3134                    }
3135                    
3136                    if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3137                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3138                    }
3139                    
3140                    splice @{$self->{open_elements}}, $i;
3141                    
3142                    $clear_up_to_marker->();
3143                    
3144                    $self->{insertion_mode} = 'in table';
3145                    
3146                    !!!next-token;
3147                    redo B;
3148                  } elsif ($self->{insertion_mode} eq 'in cell') {
3149                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3150                    ## Ignore the token
3151                    !!!next-token;
3152                    redo B;
3153                  } else {
3154                    #
3155                  }
3156                } elsif ({
3157                          table => 1, tbody => 1, tfoot => 1,
3158                          thead => 1, tr => 1,
3159                         }->{$token->{tag_name}} and
3160                         $self->{insertion_mode} eq 'in cell') {
3161                  ## have an element in table scope
3162                my $i;                my $i;
3163                  my $tn;
3164                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3165                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
3166                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq $token->{tag_name}) {
3167                    $i = $_;                    $i = $_;
3168                    last INSCOPE;                    last INSCOPE;
3169                    } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {
3170                      $tn = $node->[1];
3171                      ## NOTE: There is exactly one |td| or |th| element
3172                      ## in scope in the stack of open elements by definition.
3173                  } elsif ({                  } elsif ({
3174                            table => 1, html => 1,                            table => 1, html => 1,
3175                           }->{$node->[1]}) {                           }->{$node->[1]}) {
# Line 3949  sub _tree_construction_main ($) { Line 3182  sub _tree_construction_main ($) {
3182                  !!!next-token;                  !!!next-token;
3183                  redo B;                  redo B;
3184                }                }
                 
               ## generate implied end tags  
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => 1, th => 1, tr => 1,  
                    tbody => 1, tfoot=> 1, thead => 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->();  
3185    
3186                $self->{insertion_mode} = 'in table';                ## Close the cell
3187                  !!!back-token; # </?>
3188                !!!next-token;                $token = {type => 'end tag', tag_name => $tn};
3189                redo B;                redo B;
3190              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table' and
3191                         $self->{insertion_mode} eq 'in caption') {
3192                !!!parse-error (type => 'not closed:caption');                !!!parse-error (type => 'not closed:caption');
3193    
3194                ## As if </caption>                ## As if </caption>
# Line 4025  sub _tree_construction_main ($) { Line 3239  sub _tree_construction_main ($) {
3239                ## reprocess                ## reprocess
3240                redo B;                redo B;
3241              } elsif ({              } elsif ({
3242                        body => 1, col => 1, colgroup => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
                       html => 1, tbody => 1, td => 1, tfoot => 1,  
                       th => 1, thead => 1, tr => 1,  
3243                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3244                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                if ($self->{insertion_mode} eq 'in cell' or
3245                ## Ignore the token                    $self->{insertion_mode} eq 'in caption') {
3246                redo B;                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
             } else {  
               #  
             }  
           } else {  
             #  
           }  
                 
           $in_body->($insert_to_current);  
           redo B;  
         } elsif ($self->{insertion_mode} eq 'in column group') {  
           if ($token->{type} eq 'character') {  
             if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {  
               $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);  
               unless (length $token->{data}) {  
                 !!!next-token;  
                 redo B;  
               }  
             }  
               
             #  
           } elsif ($token->{type} eq 'start tag') {  
             if ($token->{tag_name} eq 'col') {  
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               pop @{$self->{open_elements}};  
               !!!next-token;  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'colgroup') {  
               if ($self->{open_elements}->[-1]->[1] eq 'html') {  
                 !!!parse-error (type => 'unmatched end tag:colgroup');  
3247                  ## Ignore the token                  ## Ignore the token
3248                  !!!next-token;                  !!!next-token;
3249                  redo B;                  redo B;
3250                } else {                } else {
3251                  pop @{$self->{open_elements}}; # colgroup                  #
                 $self->{insertion_mode} = 'in table';  
                 !!!next-token;  
                 redo B;              
3252                }                }
3253              } elsif ($token->{tag_name} eq 'col') {              } elsif ({
3254                !!!parse-error (type => 'unmatched end tag:col');                        tbody => 1, tfoot => 1,
3255                          thead => 1, tr => 1,
3256                         }->{$token->{tag_name}} and
3257                         $self->{insertion_mode} eq 'in caption') {
3258                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3259                ## Ignore the token                ## Ignore the token
3260                !!!next-token;                !!!next-token;
3261                redo B;                redo B;
3262              } else {              } else {
3263                #                #
3264              }              }
3265            } else {        } else {
3266              #          die "$0: $token->{type}: Unknown token type";
3267            }        }
3268    
3269            ## As if </colgroup>        $insert = $insert_to_current;
3270            if ($self->{open_elements}->[-1]->[1] eq 'html') {        #
3271              !!!parse-error (type => 'unmatched end tag:colgroup');      } elsif ($self->{insertion_mode} eq 'in row' or
3272              ## Ignore the token               $self->{insertion_mode} eq 'in table body' or
3273              !!!next-token;               $self->{insertion_mode} eq 'in table') {
             redo B;  
           } else {  
             pop @{$self->{open_elements}}; # colgroup  
             $self->{insertion_mode} = 'in table';  
             ## reprocess  
             redo B;  
           }  
         } elsif ($self->{insertion_mode} eq 'in table body') {  
3274            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3275              ## NOTE: This is a "character in table" code clone.              ## NOTE: There are "character in table" code clones.
3276              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3277                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3278                                
# Line 4117  sub _tree_construction_main ($) { Line 3289  sub _tree_construction_main ($) {
3289              ## into the current node" while characters might not be              ## into the current node" while characters might not be
3290              ## result in a new Text node.              ## result in a new Text node.
3291              $reconstruct_active_formatting_elements->($insert_to_foster);              $reconstruct_active_formatting_elements->($insert_to_foster);
3292                
3293              if ({              if ({
3294                   table => 1, tbody => 1, tfoot => 1,                   table => 1, tbody => 1, tfoot => 1,
3295                   thead => 1, tr => 1,                   thead => 1, tr => 1,
# Line 4159  sub _tree_construction_main ($) { Line 3331  sub _tree_construction_main ($) {
3331              redo B;              redo B;
3332            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3333              if ({              if ({
3334                   tr => 1,                   tr => ($self->{insertion_mode} ne 'in row'),
3335                   th => 1, td => 1,                   th => 1, td => 1,
3336                  }->{$token->{tag_name}}) {                  }->{$token->{tag_name}}) {
3337                unless ($token->{tag_name} eq 'tr') {                if ($self->{insertion_mode} eq 'in table') {
3338                  !!!parse-error (type => 'missing start tag:tr');                  ## Clear back to table context
3339                    while ($self->{open_elements}->[-1]->[1] ne 'table' and
3340                           $self->{open_elements}->[-1]->[1] ne 'html') {
3341                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3342                      pop @{$self->{open_elements}};
3343                    }
3344                    
3345                    !!!insert-element ('tbody');
3346                    $self->{insertion_mode} = 'in table body';
3347                    ## reprocess in the "in table body" insertion mode...
3348                }                }
3349    
3350                ## Clear back to table body context                if ($self->{insertion_mode} eq 'in table body') {
3351                    unless ($token->{tag_name} eq 'tr') {
3352                      !!!parse-error (type => 'missing start tag:tr');
3353                    }
3354                    
3355                    ## Clear back to table body context
3356                    while (not {
3357                      tbody => 1, tfoot => 1, thead => 1, html => 1,
3358                    }->{$self->{open_elements}->[-1]->[1]}) {
3359                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3360                      pop @{$self->{open_elements}};
3361                    }
3362                    
3363                    $self->{insertion_mode} = 'in row';
3364                    if ($token->{tag_name} eq 'tr') {
3365                      !!!insert-element ($token->{tag_name}, $token->{attributes});
3366                      !!!next-token;
3367                      redo B;
3368                    } else {
3369                      !!!insert-element ('tr');
3370                      ## reprocess in the "in row" insertion mode
3371                    }
3372                  }
3373    
3374                  ## Clear back to table row context
3375                while (not {                while (not {
3376                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tr => 1, html => 1,
3377                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
3378                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3379                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3380                }                }
3381                                
3382                $self->{insertion_mode} = 'in row';                !!!insert-element ($token->{tag_name}, $token->{attributes});
3383                if ($token->{tag_name} eq 'tr') {                $self->{insertion_mode} = 'in cell';
3384                  !!!insert-element ($token->{tag_name}, $token->{attributes});  
3385                  !!!next-token;                push @$active_formatting_elements, ['#marker', ''];
3386                } else {                
3387                  !!!insert-element ('tr');                !!!next-token;
                 ## reprocess  
               }  
3388                redo B;                redo B;
3389              } elsif ({              } elsif ({
3390                        caption => 1, col => 1, colgroup => 1,                        caption => 1, col => 1, colgroup => 1,
3391                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
3392                          tr => 1, # $self->{insertion_mode} eq 'in row'
3393                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3394                ## have an element in table scope                if ($self->{insertion_mode} eq 'in row') {
3395                my $i;                  ## As if </tr>
3396                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  ## have an element in table scope
3397                  my $node = $self->{open_elements}->[$_];                  my $i;
3398                  if ({                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3399                       tbody => 1, thead => 1, tfoot => 1,                    my $node = $self->{open_elements}->[$_];
3400                      }->{$node->[1]}) {                    if ($node->[1] eq 'tr') {
3401                    $i = $_;                      $i = $_;
3402                    last INSCOPE;                      last INSCOPE;
3403                  } elsif ({                    } elsif ({
3404                            table => 1, html => 1,                              table => 1, html => 1,
3405                           }->{$node->[1]}) {                             }->{$node->[1]}) {
3406                    last INSCOPE;                      last INSCOPE;
3407                      }
3408                    } # INSCOPE
3409                    unless (defined $i) {
3410                      !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});
3411                      ## Ignore the token
3412                      !!!next-token;
3413                      redo B;
3414                    }
3415                    
3416                    ## Clear back to table row context
3417                    while (not {
3418                      tr => 1, html => 1,
3419                    }->{$self->{open_elements}->[-1]->[1]}) {
3420                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3421                      pop @{$self->{open_elements}};
3422                    }
3423                    
3424                    pop @{$self->{open_elements}}; # tr
3425                    $self->{insertion_mode} = 'in table body';
3426                    if ($token->{tag_name} eq 'tr') {
3427                      ## reprocess
3428                      redo B;
3429                    } else {
3430                      ## reprocess in the "in table body" insertion mode...
3431                  }                  }
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
3432                }                }
3433    
3434                ## Clear back to table body context                if ($self->{insertion_mode} eq 'in table body') {
3435                while (not {                  ## have an element in table scope
3436                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  my $i;
3437                }->{$self->{open_elements}->[-1]->[1]}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3438                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                    my $node = $self->{open_elements}->[$_];
3439                      if ({
3440                           tbody => 1, thead => 1, tfoot => 1,
3441                          }->{$node->[1]}) {
3442                        $i = $_;
3443                        last INSCOPE;
3444                      } elsif ({
3445                                table => 1, html => 1,
3446                               }->{$node->[1]}) {
3447                        last INSCOPE;
3448                      }
3449                    } # INSCOPE
3450                    unless (defined $i) {
3451                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3452                      ## Ignore the token
3453                      !!!next-token;
3454                      redo B;
3455                    }
3456    
3457                    ## Clear back to table body context
3458                    while (not {
3459                      tbody => 1, tfoot => 1, thead => 1, html => 1,
3460                    }->{$self->{open_elements}->[-1]->[1]}) {
3461                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3462                      pop @{$self->{open_elements}};
3463                    }
3464                    
3465                    ## As if <{current node}>
3466                    ## have an element in table scope
3467                    ## true by definition
3468                    
3469                    ## Clear back to table body context
3470                    ## nop by definition
3471                    
3472                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3473                    $self->{insertion_mode} = 'in table';
3474                    ## reprocess in "in table" insertion mode...
3475                }                }
3476    
3477                ## As if <{current node}>                if ($token->{tag_name} eq 'col') {
3478                ## have an element in table scope                  ## Clear back to table context
3479                ## true by definition                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
3480                           $self->{open_elements}->[-1]->[1] ne 'html') {
3481                ## Clear back to table body context                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3482                ## nop by definition                    pop @{$self->{open_elements}};
3483                    }
3484                pop @{$self->{open_elements}};                  
3485                $self->{insertion_mode} = 'in table';                  !!!insert-element ('colgroup');
3486                ## reprocess                  $self->{insertion_mode} = 'in column group';
3487                redo B;                  ## reprocess
3488                    redo B;
3489                  } elsif ({
3490                            caption => 1,
3491                            colgroup => 1,
3492                            tbody => 1, tfoot => 1, thead => 1,
3493                           }->{$token->{tag_name}}) {
3494                    ## Clear back to table context
3495                    while ($self->{open_elements}->[-1]->[1] ne 'table' and
3496                           $self->{open_elements}->[-1]->[1] ne 'html') {
3497                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3498                      pop @{$self->{open_elements}};
3499                    }
3500                    
3501                    push @$active_formatting_elements, ['#marker', '']
3502                        if $token->{tag_name} eq 'caption';
3503                    
3504                    !!!insert-element ($token->{tag_name}, $token->{attributes});
3505                    $self->{insertion_mode} = {
3506                                               caption => 'in caption',
3507                                               colgroup => 'in column group',
3508                                               tbody => 'in table body',
3509                                               tfoot => 'in table body',
3510                                               thead => 'in table body',
3511                                              }->{$token->{tag_name}};
3512                    !!!next-token;
3513                    redo B;
3514                  } else {
3515                    die "$0: in table: <>: $token->{tag_name}";
3516                  }
3517              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
3518                ## NOTE: This is a code clone of "table in table"                ## NOTE: There are code clones for this "table in table"
3519                !!!parse-error (type => 'not closed:table');                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3520    
3521                ## As if </table>                ## As if </table>
3522                ## have a table element in table scope                ## have a table element in table scope
# Line 4273  sub _tree_construction_main ($) { Line 3559  sub _tree_construction_main ($) {
3559    
3560                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
3561    
3562                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
3563    
3564                ## reprocess                ## reprocess
3565                redo B;                redo B;
# Line 4281  sub _tree_construction_main ($) { Line 3567  sub _tree_construction_main ($) {
3567                #                #
3568              }              }
3569            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3570              if ({              if ($token->{tag_name} eq 'tr' and
3571                   tbody => 1, tfoot => 1, thead => 1,                  $self->{insertion_mode} eq 'in row') {
                 }->{$token->{tag_name}}) {  
3572                ## have an element in table scope                ## have an element in table scope
3573                my $i;                my $i;
3574                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 4304  sub _tree_construction_main ($) { Line 3589  sub _tree_construction_main ($) {
3589                  redo B;                  redo B;
3590                }                }
3591    
3592                ## Clear back to table body context                ## Clear back to table row context
3593                while (not {                while (not {
3594                  tbody => 1, tfoot => 1, thead => 1, html => 1,                  tr => 1, html => 1,
3595                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
3596                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3597                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3598                }                }
3599    
3600                pop @{$self->{open_elements}};                pop @{$self->{open_elements}}; # tr
3601                $self->{insertion_mode} = 'in table';                $self->{insertion_mode} = 'in table body';
3602                !!!next-token;                !!!next-token;
3603                redo B;                redo B;
3604              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
3605                ## have an element in table scope                if ($self->{insertion_mode} eq 'in row') {
3606                my $i;                  ## As if </tr>
3607                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  ## have an element in table scope
3608                  my $node = $self->{open_elements}->[$_];                  my $i;
3609                  if ({                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3610                       tbody => 1, thead => 1, tfoot => 1,                    my $node = $self->{open_elements}->[$_];
3611                      }->{$node->[1]}) {                    if ($node->[1] eq 'tr') {
3612                    $i = $_;                      $i = $_;
3613                    last INSCOPE;                      last INSCOPE;
3614                  } elsif ({                    } elsif ({
3615                            table => 1, html => 1,                              table => 1, html => 1,
3616                           }->{$node->[1]}) {                             }->{$node->[1]}) {
3617                    last INSCOPE;                      last INSCOPE;
3618                      }
3619                    } # INSCOPE
3620                    unless (defined $i) {
3621                      !!!parse-error (type => 'unmatched end tag:'.$token->{type});
3622                      ## Ignore the token
3623                      !!!next-token;
3624                      redo B;
3625                  }                  }
3626                } # INSCOPE                  
3627                unless (defined $i) {                  ## Clear back to table row context
3628                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  while (not {
3629                  ## Ignore the token                    tr => 1, html => 1,
                 !!!next-token;  
                 redo B;  
               }  
   
               ## Clear back to table body context  
               while (not {  
                 tbody => 1, tfoot => 1, thead => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
   
               ## As if <{current node}>  
               ## have an element in table scope  
               ## true by definition  
   
               ## Clear back to table body context  
               ## nop by definition  
   
               pop @{$self->{open_elements}};  
               $self->{insertion_mode} = 'in table';  
               ## reprocess  
               redo B;  
             } elsif ({  
                       body => 1, caption => 1, col => 1, colgroup => 1,  
                       html => 1, td => 1, th => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
           }  
             
           ## As if in table  
           !!!parse-error (type => 'in table:'.$token->{tag_name});  
           $in_body->($insert_to_foster);  
           redo B;  
         } elsif ($self->{insertion_mode} eq 'in row') {  
           if ($token->{type} eq 'character') {  
             ## NOTE: This is a "character in table" code clone.  
             if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {  
               $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);  
                 
               unless (length $token->{data}) {  
                 !!!next-token;  
                 redo B;  
               }  
             }  
   
             !!!parse-error (type => 'in table:#character');  
   
             ## As if in body, but insert into foster parent element  
             ## ISSUE: Spec says that "whenever a node would be inserted  
             ## into the current node" while characters might not be  
             ## result in a new Text node.  
             $reconstruct_active_formatting_elements->($insert_to_foster);  
               
             if ({  
                  table => 1, tbody => 1, tfoot => 1,  
                  thead => 1, tr => 1,  
3630                  }->{$self->{open_elements}->[-1]->[1]}) {                  }->{$self->{open_elements}->[-1]->[1]}) {
3631                # MUST                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3632                my $foster_parent_element;                    pop @{$self->{open_elements}};
3633                my $next_sibling;                  }
3634                my $prev_sibling;                  
3635                OE: for (reverse 0..$#{$self->{open_elements}}) {                  pop @{$self->{open_elements}}; # tr
3636                  if ($self->{open_elements}->[$_]->[1] eq 'table') {                  $self->{insertion_mode} = 'in table body';
3637                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                  ## reprocess in the "in table body" insertion mode...
3638                    if (defined $parent and $parent->node_type == 1) {                }
3639                      $foster_parent_element = $parent;  
3640                      $next_sibling = $self->{open_elements}->[$_]->[0];                if ($self->{insertion_mode} eq 'in table body') {
3641                      $prev_sibling = $next_sibling->previous_sibling;                  ## have an element in table scope
3642                    } else {                  my $i;
3643                      $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3644                      $prev_sibling = $foster_parent_element->last_child;                    my $node = $self->{open_elements}->[$_];
3645                      if ({
3646                           tbody => 1, thead => 1, tfoot => 1,
3647                          }->{$node->[1]}) {
3648                        $i = $_;
3649                        last INSCOPE;
3650                      } elsif ({
3651                                table => 1, html => 1,
3652                               }->{$node->[1]}) {
3653                        last INSCOPE;
3654                    }                    }
3655                    last OE;                  } # INSCOPE
3656                    unless (defined $i) {
3657                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3658                      ## Ignore the token
3659                      !!!next-token;
3660                      redo B;
3661                  }                  }
3662                } # OE                  
3663                $foster_parent_element = $self->{open_elements}->[0]->[0] and                  ## Clear back to table body context
3664                $prev_sibling = $foster_parent_element->last_child                  while (not {
3665                  unless defined $foster_parent_element;                    tbody => 1, tfoot => 1, thead => 1, html => 1,
3666                if (defined $prev_sibling and                  }->{$self->{open_elements}->[-1]->[1]}) {
3667                    $prev_sibling->node_type == 3) {                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3668                  $prev_sibling->manakai_append_text ($token->{data});                    pop @{$self->{open_elements}};
               } else {  
                 $foster_parent_element->insert_before  
                   ($self->{document}->create_text_node ($token->{data}),  
                    $next_sibling);  
               }  
             } else {  
               $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});  
             }  
               
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ($token->{tag_name} eq 'th' or  
                 $token->{tag_name} eq 'td') {  
               ## Clear back to table row context  
               while (not {  
                 tr => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
                 
               !!!insert-element ($token->{tag_name}, $token->{attributes});  
               $self->{insertion_mode} = 'in cell';  
   
               push @$active_formatting_elements, ['#marker', ''];  
                 
               !!!next-token;  
               redo B;  
             } elsif ({  
                       caption => 1, col => 1, colgroup => 1,  
                       tbody => 1, tfoot => 1, thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               ## As if </tr>  
               ## have an element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'tr') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
3669                  }                  }
3670                } # INSCOPE                  
3671                unless (defined $i) {                  ## As if <{current node}>
3672                  !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name});                  ## have an element in table scope
3673                  ## Ignore the token                  ## true by definition
3674                  !!!next-token;                  
3675                  redo B;                  ## Clear back to table body context
3676                }                  ## nop by definition
3677                    
               ## Clear back to table row context  
               while (not {  
                 tr => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
3678                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3679                    $self->{insertion_mode} = 'in table';
3680                    ## reprocess in the "in table" insertion mode...
3681                }                }
3682    
               pop @{$self->{open_elements}}; # tr  
               $self->{insertion_mode} = 'in table body';  
               ## reprocess  
               redo B;  
             } elsif ($token->{tag_name} eq 'table') {  
               ## NOTE: This is a code clone of "table in table"  
               !!!parse-error (type => 'not closed:table');  
   
               ## As if </table>  
3683                ## have a table element in table scope                ## have a table element in table scope
3684                my $i;                my $i;
3685                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3686                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
3687                  if ($node->[1] eq 'table') {                  if ($node->[1] eq $token->{tag_name}) {
3688                    $i = $_;                    $i = $_;
3689                    last INSCOPE;                    last INSCOPE;
3690                  } elsif ({                  } elsif ({
# Line 4510  sub _tree_construction_main ($) { Line 3694  sub _tree_construction_main ($) {
3694                  }                  }
3695                } # INSCOPE                } # INSCOPE
3696                unless (defined $i) {                unless (defined $i) {
3697                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3698                  ## Ignore tokens </table><table>                  ## Ignore the token
3699                  !!!next-token;                  !!!next-token;
3700                  redo B;                  redo B;
3701                }                }
3702                  
3703                ## generate implied end tags                ## generate implied end tags
3704                if ({                if ({
3705                     dd => 1, dt => 1, li => 1, p => 1,                     dd => 1, dt => 1, li => 1, p => 1,
3706                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3707                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3708                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
                 !!!back-token; # <table>  
                 $token = {type => 'end tag', tag_name => 'table'};  
3709                  !!!back-token;                  !!!back-token;
3710                  $token = {type => 'end tag',                  $token = {type => 'end tag',
3711                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3712                  redo B;                  redo B;
3713                }                }
3714                  
3715                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
3716                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3717                }                }
3718                    
3719                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
3720                  
3721                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
3722                  
               ## reprocess  
               redo B;  
             } else {  
               #  
             }  
           } elsif ($token->{type} eq 'end tag') {  
             if ($token->{tag_name} eq 'tr') {  
               ## have an 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;  
               }  
   
               ## Clear back to table row context  
               while (not {  
                 tr => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
   
               pop @{$self->{open_elements}}; # tr  
               $self->{insertion_mode} = 'in table body';  
3723                !!!next-token;                !!!next-token;
3724                redo B;                redo B;
             } elsif ($token->{tag_name} eq 'table') {  
               ## As if </tr>  
               ## have an element in table scope  
               my $i;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'tr') {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $i) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{type});  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
               }  
   
               ## Clear back to table row context  
               while (not {  
                 tr => 1, html => 1,  
               }->{$self->{open_elements}->[-1]->[1]}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
                 pop @{$self->{open_elements}};  
               }  
   
               pop @{$self->{open_elements}}; # tr  
               $self->{insertion_mode} = 'in table body';  
               ## reprocess  
               redo B;  
3725              } elsif ({              } elsif ({
3726                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
3727                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}} and
3728                ## have an element in table scope                       ($self->{insertion_mode} eq 'in row' or
3729                my $i;                        $self->{insertion_mode} eq 'in table body')) {
3730                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                if ($self->{insertion_mode} eq 'in row') {
3731                  my $node = $self->{open_elements}->[$_];                  ## have an element in table scope
3732                  if ($node->[1] eq $token->{tag_name}) {                  my $i;
3733                    $i = $_;                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3734                    last INSCOPE;                    my $node = $self->{open_elements}->[$_];
3735                  } elsif ({                    if ($node->[1] eq $token->{tag_name}) {
3736                            table => 1, html => 1,                      $i = $_;
3737                           }->{$node->[1]}) {                      last INSCOPE;
3738                    last INSCOPE;                    } elsif ({
3739                                table => 1, html => 1,
3740                               }->{$node->[1]}) {
3741                        last INSCOPE;
3742                      }
3743                    } # INSCOPE
3744                      unless (defined $i) {
3745                        !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3746                        ## Ignore the token
3747                        !!!next-token;
3748                        redo B;
3749                      }
3750                    
3751                    ## As if </tr>
3752                    ## have an element in table scope
3753                    my $i;
3754                    INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3755                      my $node = $self->{open_elements}->[$_];
3756                      if ($node->[1] eq 'tr') {
3757                        $i = $_;
3758                        last INSCOPE;
3759                      } elsif ({
3760                                table => 1, html => 1,
3761                               }->{$node->[1]}) {
3762                        last INSCOPE;
3763                      }
3764                    } # INSCOPE
3765                      unless (defined $i) {
3766                        !!!parse-error (type => 'unmatched end tag:tr');
3767                        ## Ignore the token
3768                        !!!next-token;
3769                        redo B;
3770                      }
3771                    
3772                    ## Clear back to table row context
3773                    while (not {
3774                      tr => 1, html => 1,
3775                    }->{$self->{open_elements}->[-1]->[1]}) {
3776                      !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3777                      pop @{$self->{open_elements}};
3778                  }                  }
3779                } # INSCOPE                  
3780                unless (defined $i) {                  pop @{$self->{open_elements}}; # tr
3781                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  $self->{insertion_mode} = 'in table body';
3782                  ## Ignore the token                  ## reprocess in the "in table body" insertion mode...
                 !!!next-token;  
                 redo B;  
3783                }                }
3784    
               ## As if </tr>  
3785                ## have an element in table scope                ## have an element in table scope
3786                my $i;                my $i;
3787                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3788                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
3789                  if ($node->[1] eq 'tr') {                  if ($node->[1] eq $token->{tag_name}) {
3790                    $i = $_;                    $i = $_;
3791                    last INSCOPE;                    last INSCOPE;
3792                  } elsif ({                  } elsif ({
# Line 4649  sub _tree_construction_main ($) { Line 3796  sub _tree_construction_main ($) {
3796                  }                  }
3797                } # INSCOPE                } # INSCOPE
3798                unless (defined $i) {                unless (defined $i) {
3799                  !!!parse-error (type => 'unmatched end tag:tr');                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3800                  ## Ignore the token                  ## Ignore the token
3801                  !!!next-token;                  !!!next-token;
3802                  redo B;                  redo B;
3803                }                }
3804    
3805                ## Clear back to table row context                ## Clear back to table body context
3806                while (not {                while (not {
3807                  tr => 1, html => 1,                  tbody => 1, tfoot => 1, thead => 1, html => 1,
3808                }->{$self->{open_elements}->[-1]->[1]}) {                }->{$self->{open_elements}->[-1]->[1]}) {
3809                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3810                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
3811                }                }
3812    
3813                pop @{$self->{open_elements}}; # tr                pop @{$self->{open_elements}};
3814                $self->{insertion_mode} = 'in table body';                $self->{insertion_mode} = 'in table';
3815                ## reprocess                !!!next-token;
3816                redo B;                redo B;
3817              } elsif ({              } elsif ({
3818                        body => 1, caption => 1, col => 1,                        body => 1, caption => 1, col => 1, colgroup => 1,
3819                        colgroup => 1, html => 1, td => 1, th => 1,                        html => 1, td => 1, th => 1,
3820                          tr => 1, # $self->{insertion_mode} eq 'in row'
3821                          tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} eq 'in table'
3822                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
3823                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3824                ## Ignore the token                ## Ignore the token
# Line 4679  sub _tree_construction_main ($) { Line 3828  sub _tree_construction_main ($) {
3828                #                #
3829              }              }
3830            } else {            } else {
3831              #              die "$0: $token->{type}: Unknown token type";
3832            }            }
3833    
3834            ## As if in table        !!!parse-error (type => 'in table:'.$token->{tag_name});
           !!!parse-error (type => 'in table:'.$token->{tag_name});  
           $in_body->($insert_to_foster);  
           redo B;  
         } elsif ($self->{insertion_mode} eq 'in cell') {  
           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});  
3835    
3836              !!!next-token;        $insert = $insert_to_foster;
3837              redo B;        #
3838            } elsif ($token->{type} eq 'start tag') {      } elsif ($self->{insertion_mode} eq 'in column group') {
3839              if ({            if ($token->{type} eq 'character') {
3840                   caption => 1, col => 1, colgroup => 1,              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3841                   tbody => 1, td => 1, tfoot => 1, th => 1,                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3842                   thead => 1, tr => 1,                unless (length $token->{data}) {
                 }->{$token->{tag_name}}) {  
               ## have an element in table scope  
               my $tn;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq 'td' or $node->[1] eq 'th') {  
                   $tn = $node->[1];  
                   last INSCOPE;  
                 } elsif ({  
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
                   last INSCOPE;  
                 }  
               } # INSCOPE  
               unless (defined $tn) {  
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
                 ## Ignore the token  
3843                  !!!next-token;                  !!!next-token;
3844                  redo B;                  redo B;
3845                }                }
3846                }
3847                ## Close the cell              
3848                !!!back-token; # <?>              #
3849                $token = {type => 'end tag', tag_name => $tn};            } elsif ($token->{type} eq 'start tag') {
3850                if ($token->{tag_name} eq 'col') {
3851                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3852                  pop @{$self->{open_elements}};
3853                  !!!next-token;
3854                redo B;                redo B;
3855              } else {              } else {
3856                #                #
3857              }              }
3858            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3859              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {              if ($token->{tag_name} eq 'colgroup') {
3860                ## have an element in table scope                if ($self->{open_elements}->[-1]->[1] eq 'html') {
3861                my $i;                  !!!parse-error (type => 'unmatched end tag:colgroup');
               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});  
3862                  ## Ignore the token                  ## Ignore the token
3863                  !!!next-token;                  !!!next-token;
3864                  redo B;                  redo B;
3865                  } else {
3866                    pop @{$self->{open_elements}}; # colgroup
3867                    $self->{insertion_mode} = 'in table';
3868                    !!!next-token;
3869                    redo B;            
3870                }                }
3871                              } elsif ($token->{tag_name} eq 'col') {
3872                ## generate implied end tags                !!!parse-error (type => 'unmatched end tag:col');
               if ({  
                    dd => 1, dt => 1, li => 1, p => 1,  
                    td => ($token->{tag_name} eq 'th'),  
                    th => ($token->{tag_name} eq 'td'),  
                    tr => 1,  
                    tbody => 1, tfoot=> 1, thead => 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 $token->{tag_name}) {  
                 !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);  
               }  
   
               splice @{$self->{open_elements}}, $i;  
   
               $clear_up_to_marker->();  
   
               $self->{insertion_mode} = 'in row';  
   
               !!!next-token;  
               redo B;  
             } elsif ({  
                       body => 1, caption => 1, col => 1,  
                       colgroup => 1, html => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
3873                ## Ignore the token                ## Ignore the token
3874                !!!next-token;                !!!next-token;
3875                redo B;                redo B;
             } elsif ({  
                       table => 1, tbody => 1, tfoot => 1,  
                       thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               ## have an element in table scope  
               my $i;  
               my $tn;  
               INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                 my $node = $self->{open_elements}->[$_];  
                 if ($node->[1] eq $token->{tag_name}) {  
                   $i = $_;  
                   last INSCOPE;  
                 } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {  
                   $tn = $node->[1];  
                   ## NOTE: There is exactly one |td| or |th| element  
                   ## in scope in the stack of open elements by definition.  
                 } 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;  
               }  
   
               ## Close the cell  
               !!!back-token; # </?>  
               $token = {type => 'end tag', tag_name => $tn};  
               redo B;  
3876              } else {              } else {
3877                #                #
3878              }              }
3879            } else {            } else {
3880              #              #
3881            }            }
3882              
3883            $in_body->($insert_to_current);            ## As if </colgroup>
3884            redo B;            if ($self->{open_elements}->[-1]->[1] eq 'html') {
3885          } elsif ($self->{insertion_mode} eq 'in select') {              !!!parse-error (type => 'unmatched end tag:colgroup');
3886                ## Ignore the token
3887                !!!next-token;
3888                redo B;
3889              } else {
3890                pop @{$self->{open_elements}}; # colgroup
3891                $self->{insertion_mode} = 'in table';
3892                ## reprocess
3893                redo B;
3894              }
3895        } elsif ($self->{insertion_mode} eq 'in select') {
3896            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3897              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
3898              !!!next-token;              !!!next-token;
# Line 5000  sub _tree_construction_main ($) { Line 4066  sub _tree_construction_main ($) {
4066            ## Ignore the token            ## Ignore the token
4067            !!!next-token;            !!!next-token;
4068            redo B;            redo B;
4069          } elsif ($self->{insertion_mode} eq 'after body') {      } elsif ($self->{insertion_mode} eq 'after body' or
4070            if ($token->{type} eq 'character') {               $self->{insertion_mode} eq 'after html body') {
4071              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {        if ($token->{type} eq 'character') {
4072                my $data = $1;          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4073                ## As if in body            my $data = $1;
4074                $reconstruct_active_formatting_elements->($insert_to_current);            ## As if in body
4075              $reconstruct_active_formatting_elements->($insert_to_current);
4076                                
4077                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4078              
4079              unless (length $token->{data}) {
4080                !!!next-token;
4081                redo B;
4082              }
4083            }
4084            
4085            if ($self->{insertion_mode} eq 'after html body') {
4086              !!!parse-error (type => 'after html:#character');
4087    
4088                unless (length $token->{data}) {            ## Reprocess in the "main" phase, "after body" insertion mode...
4089                  !!!next-token;          }
4090                  redo B;          
4091                }          ## "after body" insertion mode
4092              }          !!!parse-error (type => 'after body:#character');
4093                
4094              #          $self->{insertion_mode} = 'in body';
4095              !!!parse-error (type => 'after body:#character');          ## reprocess
4096            } elsif ($token->{type} eq 'start tag') {          redo B;
4097              !!!parse-error (type => 'after body:'.$token->{tag_name});        } elsif ($token->{type} eq 'start tag') {
4098              #          if ($self->{insertion_mode} eq 'after html body') {
4099            } elsif ($token->{type} eq 'end tag') {            !!!parse-error (type => 'after html:'.$token->{tag_name});
4100              if ($token->{tag_name} eq 'html') {            
4101                if (defined $self->{inner_html_node}) {            ## Reprocess in the "main" phase, "after body" insertion mode...
4102                  !!!parse-error (type => 'unmatched end tag:html');          }
4103                  ## Ignore the token  
4104                  !!!next-token;          ## "after body" insertion mode
4105                  redo B;          !!!parse-error (type => 'after body:'.$token->{tag_name});
4106                } else {  
4107                  $previous_insertion_mode = $self->{insertion_mode};          $self->{insertion_mode} = 'in body';
4108                  $self->{insertion_mode} = 'trailing end';          ## reprocess
4109                  !!!next-token;          redo B;
4110                  redo B;        } elsif ($token->{type} eq 'end tag') {
4111                }          if ($self->{insertion_mode} eq 'after html body') {
4112              } else {            !!!parse-error (type => 'after html:/'.$token->{tag_name});
4113                !!!parse-error (type => 'after body:/'.$token->{tag_name});            
4114              }            $self->{insertion_mode} = 'after body';
4115              ## Reprocess in the "main" phase, "after body" insertion mode...
4116            }
4117    
4118            ## "after body" insertion mode
4119            if ($token->{tag_name} eq 'html') {
4120              if (defined $self->{inner_html_node}) {
4121                !!!parse-error (type => 'unmatched end tag:html');
4122                ## Ignore the token
4123                !!!next-token;
4124                redo B;
4125            } else {            } else {
4126              die "$0: $token->{type}: Unknown token type";              $self->{insertion_mode} = 'after html body';
4127                !!!next-token;
4128                redo B;
4129            }            }
4130            } else {
4131              !!!parse-error (type => 'after body:/'.$token->{tag_name});
4132    
4133            $self->{insertion_mode} = 'in body';            $self->{insertion_mode} = 'in body';
4134            ## reprocess            ## reprocess
4135            redo B;            redo B;
4136      } elsif ($self->{insertion_mode} eq 'in frameset') {          }
4137          } else {
4138            die "$0: $token->{type}: Unknown token type";
4139          }
4140        } elsif ($self->{insertion_mode} eq 'in frameset' or
4141                 $self->{insertion_mode} eq 'after frameset' or
4142                 $self->{insertion_mode} eq 'after html frameset') {
4143        if ($token->{type} eq 'character') {        if ($token->{type} eq 'character') {
4144          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4145            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);            $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4146              
4147            unless (length $token->{data}) {            unless (length $token->{data}) {
4148              !!!next-token;              !!!next-token;
4149              redo B;              redo B;
4150            }            }
4151          }          }
4152            
4153            if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
4154              if ($self->{insertion_mode} eq 'in frameset') {
4155                !!!parse-error (type => 'in frameset:#character');
4156              } elsif ($self->{insertion_mode} eq 'after frameset') {
4157                !!!parse-error (type => 'after frameset:#character');
4158              } else { # "after html frameset"
4159                !!!parse-error (type => 'after html:#character');
4160    
4161          !!!parse-error (type => 'in frameset:#character');              $self->{insertion_mode} = 'after frameset';
4162          ## Ignore the token              ## Reprocess in the "main" phase, "after frameset"...
4163          !!!next-token;              !!!parse-error (type => 'after frameset:#character');
4164          redo B;            }
4165              
4166              ## Ignore the token.
4167              if (length $token->{data}) {
4168                ## reprocess the rest of characters
4169              } else {
4170                !!!next-token;
4171              }
4172              redo B;
4173            }
4174            
4175            die qq[$0: Character "$token->{data}"];
4176        } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{type} eq 'start tag') {
4177          if ($token->{tag_name} eq 'frameset') {          if ($self->{insertion_mode} eq 'after html frameset') {
4178              !!!parse-error (type => 'after html:'.$token->{tag_name});
4179    
4180              $self->{insertion_mode} = 'after frameset';
4181              ## Process in the "main" phase, "after frameset" insertion mode...
4182            }
4183    
4184            if ($token->{tag_name} eq 'frameset' and
4185                $self->{insertion_mode} eq 'in frameset') {
4186            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
4187            !!!next-token;            !!!next-token;
4188            redo B;            redo B;
4189          } elsif ($token->{tag_name} eq 'frame') {          } elsif ($token->{tag_name} eq 'frame' and
4190                     $self->{insertion_mode} eq 'in frameset') {
4191            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes});
4192            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4193            !!!next-token;            !!!next-token;
4194            redo B;            redo B;
4195          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
4196            $in_body->($insert_to_current);            ## NOTE: As if in body.
4197              $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
4198            redo B;            redo B;
4199          } else {          } else {
4200            !!!parse-error (type => 'in frameset:'.$token->{tag_name});            if ($self->{insertion_mode} eq 'in frameset') {
4201                !!!parse-error (type => 'in frameset:'.$token->{tag_name});
4202              } else {
4203                !!!parse-error (type => 'after frameset:'.$token->{tag_name});
4204              }
4205            ## Ignore the token            ## Ignore the token
4206            !!!next-token;            !!!next-token;
4207            redo B;            redo B;
4208          }          }
4209        } elsif ($token->{type} eq 'end tag') {        } elsif ($token->{type} eq 'end tag') {
4210          if ($token->{tag_name} eq 'frameset') {          if ($self->{insertion_mode} eq 'after html frameset') {
4211              !!!parse-error (type => 'after html:/'.$token->{tag_name});
4212    
4213              $self->{insertion_mode} = 'after frameset';
4214              ## Process in the "main" phase, "after frameset" insertion mode...
4215            }
4216    
4217            if ($token->{tag_name} eq 'frameset' and
4218                $self->{insertion_mode} eq 'in frameset') {
4219            if ($self->{open_elements}->[-1]->[1] eq 'html' and            if ($self->{open_elements}->[-1]->[1] eq 'html' and
4220                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
4221              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
# Line 5094  sub _tree_construction_main ($) { Line 4231  sub _tree_construction_main ($) {
4231              $self->{insertion_mode} = 'after frameset';              $self->{insertion_mode} = 'after frameset';
4232            }            }
4233            redo B;            redo B;
4234            } elsif ($token->{tag_name} eq 'html' and
4235                     $self->{insertion_mode} eq 'after frameset') {
4236              $self->{insertion_mode} = 'after html frameset';
4237              !!!next-token;
4238              redo B;
4239          } else {          } else {
4240            !!!parse-error (type => 'in frameset:/'.$token->{tag_name});            if ($self->{insertion_mode} eq 'in frameset') {
4241                !!!parse-error (type => 'in frameset:/'.$token->{tag_name});
4242              } else {
4243                !!!parse-error (type => 'after frameset:/'.$token->{tag_name});
4244              }
4245            ## Ignore the token            ## Ignore the token
4246            !!!next-token;            !!!next-token;
4247            redo B;            redo B;
# Line 5103  sub _tree_construction_main ($) { Line 4249  sub _tree_construction_main ($) {
4249        } else {        } else {
4250          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4251        }        }
     } elsif ($self->{insertion_mode} eq 'after frameset') {  
       if ($token->{type} eq 'character') {  
             if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {  
               $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);  
4252    
4253                unless (length $token->{data}) {        ## ISSUE: An issue in spec here
4254                  !!!next-token;      } else {
4255                  redo B;        die "$0: $self->{insertion_mode}: Unknown insertion mode";
4256                }      }
             }  
4257    
4258              if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {      ## "in body" insertion mode
4259                !!!parse-error (type => 'after frameset:#character');      if ($token->{type} eq 'start tag') {
4260          if ($token->{tag_name} eq 'script') {
4261            ## NOTE: This is an "as if in head" code clone
4262            $script_start_tag->($insert);
4263            redo B;
4264          } elsif ($token->{tag_name} eq 'style') {
4265            ## NOTE: This is an "as if in head" code clone
4266            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
4267            redo B;
4268          } elsif ({
4269                    base => 1, link => 1,
4270                   }->{$token->{tag_name}}) {
4271            ## NOTE: This is an "as if in head" code clone, only "-t" differs
4272            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4273            pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4274            !!!next-token;
4275            redo B;
4276          } elsif ($token->{tag_name} eq 'meta') {
4277            ## NOTE: This is an "as if in head" code clone, only "-t" differs
4278            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4279            pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4280    
4281                ## Ignore the token.          unless ($self->{confident}) {
4282                if (length $token->{data}) {            my $charset;
4283                  ## reprocess the rest of characters            if ($token->{attributes}->{charset}) { ## TODO: And if supported
4284                } else {              $charset = $token->{attributes}->{charset}->{value};
4285                  !!!next-token;            }
4286                }            if ($token->{attributes}->{'http-equiv'}) {
4287                redo B;              ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.
4288              }              if ($token->{attributes}->{'http-equiv'}->{value}
4289                    =~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*=
4290                        [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4291                        ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
4292                  $charset = defined $1 ? $1 : defined $2 ? $2 : $3;
4293                } ## TODO: And if supported
4294              }
4295              ## TODO: Change the encoding
4296            }
4297    
4298          die qq[$0: Character "$token->{data}"];          !!!next-token;
4299        } elsif ($token->{type} eq 'start tag') {          redo B;
4300          if ($token->{tag_name} eq 'noframes') {        } elsif ($token->{tag_name} eq 'title') {
4301            $in_body->($insert_to_current);          !!!parse-error (type => 'in body:title');
4302            redo B;          ## NOTE: This is an "as if in head" code clone
4303          } else {          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {
4304            !!!parse-error (type => 'after frameset:'.$token->{tag_name});            if (defined $self->{head_element}) {
4305                $self->{head_element}->append_child ($_[0]);
4306              } else {
4307                $insert->($_[0]);
4308              }
4309            });
4310            redo B;
4311          } elsif ($token->{tag_name} eq 'body') {
4312            !!!parse-error (type => 'in body:body');
4313                  
4314            if (@{$self->{open_elements}} == 1 or
4315                $self->{open_elements}->[1]->[1] ne 'body') {
4316            ## Ignore the token            ## Ignore the token
4317            } else {
4318              my $body_el = $self->{open_elements}->[1]->[0];
4319              for my $attr_name (keys %{$token->{attributes}}) {
4320                unless ($body_el->has_attribute_ns (undef, $attr_name)) {
4321                  $body_el->set_attribute_ns
4322                    (undef, [undef, $attr_name],
4323                     $token->{attributes}->{$attr_name}->{value});
4324                }
4325              }
4326            }
4327            !!!next-token;
4328            redo B;
4329          } elsif ({
4330                    address => 1, blockquote => 1, center => 1, dir => 1,
4331                    div => 1, dl => 1, fieldset => 1, listing => 1,
4332                    menu => 1, ol => 1, p => 1, ul => 1,
4333                    pre => 1,
4334                   }->{$token->{tag_name}}) {
4335            ## has a p element in scope
4336            INSCOPE: for (reverse @{$self->{open_elements}}) {
4337              if ($_->[1] eq 'p') {
4338                !!!back-token;
4339                $token = {type => 'end tag', tag_name => 'p'};
4340                redo B;
4341              } elsif ({
4342                        table => 1, caption => 1, td => 1, th => 1,
4343                        button => 1, marquee => 1, object => 1, html => 1,
4344                       }->{$_->[1]}) {
4345                last INSCOPE;
4346              }
4347            } # INSCOPE
4348              
4349            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4350            if ($token->{tag_name} eq 'pre') {
4351              !!!next-token;
4352              if ($token->{type} eq 'character') {
4353                $token->{data} =~ s/^\x0A//;
4354                unless (length $token->{data}) {
4355                  !!!next-token;
4356                }
4357              }
4358            } else {
4359            !!!next-token;            !!!next-token;
           redo B;  
4360          }          }
4361        } elsif ($token->{type} eq 'end tag') {          redo B;
4362          if ($token->{tag_name} eq 'html') {        } elsif ($token->{tag_name} eq 'form') {
4363            $previous_insertion_mode = $self->{insertion_mode};          if (defined $self->{form_element}) {
4364            $self->{insertion_mode} = 'trailing end';            !!!parse-error (type => 'in form:form');
4365              ## Ignore the token
4366            !!!next-token;            !!!next-token;
4367            redo B;            redo B;
4368          } else {          } else {
4369            !!!parse-error (type => 'after frameset:/'.$token->{tag_name});            ## has a p element in scope
4370            ## Ignore the token            INSCOPE: for (reverse @{$self->{open_elements}}) {
4371                if ($_->[1] eq 'p') {
4372                  !!!back-token;
4373                  $token = {type => 'end tag', tag_name => 'p'};
4374                  redo B;
4375                } elsif ({
4376                          table => 1, caption => 1, td => 1, th => 1,
4377                          button => 1, marquee => 1, object => 1, html => 1,
4378                         }->{$_->[1]}) {
4379                  last INSCOPE;
4380                }
4381              } # INSCOPE
4382                
4383              !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4384              $self->{form_element} = $self->{open_elements}->[-1]->[0];
4385            !!!next-token;            !!!next-token;
4386            redo B;            redo B;
4387          }          }
4388        } else {        } elsif ($token->{tag_name} eq 'li') {
4389          die "$0: $token->{type}: Unknown token type";          ## has a p element in scope
4390        }          INSCOPE: for (reverse @{$self->{open_elements}}) {
4391              if ($_->[1] eq 'p') {
4392                !!!back-token;
4393                $token = {type => 'end tag', tag_name => 'p'};
4394                redo B;
4395              } elsif ({
4396                        table => 1, caption => 1, td => 1, th => 1,
4397                        button => 1, marquee => 1, object => 1, html => 1,
4398                       }->{$_->[1]}) {
4399                last INSCOPE;
4400              }
4401            } # INSCOPE
4402              
4403            ## Step 1
4404            my $i = -1;
4405            my $node = $self->{open_elements}->[$i];
4406            LI: {
4407              ## Step 2
4408              if ($node->[1] eq 'li') {
4409                if ($i != -1) {
4410                  !!!parse-error (type => 'end tag missing:'.
4411                                  $self->{open_elements}->[-1]->[1]);
4412                }
4413                splice @{$self->{open_elements}}, $i;
4414                last LI;
4415              }
4416              
4417              ## Step 3
4418              if (not $formatting_category->{$node->[1]} and
4419                  #not $phrasing_category->{$node->[1]} and
4420                  ($special_category->{$node->[1]} or
4421                   $scoping_category->{$node->[1]}) and
4422                  $node->[1] ne 'address' and $node->[1] ne 'div') {
4423                last LI;
4424              }
4425              
4426              ## Step 4
4427              $i--;
4428              $node = $self->{open_elements}->[$i];
4429              redo LI;
4430            } # LI
4431              
4432            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4433            !!!next-token;
4434            redo B;
4435          } elsif ($token->{tag_name} eq 'dd' or $token->{tag_name} eq 'dt') {
4436            ## has a p element in scope
4437            INSCOPE: for (reverse @{$self->{open_elements}}) {
4438              if ($_->[1] eq 'p') {
4439                !!!back-token;
4440                $token = {type => 'end tag', tag_name => 'p'};
4441                redo B;
4442              } elsif ({
4443                        table => 1, caption => 1, td => 1, th => 1,
4444                        button => 1, marquee => 1, object => 1, html => 1,
4445                       }->{$_->[1]}) {
4446                last INSCOPE;
4447              }
4448            } # INSCOPE
4449              
4450            ## Step 1
4451            my $i = -1;
4452            my $node = $self->{open_elements}->[$i];
4453            LI: {
4454              ## Step 2
4455              if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {
4456                if ($i != -1) {
4457                  !!!parse-error (type => 'end tag missing:'.
4458                                  $self->{open_elements}->[-1]->[1]);
4459                }
4460                splice @{$self->{open_elements}}, $i;
4461                last LI;
4462              }
4463              
4464              ## Step 3
4465              if (not $formatting_category->{$node->[1]} and
4466                  #not $phrasing_category->{$node->[1]} and
4467                  ($special_category->{$node->[1]} or
4468                   $scoping_category->{$node->[1]}) and
4469                  $node->[1] ne 'address' and $node->[1] ne 'div') {
4470                last LI;
4471              }
4472              
4473              ## Step 4
4474              $i--;
4475              $node = $self->{open_elements}->[$i];
4476              redo LI;
4477            } # LI
4478              
4479            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4480            !!!next-token;
4481            redo B;
4482          } elsif ($token->{tag_name} eq 'plaintext') {
4483            ## has a p element in scope
4484            INSCOPE: for (reverse @{$self->{open_elements}}) {
4485              if ($_->[1] eq 'p') {
4486                !!!back-token;
4487                $token = {type => 'end tag', tag_name => 'p'};
4488                redo B;
4489              } elsif ({
4490                        table => 1, caption => 1, td => 1, th => 1,
4491                        button => 1, marquee => 1, object => 1, html => 1,
4492                       }->{$_->[1]}) {
4493                last INSCOPE;
4494              }
4495            } # INSCOPE
4496              
4497            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4498              
4499            $self->{content_model} = PLAINTEXT_CONTENT_MODEL;
4500              
4501            !!!next-token;
4502            redo B;
4503          } elsif ({
4504                    h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
4505                   }->{$token->{tag_name}}) {
4506            ## has a p element in scope
4507            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4508              my $node = $self->{open_elements}->[$_];
4509              if ($node->[1] eq 'p') {
4510                !!!back-token;
4511                $token = {type => 'end tag', tag_name => 'p'};
4512                redo B;
4513              } elsif ({
4514                        table => 1, caption => 1, td => 1, th => 1,
4515                        button => 1, marquee => 1, object => 1, html => 1,
4516                       }->{$node->[1]}) {
4517                last INSCOPE;
4518              }
4519            } # INSCOPE
4520              
4521            ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>
4522            ## has an element in scope
4523            #my $i;
4524            #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4525            #  my $node = $self->{open_elements}->[$_];
4526            #  if ({
4527            #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
4528            #      }->{$node->[1]}) {
4529            #    $i = $_;
4530            #    last INSCOPE;
4531            #  } elsif ({
4532            #            table => 1, caption => 1, td => 1, th => 1,
4533            #            button => 1, marquee => 1, object => 1, html => 1,
4534            #           }->{$node->[1]}) {
4535            #    last INSCOPE;
4536            #  }
4537            #} # INSCOPE
4538            #  
4539            #if (defined $i) {
4540            #  !!! parse-error (type => 'in hn:hn');
4541            #  splice @{$self->{open_elements}}, $i;
4542            #}
4543              
4544            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4545              
4546            !!!next-token;
4547            redo B;
4548          } elsif ($token->{tag_name} eq 'a') {
4549            AFE: for my $i (reverse 0..$#$active_formatting_elements) {
4550              my $node = $active_formatting_elements->[$i];
4551              if ($node->[1] eq 'a') {
4552                !!!parse-error (type => 'in a:a');
4553                
4554                !!!back-token;
4555                $token = {type => 'end tag', tag_name => 'a'};
4556                $formatting_end_tag->($token->{tag_name});
4557                
4558                AFE2: for (reverse 0..$#$active_formatting_elements) {
4559                  if ($active_formatting_elements->[$_]->[0] eq $node->[0]) {
4560                    splice @$active_formatting_elements, $_, 1;
4561                    last AFE2;
4562                  }
4563                } # AFE2
4564                OE: for (reverse 0..$#{$self->{open_elements}}) {
4565                  if ($self->{open_elements}->[$_]->[0] eq $node->[0]) {
4566                    splice @{$self->{open_elements}}, $_, 1;
4567                    last OE;
4568                  }
4569                } # OE
4570                last AFE;
4571              } elsif ($node->[0] eq '#marker') {
4572                last AFE;
4573              }
4574            } # AFE
4575              
4576            $reconstruct_active_formatting_elements->($insert_to_current);
4577    
4578        ## ISSUE: An issue in spec here          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4579      } elsif ($self->{insertion_mode} eq 'trailing end') {          push @$active_formatting_elements, $self->{open_elements}->[-1];
4580        ## states in the main stage is preserved yet # MUST  
4581                  !!!next-token;
4582        if ($token->{type} eq 'character') {          redo B;
4583          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {        } elsif ({
4584            my $data = $1;                  b => 1, big => 1, em => 1, font => 1, i => 1,
4585            ## As if in the main phase.                  s => 1, small => 1, strile => 1,
4586            ## NOTE: The insertion mode in the main phase                  strong => 1, tt => 1, u => 1,
4587            ## just before the phase has been changed to the trailing                 }->{$token->{tag_name}}) {
4588            ## end phase is either "after body" or "after frameset".          $reconstruct_active_formatting_elements->($insert_to_current);
4589            $reconstruct_active_formatting_elements->($insert_to_current);          
4590            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4591            push @$active_formatting_elements, $self->{open_elements}->[-1];
4592            
4593            !!!next-token;
4594            redo B;
4595          } elsif ($token->{tag_name} eq 'nobr') {
4596            $reconstruct_active_formatting_elements->($insert_to_current);
4597    
4598            ## has a |nobr| element in scope
4599            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4600              my $node = $self->{open_elements}->[$_];
4601              if ($node->[1] eq 'nobr') {
4602                !!!parse-error (type => 'not closed:nobr');
4603                !!!back-token;
4604                $token = {type => 'end tag', tag_name => 'nobr'};
4605                redo B;
4606              } elsif ({
4607                        table => 1, caption => 1, td => 1, th => 1,
4608                        button => 1, marquee => 1, object => 1, html => 1,
4609                       }->{$node->[1]}) {
4610                last INSCOPE;
4611              }
4612            } # INSCOPE
4613            
4614            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4615            push @$active_formatting_elements, $self->{open_elements}->[-1];
4616            
4617            !!!next-token;
4618            redo B;
4619          } elsif ($token->{tag_name} eq 'button') {
4620            ## has a button element in scope
4621            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4622              my $node = $self->{open_elements}->[$_];
4623              if ($node->[1] eq 'button') {
4624                !!!parse-error (type => 'in button:button');
4625                !!!back-token;
4626                $token = {type => 'end tag', tag_name => 'button'};
4627                redo B;
4628              } elsif ({
4629                        table => 1, caption => 1, td => 1, th => 1,
4630                        button => 1, marquee => 1, object => 1, html => 1,
4631                       }->{$node->[1]}) {
4632                last INSCOPE;
4633              }
4634            } # INSCOPE
4635                        
4636            $self->{open_elements}->[-1]->[0]->manakai_append_text ($data);          $reconstruct_active_formatting_elements->($insert_to_current);
4637                        
4638            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4639            push @$active_formatting_elements, ['#marker', ''];
4640    
4641            !!!next-token;
4642            redo B;
4643          } elsif ($token->{tag_name} eq 'marquee' or
4644                   $token->{tag_name} eq 'object') {
4645            $reconstruct_active_formatting_elements->($insert_to_current);
4646            
4647            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4648            push @$active_formatting_elements, ['#marker', ''];
4649            
4650            !!!next-token;
4651            redo B;
4652          } elsif ($token->{tag_name} eq 'xmp') {
4653            $reconstruct_active_formatting_elements->($insert_to_current);
4654            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
4655            redo B;
4656          } elsif ($token->{tag_name} eq 'table') {
4657            ## has a p element in scope
4658            INSCOPE: for (reverse @{$self->{open_elements}}) {
4659              if ($_->[1] eq 'p') {
4660                !!!back-token;
4661                $token = {type => 'end tag', tag_name => 'p'};
4662                redo B;
4663              } elsif ({
4664                        table => 1, caption => 1, td => 1, th => 1,
4665                        button => 1, marquee => 1, object => 1, html => 1,
4666                       }->{$_->[1]}) {
4667                last INSCOPE;
4668              }
4669            } # INSCOPE
4670              
4671            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4672              
4673            $self->{insertion_mode} = 'in table';
4674              
4675            !!!next-token;
4676            redo B;
4677          } elsif ({
4678                    area => 1, basefont => 1, bgsound => 1, br => 1,
4679                    embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,
4680                    image => 1,
4681                   }->{$token->{tag_name}}) {
4682            if ($token->{tag_name} eq 'image') {
4683              !!!parse-error (type => 'image');
4684              $token->{tag_name} = 'img';
4685            }
4686    
4687            ## NOTE: There is an "as if <br>" code clone.
4688            $reconstruct_active_formatting_elements->($insert_to_current);
4689            
4690            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4691            pop @{$self->{open_elements}};
4692            
4693            !!!next-token;
4694            redo B;
4695          } elsif ($token->{tag_name} eq 'hr') {
4696            ## has a p element in scope
4697            INSCOPE: for (reverse @{$self->{open_elements}}) {
4698              if ($_->[1] eq 'p') {
4699                !!!back-token;
4700                $token = {type => 'end tag', tag_name => 'p'};
4701                redo B;
4702              } elsif ({
4703                        table => 1, caption => 1, td => 1, th => 1,
4704                        button => 1, marquee => 1, object => 1, html => 1,
4705                       }->{$_->[1]}) {
4706                last INSCOPE;
4707              }
4708            } # INSCOPE
4709              
4710            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4711            pop @{$self->{open_elements}};
4712              
4713            !!!next-token;
4714            redo B;
4715          } elsif ($token->{tag_name} eq 'input') {
4716            $reconstruct_active_formatting_elements->($insert_to_current);
4717            
4718            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4719            ## TODO: associate with $self->{form_element} if defined
4720            pop @{$self->{open_elements}};
4721            
4722            !!!next-token;
4723            redo B;
4724          } elsif ($token->{tag_name} eq 'isindex') {
4725            !!!parse-error (type => 'isindex');
4726            
4727            if (defined $self->{form_element}) {
4728              ## Ignore the token
4729              !!!next-token;
4730              redo B;
4731            } else {
4732              my $at = $token->{attributes};
4733              my $form_attrs;
4734              $form_attrs->{action} = $at->{action} if $at->{action};
4735              my $prompt_attr = $at->{prompt};
4736              $at->{name} = {name => 'name', value => 'isindex'};
4737              delete $at->{action};
4738              delete $at->{prompt};
4739              my @tokens = (
4740                            {type => 'start tag', tag_name => 'form',
4741                             attributes => $form_attrs},
4742                            {type => 'start tag', tag_name => 'hr'},
4743                            {type => 'start tag', tag_name => 'p'},
4744                            {type => 'start tag', tag_name => 'label'},
4745                           );
4746              if ($prompt_attr) {
4747                push @tokens, {type => 'character', data => $prompt_attr->{value}};
4748              } else {
4749                push @tokens, {type => 'character',
4750                               data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
4751                ## TODO: make this configurable
4752              }
4753              push @tokens,
4754                            {type => 'start tag', tag_name => 'input', attributes => $at},
4755                            #{type => 'character', data => ''}, # SHOULD
4756                            {type => 'end tag', tag_name => 'label'},
4757                            {type => 'end tag', tag_name => 'p'},
4758                            {type => 'start tag', tag_name => 'hr'},
4759                            {type => 'end tag', tag_name => 'form'};
4760              $token = shift @tokens;
4761              !!!back-token (@tokens);
4762              redo B;
4763            }
4764          } elsif ($token->{tag_name} eq 'textarea') {
4765            my $tag_name = $token->{tag_name};
4766            my $el;
4767            !!!create-element ($el, $token->{tag_name}, $token->{attributes});
4768            
4769            ## TODO: $self->{form_element} if defined
4770            $self->{content_model} = RCDATA_CONTENT_MODEL;
4771            delete $self->{escape}; # MUST
4772            
4773            $insert->($el);
4774            
4775            my $text = '';
4776            !!!next-token;
4777            if ($token->{type} eq 'character') {
4778              $token->{data} =~ s/^\x0A//;
4779            unless (length $token->{data}) {            unless (length $token->{data}) {
4780              !!!next-token;              !!!next-token;
             redo B;  
4781            }            }
4782          }          }
4783            while ($token->{type} eq 'character') {
4784              $text .= $token->{data};
4785              !!!next-token;
4786            }
4787            if (length $text) {
4788              $el->manakai_append_text ($text);
4789            }
4790            
4791            $self->{content_model} = PCDATA_CONTENT_MODEL;
4792            
4793            if ($token->{type} eq 'end tag' and
4794                $token->{tag_name} eq $tag_name) {
4795              ## Ignore the token
4796            } else {
4797              !!!parse-error (type => 'in RCDATA:#'.$token->{type});
4798            }
4799            !!!next-token;
4800            redo B;
4801          } elsif ({
4802                    iframe => 1,
4803                    noembed => 1,
4804                    noframes => 1,
4805                    noscript => 0, ## TODO: 1 if scripting is enabled
4806                   }->{$token->{tag_name}}) {
4807            ## NOTE: There are two "as if in body" code clones.
4808            $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
4809            redo B;
4810          } elsif ($token->{tag_name} eq 'select') {
4811            $reconstruct_active_formatting_elements->($insert_to_current);
4812            
4813            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4814            
4815            $self->{insertion_mode} = 'in select';
4816            !!!next-token;
4817            redo B;
4818          } elsif ({
4819                    caption => 1, col => 1, colgroup => 1, frame => 1,
4820                    frameset => 1, head => 1, option => 1, optgroup => 1,
4821                    tbody => 1, td => 1, tfoot => 1, th => 1,
4822                    thead => 1, tr => 1,
4823                   }->{$token->{tag_name}}) {
4824            !!!parse-error (type => 'in body:'.$token->{tag_name});
4825            ## Ignore the token
4826            !!!next-token;
4827            redo B;
4828            
4829            ## ISSUE: An issue on HTML5 new elements in the spec.
4830          } else {
4831            $reconstruct_active_formatting_elements->($insert_to_current);
4832            
4833            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
4834            
4835            !!!next-token;
4836            redo B;
4837          }
4838        } elsif ($token->{type} eq 'end tag') {
4839          if ($token->{tag_name} eq 'body') {
4840            if (@{$self->{open_elements}} > 1 and
4841                $self->{open_elements}->[1]->[1] eq 'body') {
4842              for (@{$self->{open_elements}}) {
4843                unless ({
4844                           dd => 1, dt => 1, li => 1, p => 1, td => 1,
4845                           th => 1, tr => 1, body => 1, html => 1,
4846                         tbody => 1, tfoot => 1, thead => 1,
4847                        }->{$_->[1]}) {
4848                  !!!parse-error (type => 'not closed:'.$_->[1]);
4849                }
4850              }
4851    
4852          !!!parse-error (type => 'after html:#character');            $self->{insertion_mode} = 'after body';
4853          $self->{insertion_mode} = $previous_insertion_mode;            !!!next-token;
4854          ## reprocess            redo B;
4855            } else {
4856              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4857              ## Ignore the token
4858              !!!next-token;
4859              redo B;
4860            }
4861          } elsif ($token->{tag_name} eq 'html') {
4862            if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {
4863              ## ISSUE: There is an issue in the spec.
4864              if ($self->{open_elements}->[-1]->[1] ne 'body') {
4865                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]);
4866              }
4867              $self->{insertion_mode} = 'after body';
4868              ## reprocess
4869              redo B;
4870            } else {
4871              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4872              ## Ignore the token
4873              !!!next-token;
4874              redo B;
4875            }
4876          } elsif ({
4877                    address => 1, blockquote => 1, center => 1, dir => 1,
4878                    div => 1, dl => 1, fieldset => 1, listing => 1,
4879                    menu => 1, ol => 1, pre => 1, ul => 1,
4880                    p => 1,
4881                    dd => 1, dt => 1, li => 1,
4882                    button => 1, marquee => 1, object => 1,
4883                   }->{$token->{tag_name}}) {
4884            ## has an element in scope
4885            my $i;
4886            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4887              my $node = $self->{open_elements}->[$_];
4888              if ($node->[1] eq $token->{tag_name}) {
4889                ## generate implied end tags
4890                if ({
4891                     dd => ($token->{tag_name} ne 'dd'),
4892                     dt => ($token->{tag_name} ne 'dt'),
4893                     li => ($token->{tag_name} ne 'li'),
4894                     p => ($token->{tag_name} ne 'p'),
4895                     td => 1, th => 1, tr => 1,
4896                     tbody => 1, tfoot=> 1, thead => 1,
4897                    }->{$self->{open_elements}->[-1]->[1]}) {
4898                  !!!back-token;
4899                  $token = {type => 'end tag',
4900                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4901                  redo B;
4902                }
4903                $i = $_;
4904                last INSCOPE unless $token->{tag_name} eq 'p';
4905              } elsif ({
4906                        table => 1, caption => 1, td => 1, th => 1,
4907                        button => 1, marquee => 1, object => 1, html => 1,
4908                       }->{$node->[1]}) {
4909                last INSCOPE;
4910              }
4911            } # INSCOPE
4912            
4913            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
4914              if (defined $i) {
4915                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4916              } else {
4917                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4918              }
4919            }
4920            
4921            if (defined $i) {
4922              splice @{$self->{open_elements}}, $i;
4923            } elsif ($token->{tag_name} eq 'p') {
4924              ## As if <p>, then reprocess the current token
4925              my $el;
4926              !!!create-element ($el, 'p');
4927              $insert->($el);
4928            }
4929            $clear_up_to_marker->()
4930              if {
4931                button => 1, marquee => 1, object => 1,
4932              }->{$token->{tag_name}};
4933            !!!next-token;
4934          redo B;          redo B;
4935        } elsif ($token->{type} eq 'start tag') {        } elsif ($token->{tag_name} eq 'form') {
4936          !!!parse-error (type => 'after html:'.$token->{tag_name});          ## has an element in scope
4937          $self->{insertion_mode} = $previous_insertion_mode;          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4938          ## reprocess            my $node = $self->{open_elements}->[$_];
4939              if ($node->[1] eq $token->{tag_name}) {
4940                ## generate implied end tags
4941                if ({
4942                     dd => 1, dt => 1, li => 1, p => 1,
4943                     td => 1, th => 1, tr => 1,
4944                     tbody => 1, tfoot=> 1, thead => 1,
4945                    }->{$self->{open_elements}->[-1]->[1]}) {
4946                  !!!back-token;
4947                  $token = {type => 'end tag',
4948                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4949                  redo B;
4950                }
4951                last INSCOPE;
4952              } elsif ({
4953                        table => 1, caption => 1, td => 1, th => 1,
4954                        button => 1, marquee => 1, object => 1, html => 1,
4955                       }->{$node->[1]}) {
4956                last INSCOPE;
4957              }
4958            } # INSCOPE
4959            
4960            if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {
4961              pop @{$self->{open_elements}};
4962            } else {
4963              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4964            }
4965    
4966            undef $self->{form_element};
4967            !!!next-token;
4968          redo B;          redo B;
4969        } elsif ($token->{type} eq 'end tag') {        } elsif ({
4970          !!!parse-error (type => 'after html:/'.$token->{tag_name});                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
4971          $self->{insertion_mode} = $previous_insertion_mode;                 }->{$token->{tag_name}}) {
4972          ## reprocess          ## has an element in scope
4973            my $i;
4974            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4975              my $node = $self->{open_elements}->[$_];
4976              if ({
4977                   h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
4978                  }->{$node->[1]}) {
4979                ## generate implied end tags
4980                if ({
4981                     dd => 1, dt => 1, li => 1, p => 1,
4982                     td => 1, th => 1, tr => 1,
4983                     tbody => 1, tfoot=> 1, thead => 1,
4984                    }->{$self->{open_elements}->[-1]->[1]}) {
4985                  !!!back-token;
4986                  $token = {type => 'end tag',
4987                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4988                  redo B;
4989                }
4990                $i = $_;
4991                last INSCOPE;
4992              } elsif ({
4993                        table => 1, caption => 1, td => 1, th => 1,
4994                        button => 1, marquee => 1, object => 1, html => 1,
4995                       }->{$node->[1]}) {
4996                last INSCOPE;
4997              }
4998            } # INSCOPE
4999            
5000            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {
5001              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
5002            }
5003            
5004            splice @{$self->{open_elements}}, $i if defined $i;
5005            !!!next-token;
5006            redo B;
5007          } elsif ({
5008                    a => 1,
5009                    b => 1, big => 1, em => 1, font => 1, i => 1,
5010                    nobr => 1, s => 1, small => 1, strile => 1,
5011                    strong => 1, tt => 1, u => 1,
5012                   }->{$token->{tag_name}}) {
5013            $formatting_end_tag->($token->{tag_name});
5014            redo B;
5015          } elsif ($token->{tag_name} eq 'br') {
5016            !!!parse-error (type => 'unmatched end tag:br');
5017    
5018            ## As if <br>
5019            $reconstruct_active_formatting_elements->($insert_to_current);
5020            
5021            my $el;
5022            !!!create-element ($el, 'br');
5023            $insert->($el);
5024            
5025            ## Ignore the token.
5026            !!!next-token;
5027            redo B;
5028          } elsif ({
5029                    caption => 1, col => 1, colgroup => 1, frame => 1,
5030                    frameset => 1, head => 1, option => 1, optgroup => 1,
5031                    tbody => 1, td => 1, tfoot => 1, th => 1,
5032                    thead => 1, tr => 1,
5033                    area => 1, basefont => 1, bgsound => 1,
5034                    embed => 1, hr => 1, iframe => 1, image => 1,
5035                    img => 1, input => 1, isindex => 1, noembed => 1,
5036                    noframes => 1, param => 1, select => 1, spacer => 1,
5037                    table => 1, textarea => 1, wbr => 1,
5038                    noscript => 0, ## TODO: if scripting is enabled
5039                   }->{$token->{tag_name}}) {
5040            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5041            ## Ignore the token
5042            !!!next-token;
5043          redo B;          redo B;
5044            
5045            ## ISSUE: Issue on HTML5 new elements in spec
5046            
5047        } else {        } else {
5048          die "$0: $token->{type}: Unknown token";          ## Step 1
5049            my $node_i = -1;
5050            my $node = $self->{open_elements}->[$node_i];
5051    
5052            ## Step 2
5053            S2: {
5054              if ($node->[1] eq $token->{tag_name}) {
5055                ## Step 1
5056                ## generate implied end tags
5057                if ({
5058                     dd => 1, dt => 1, li => 1, p => 1,
5059                     td => 1, th => 1, tr => 1,
5060                     tbody => 1, tfoot=> 1, thead => 1,
5061                    }->{$self->{open_elements}->[-1]->[1]}) {
5062                  !!!back-token;
5063                  $token = {type => 'end tag',
5064                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
5065                  redo B;
5066                }
5067            
5068                ## Step 2
5069                if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {
5070                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
5071                }
5072                
5073                ## Step 3
5074                splice @{$self->{open_elements}}, $node_i;
5075    
5076                !!!next-token;
5077                last S2;
5078              } else {
5079                ## Step 3
5080                if (not $formatting_category->{$node->[1]} and
5081                    #not $phrasing_category->{$node->[1]} and
5082                    ($special_category->{$node->[1]} or
5083                     $scoping_category->{$node->[1]})) {
5084                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
5085                  ## Ignore the token
5086                  !!!next-token;
5087                  last S2;
5088                }
5089              }
5090              
5091              ## Step 4
5092              $node_i--;
5093              $node = $self->{open_elements}->[$node_i];
5094              
5095              ## Step 5;
5096              redo S2;
5097            } # S2
5098            redo B;
5099        }        }
     } else {  
       die "$0: $self->{insertion_mode}: Unknown insertion mode";  
5100      }      }
5101        redo B;
5102    } # B    } # B
5103    
5104      ## NOTE: The "trailing end" phase in HTML5 is split into
5105      ## two insertion modes: "after html body" and "after html frameset".
5106      ## NOTE: States in the main stage is preserved while
5107      ## the parser stays in the trailing end phase. # MUST
5108    
5109    ## Stop parsing # MUST    ## Stop parsing # MUST
5110        
5111    ## TODO: script stuffs    ## TODO: script stuffs
# Line 5280  sub set_inner_html ($$$) { Line 5190  sub set_inner_html ($$$) {
5190    
5191      ## Step 2      ## Step 2
5192      my $node_ln = $node->local_name;      my $node_ln = $node->local_name;
5193      $p->{content_model_flag} = {      $p->{content_model} = {
5194        title => 'RCDATA',        title => RCDATA_CONTENT_MODEL,
5195        textarea => 'RCDATA',        textarea => RCDATA_CONTENT_MODEL,
5196        style => 'CDATA',        style => CDATA_CONTENT_MODEL,
5197        script => 'CDATA',        script => CDATA_CONTENT_MODEL,
5198        xmp => 'CDATA',        xmp => CDATA_CONTENT_MODEL,
5199        iframe => 'CDATA',        iframe => CDATA_CONTENT_MODEL,
5200        noembed => 'CDATA',        noembed => CDATA_CONTENT_MODEL,
5201        noframes => 'CDATA',        noframes => CDATA_CONTENT_MODEL,
5202        noscript => 'CDATA',        noscript => CDATA_CONTENT_MODEL,
5203        plaintext => 'PLAINTEXT',        plaintext => PLAINTEXT_CONTENT_MODEL,
5204      }->{$node_ln} || 'PCDATA';      }->{$node_ln};
5205         ## ISSUE: What is "the name of the element"? local name?      $p->{content_model} = PCDATA_CONTENT_MODEL
5206            unless defined $p->{content_model};
5207            ## ISSUE: What is "the name of the element"? local name?
5208    
5209      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
5210    

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.53

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24