/[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.42 by wakaba, Sat Jul 21 06:59:16 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 2192  sub _tree_construction_main ($) { Line 2199  sub _tree_construction_main ($) {
2199      $insert->($el); # /context node/->append_child ($el)      $insert->($el); # /context node/->append_child ($el)
2200    
2201      ## Step 3      ## Step 3
2202      $self->{content_model_flag} = $content_model_flag; # CDATA or RCDATA      $self->{content_model} = $content_model_flag; # CDATA or RCDATA
2203      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
2204    
2205      ## Step 4      ## Step 4
# Line 2210  sub _tree_construction_main ($) { Line 2217  sub _tree_construction_main ($) {
2217      }      }
2218    
2219      ## Step 6      ## Step 6
2220      $self->{content_model_flag} = 'PCDATA';      $self->{content_model} = PCDATA_CONTENT_MODEL;
2221    
2222      ## Step 7      ## Step 7
2223      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) {
2224        ## Ignore the token        ## Ignore the token
2225        } elsif ($content_model_flag == CDATA_CONTENT_MODEL) {
2226          !!!parse-error (type => 'in CDATA:#'.$token->{type});
2227        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
2228          !!!parse-error (type => 'in RCDATA:#'.$token->{type});
2229      } else {      } else {
2230        !!!parse-error (type => 'in '.$content_model_flag.':#'.$token->{type});        die "$0: $content_model_flag in parse_rcdata";
2231      }      }
2232      !!!next-token;      !!!next-token;
2233    }; # $parse_rcdata    }; # $parse_rcdata
# Line 2227  sub _tree_construction_main ($) { Line 2238  sub _tree_construction_main ($) {
2238      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2239      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
2240    
2241      $self->{content_model_flag} = 'CDATA';      $self->{content_model} = CDATA_CONTENT_MODEL;
2242      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
2243            
2244      my $text = '';      my $text = '';
# Line 2240  sub _tree_construction_main ($) { Line 2251  sub _tree_construction_main ($) {
2251        $script_el->manakai_append_text ($text);        $script_el->manakai_append_text ($text);
2252      }      }
2253                                
2254      $self->{content_model_flag} = 'PCDATA';      $self->{content_model} = PCDATA_CONTENT_MODEL;
2255    
2256      if ($token->{type} eq 'end tag' and      if ($token->{type} eq 'end tag' and
2257          $token->{tag_name} eq 'script') {          $token->{tag_name} eq 'script') {
# Line 2494  sub _tree_construction_main ($) { Line 2505  sub _tree_construction_main ($) {
2505          return;          return;
2506        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
2507          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
2508          $parse_rcdata->('CDATA', $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
2509          return;          return;
2510        } elsif ({        } elsif ({
2511                  base => 1, link => 1,                  base => 1, link => 1,
# Line 2531  sub _tree_construction_main ($) { Line 2542  sub _tree_construction_main ($) {
2542        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
2543          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
2544          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
2545          $parse_rcdata->('RCDATA', sub {          $parse_rcdata->(RCDATA_CONTENT_MODEL, sub {
2546            if (defined $self->{head_element}) {            if (defined $self->{head_element}) {
2547              $self->{head_element}->append_child ($_[0]);              $self->{head_element}->append_child ($_[0]);
2548            } else {            } else {
# Line 2727  sub _tree_construction_main ($) { Line 2738  sub _tree_construction_main ($) {
2738                        
2739          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2740                        
2741          $self->{content_model_flag} = 'PLAINTEXT';          $self->{content_model} = PLAINTEXT_CONTENT_MODEL;
2742                        
2743          !!!next-token;          !!!next-token;
2744          return;          return;
# Line 2882  sub _tree_construction_main ($) { Line 2893  sub _tree_construction_main ($) {
2893          return;          return;
2894        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
2895          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2896          $parse_rcdata->('CDATA', $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
2897          return;          return;
2898        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
2899          ## has a p element in scope          ## has a p element in scope
# Line 2998  sub _tree_construction_main ($) { Line 3009  sub _tree_construction_main ($) {
3009          !!!create-element ($el, $token->{tag_name}, $token->{attributes});          !!!create-element ($el, $token->{tag_name}, $token->{attributes});
3010                    
3011          ## TODO: $self->{form_element} if defined          ## TODO: $self->{form_element} if defined
3012          $self->{content_model_flag} = 'RCDATA';          $self->{content_model} = RCDATA_CONTENT_MODEL;
3013          delete $self->{escape}; # MUST          delete $self->{escape}; # MUST
3014                    
3015          $insert->($el);          $insert->($el);
# Line 3019  sub _tree_construction_main ($) { Line 3030  sub _tree_construction_main ($) {
3030            $el->manakai_append_text ($text);            $el->manakai_append_text ($text);
3031          }          }
3032                    
3033          $self->{content_model_flag} = 'PCDATA';          $self->{content_model} = PCDATA_CONTENT_MODEL;
3034                    
3035          if ($token->{type} eq 'end tag' and          if ($token->{type} eq 'end tag' and
3036              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
# Line 3035  sub _tree_construction_main ($) { Line 3046  sub _tree_construction_main ($) {
3046                  noframes => 1,                  noframes => 1,
3047                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
3048                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
3049          $parse_rcdata->('CDATA', $insert);          $parse_rcdata->(CDATA_CONTENT_MODEL, $insert);
3050          return;          return;
3051        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
3052          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 3519  sub _tree_construction_main ($) { Line 3530  sub _tree_construction_main ($) {
3530                }                }
3531                my $parent = defined $self->{head_element} ? $self->{head_element}                my $parent = defined $self->{head_element} ? $self->{head_element}
3532                    : $self->{open_elements}->[-1]->[0];                    : $self->{open_elements}->[-1]->[0];
3533                $parse_rcdata->('RCDATA', sub { $parent->append_child ($_[0]) });                $parse_rcdata->(RCDATA_CONTENT_MODEL,
3534                                  sub { $parent->append_child ($_[0]) });
3535                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3536                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
3537                redo B;                redo B;
# Line 3531  sub _tree_construction_main ($) { Line 3543  sub _tree_construction_main ($) {
3543                  !!!parse-error (type => 'after head:'.$token->{tag_name});                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3544                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3545                }                }
3546                $parse_rcdata->('CDATA', $insert_to_current);                $parse_rcdata->(CDATA_CONTENT_MODEL, $insert_to_current);
3547                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
3548                    if $self->{insertion_mode} eq 'after head';                    if $self->{insertion_mode} eq 'after head';
3549                redo B;                redo B;
# Line 3545  sub _tree_construction_main ($) { Line 3557  sub _tree_construction_main ($) {
3557                } elsif ($self->{insertion_mode} eq 'in head noscript') {                } elsif ($self->{insertion_mode} eq 'in head noscript') {
3558                  !!!parse-error (type => 'in noscript:noscript');                  !!!parse-error (type => 'in noscript:noscript');
3559                  ## Ignore the token                  ## Ignore the token
3560                    !!!next-token;
3561                  redo B;                  redo B;
3562                } else {                } else {
3563                  #                  #
# Line 3633  sub _tree_construction_main ($) { Line 3646  sub _tree_construction_main ($) {
3646            redo B;            redo B;
3647    
3648            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
3649          } elsif ($self->{insertion_mode} eq 'in body') {          } elsif ($self->{insertion_mode} eq 'in body' or
3650                     $self->{insertion_mode} eq 'in caption') {
3651            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3652              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
3653              $reconstruct_active_formatting_elements->($insert_to_current);              $reconstruct_active_formatting_elements->($insert_to_current);
# Line 3642  sub _tree_construction_main ($) { Line 3656  sub _tree_construction_main ($) {
3656    
3657              !!!next-token;              !!!next-token;
3658              redo B;              redo B;
           } else {  
             $in_body->($insert_to_current);  
             redo B;  
           }  
         } elsif ($self->{insertion_mode} eq 'in table') {  
           if ($token->{type} eq 'character') {  
             ## NOTE: There are "character in table" code clones.  
             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,  
                 }->{$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});  
               } 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;  
3659            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3660              if ({              if ({
3661                   caption => 1,                   caption => 1, col => 1, colgroup => 1, tbody => 1,
3662                   colgroup => 1,                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,
3663                   tbody => 1, tfoot => 1, thead => 1,                  }->{$token->{tag_name}} and
3664                  }->{$token->{tag_name}}) {                  $self->{insertion_mode} eq 'in caption') {
3665                ## Clear back to table context                !!!parse-error (type => 'not closed:caption');
               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]);  
                 pop @{$self->{open_elements}};  
               }  
   
               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;  
             } elsif ({  
                       col => 1,  
                       td => 1, th => 1, tr => 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]);  
                 pop @{$self->{open_elements}};  
               }  
   
               !!!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]);  
3666    
3667                ## As if </table>                ## As if </caption>
3668                ## have a table element in table scope                ## have a table element in table scope
3669                my $i;                my $i;
3670                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3671                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
3672                  if ($node->[1] eq 'table') {                  if ($node->[1] eq 'caption') {
3673                    $i = $_;                    $i = $_;
3674                    last INSCOPE;                    last INSCOPE;
3675                  } elsif ({                  } elsif ({
# Line 3766  sub _tree_construction_main ($) { Line 3679  sub _tree_construction_main ($) {
3679                  }                  }
3680                } # INSCOPE                } # INSCOPE
3681                unless (defined $i) {                unless (defined $i) {
3682                  !!!parse-error (type => 'unmatched end tag:table');                  !!!parse-error (type => 'unmatched end tag:caption');
3683                  ## Ignore tokens </table><table>                  ## Ignore the token
3684                  !!!next-token;                  !!!next-token;
3685                  redo B;                  redo B;
3686                }                }
# Line 3778  sub _tree_construction_main ($) { Line 3691  sub _tree_construction_main ($) {
3691                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3692                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3693                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3694                  !!!back-token; # <table>                  !!!back-token; # <?>
3695                  $token = {type => 'end tag', tag_name => 'table'};                  $token = {type => 'end tag', tag_name => 'caption'};
3696                  !!!back-token;                  !!!back-token;
3697                  $token = {type => 'end tag',                  $token = {type => 'end tag',
3698                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3699                  redo B;                  redo B;
3700                }                }
3701    
3702                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3703                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3704                }                }
3705    
3706                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
3707    
3708                $self->_reset_insertion_mode;                $clear_up_to_marker->();
3709    
3710                  $self->{insertion_mode} = 'in table';
3711    
3712                ## reprocess                ## reprocess
3713                redo B;                redo B;
# Line 3800  sub _tree_construction_main ($) { Line 3715  sub _tree_construction_main ($) {
3715                #                #
3716              }              }
3717            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3718              if ($token->{tag_name} eq 'table') {              if ($token->{tag_name} eq 'caption' and
3719                    $self->{insertion_mode} eq 'in caption') {
3720                ## have a table element in table scope                ## have a table element in table scope
3721                my $i;                my $i;
3722                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 3833  sub _tree_construction_main ($) { Line 3749  sub _tree_construction_main ($) {
3749                  redo B;                  redo B;
3750                }                }
3751    
3752                if ($self->{open_elements}->[-1]->[1] ne 'table') {                if ($self->{open_elements}->[-1]->[1] ne 'caption') {
3753                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3754                }                }
3755    
3756                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
3757    
3758                $self->_reset_insertion_mode;                $clear_up_to_marker->();
3759    
3760                  $self->{insertion_mode} = 'in table';
3761    
3762                !!!next-token;                !!!next-token;
3763                redo B;                redo B;
3764              } elsif ({              } elsif ($token->{tag_name} eq 'table' and
3765                        body => 1, caption => 1, col => 1, colgroup => 1,                       $self->{insertion_mode} eq 'in caption') {
                       html => 1, tbody => 1, td => 1, tfoot => 1, th => 1,  
                       thead => 1, tr => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});  
               ## Ignore the token  
               !!!next-token;  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
           }  
   
           !!!parse-error (type => 'in table:'.$token->{tag_name});  
           $in_body->($insert_to_foster);  
           redo B;  
         } elsif ($self->{insertion_mode} eq 'in caption') {  
           if ($token->{type} eq 'character') {  
             ## NOTE: This is a code clone of "character in body".  
             $reconstruct_active_formatting_elements->($insert_to_current);  
               
             $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});  
   
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ({  
                  caption => 1, col => 1, colgroup => 1, tbody => 1,  
                  td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,  
                 }->{$token->{tag_name}}) {  
3766                !!!parse-error (type => 'not closed:caption');                !!!parse-error (type => 'not closed:caption');
3767    
3768                ## As if </caption>                ## As if </caption>
# Line 3905  sub _tree_construction_main ($) { Line 3792  sub _tree_construction_main ($) {
3792                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3793                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3794                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3795                  !!!back-token; # <?>                  !!!back-token; # </table>
3796                  $token = {type => 'end tag', tag_name => 'caption'};                  $token = {type => 'end tag', tag_name => 'caption'};
3797                  !!!back-token;                  !!!back-token;
3798                  $token = {type => 'end tag',                  $token = {type => 'end tag',
# Line 3925  sub _tree_construction_main ($) { Line 3812  sub _tree_construction_main ($) {
3812    
3813                ## reprocess                ## reprocess
3814                redo B;                redo B;
3815                } elsif ({
3816                          body => 1, col => 1, colgroup => 1,
3817                          html => 1, tbody => 1, td => 1, tfoot => 1,
3818                          th => 1, thead => 1, tr => 1,
3819                         }->{$token->{tag_name}} and
3820                         $self->{insertion_mode} eq 'in caption') {
3821                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3822                  ## Ignore the token
3823                  !!!next-token;
3824                  redo B;
3825              } else {              } else {
3826                #                #
3827              }              }
3828            } elsif ($token->{type} eq 'end tag') {            } else {
3829              if ($token->{tag_name} eq 'caption') {              #
3830              }
3831    
3832              $in_body->($insert_to_current);
3833              redo B;
3834            } elsif ($self->{insertion_mode} eq 'in table') {
3835              if ($token->{type} eq 'character') {
3836                ## NOTE: There are "character in table" code clones.
3837                if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3838                  $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
3839                  
3840                  unless (length $token->{data}) {
3841                    !!!next-token;
3842                    redo B;
3843                  }
3844                }
3845    
3846                !!!parse-error (type => 'in table:#character');
3847    
3848                ## As if in body, but insert into foster parent element
3849                ## ISSUE: Spec says that "whenever a node would be inserted
3850                ## into the current node" while characters might not be
3851                ## result in a new Text node.
3852                $reconstruct_active_formatting_elements->($insert_to_foster);
3853                
3854                if ({
3855                     table => 1, tbody => 1, tfoot => 1,
3856                     thead => 1, tr => 1,
3857                    }->{$self->{open_elements}->[-1]->[1]}) {
3858                  # MUST
3859                  my $foster_parent_element;
3860                  my $next_sibling;
3861                  my $prev_sibling;
3862                  OE: for (reverse 0..$#{$self->{open_elements}}) {
3863                    if ($self->{open_elements}->[$_]->[1] eq 'table') {
3864                      my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3865                      if (defined $parent and $parent->node_type == 1) {
3866                        $foster_parent_element = $parent;
3867                        $next_sibling = $self->{open_elements}->[$_]->[0];
3868                        $prev_sibling = $next_sibling->previous_sibling;
3869                      } else {
3870                        $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
3871                        $prev_sibling = $foster_parent_element->last_child;
3872                      }
3873                      last OE;
3874                    }
3875                  } # OE
3876                  $foster_parent_element = $self->{open_elements}->[0]->[0] and
3877                  $prev_sibling = $foster_parent_element->last_child
3878                    unless defined $foster_parent_element;
3879                  if (defined $prev_sibling and
3880                      $prev_sibling->node_type == 3) {
3881                    $prev_sibling->manakai_append_text ($token->{data});
3882                  } else {
3883                    $foster_parent_element->insert_before
3884                      ($self->{document}->create_text_node ($token->{data}),
3885                       $next_sibling);
3886                  }
3887                } else {
3888                  $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
3889                }
3890                
3891                !!!next-token;
3892                redo B;
3893              } elsif ($token->{type} eq 'start tag') {
3894                if ({
3895                     caption => 1,
3896                     colgroup => 1,
3897                     tbody => 1, tfoot => 1, thead => 1,
3898                    }->{$token->{tag_name}}) {
3899                  ## Clear back to table context
3900                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
3901                         $self->{open_elements}->[-1]->[1] ne 'html') {
3902                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3903                    pop @{$self->{open_elements}};
3904                  }
3905    
3906                  push @$active_formatting_elements, ['#marker', '']
3907                    if $token->{tag_name} eq 'caption';
3908    
3909                  !!!insert-element ($token->{tag_name}, $token->{attributes});
3910                  $self->{insertion_mode} = {
3911                                     caption => 'in caption',
3912                                     colgroup => 'in column group',
3913                                     tbody => 'in table body',
3914                                     tfoot => 'in table body',
3915                                     thead => 'in table body',
3916                                    }->{$token->{tag_name}};
3917                  !!!next-token;
3918                  redo B;
3919                } elsif ({
3920                          col => 1,
3921                          td => 1, th => 1, tr => 1,
3922                         }->{$token->{tag_name}}) {
3923                  ## Clear back to table context
3924                  while ($self->{open_elements}->[-1]->[1] ne 'table' and
3925                         $self->{open_elements}->[-1]->[1] ne 'html') {
3926                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3927                    pop @{$self->{open_elements}};
3928                  }
3929    
3930                  !!!insert-element ($token->{tag_name} eq 'col' ? 'colgroup' : 'tbody');
3931                  $self->{insertion_mode} = $token->{tag_name} eq 'col'
3932                    ? 'in column group' : 'in table body';
3933                  ## reprocess
3934                  redo B;
3935                } elsif ($token->{tag_name} eq 'table') {
3936                  ## NOTE: There are code clones for this "table in table"
3937                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3938    
3939                  ## As if </table>
3940                ## have a table element in table scope                ## have a table element in table scope
3941                my $i;                my $i;
3942                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3943                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
3944                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] eq 'table') {
3945                    $i = $_;                    $i = $_;
3946                    last INSCOPE;                    last INSCOPE;
3947                  } elsif ({                  } elsif ({
# Line 3944  sub _tree_construction_main ($) { Line 3951  sub _tree_construction_main ($) {
3951                  }                  }
3952                } # INSCOPE                } # INSCOPE
3953                unless (defined $i) {                unless (defined $i) {
3954                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                  !!!parse-error (type => 'unmatched end tag:table');
3955                  ## Ignore the token                  ## Ignore tokens </table><table>
3956                  !!!next-token;                  !!!next-token;
3957                  redo B;                  redo B;
3958                }                }
# Line 3956  sub _tree_construction_main ($) { Line 3963  sub _tree_construction_main ($) {
3963                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
3964                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
3965                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
3966                    !!!back-token; # <table>
3967                    $token = {type => 'end tag', tag_name => 'table'};
3968                  !!!back-token;                  !!!back-token;
3969                  $token = {type => 'end tag',                  $token = {type => 'end tag',
3970                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3971                  redo B;                  redo B;
3972                }                }
3973    
3974                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
3975                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3976                }                }
3977    
3978                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
3979    
3980                $clear_up_to_marker->();                $self->_reset_insertion_mode;
   
               $self->{insertion_mode} = 'in table';  
3981    
3982                !!!next-token;                ## reprocess
3983                redo B;                redo B;
3984              } elsif ($token->{tag_name} eq 'table') {              } else {
3985                !!!parse-error (type => 'not closed:caption');                #
3986                }
3987                ## As if </caption>            } elsif ($token->{type} eq 'end tag') {
3988                if ($token->{tag_name} eq 'table') {
3989                ## have a table element in table scope                ## have a table element in table scope
3990                my $i;                my $i;
3991                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3992                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
3993                  if ($node->[1] eq 'caption') {                  if ($node->[1] eq $token->{tag_name}) {
3994                    $i = $_;                    $i = $_;
3995                    last INSCOPE;                    last INSCOPE;
3996                  } elsif ({                  } elsif ({
# Line 3992  sub _tree_construction_main ($) { Line 4000  sub _tree_construction_main ($) {
4000                  }                  }
4001                } # INSCOPE                } # INSCOPE
4002                unless (defined $i) {                unless (defined $i) {
4003                  !!!parse-error (type => 'unmatched end tag:caption');                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4004                  ## Ignore the token                  ## Ignore the token
4005                  !!!next-token;                  !!!next-token;
4006                  redo B;                  redo B;
# Line 4004  sub _tree_construction_main ($) { Line 4012  sub _tree_construction_main ($) {
4012                     td => 1, th => 1, tr => 1,                     td => 1, th => 1, tr => 1,
4013                     tbody => 1, tfoot=> 1, thead => 1,                     tbody => 1, tfoot=> 1, thead => 1,
4014                    }->{$self->{open_elements}->[-1]->[1]}) {                    }->{$self->{open_elements}->[-1]->[1]}) {
                 !!!back-token; # </table>  
                 $token = {type => 'end tag', tag_name => 'caption'};  
4015                  !!!back-token;                  !!!back-token;
4016                  $token = {type => 'end tag',                  $token = {type => 'end tag',
4017                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
4018                  redo B;                  redo B;
4019                }                }
4020    
4021                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                if ($self->{open_elements}->[-1]->[1] ne 'table') {
4022                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
4023                }                }
4024    
4025                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
4026    
4027                $clear_up_to_marker->();                $self->_reset_insertion_mode;
   
               $self->{insertion_mode} = 'in table';  
4028    
4029                ## reprocess                !!!next-token;
4030                redo B;                redo B;
4031              } elsif ({              } elsif ({
4032                        body => 1, col => 1, colgroup => 1,                        body => 1, caption => 1, col => 1, colgroup => 1,
4033                        html => 1, tbody => 1, td => 1, tfoot => 1,                        html => 1, tbody => 1, td => 1, tfoot => 1, th => 1,
4034                        th => 1, thead => 1, tr => 1,                        thead => 1, tr => 1,
4035                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4036                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
4037                ## Ignore the token                ## Ignore the token
4038                  !!!next-token;
4039                redo B;                redo B;
4040              } else {              } else {
4041                #                #
# Line 4038  sub _tree_construction_main ($) { Line 4043  sub _tree_construction_main ($) {
4043            } else {            } else {
4044              #              #
4045            }            }
4046                  
4047            $in_body->($insert_to_current);            !!!parse-error (type => 'in table:'.$token->{tag_name});
4048              $in_body->($insert_to_foster);
4049            redo B;            redo B;
4050          } elsif ($self->{insertion_mode} eq 'in column group') {          } elsif ($self->{insertion_mode} eq 'in column group') {
4051            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
# Line 5280  sub set_inner_html ($$$) { Line 5286  sub set_inner_html ($$$) {
5286    
5287      ## Step 2      ## Step 2
5288      my $node_ln = $node->local_name;      my $node_ln = $node->local_name;
5289      $p->{content_model_flag} = {      $p->{content_model} = {
5290        title => 'RCDATA',        title => RCDATA_CONTENT_MODEL,
5291        textarea => 'RCDATA',        textarea => RCDATA_CONTENT_MODEL,
5292        style => 'CDATA',        style => CDATA_CONTENT_MODEL,
5293        script => 'CDATA',        script => CDATA_CONTENT_MODEL,
5294        xmp => 'CDATA',        xmp => CDATA_CONTENT_MODEL,
5295        iframe => 'CDATA',        iframe => CDATA_CONTENT_MODEL,
5296        noembed => 'CDATA',        noembed => CDATA_CONTENT_MODEL,
5297        noframes => 'CDATA',        noframes => CDATA_CONTENT_MODEL,
5298        noscript => 'CDATA',        noscript => CDATA_CONTENT_MODEL,
5299        plaintext => 'PLAINTEXT',        plaintext => PLAINTEXT_CONTENT_MODEL,
5300      }->{$node_ln} || 'PCDATA';      }->{$node_ln};
5301         ## ISSUE: What is "the name of the element"? local name?      $p->{content_model} = PCDATA_CONTENT_MODEL
5302            unless defined $p->{content_model};
5303            ## ISSUE: What is "the name of the element"? local name?
5304    
5305      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $node_ln];
5306    

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24