/[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.220 by wakaba, Sun Jul 26 09:11:18 2009 UTC revision 1.228 by wakaba, Sun Aug 16 06:47:59 2009 UTC
# Line 911  sub _tree_construction_initial ($) { Line 911  sub _tree_construction_initial ($) {
911    
912    INITIAL: {    INITIAL: {
913      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
914        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"        ## NOTE: Conformance checkers MAY, instead of reporting "not
915        ## error, switch to a conformance checking mode for another        ## HTML5" error, switch to a conformance checking mode for
916        ## language.        ## another language.  (We don't support such mode switchings; it
917          ## is nonsense to do anything different from what browsers do.)
918        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
919        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
920        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive        my $doctype = $self->{document}->create_document_type_definition
921        if (not defined $token->{name} or # <!DOCTYPE>            ($doctype_name);
922            defined $token->{sysid}) {  
923          $doctype_name =~ tr/A-Z/a-z/; # ASCII case-insensitive
924          if ($doctype_name ne 'html') {
925          !!!cp ('t1');          !!!cp ('t1');
926          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
927        } elsif ($doctype_name ne 'HTML') {        } elsif (defined $token->{pubid}) {
928          !!!cp ('t2');          !!!cp ('t2');
929            ## XXX Obsolete permitted DOCTYPEs
930          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
931        } elsif (defined $token->{pubid}) {        } elsif (defined $token->{sysid}) {
932          if ($token->{pubid} eq 'XSLT-compat') {          if ($token->{sysid} eq 'about:legacy-compat') {
933            !!!cp ('t1.2');            !!!cp ('t1.2'); ## <!DOCTYPE HTML SYSTEM "about:legacy-compat">
934            !!!parse-error (type => 'XSLT-compat', token => $token,            !!!parse-error (type => 'XSLT-compat', token => $token,
935                            level => $self->{level}->{should});                            level => $self->{level}->{should});
936          } else {          } else {
937            !!!parse-error (type => 'not HTML5', token => $token);            !!!parse-error (type => 'not HTML5', token => $token);
938          }          }
939        } else {        } else { ## <!DOCTYPE HTML>
940          !!!cp ('t3');          !!!cp ('t3');
941          #          #
942        }        }
943                
       my $doctype = $self->{document}->create_document_type_definition  
         ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?  
944        ## NOTE: Default value for both |public_id| and |system_id| attributes        ## NOTE: Default value for both |public_id| and |system_id| attributes
945        ## are empty strings, so that we don't set any value in missing cases.        ## are empty strings, so that we don't set any value in missing cases.
946        $doctype->public_id ($token->{pubid}) if defined $token->{pubid};        $doctype->public_id ($token->{pubid}) if defined $token->{pubid};
947        $doctype->system_id ($token->{sysid}) if defined $token->{sysid};        $doctype->system_id ($token->{sysid}) if defined $token->{sysid};
948    
949        ## NOTE: Other DocumentType attributes are null or empty lists.        ## NOTE: Other DocumentType attributes are null or empty lists.
950        ## In Firefox3, |internalSubset| attribute is set to the empty        ## In Firefox3, |internalSubset| attribute is set to the empty
951        ## string, while |null| is an allowed value for the attribute        ## string, while |null| is an allowed value for the attribute
952        ## according to DOM3 Core.        ## according to DOM3 Core.
953        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
954                
955        if ($token->{quirks} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'html') {
956          !!!cp ('t4');          !!!cp ('t4');
957          $self->{document}->manakai_compat_mode ('quirks');          $self->{document}->manakai_compat_mode ('quirks');
958        } elsif (defined $token->{pubid}) {        } elsif (defined $token->{pubid}) {
# Line 1419  sub _tree_construction_main ($) { Line 1422  sub _tree_construction_main ($) {
1422      ## Step 3      ## Step 3
1423      ## TODO: Mark as "already executed", if ...      ## TODO: Mark as "already executed", if ...
1424    
1425      ## Step 4      ## Step 4 (HTML5 revision 2702)
1426      $insert->($script_el);      $insert->($script_el);
   
     ## ISSUE: $script_el is not put into the stack  
1427      push @{$self->{open_elements}}, [$script_el, $el_category->{script}];      push @{$self->{open_elements}}, [$script_el, $el_category->{script}];
1428    
1429      ## Step 5      ## Step 5
# Line 1874  sub _tree_construction_main ($) { Line 1875  sub _tree_construction_main ($) {
1875          } elsif ({          } elsif ({
1876                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
1877                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
1878                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,                    em => 1, embed => 1, h1 => 1, h2 => 1, h3 => 1,
1879                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
1880                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
1881                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
1882                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
1883                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
1884                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}} or
1885                     ($token->{tag_name} eq 'font' and
1886                      ($token->{attributes}->{color} or
1887                       $token->{attributes}->{face} or
1888                       $token->{attributes}->{size}))) {
1889            !!!cp ('t87.2');            !!!cp ('t87.2');
1890            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
1891                            text => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
# Line 2263  sub _tree_construction_main ($) { Line 2268  sub _tree_construction_main ($) {
2268    
2269            ## NOTE: There is a "as if in head" code clone.            ## NOTE: There is a "as if in head" code clone.
2270            $parse_rcdata->(RCDATA_CONTENT_MODEL);            $parse_rcdata->(RCDATA_CONTENT_MODEL);
2271            ## ISSUE: A spec bug [Bug 6038]  
2272              ## NOTE: At this point the stack of open elements contain
2273              ## the |head| element (index == -2) and the |script| element
2274              ## (index == -1).  In the "after head" insertion mode the
2275              ## |head| element is inserted only for the purpose of
2276              ## providing the context for the |script| element, and
2277              ## therefore we can now and have to remove the element from
2278              ## the stack.
2279            splice @{$self->{open_elements}}, -2, 1, () # <head>            splice @{$self->{open_elements}}, -2, 1, () # <head>
2280                if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM;                if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM;
2281            next B;            next B;
# Line 2498  sub _tree_construction_main ($) { Line 2510  sub _tree_construction_main ($) {
2510                ## Ignore the token                ## Ignore the token
2511                !!!next-token;                !!!next-token;
2512                next B;                next B;
2513              } elsif ($token->{tag_name} eq 'br') {          } elsif ($token->{tag_name} eq 'br') {
2514                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {            if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2515                  !!!cp ('t142.2');              !!!cp ('t142.2');
2516                  ## (before head) as if <head>, (in head) as if </head>              ## (before head) as if <head>, (in head) as if </head>
2517                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);              !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
2518                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});              $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2519                  $self->{insertion_mode} = AFTER_HEAD_IM;              $self->{insertion_mode} = AFTER_HEAD_IM;
2520        
2521                  ## Reprocess in the "after head" insertion mode...              ## Reprocess in the "after head" insertion mode...
2522                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {            } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
2523                  !!!cp ('t143.2');              !!!cp ('t143.2');
2524                  ## As if </head>              ## As if </head>
2525                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
2526                  $self->{insertion_mode} = AFTER_HEAD_IM;              $self->{insertion_mode} = AFTER_HEAD_IM;
2527        
2528                  ## Reprocess in the "after head" insertion mode...              ## Reprocess in the "after head" insertion mode...
2529                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {            } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
2530                  !!!cp ('t143.3');              !!!cp ('t143.3');
2531                  ## NOTE: Two parse errors for <head><noscript></br>              ## NOTE: Two parse errors for <head><noscript></br>
2532                  !!!parse-error (type => 'unmatched end tag',              !!!parse-error (type => 'unmatched end tag',
2533                                  text => 'br', token => $token);                              text => 'br', token => $token);
2534                  ## As if </noscript>              ## As if </noscript>
2535                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
2536                  $self->{insertion_mode} = IN_HEAD_IM;              $self->{insertion_mode} = IN_HEAD_IM;
2537    
2538                  ## Reprocess in the "in head" insertion mode...              ## Reprocess in the "in head" insertion mode...
2539                  ## As if </head>              ## As if </head>
2540                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
2541                  $self->{insertion_mode} = AFTER_HEAD_IM;              $self->{insertion_mode} = AFTER_HEAD_IM;
2542    
2543                  ## Reprocess in the "after head" insertion mode...              ## Reprocess in the "after head" insertion mode...
2544                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
2545                  !!!cp ('t143.4');              !!!cp ('t143.4');
2546                  #              #
2547                } else {            } else {
2548                  die "$0: $self->{insertion_mode}: Unknown insertion mode";              die "$0: $self->{insertion_mode}: Unknown insertion mode";
2549                }            }
2550    
2551                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.            #
2552                !!!parse-error (type => 'unmatched end tag',          } else { ## Other end tags
                               text => 'br', token => $token);  
               ## Ignore the token  
               !!!next-token;  
               next B;  
             } else {  
2553                !!!cp ('t145');                !!!cp ('t145');
2554                !!!parse-error (type => 'unmatched end tag',                !!!parse-error (type => 'unmatched end tag',
2555                                text => $token->{tag_name}, token => $token);                                text => $token->{tag_name}, token => $token);
# Line 2586  sub _tree_construction_main ($) { Line 2593  sub _tree_construction_main ($) {
2593              !!!insert-element ('body',, $token);              !!!insert-element ('body',, $token);
2594              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
2595              ## reprocess              ## reprocess
2596              next B;          next B;
2597        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
2598          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2599            !!!cp ('t149.1');            !!!cp ('t149.1');
# Line 3852  sub _tree_construction_main ($) { Line 3859  sub _tree_construction_main ($) {
3859                     tbody => 1, tfoot => 1, thead => 1,                     tbody => 1, tfoot => 1, thead => 1,
3860                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
3861                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
3862            ## TODO: The type below is not good - <select> is replaced by </select>  
3863            !!!parse-error (type => 'not closed', text => 'select',            ## 1. Parse error.
3864                            token => $token);            if ($token->{tag_name} eq 'select') {
3865            ## NOTE: As if the token were </select> (<select> case) or                !!!parse-error (type => 'select in select', ## XXX: documentation
3866            ## as if there were </select> (otherwise).                                token => $token);
3867            ## have an element in table scope            } else {
3868                !!!parse-error (type => 'not closed', text => 'select',
3869                                token => $token);
3870              }
3871    
3872              ## 2./<select>-1. Unless "have an element in table scope" (select):
3873            my $i;            my $i;
3874            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3875              my $node = $self->{open_elements}->[$_];              my $node = $self->{open_elements}->[$_];
# Line 3872  sub _tree_construction_main ($) { Line 3884  sub _tree_construction_main ($) {
3884            } # INSCOPE            } # INSCOPE
3885            unless (defined $i) {            unless (defined $i) {
3886              !!!cp ('t280');              !!!cp ('t280');
3887              !!!parse-error (type => 'unmatched end tag',              if ($token->{tag_name} eq 'select') {
3888                              text => 'select', token => $token);                ## NOTE: This error would be raised when
3889              ## Ignore the token                ## |select.innerHTML = '<select>'| is executed; in this
3890                  ## case two errors, "select in select" and "unmatched
3891                  ## end tags" are reported to the user, the latter might
3892                  ## be confusing but this is what the spec requires.
3893                  !!!parse-error (type => 'unmatched end tag',
3894                                  text => 'select',
3895                                  token => $token);
3896                }
3897                ## Ignore the token.
3898              !!!nack ('t280.1');              !!!nack ('t280.1');
3899              !!!next-token;              !!!next-token;
3900              next B;              next B;
3901            }            }
3902    
3903              ## 3. Otherwise, as if there were <select>:
3904                                
3905            !!!cp ('t281');            !!!cp ('t281');
3906            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
# Line 3895  sub _tree_construction_main ($) { Line 3917  sub _tree_construction_main ($) {
3917              ## Reprocess the token.              ## Reprocess the token.
3918              next B;              next B;
3919            }            }
3920            } elsif ($token->{tag_name} eq 'script') {
3921              !!!cp ('t281.3');
3922              ## NOTE: This is an "as if in head" code clone
3923              $script_start_tag->();
3924              next B;
3925          } else {          } else {
3926            !!!cp ('t282');            !!!cp ('t282');
3927            !!!parse-error (type => 'in select',            !!!parse-error (type => 'in select',
# Line 4414  sub _tree_construction_main ($) { Line 4441  sub _tree_construction_main ($) {
4441                  table => 1,                  table => 1,
4442                  hr => 1,                  hr => 1,
4443                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
4444    
4445            ## 1. When there is an opening |form| element:
4446          if ($token->{tag_name} eq 'form' and defined $self->{form_element}) {          if ($token->{tag_name} eq 'form' and defined $self->{form_element}) {
4447            !!!cp ('t350');            !!!cp ('t350');
4448            !!!parse-error (type => 'in form:form', token => $token);            !!!parse-error (type => 'in form:form', token => $token);
# Line 4423  sub _tree_construction_main ($) { Line 4452  sub _tree_construction_main ($) {
4452            next B;            next B;
4453          }          }
4454    
4455            ## 2. Close the |p| element, if any.
4456          if ($token->{tag_name} ne 'table' or # The Hixie Quirk          if ($token->{tag_name} ne 'table' or # The Hixie Quirk
4457              $self->{document}->manakai_compat_mode ne 'quirks') {              $self->{document}->manakai_compat_mode ne 'quirks') {
4458            ## has a p element in scope            ## has a p element in scope
# Line 4439  sub _tree_construction_main ($) { Line 4469  sub _tree_construction_main ($) {
4469              }              }
4470            } # INSCOPE            } # INSCOPE
4471          }          }
4472              
4473            ## 3. Close the opening <hn> element, if any.
4474            if ({h1 => 1, h2 => 1, h3 => 1,
4475                 h4 => 1, h5 => 1, h6 => 1}->{$token->{tag_name}}) {
4476              if ($self->{open_elements}->[-1]->[1] == HEADING_EL) {
4477                !!!parse-error (type => 'not closed',
4478                                text => $self->{open_elements}->[-1]->[0]->manakai_local_name,
4479                                token => $token);
4480                pop @{$self->{open_elements}};
4481              }
4482            }
4483    
4484            ## 4. Insertion.
4485          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
4486          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
4487            !!!nack ('t346.1');            !!!nack ('t346.1');
# Line 4483  sub _tree_construction_main ($) { Line 4525  sub _tree_construction_main ($) {
4525        } elsif ($token->{tag_name} eq 'li') {        } elsif ($token->{tag_name} eq 'li') {
4526          ## NOTE: As normal, but imply </li> when there's another <li> ...          ## NOTE: As normal, but imply </li> when there's another <li> ...
4527    
4528          ## NOTE: Special, Scope (<li><foo><li> == <li><foo><li/></foo></li>)          ## NOTE: Special, Scope (<li><foo><li> == <li><foo><li/></foo></li>)::
4529            ## Interpreted as <li><foo/></li><li/> (non-conforming)            ## Interpreted as <li><foo/></li><li/> (non-conforming):
4530            ## blockquote (O9.27), center (O), dd (Fx3, O, S3.1.2, IE7),            ## blockquote (O9.27), center (O), dd (Fx3, O, S3.1.2, IE7),
4531            ## dt (Fx, O, S, IE), dl (O), fieldset (O, S, IE), form (Fx, O, S),            ## dt (Fx, O, S, IE), dl (O), fieldset (O, S, IE), form (Fx, O, S),
4532            ## hn (O), pre (O), applet (O, S), button (O, S), marquee (Fx, O, S),            ## hn (O), pre (O), applet (O, S), button (O, S), marquee (Fx, O, S),
4533            ## object (Fx)            ## object (Fx)
4534            ## Generate non-tree (non-conforming)            ## Generate non-tree (non-conforming):
4535            ## basefont (IE7 (where basefont is non-void)), center (IE),            ## basefont (IE7 (where basefont is non-void)), center (IE),
4536            ## form (IE), hn (IE)            ## form (IE), hn (IE)
4537          ## address, div, p (<li><foo><li> == <li><foo/></li><li/>)          ## address, div, p (<li><foo><li> == <li><foo/></li><li/>)::
4538            ## Interpreted as <li><foo><li/></foo></li> (non-conforming)            ## Interpreted as <li><foo><li/></foo></li> (non-conforming):
4539            ## div (Fx, S)            ## div (Fx, S)
4540    
4541          my $non_optional;          my $non_optional;
# Line 4840  sub _tree_construction_main ($) { Line 4882  sub _tree_construction_main ($) {
4882            next B;            next B;
4883          }          }
4884        } elsif ($token->{tag_name} eq 'textarea') {        } elsif ($token->{tag_name} eq 'textarea') {
4885          ## Step 1          ## 1. Insert
4886          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
4887                    
4888          ## Step 2          ## Step 2 # XXX
4889          ## TODO: $self->{form_element} if defined          ## TODO: $self->{form_element} if defined
4890    
4891          ## Step 3          ## 2. Drop U+000A LINE FEED
4892          $self->{ignore_newline} = 1;          $self->{ignore_newline} = 1;
4893    
4894          ## Step 4          ## 3. RCDATA
         ## ISSUE: This step is wrong. (r2302 enbugged)  
   
         ## Step 5  
4895          $self->{content_model} = RCDATA_CONTENT_MODEL;          $self->{content_model} = RCDATA_CONTENT_MODEL;
4896          delete $self->{escape}; # MUST          delete $self->{escape}; # MUST
4897    
4898          ## Step 6-7          ## 4., 6. Insertion mode
4899          $self->{insertion_mode} |= IN_CDATA_RCDATA_IM;          $self->{insertion_mode} |= IN_CDATA_RCDATA_IM;
4900    
4901            ## XXX: 5. frameset-ok flag
4902    
4903          !!!nack ('t392.1');          !!!nack ('t392.1');
4904          !!!next-token;          !!!next-token;
4905          next B;          next B;
# Line 5030  sub _tree_construction_main ($) { Line 5071  sub _tree_construction_main ($) {
5071        }        }
5072      } elsif ($token->{type} == END_TAG_TOKEN) {      } elsif ($token->{type} == END_TAG_TOKEN) {
5073        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
5074          ## has a |body| element in scope  
5075            ## 1. If not "have an element in scope":
5076            ## "has a |body| element in scope"
5077          my $i;          my $i;
5078          INSCOPE: {          INSCOPE: {
5079            for (reverse @{$self->{open_elements}}) {            for (reverse @{$self->{open_elements}}) {
# Line 5053  sub _tree_construction_main ($) { Line 5096  sub _tree_construction_main ($) {
5096            next B;            next B;
5097          } # INSCOPE          } # INSCOPE
5098    
5099            ## 2. If unclosed elements:
5100          for (@{$self->{open_elements}}) {          for (@{$self->{open_elements}}) {
5101            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL ||            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL ||
5102                    $_->[1] == OPTGROUP_EL ||                    $_->[1] == OPTGROUP_EL ||
# Line 5068  sub _tree_construction_main ($) { Line 5112  sub _tree_construction_main ($) {
5112            }            }
5113          }          }
5114    
5115            ## 3. Switch the insertion mode.
5116          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
5117          !!!next-token;          !!!next-token;
5118          next B;          next B;

Legend:
Removed from v.1.220  
changed lines
  Added in v.1.228

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24