/[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.215 by wakaba, Thu Jul 2 22:11:51 2009 UTC revision 1.236 by wakaba, Sun Sep 6 08:15:37 2009 UTC
# Line 179  my $el_category = { Line 179  my $el_category = {
179    dt => DTDD_EL,    dt => DTDD_EL,
180    em => FORMATTING_EL,    em => FORMATTING_EL,
181    embed => MISC_SPECIAL_EL,    embed => MISC_SPECIAL_EL,
   eventsource => MISC_SPECIAL_EL,  
182    fieldset => MISC_SPECIAL_EL,    fieldset => MISC_SPECIAL_EL,
183    figure => MISC_SPECIAL_EL,    figure => MISC_SPECIAL_EL,
184    font => FORMATTING_EL,    font => FORMATTING_EL,
# Line 203  my $el_category = { Line 202  my $el_category = {
202    #image => MISC_SPECIAL_EL, ## NOTE: Commented out in the spec.    #image => MISC_SPECIAL_EL, ## NOTE: Commented out in the spec.
203    input => MISC_SPECIAL_EL,    input => MISC_SPECIAL_EL,
204    isindex => MISC_SPECIAL_EL,    isindex => MISC_SPECIAL_EL,
205      ## XXX keygen? (Whether a void element is in Special or not does not
206      ## affect to the processing, however.)
207    li => LI_EL,    li => LI_EL,
208    link => MISC_SPECIAL_EL,    link => MISC_SPECIAL_EL,
209    listing => MISC_SPECIAL_EL,    listing => MISC_SPECIAL_EL,
# Line 247  my $el_category = { Line 248  my $el_category = {
248    u => FORMATTING_EL,    u => FORMATTING_EL,
249    ul => MISC_SPECIAL_EL,    ul => MISC_SPECIAL_EL,
250    wbr => MISC_SPECIAL_EL,    wbr => MISC_SPECIAL_EL,
251      xmp => MISC_SPECIAL_EL,
252  };  };
253    
254  my $el_category_f = {  my $el_category_f = {
# Line 647  sub parse_char_stream ($$$;$$) { Line 649  sub parse_char_stream ($$$;$$) {
649    
650    ## NOTE: |set_inner_html| copies most of this method's code    ## NOTE: |set_inner_html| copies most of this method's code
651    
652      ## Confidence: irrelevant.
653    $self->{confident} = 1 unless exists $self->{confident};    $self->{confident} = 1 unless exists $self->{confident};
654    
655    $self->{document}->input_encoding ($self->{input_encoding})    $self->{document}->input_encoding ($self->{input_encoding})
656        if defined $self->{input_encoding};        if defined $self->{input_encoding};
657  ## TODO: |{input_encoding}| is needless?  ## TODO: |{input_encoding}| is needless?
# Line 911  sub _tree_construction_initial ($) { Line 915  sub _tree_construction_initial ($) {
915    
916    INITIAL: {    INITIAL: {
917      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
918        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"        ## NOTE: Conformance checkers MAY, instead of reporting "not
919        ## error, switch to a conformance checking mode for another        ## HTML5" error, switch to a conformance checking mode for
920        ## language.        ## another language.  (We don't support such mode switchings; it
921          ## is nonsense to do anything different from what browsers do.)
922        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
923        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
924        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive        my $doctype = $self->{document}->create_document_type_definition
925        if (not defined $token->{name} or # <!DOCTYPE>            ($doctype_name);
926            defined $token->{sysid}) {  
927          $doctype_name =~ tr/A-Z/a-z/; # ASCII case-insensitive
928          if ($doctype_name ne 'html') {
929          !!!cp ('t1');          !!!cp ('t1');
930          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
931        } elsif ($doctype_name ne 'HTML') {        } elsif (defined $token->{pubid}) {
932          !!!cp ('t2');          !!!cp ('t2');
933            ## XXX Obsolete permitted DOCTYPEs
934          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
935        } elsif (defined $token->{pubid}) {        } elsif (defined $token->{sysid}) {
936          if ($token->{pubid} eq 'XSLT-compat') {          if ($token->{sysid} eq 'about:legacy-compat') {
937            !!!cp ('t1.2');            !!!cp ('t1.2'); ## <!DOCTYPE HTML SYSTEM "about:legacy-compat">
938            !!!parse-error (type => 'XSLT-compat', token => $token,            !!!parse-error (type => 'XSLT-compat', token => $token,
939                            level => $self->{level}->{should});                            level => $self->{level}->{should});
940          } else {          } else {
941            !!!parse-error (type => 'not HTML5', token => $token);            !!!parse-error (type => 'not HTML5', token => $token);
942          }          }
943        } else {        } else { ## <!DOCTYPE HTML>
944          !!!cp ('t3');          !!!cp ('t3');
945          #          #
946        }        }
947                
       my $doctype = $self->{document}->create_document_type_definition  
         ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?  
948        ## NOTE: Default value for both |public_id| and |system_id| attributes        ## NOTE: Default value for both |public_id| and |system_id| attributes
949        ## 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.
950        $doctype->public_id ($token->{pubid}) if defined $token->{pubid};        $doctype->public_id ($token->{pubid}) if defined $token->{pubid};
951        $doctype->system_id ($token->{sysid}) if defined $token->{sysid};        $doctype->system_id ($token->{sysid}) if defined $token->{sysid};
952    
953        ## NOTE: Other DocumentType attributes are null or empty lists.        ## NOTE: Other DocumentType attributes are null or empty lists.
954        ## In Firefox3, |internalSubset| attribute is set to the empty        ## In Firefox3, |internalSubset| attribute is set to the empty
955        ## string, while |null| is an allowed value for the attribute        ## string, while |null| is an allowed value for the attribute
956        ## according to DOM3 Core.        ## according to DOM3 Core.
957        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
958                
959        if ($token->{quirks} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'html') {
960          !!!cp ('t4');          !!!cp ('t4');
961          $self->{document}->manakai_compat_mode ('quirks');          $self->{document}->manakai_compat_mode ('quirks');
962        } elsif (defined $token->{pubid}) {        } elsif (defined $token->{pubid}) {
# Line 1419  sub _tree_construction_main ($) { Line 1426  sub _tree_construction_main ($) {
1426      ## Step 3      ## Step 3
1427      ## TODO: Mark as "already executed", if ...      ## TODO: Mark as "already executed", if ...
1428    
1429      ## Step 4      ## Step 4 (HTML5 revision 2702)
1430      $insert->($script_el);      $insert->($script_el);
   
     ## ISSUE: $script_el is not put into the stack  
1431      push @{$self->{open_elements}}, [$script_el, $el_category->{script}];      push @{$self->{open_elements}}, [$script_el, $el_category->{script}];
1432    
1433      ## Step 5      ## Step 5
# Line 1437  sub _tree_construction_main ($) { Line 1442  sub _tree_construction_main ($) {
1442    }; # $script_start_tag    }; # $script_start_tag
1443    
1444    ## NOTE: $open_tables->[-1]->[0] is the "current table" element node.    ## NOTE: $open_tables->[-1]->[0] is the "current table" element node.
1445    ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.    ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag (OBSOLETE; unused).
1446    ## NOTE: $open_tables->[-1]->[2] is set false when non-Text node inserted.    ## NOTE: $open_tables->[-1]->[2] is set false when non-Text node inserted.
1447    my $open_tables = [[$self->{open_elements}->[0]->[0]]];    my $open_tables = [[$self->{open_elements}->[0]->[0]]];
1448    
# Line 1607  sub _tree_construction_main ($) { Line 1612  sub _tree_construction_main ($) {
1612                
1613        ## Step 8        ## Step 8
1614        if ($common_ancestor_node->[1] & TABLE_ROWS_EL) {        if ($common_ancestor_node->[1] & TABLE_ROWS_EL) {
1615            ## Foster parenting.
1616          my $foster_parent_element;          my $foster_parent_element;
1617          my $next_sibling;          my $next_sibling;
1618          OE: for (reverse 0..$#{$self->{open_elements}}) {          OE: for (reverse 0..$#{$self->{open_elements}}) {
1619            if ($self->{open_elements}->[$_]->[1] == TABLE_EL) {            if ($self->{open_elements}->[$_]->[1] == TABLE_EL) {
1620                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;              !!!cp ('t65.2');
1621                               if (defined $parent and $parent->node_type == 1) {              $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
1622                                 !!!cp ('t65.1');              $next_sibling = $self->{open_elements}->[$_]->[0];
1623                                 $foster_parent_element = $parent;              undef $next_sibling
1624                                 $next_sibling = $self->{open_elements}->[$_]->[0];                  unless $next_sibling->parent_node eq $foster_parent_element;
1625                               } else {              last OE;
1626                                 !!!cp ('t65.2');            }
1627                                 $foster_parent_element          } # OE
1628                                   = $self->{open_elements}->[$_ - 1]->[0];          $foster_parent_element ||= $self->{open_elements}->[0]->[0];
1629                               }  
                              last OE;  
                            }  
                          } # OE  
                          $foster_parent_element = $self->{open_elements}->[0]->[0]  
                            unless defined $foster_parent_element;  
1630          $foster_parent_element->insert_before ($last_node->[0], $next_sibling);          $foster_parent_element->insert_before ($last_node->[0], $next_sibling);
1631          $open_tables->[-1]->[1] = 1; # tainted          $open_tables->[-1]->[1] = 1; # tainted
1632        } else {        } else {
# Line 1681  sub _tree_construction_main ($) { Line 1682  sub _tree_construction_main ($) {
1682      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
1683    }; # $insert_to_current    }; # $insert_to_current
1684    
1685      ## Foster parenting.  Note that there are three "foster parenting"
1686      ## code in the parser: for elements (this one), for texts, and for
1687      ## elements in the AAA code.
1688    my $insert_to_foster = sub {    my $insert_to_foster = sub {
1689      my $child = shift;      my $child = shift;
1690      if ($self->{open_elements}->[-1]->[1] & TABLE_ROWS_EL) {      if ($self->{open_elements}->[-1]->[1] & TABLE_ROWS_EL) {
# Line 1689  sub _tree_construction_main ($) { Line 1693  sub _tree_construction_main ($) {
1693        my $next_sibling;        my $next_sibling;
1694        OE: for (reverse 0..$#{$self->{open_elements}}) {        OE: for (reverse 0..$#{$self->{open_elements}}) {
1695          if ($self->{open_elements}->[$_]->[1] == TABLE_EL) {          if ($self->{open_elements}->[$_]->[1] == TABLE_EL) {
1696                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;            !!!cp ('t71');
1697                               if (defined $parent and $parent->node_type == 1) {            $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
1698                                 !!!cp ('t70');            $next_sibling = $self->{open_elements}->[$_]->[0];
1699                                 $foster_parent_element = $parent;            undef $next_sibling
1700                                 $next_sibling = $self->{open_elements}->[$_]->[0];                unless $next_sibling->parent_node eq $foster_parent_element;
1701                               } else {            last OE;
1702                                 !!!cp ('t71');          }
1703                                 $foster_parent_element        } # OE
1704                                   = $self->{open_elements}->[$_ - 1]->[0];        $foster_parent_element ||= $self->{open_elements}->[0]->[0];
1705                               }  
1706                               last OE;        $foster_parent_element->insert_before ($child, $next_sibling);
                            }  
                          } # OE  
                          $foster_parent_element = $self->{open_elements}->[0]->[0]  
                            unless defined $foster_parent_element;  
                          $foster_parent_element->insert_before  
                            ($child, $next_sibling);  
1707        $open_tables->[-1]->[1] = 1; # tainted        $open_tables->[-1]->[1] = 1; # tainted
1708      } else {      } else {
1709        !!!cp ('t72');        !!!cp ('t72');
# Line 1733  sub _tree_construction_main ($) { Line 1731  sub _tree_construction_main ($) {
1731    ## document.write ("b")</script>|    ## document.write ("b")</script>|
1732    
1733    B: while (1) {    B: while (1) {
1734    
1735        ## The "in table text" insertion mode.
1736        if ($self->{insertion_mode} & TABLE_IMS and
1737            not $self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
1738            not $self->{insertion_mode} & IN_CDATA_RCDATA_IM) {
1739          C: {
1740            my $s;
1741            if ($token->{type} == CHARACTER_TOKEN) {
1742              !!!cp ('t194');
1743              $self->{pending_chars} ||= [];
1744              push @{$self->{pending_chars}}, $token;
1745              !!!next-token;
1746              next B;
1747            } else {
1748              if ($self->{pending_chars}) {
1749                $s = join '', map { $_->{data} } @{$self->{pending_chars}};
1750                delete $self->{pending_chars};
1751                if ($s =~ /[^\x09\x0A\x0C\x0D\x20]/) {
1752                  !!!cp ('t195');
1753                  #
1754                } else {
1755                  !!!cp ('t195.1');
1756                  #$self->{open_elements}->[-1]->[0]->manakai_append_text ($s);
1757                  $self->{open_elements}->[-1]->[0]->append_child
1758                      ($self->{document}->create_text_node ($s));
1759                  last C;
1760                }
1761              } else {
1762                !!!cp ('t195.2');
1763                last C;
1764              }
1765            }
1766    
1767            ## Foster parenting.
1768            !!!parse-error (type => 'in table:#text', token => $token);
1769    
1770            ## NOTE: As if in body, but insert into the foster parent element.
1771            $reconstruct_active_formatting_elements->($insert_to_foster);
1772                
1773            if ($self->{open_elements}->[-1]->[1] & TABLE_ROWS_EL) {
1774              # MUST
1775              my $foster_parent_element;
1776              my $next_sibling;
1777              OE: for (reverse 0..$#{$self->{open_elements}}) {
1778                if ($self->{open_elements}->[$_]->[1] == TABLE_EL) {
1779                  !!!cp ('t197');
1780                  $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
1781                  $next_sibling = $self->{open_elements}->[$_]->[0];
1782                  undef $next_sibling
1783                    unless $next_sibling->parent_node eq $foster_parent_element;
1784                  last OE;
1785                }
1786              } # OE
1787              $foster_parent_element ||= $self->{open_elements}->[0]->[0];
1788    
1789              !!!cp ('t199');
1790              $foster_parent_element->insert_before
1791                  ($self->{document}->create_text_node ($s), $next_sibling);
1792    
1793              $open_tables->[-1]->[1] = 1; # tainted
1794              $open_tables->[-1]->[2] = 1; # ~node inserted
1795            } else {
1796              ## NOTE: Fragment case or in a foster parent'ed element
1797              ## (e.g. |<table><span>a|).  In fragment case, whether the
1798              ## character is appended to existing node or a new node is
1799              ## created is irrelevant, since the foster parent'ed nodes
1800              ## are discarded and fragment parsing does not invoke any
1801              ## script.
1802              !!!cp ('t200');
1803              $self->{open_elements}->[-1]->[0]->manakai_append_text ($s);
1804            }
1805          } # C
1806        } # TABLE_IMS
1807    
1808      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
1809        !!!cp ('t73');        !!!cp ('t73');
1810        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
# Line 1874  sub _tree_construction_main ($) { Line 1946  sub _tree_construction_main ($) {
1946          } elsif ({          } elsif ({
1947                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
1948                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
1949                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,                    em => 1, embed => 1, h1 => 1, h2 => 1, h3 => 1,
1950                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
1951                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
1952                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
1953                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
1954                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
1955                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}} or
1956                     ($token->{tag_name} eq 'font' and
1957                      ($token->{attributes}->{color} or
1958                       $token->{attributes}->{face} or
1959                       $token->{attributes}->{size}))) {
1960            !!!cp ('t87.2');            !!!cp ('t87.2');
1961            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
1962                            text => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
# Line 1956  sub _tree_construction_main ($) { Line 2032  sub _tree_construction_main ($) {
2032          }          }
2033        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
2034          ## NOTE: "using the rules for secondary insertion mode" then "continue"          ## NOTE: "using the rules for secondary insertion mode" then "continue"
2035          !!!cp ('t87.5');          if ($token->{tag_name} eq 'script') {
2036          #            !!!cp ('t87.41');
2037              #
2038              ## XXXscript: Execute script here.
2039            } else {
2040              !!!cp ('t87.5');
2041              #
2042            }
2043        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
2044          !!!cp ('t87.6');          !!!cp ('t87.6');
2045          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
# Line 2141  sub _tree_construction_main ($) { Line 2223  sub _tree_construction_main ($) {
2223            !!!ack ('t103.1');            !!!ack ('t103.1');
2224            !!!next-token;            !!!next-token;
2225            next B;            next B;
2226          } elsif ($token->{tag_name} eq 'command' or          } elsif ($token->{tag_name} eq 'command') {
                  $token->{tag_name} eq 'eventsource') {  
2227            if ($self->{insertion_mode} == IN_HEAD_IM) {            if ($self->{insertion_mode} == IN_HEAD_IM) {
2228              ## NOTE: If the insertion mode at the time of the emission              ## NOTE: If the insertion mode at the time of the emission
2229              ## of the token was "before head", $self->{insertion_mode}              ## of the token was "before head", $self->{insertion_mode}
# Line 2257  sub _tree_construction_main ($) { Line 2338  sub _tree_construction_main ($) {
2338    
2339            ## NOTE: There is a "as if in head" code clone.            ## NOTE: There is a "as if in head" code clone.
2340            $parse_rcdata->(RCDATA_CONTENT_MODEL);            $parse_rcdata->(RCDATA_CONTENT_MODEL);
2341            ## ISSUE: A spec bug [Bug 6038]  
2342              ## NOTE: At this point the stack of open elements contain
2343              ## the |head| element (index == -2) and the |script| element
2344              ## (index == -1).  In the "after head" insertion mode the
2345              ## |head| element is inserted only for the purpose of
2346              ## providing the context for the |script| element, and
2347              ## therefore we can now and have to remove the element from
2348              ## the stack.
2349            splice @{$self->{open_elements}}, -2, 1, () # <head>            splice @{$self->{open_elements}}, -2, 1, () # <head>
2350                if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM;                if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM;
2351            next B;            next B;
# Line 2492  sub _tree_construction_main ($) { Line 2580  sub _tree_construction_main ($) {
2580                ## Ignore the token                ## Ignore the token
2581                !!!next-token;                !!!next-token;
2582                next B;                next B;
2583              } elsif ($token->{tag_name} eq 'br') {          } elsif ($token->{tag_name} eq 'br') {
2584                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {            if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2585                  !!!cp ('t142.2');              !!!cp ('t142.2');
2586                  ## (before head) as if <head>, (in head) as if </head>              ## (before head) as if <head>, (in head) as if </head>
2587                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);              !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
2588                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});              $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2589                  $self->{insertion_mode} = AFTER_HEAD_IM;              $self->{insertion_mode} = AFTER_HEAD_IM;
2590        
2591                  ## Reprocess in the "after head" insertion mode...              ## Reprocess in the "after head" insertion mode...
2592                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {            } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
2593                  !!!cp ('t143.2');              !!!cp ('t143.2');
2594                  ## As if </head>              ## As if </head>
2595                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
2596                  $self->{insertion_mode} = AFTER_HEAD_IM;              $self->{insertion_mode} = AFTER_HEAD_IM;
2597        
2598                  ## Reprocess in the "after head" insertion mode...              ## Reprocess in the "after head" insertion mode...
2599                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {            } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
2600                  !!!cp ('t143.3');              !!!cp ('t143.3');
2601                  ## NOTE: Two parse errors for <head><noscript></br>              ## NOTE: Two parse errors for <head><noscript></br>
2602                  !!!parse-error (type => 'unmatched end tag',              !!!parse-error (type => 'unmatched end tag',
2603                                  text => 'br', token => $token);                              text => 'br', token => $token);
2604                  ## As if </noscript>              ## As if </noscript>
2605                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
2606                  $self->{insertion_mode} = IN_HEAD_IM;              $self->{insertion_mode} = IN_HEAD_IM;
2607    
2608                  ## Reprocess in the "in head" insertion mode...              ## Reprocess in the "in head" insertion mode...
2609                  ## As if </head>              ## As if </head>
2610                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
2611                  $self->{insertion_mode} = AFTER_HEAD_IM;              $self->{insertion_mode} = AFTER_HEAD_IM;
2612    
2613                  ## Reprocess in the "after head" insertion mode...              ## Reprocess in the "after head" insertion mode...
2614                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
2615                  !!!cp ('t143.4');              !!!cp ('t143.4');
2616                  #              #
2617                } else {            } else {
2618                  die "$0: $self->{insertion_mode}: Unknown insertion mode";              die "$0: $self->{insertion_mode}: Unknown insertion mode";
2619                }            }
2620    
2621                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.            #
2622                !!!parse-error (type => 'unmatched end tag',          } else { ## Other end tags
                               text => 'br', token => $token);  
               ## Ignore the token  
               !!!next-token;  
               next B;  
             } else {  
2623                !!!cp ('t145');                !!!cp ('t145');
2624                !!!parse-error (type => 'unmatched end tag',                !!!parse-error (type => 'unmatched end tag',
2625                                text => $token->{tag_name}, token => $token);                                text => $token->{tag_name}, token => $token);
# Line 2580  sub _tree_construction_main ($) { Line 2663  sub _tree_construction_main ($) {
2663              !!!insert-element ('body',, $token);              !!!insert-element ('body',, $token);
2664              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
2665              ## reprocess              ## reprocess
2666              next B;          next B;
2667        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
2668          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2669            !!!cp ('t149.1');            !!!cp ('t149.1');
# Line 3008  sub _tree_construction_main ($) { Line 3091  sub _tree_construction_main ($) {
3091        $insert = $insert_to_current;        $insert = $insert_to_current;
3092        #        #
3093      } elsif ($self->{insertion_mode} & TABLE_IMS) {      } elsif ($self->{insertion_mode} & TABLE_IMS) {
3094        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == START_TAG_TOKEN) {
         if (not $open_tables->[-1]->[1] and # tainted  
             $token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {  
           $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);  
                 
           unless (length $token->{data}) {  
             !!!cp ('t194');  
             !!!next-token;  
             next B;  
           } else {  
             !!!cp ('t195');  
           }  
         }  
   
         !!!parse-error (type => 'in table:#text', token => $token);  
   
         ## NOTE: As if in body, but insert into the foster parent element.  
         $reconstruct_active_formatting_elements->($insert_to_foster);  
               
         if ($self->{open_elements}->[-1]->[1] & TABLE_ROWS_EL) {  
           # MUST  
           my $foster_parent_element;  
           my $next_sibling;  
           my $prev_sibling;  
           OE: for (reverse 0..$#{$self->{open_elements}}) {  
             if ($self->{open_elements}->[$_]->[1] == TABLE_EL) {  
               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;  
               if (defined $parent and $parent->node_type == 1) {  
                 $foster_parent_element = $parent;  
                 !!!cp ('t196');  
                 $next_sibling = $self->{open_elements}->[$_]->[0];  
                 $prev_sibling = $next_sibling->previous_sibling;  
                 #  
               } else {  
                 !!!cp ('t197');  
                 $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;  
           undef $prev_sibling unless $open_tables->[-1]->[2]; # ~node inserted  
           if (defined $prev_sibling and  
               $prev_sibling->node_type == 3) {  
             !!!cp ('t198');  
             $prev_sibling->manakai_append_text ($token->{data});  
           } else {  
             !!!cp ('t199');  
             $foster_parent_element->insert_before  
                 ($self->{document}->create_text_node ($token->{data}),  
                  $next_sibling);  
           }  
           $open_tables->[-1]->[1] = 1; # tainted  
           $open_tables->[-1]->[2] = 1; # ~node inserted  
         } else {  
           ## NOTE: Fragment case or in a foster parent'ed element  
           ## (e.g. |<table><span>a|).  In fragment case, whether the  
           ## character is appended to existing node or a new node is  
           ## created is irrelevant, since the foster parent'ed nodes  
           ## are discarded and fragment parsing does not invoke any  
           ## script.  
           !!!cp ('t200');  
           $self->{open_elements}->[-1]->[0]->manakai_append_text  
               ($token->{data});  
         }  
               
         !!!next-token;  
         next B;  
       } elsif ($token->{type} == START_TAG_TOKEN) {  
3095          if ({          if ({
3096               tr => (($self->{insertion_mode} & IM_MASK) != IN_ROW_IM),               tr => (($self->{insertion_mode} & IM_MASK) != IN_ROW_IM),
3097               th => 1, td => 1,               th => 1, td => 1,
# Line 3348  sub _tree_construction_main ($) { Line 3359  sub _tree_construction_main ($) {
3359            !!!ack-later;            !!!ack-later;
3360            next B;            next B;
3361          } elsif ($token->{tag_name} eq 'style') {          } elsif ($token->{tag_name} eq 'style') {
3362            if (not $open_tables->[-1]->[1]) { # tainted            !!!cp ('t227.8');
3363              !!!cp ('t227.8');            ## NOTE: This is a "as if in head" code clone.
3364              ## NOTE: This is a "as if in head" code clone.            $parse_rcdata->(CDATA_CONTENT_MODEL);
3365              $parse_rcdata->(CDATA_CONTENT_MODEL);            $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
3366              $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted            next B;
             next B;  
           } else {  
             !!!cp ('t227.7');  
             #  
           }  
3367          } elsif ($token->{tag_name} eq 'script') {          } elsif ($token->{tag_name} eq 'script') {
3368            if (not $open_tables->[-1]->[1]) { # tainted            !!!cp ('t227.6');
3369              !!!cp ('t227.6');            ## NOTE: This is a "as if in head" code clone.
3370              ## NOTE: This is a "as if in head" code clone.            $script_start_tag->();
3371              $script_start_tag->();            $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
3372              $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted            next B;
             next B;  
           } else {  
             !!!cp ('t227.5');  
             #  
           }  
3373          } elsif ($token->{tag_name} eq 'input') {          } elsif ($token->{tag_name} eq 'input') {
3374            if (not $open_tables->[-1]->[1]) { # tainted            if ($token->{attributes}->{type}) {
3375              if ($token->{attributes}->{type}) { ## TODO: case              my $type = $token->{attributes}->{type}->{value};
3376                my $type = lc $token->{attributes}->{type}->{value};              $type =~ tr/A-Z/a-z/; ## ASCII case-insensitive.
3377                if ($type eq 'hidden') {              if ($type eq 'hidden') {
3378                  !!!cp ('t227.3');                !!!cp ('t227.3');
3379                  !!!parse-error (type => 'in table',                !!!parse-error (type => 'in table',
3380                                  text => $token->{tag_name}, token => $token);                                text => $token->{tag_name}, token => $token);
3381    
3382                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
3383                  $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted                $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
3384    
3385                  ## TODO: form element pointer                ## TODO: form element pointer
3386    
3387                  pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
3388    
3389                  !!!next-token;                !!!next-token;
3390                  !!!ack ('t227.2.1');                !!!ack ('t227.2.1');
3391                  next B;                next B;
               } else {  
                 !!!cp ('t227.2');  
                 #  
               }  
3392              } else {              } else {
3393                !!!cp ('t227.1');                !!!cp ('t227.1');
3394                #                #
# Line 3837  sub _tree_construction_main ($) { Line 3834  sub _tree_construction_main ($) {
3834            !!!next-token;            !!!next-token;
3835            next B;            next B;
3836          } elsif ({          } elsif ({
3837                     select => 1, input => 1, textarea => 1,                     select => 1, input => 1, textarea => 1, keygen => 1,
3838                   }->{$token->{tag_name}} or                   }->{$token->{tag_name}} or
3839                   (($self->{insertion_mode} & IM_MASK)                   (($self->{insertion_mode} & IM_MASK)
3840                        == IN_SELECT_IN_TABLE_IM and                        == IN_SELECT_IN_TABLE_IM and
# Line 3846  sub _tree_construction_main ($) { Line 3843  sub _tree_construction_main ($) {
3843                     tbody => 1, tfoot => 1, thead => 1,                     tbody => 1, tfoot => 1, thead => 1,
3844                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
3845                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
3846            ## TODO: The type below is not good - <select> is replaced by </select>  
3847            !!!parse-error (type => 'not closed', text => 'select',            ## 1. Parse error.
3848                            token => $token);            if ($token->{tag_name} eq 'select') {
3849            ## NOTE: As if the token were </select> (<select> case) or                !!!parse-error (type => 'select in select', ## XXX: documentation
3850            ## as if there were </select> (otherwise).                                token => $token);
3851            ## have an element in table scope            } else {
3852                !!!parse-error (type => 'not closed', text => 'select',
3853                                token => $token);
3854              }
3855    
3856              ## 2./<select>-1. Unless "have an element in table scope" (select):
3857            my $i;            my $i;
3858            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3859              my $node = $self->{open_elements}->[$_];              my $node = $self->{open_elements}->[$_];
# Line 3866  sub _tree_construction_main ($) { Line 3868  sub _tree_construction_main ($) {
3868            } # INSCOPE            } # INSCOPE
3869            unless (defined $i) {            unless (defined $i) {
3870              !!!cp ('t280');              !!!cp ('t280');
3871              !!!parse-error (type => 'unmatched end tag',              if ($token->{tag_name} eq 'select') {
3872                              text => 'select', token => $token);                ## NOTE: This error would be raised when
3873              ## Ignore the token                ## |select.innerHTML = '<select>'| is executed; in this
3874                  ## case two errors, "select in select" and "unmatched
3875                  ## end tags" are reported to the user, the latter might
3876                  ## be confusing but this is what the spec requires.
3877                  !!!parse-error (type => 'unmatched end tag',
3878                                  text => 'select',
3879                                  token => $token);
3880                }
3881                ## Ignore the token.
3882              !!!nack ('t280.1');              !!!nack ('t280.1');
3883              !!!next-token;              !!!next-token;
3884              next B;              next B;
3885            }            }
3886    
3887              ## 3. Otherwise, as if there were <select>:
3888                                
3889            !!!cp ('t281');            !!!cp ('t281');
3890            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
# Line 3889  sub _tree_construction_main ($) { Line 3901  sub _tree_construction_main ($) {
3901              ## Reprocess the token.              ## Reprocess the token.
3902              next B;              next B;
3903            }            }
3904            } elsif ($token->{tag_name} eq 'script') {
3905              !!!cp ('t281.3');
3906              ## NOTE: This is an "as if in head" code clone
3907              $script_start_tag->();
3908              next B;
3909          } else {          } else {
3910            !!!cp ('t282');            !!!cp ('t282');
3911            !!!parse-error (type => 'in select',            !!!parse-error (type => 'in select',
# Line 4300  sub _tree_construction_main ($) { Line 4317  sub _tree_construction_main ($) {
4317          $parse_rcdata->(CDATA_CONTENT_MODEL);          $parse_rcdata->(CDATA_CONTENT_MODEL);
4318          next B;          next B;
4319        } elsif ({        } elsif ({
4320                  base => 1, command => 1, eventsource => 1, link => 1,                  base => 1, command => 1, link => 1,
4321                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
4322          !!!cp ('t334');          !!!cp ('t334');
4323          ## NOTE: This is an "as if in head" code clone, only "-t" differs          ## NOTE: This is an "as if in head" code clone, only "-t" differs
# Line 4408  sub _tree_construction_main ($) { Line 4425  sub _tree_construction_main ($) {
4425                  table => 1,                  table => 1,
4426                  hr => 1,                  hr => 1,
4427                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
4428    
4429            ## 1. When there is an opening |form| element:
4430          if ($token->{tag_name} eq 'form' and defined $self->{form_element}) {          if ($token->{tag_name} eq 'form' and defined $self->{form_element}) {
4431            !!!cp ('t350');            !!!cp ('t350');
4432            !!!parse-error (type => 'in form:form', token => $token);            !!!parse-error (type => 'in form:form', token => $token);
# Line 4417  sub _tree_construction_main ($) { Line 4436  sub _tree_construction_main ($) {
4436            next B;            next B;
4437          }          }
4438    
4439          ## has a p element in scope          ## 2. Close the |p| element, if any.
4440          INSCOPE: for (reverse @{$self->{open_elements}}) {          if ($token->{tag_name} ne 'table' or # The Hixie Quirk
4441            if ($_->[1] == P_EL) {              $self->{document}->manakai_compat_mode ne 'quirks') {
4442              !!!cp ('t344');            ## has a p element in scope
4443              !!!back-token; # <form>            INSCOPE: for (reverse @{$self->{open_elements}}) {
4444              $token = {type => END_TAG_TOKEN, tag_name => 'p',              if ($_->[1] == P_EL) {
4445                        line => $token->{line}, column => $token->{column}};                !!!cp ('t344');
4446              next B;                !!!back-token; # <form>
4447            } elsif ($_->[1] & SCOPING_EL) {                $token = {type => END_TAG_TOKEN, tag_name => 'p',
4448              !!!cp ('t345');                          line => $token->{line}, column => $token->{column}};
4449              last INSCOPE;                next B;
4450                } elsif ($_->[1] & SCOPING_EL) {
4451                  !!!cp ('t345');
4452                  last INSCOPE;
4453                }
4454              } # INSCOPE
4455            }
4456    
4457            ## 3. Close the opening <hn> element, if any.
4458            if ({h1 => 1, h2 => 1, h3 => 1,
4459                 h4 => 1, h5 => 1, h6 => 1}->{$token->{tag_name}}) {
4460              if ($self->{open_elements}->[-1]->[1] == HEADING_EL) {
4461                !!!parse-error (type => 'not closed',
4462                                text => $self->{open_elements}->[-1]->[0]->manakai_local_name,
4463                                token => $token);
4464                pop @{$self->{open_elements}};
4465            }            }
4466          } # INSCOPE          }
4467              
4468            ## 4. Insertion.
4469          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
4470          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
4471            !!!nack ('t346.1');            !!!nack ('t346.1');
# Line 4474  sub _tree_construction_main ($) { Line 4509  sub _tree_construction_main ($) {
4509        } elsif ($token->{tag_name} eq 'li') {        } elsif ($token->{tag_name} eq 'li') {
4510          ## NOTE: As normal, but imply </li> when there's another <li> ...          ## NOTE: As normal, but imply </li> when there's another <li> ...
4511    
4512          ## NOTE: Special, Scope (<li><foo><li> == <li><foo><li/></foo></li>)          ## NOTE: Special, Scope (<li><foo><li> == <li><foo><li/></foo></li>)::
4513            ## Interpreted as <li><foo/></li><li/> (non-conforming)            ## Interpreted as <li><foo/></li><li/> (non-conforming):
4514            ## blockquote (O9.27), center (O), dd (Fx3, O, S3.1.2, IE7),            ## blockquote (O9.27), center (O), dd (Fx3, O, S3.1.2, IE7),
4515            ## 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),
4516            ## 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),
4517            ## object (Fx)            ## object (Fx)
4518            ## Generate non-tree (non-conforming)            ## Generate non-tree (non-conforming):
4519            ## basefont (IE7 (where basefont is non-void)), center (IE),            ## basefont (IE7 (where basefont is non-void)), center (IE),
4520            ## form (IE), hn (IE)            ## form (IE), hn (IE)
4521          ## address, div, p (<li><foo><li> == <li><foo/></li><li/>)          ## address, div, p (<li><foo><li> == <li><foo/></li><li/>)::
4522            ## Interpreted as <li><foo><li/></foo></li> (non-conforming)            ## Interpreted as <li><foo><li/></foo></li> (non-conforming):
4523            ## div (Fx, S)            ## div (Fx, S)
4524    
4525          my $non_optional;          my $non_optional;
# Line 4831  sub _tree_construction_main ($) { Line 4866  sub _tree_construction_main ($) {
4866            next B;            next B;
4867          }          }
4868        } elsif ($token->{tag_name} eq 'textarea') {        } elsif ($token->{tag_name} eq 'textarea') {
4869          ## Step 1          ## 1. Insert
4870          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
4871                    
4872          ## Step 2          ## Step 2 # XXX
4873          ## TODO: $self->{form_element} if defined          ## TODO: $self->{form_element} if defined
4874    
4875          ## Step 3          ## 2. Drop U+000A LINE FEED
4876          $self->{ignore_newline} = 1;          $self->{ignore_newline} = 1;
4877    
4878          ## Step 4          ## 3. RCDATA
         ## ISSUE: This step is wrong. (r2302 enbugged)  
   
         ## Step 5  
4879          $self->{content_model} = RCDATA_CONTENT_MODEL;          $self->{content_model} = RCDATA_CONTENT_MODEL;
4880          delete $self->{escape}; # MUST          delete $self->{escape}; # MUST
4881    
4882          ## Step 6-7          ## 4., 6. Insertion mode
4883          $self->{insertion_mode} |= IN_CDATA_RCDATA_IM;          $self->{insertion_mode} |= IN_CDATA_RCDATA_IM;
4884    
4885            ## XXX: 5. frameset-ok flag
4886    
4887          !!!nack ('t392.1');          !!!nack ('t392.1');
4888          !!!next-token;          !!!next-token;
4889          next B;          next B;
# Line 4995  sub _tree_construction_main ($) { Line 5029  sub _tree_construction_main ($) {
5029          } elsif ({          } elsif ({
5030                    area => 1, basefont => 1, bgsound => 1, br => 1,                    area => 1, basefont => 1, bgsound => 1, br => 1,
5031                    embed => 1, img => 1, spacer => 1, wbr => 1,                    embed => 1, img => 1, spacer => 1, wbr => 1,
5032                      keygen => 1,
5033                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
5034            !!!cp ('t388.1');            !!!cp ('t388.1');
5035            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
# Line 5021  sub _tree_construction_main ($) { Line 5056  sub _tree_construction_main ($) {
5056        }        }
5057      } elsif ($token->{type} == END_TAG_TOKEN) {      } elsif ($token->{type} == END_TAG_TOKEN) {
5058        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
5059          ## has a |body| element in scope  
5060            ## 1. If not "have an element in scope":
5061            ## "has a |body| element in scope"
5062          my $i;          my $i;
5063          INSCOPE: {          INSCOPE: {
5064            for (reverse @{$self->{open_elements}}) {            for (reverse @{$self->{open_elements}}) {
# Line 5044  sub _tree_construction_main ($) { Line 5081  sub _tree_construction_main ($) {
5081            next B;            next B;
5082          } # INSCOPE          } # INSCOPE
5083    
5084            ## 2. If unclosed elements:
5085          for (@{$self->{open_elements}}) {          for (@{$self->{open_elements}}) {
5086            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL ||
5087                      $_->[1] == OPTGROUP_EL ||
5088                      $_->[1] == OPTION_EL ||
5089                      $_->[1] == RUBY_COMPONENT_EL) {
5090              !!!cp ('t403');              !!!cp ('t403');
5091              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
5092                              text => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
# Line 5056  sub _tree_construction_main ($) { Line 5097  sub _tree_construction_main ($) {
5097            }            }
5098          }          }
5099    
5100            ## 3. Switch the insertion mode.
5101          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
5102          !!!next-token;          !!!next-token;
5103          next B;          next B;
# Line 5442  sub _tree_construction_main ($) { Line 5484  sub _tree_construction_main ($) {
5484    ## TODO: script stuffs    ## TODO: script stuffs
5485  } # _tree_construct_main  } # _tree_construct_main
5486    
5487    ## XXX: How this method is organized is somewhat out of date, although
5488    ## it still does what the current spec documents.
5489  sub set_inner_html ($$$$;$) {  sub set_inner_html ($$$$;$) {
5490    my $class = shift;    my $class = shift;
5491    my $node = shift;    my $node = shift; # /context/
5492    #my $s = \$_[0];    #my $s = \$_[0];
5493    my $onerror = $_[1];    my $onerror = $_[1];
5494    my $get_wrapper = $_[2] || sub ($) { return $_[0] };    my $get_wrapper = $_[2] || sub ($) { return $_[0] };
5495    
   ## ISSUE: Should {confident} be true?  
   
5496    my $nt = $node->node_type;    my $nt = $node->node_type;
5497    if ($nt == 9) {    if ($nt == 9) { # Document (invoke the algorithm with no /context/ element)
5498      # MUST      # MUST
5499            
5500      ## Step 1 # MUST      ## Step 1 # MUST
# Line 5467  sub set_inner_html ($$$$;$) { Line 5509  sub set_inner_html ($$$$;$) {
5509    
5510      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
5511      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);
5512    } elsif ($nt == 1) {    } elsif ($nt == 1) { # Element (invoke the algorithm with /context/ element)
5513      ## TODO: If non-html element      ## TODO: If non-html element
5514    
5515      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
5516    
5517  ## TODO: Support for $get_wrapper  ## TODO: Support for $get_wrapper
5518    
5519      ## Step 1 # MUST      ## F1. Create an HTML document.
5520      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
5521      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
5522      $doc->manakai_is_html (1);      $doc->manakai_is_html (1);
5523    
5524        ## F2. Propagate quirkness flag
5525        my $node_doc = $node->owner_document;
5526        $doc->manakai_compat_mode ($node_doc->manakai_compat_mode);
5527    
5528        ## F3. Create an HTML parser
5529      my $p = $class->new;      my $p = $class->new;
5530      $p->{document} = $doc;      $p->{document} = $doc;
5531    
# Line 5605  sub set_inner_html ($$$$;$) { Line 5653  sub set_inner_html ($$$$;$) {
5653      $p->_initialize_tokenizer;      $p->_initialize_tokenizer;
5654      $p->_initialize_tree_constructor;      $p->_initialize_tree_constructor;
5655    
5656      ## Step 2      ## F4. If /context/ is not undef...
5657    
5658        ## F4.1. content model flag
5659      my $node_ln = $node->manakai_local_name;      my $node_ln = $node->manakai_local_name;
5660      $p->{content_model} = {      $p->{content_model} = {
5661        title => RCDATA_CONTENT_MODEL,        title => RCDATA_CONTENT_MODEL,
# Line 5625  sub set_inner_html ($$$$;$) { Line 5675  sub set_inner_html ($$$$;$) {
5675      $p->{inner_html_node} = [$node, $el_category->{$node_ln}];      $p->{inner_html_node} = [$node, $el_category->{$node_ln}];
5676        ## TODO: Foreign element OK?        ## TODO: Foreign element OK?
5677    
5678      ## Step 3      ## F4.2. Root |html| element
5679      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
5680        ('http://www.w3.org/1999/xhtml', [undef, 'html']);        ('http://www.w3.org/1999/xhtml', [undef, 'html']);
5681    
5682      ## Step 4 # MUST      ## F4.3.
5683      $doc->append_child ($root);      $doc->append_child ($root);
5684    
5685      ## Step 5 # MUST      ## F4.4.
5686      push @{$p->{open_elements}}, [$root, $el_category->{html}];      push @{$p->{open_elements}}, [$root, $el_category->{html}];
5687    
5688      undef $p->{head_element};      undef $p->{head_element};
5689      undef $p->{head_element_inserted};      undef $p->{head_element_inserted};
5690    
5691      ## Step 6 # MUST      ## F4.5.
5692      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;
5693    
5694      ## Step 7 # MUST      ## F4.6.
5695      my $anode = $node;      my $anode = $node;
5696      AN: while (defined $anode) {      AN: while (defined $anode) {
5697        if ($anode->node_type == 1) {        if ($anode->node_type == 1) {
# Line 5656  sub set_inner_html ($$$$;$) { Line 5706  sub set_inner_html ($$$$;$) {
5706        }        }
5707        $anode = $anode->parent_node;        $anode = $anode->parent_node;
5708      } # AN      } # AN
5709        
5710      ## Step 9 # MUST      ## F.5. Set the input stream.
5711        $p->{confident} = 1; ## Confident: irrelevant.
5712    
5713        ## F.6. Start the parser.
5714      {      {
5715        my $self = $p;        my $self = $p;
5716        !!!next-token;        !!!next-token;
5717      }      }
5718      $p->_tree_construction_main;      $p->_tree_construction_main;
5719    
5720      ## Step 10 # MUST      ## F.7.
5721      my @cn = @{$node->child_nodes};      my @cn = @{$node->child_nodes};
5722      for (@cn) {      for (@cn) {
5723        $node->remove_child ($_);        $node->remove_child ($_);

Legend:
Removed from v.1.215  
changed lines
  Added in v.1.236

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24