/[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.213 by wakaba, Sun Jun 28 11:03:06 2009 UTC revision 1.225 by wakaba, Sun Aug 16 05:57:24 2009 UTC
# Line 525  sub parse_byte_stream ($$$$;$$) { Line 525  sub parse_byte_stream ($$$$;$$) {
525            
526      if ($char_stream) { # if supported      if ($char_stream) { # if supported
527        ## "Change the encoding" algorithm:        ## "Change the encoding" algorithm:
   
       ## Step 1      
       if ($charset->{category} &  
           Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {  
         $charset = Message::Charset::Info->get_by_html_name ('utf-8');  
         ($char_stream, $e_status) = $charset->get_decode_handle  
             ($byte_stream,  
              byte_buffer => \ $buffer->{buffer});  
       }  
       $charset_name = $charset->get_iana_name;  
528                
529        ## Step 2        ## Step 1
530        if (defined $self->{input_encoding} and        if (defined $self->{input_encoding} and
531            $self->{input_encoding} eq $charset_name) {            $self->{input_encoding} eq $charset_name) {
532          !!!parse-error (type => 'charset label:matching',          !!!parse-error (type => 'charset label:matching',
# Line 546  sub parse_byte_stream ($$$$;$$) { Line 536  sub parse_byte_stream ($$$$;$$) {
536          return;          return;
537        }        }
538    
539          ## Step 2 (HTML5 revision 3205)
540          if (defined $self->{input_encoding} and
541              Message::Charset::Info->get_by_html_name ($self->{input_encoding})
542              ->{category} & Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
543            $self->{confident} = 1;
544            return;
545          }
546    
547          ## Step 3
548          if ($charset->{category} &
549              Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
550            $charset = Message::Charset::Info->get_by_html_name ('utf-8');
551            ($char_stream, $e_status) = $charset->get_decode_handle
552                ($byte_stream,
553                 byte_buffer => \ $buffer->{buffer});
554          }
555          $charset_name = $charset->get_iana_name;
556    
557        !!!parse-error (type => 'charset label detected',        !!!parse-error (type => 'charset label detected',
558                        text => $self->{input_encoding},                        text => $self->{input_encoding},
559                        value => $charset_name,                        value => $charset_name,
560                        level => $self->{level}->{warn},                        level => $self->{level}->{warn},
561                        token => $token);                        token => $token);
562                
563        ## Step 3        ## Step 4
564        # if (can) {        # if (can) {
565          ## change the encoding on the fly.          ## change the encoding on the fly.
566          #$self->{confident} = 1;          #$self->{confident} = 1;
567          #return;          #return;
568        # }        # }
569                
570        ## Step 4        ## Step 5
571        throw Whatpm::HTML::RestartParser ();        throw Whatpm::HTML::RestartParser ();
572      }      }
573    }; # $self->{change_encoding}    }; # $self->{change_encoding}
# Line 1411  sub _tree_construction_main ($) { Line 1419  sub _tree_construction_main ($) {
1419      ## Step 3      ## Step 3
1420      ## TODO: Mark as "already executed", if ...      ## TODO: Mark as "already executed", if ...
1421    
1422      ## Step 4      ## Step 4 (HTML5 revision 2702)
1423      $insert->($script_el);      $insert->($script_el);
   
     ## ISSUE: $script_el is not put into the stack  
1424      push @{$self->{open_elements}}, [$script_el, $el_category->{script}];      push @{$self->{open_elements}}, [$script_el, $el_category->{script}];
1425    
1426      ## Step 5      ## Step 5
# Line 1866  sub _tree_construction_main ($) { Line 1872  sub _tree_construction_main ($) {
1872          } elsif ({          } elsif ({
1873                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
1874                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
1875                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,                    em => 1, embed => 1, h1 => 1, h2 => 1, h3 => 1,
1876                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
1877                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
1878                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
1879                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
1880                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
1881                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}} or
1882                     ($token->{tag_name} eq 'font' and
1883                      ($token->{attributes}->{color} or
1884                       $token->{attributes}->{face} or
1885                       $token->{attributes}->{size}))) {
1886            !!!cp ('t87.2');            !!!cp ('t87.2');
1887            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
1888                            text => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
# Line 1948  sub _tree_construction_main ($) { Line 1958  sub _tree_construction_main ($) {
1958          }          }
1959        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
1960          ## NOTE: "using the rules for secondary insertion mode" then "continue"          ## NOTE: "using the rules for secondary insertion mode" then "continue"
1961          !!!cp ('t87.5');          if ($token->{tag_name} eq 'script') {
1962          #            !!!cp ('t87.41');
1963              #
1964              ## XXXscript: Execute script here.
1965            } else {
1966              !!!cp ('t87.5');
1967              #
1968            }
1969        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
1970          !!!cp ('t87.6');          !!!cp ('t87.6');
1971          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
# Line 2249  sub _tree_construction_main ($) { Line 2265  sub _tree_construction_main ($) {
2265    
2266            ## NOTE: There is a "as if in head" code clone.            ## NOTE: There is a "as if in head" code clone.
2267            $parse_rcdata->(RCDATA_CONTENT_MODEL);            $parse_rcdata->(RCDATA_CONTENT_MODEL);
2268            ## ISSUE: A spec bug [Bug 6038]  
2269              ## NOTE: At this point the stack of open elements contain
2270              ## the |head| element (index == -2) and the |script| element
2271              ## (index == -1).  In the "after head" insertion mode the
2272              ## |head| element is inserted only for the purpose of
2273              ## providing the context for the |script| element, and
2274              ## therefore we can now and have to remove the element from
2275              ## the stack.
2276            splice @{$self->{open_elements}}, -2, 1, () # <head>            splice @{$self->{open_elements}}, -2, 1, () # <head>
2277                if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM;                if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM;
2278            next B;            next B;
# Line 2484  sub _tree_construction_main ($) { Line 2507  sub _tree_construction_main ($) {
2507                ## Ignore the token                ## Ignore the token
2508                !!!next-token;                !!!next-token;
2509                next B;                next B;
2510              } elsif ($token->{tag_name} eq 'br') {          } elsif ($token->{tag_name} eq 'br') {
2511                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {            if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2512                  !!!cp ('t142.2');              !!!cp ('t142.2');
2513                  ## (before head) as if <head>, (in head) as if </head>              ## (before head) as if <head>, (in head) as if </head>
2514                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);              !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
2515                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});              $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
2516                  $self->{insertion_mode} = AFTER_HEAD_IM;              $self->{insertion_mode} = AFTER_HEAD_IM;
2517        
2518                  ## Reprocess in the "after head" insertion mode...              ## Reprocess in the "after head" insertion mode...
2519                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {            } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
2520                  !!!cp ('t143.2');              !!!cp ('t143.2');
2521                  ## As if </head>              ## As if </head>
2522                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
2523                  $self->{insertion_mode} = AFTER_HEAD_IM;              $self->{insertion_mode} = AFTER_HEAD_IM;
2524        
2525                  ## Reprocess in the "after head" insertion mode...              ## Reprocess in the "after head" insertion mode...
2526                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {            } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
2527                  !!!cp ('t143.3');              !!!cp ('t143.3');
2528                  ## NOTE: Two parse errors for <head><noscript></br>              ## NOTE: Two parse errors for <head><noscript></br>
2529                  !!!parse-error (type => 'unmatched end tag',              !!!parse-error (type => 'unmatched end tag',
2530                                  text => 'br', token => $token);                              text => 'br', token => $token);
2531                  ## As if </noscript>              ## As if </noscript>
2532                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
2533                  $self->{insertion_mode} = IN_HEAD_IM;              $self->{insertion_mode} = IN_HEAD_IM;
2534    
2535                  ## Reprocess in the "in head" insertion mode...              ## Reprocess in the "in head" insertion mode...
2536                  ## As if </head>              ## As if </head>
2537                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
2538                  $self->{insertion_mode} = AFTER_HEAD_IM;              $self->{insertion_mode} = AFTER_HEAD_IM;
2539    
2540                  ## Reprocess in the "after head" insertion mode...              ## Reprocess in the "after head" insertion mode...
2541                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
2542                  !!!cp ('t143.4');              !!!cp ('t143.4');
2543                  #              #
2544                } else {            } else {
2545                  die "$0: $self->{insertion_mode}: Unknown insertion mode";              die "$0: $self->{insertion_mode}: Unknown insertion mode";
2546                }            }
2547    
2548                ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.            #
2549                !!!parse-error (type => 'unmatched end tag',          } else { ## Other end tags
                               text => 'br', token => $token);  
               ## Ignore the token  
               !!!next-token;  
               next B;  
             } else {  
2550                !!!cp ('t145');                !!!cp ('t145');
2551                !!!parse-error (type => 'unmatched end tag',                !!!parse-error (type => 'unmatched end tag',
2552                                text => $token->{tag_name}, token => $token);                                text => $token->{tag_name}, token => $token);
# Line 2572  sub _tree_construction_main ($) { Line 2590  sub _tree_construction_main ($) {
2590              !!!insert-element ('body',, $token);              !!!insert-element ('body',, $token);
2591              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
2592              ## reprocess              ## reprocess
2593              next B;          next B;
2594        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
2595          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
2596            !!!cp ('t149.1');            !!!cp ('t149.1');
# Line 3829  sub _tree_construction_main ($) { Line 3847  sub _tree_construction_main ($) {
3847            !!!next-token;            !!!next-token;
3848            next B;            next B;
3849          } elsif ({          } elsif ({
3850                     select => 1, input => 1, textarea => 1,                     select => 1, input => 1, textarea => 1, keygen => 1,
3851                   }->{$token->{tag_name}} or                   }->{$token->{tag_name}} or
3852                   (($self->{insertion_mode} & IM_MASK)                   (($self->{insertion_mode} & IM_MASK)
3853                        == IN_SELECT_IN_TABLE_IM and                        == IN_SELECT_IN_TABLE_IM and
# Line 3838  sub _tree_construction_main ($) { Line 3856  sub _tree_construction_main ($) {
3856                     tbody => 1, tfoot => 1, thead => 1,                     tbody => 1, tfoot => 1, thead => 1,
3857                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
3858                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
3859            ## TODO: The type below is not good - <select> is replaced by </select>  
3860            !!!parse-error (type => 'not closed', text => 'select',            ## 1. Parse error.
3861                            token => $token);            if ($token->{tag_name} eq 'select') {
3862            ## NOTE: As if the token were </select> (<select> case) or                !!!parse-error (type => 'select in select', ## XXX: documentation
3863            ## as if there were </select> (otherwise).                                token => $token);
3864            ## have an element in table scope            } else {
3865                !!!parse-error (type => 'not closed', text => 'select',
3866                                token => $token);
3867              }
3868    
3869              ## 2./<select>-1. Unless "have an element in table scope" (select):
3870            my $i;            my $i;
3871            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3872              my $node = $self->{open_elements}->[$_];              my $node = $self->{open_elements}->[$_];
# Line 3858  sub _tree_construction_main ($) { Line 3881  sub _tree_construction_main ($) {
3881            } # INSCOPE            } # INSCOPE
3882            unless (defined $i) {            unless (defined $i) {
3883              !!!cp ('t280');              !!!cp ('t280');
3884              !!!parse-error (type => 'unmatched end tag',              if ($token->{tag_name} eq 'select') {
3885                              text => 'select', token => $token);                ## NOTE: This error would be raised when
3886              ## Ignore the token                ## |select.innerHTML = '<select>'| is executed; in this
3887                  ## case two errors, "select in select" and "unmatched
3888                  ## end tags" are reported to the user, the latter might
3889                  ## be confusing but this is what the spec requires.
3890                  !!!parse-error (type => 'unmatched end tag',
3891                                  text => 'select',
3892                                  token => $token);
3893                }
3894                ## Ignore the token.
3895              !!!nack ('t280.1');              !!!nack ('t280.1');
3896              !!!next-token;              !!!next-token;
3897              next B;              next B;
3898            }            }
3899    
3900              ## 3. Otherwise, as if there were <select>:
3901                                
3902            !!!cp ('t281');            !!!cp ('t281');
3903            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
# Line 4400  sub _tree_construction_main ($) { Line 4433  sub _tree_construction_main ($) {
4433                  table => 1,                  table => 1,
4434                  hr => 1,                  hr => 1,
4435                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
4436    
4437            ## 1. When there is an opening |form| element:
4438          if ($token->{tag_name} eq 'form' and defined $self->{form_element}) {          if ($token->{tag_name} eq 'form' and defined $self->{form_element}) {
4439            !!!cp ('t350');            !!!cp ('t350');
4440            !!!parse-error (type => 'in form:form', token => $token);            !!!parse-error (type => 'in form:form', token => $token);
# Line 4409  sub _tree_construction_main ($) { Line 4444  sub _tree_construction_main ($) {
4444            next B;            next B;
4445          }          }
4446    
4447          ## has a p element in scope          ## 2. Close the |p| element, if any.
4448          INSCOPE: for (reverse @{$self->{open_elements}}) {          if ($token->{tag_name} ne 'table' or # The Hixie Quirk
4449            if ($_->[1] == P_EL) {              $self->{document}->manakai_compat_mode ne 'quirks') {
4450              !!!cp ('t344');            ## has a p element in scope
4451              !!!back-token; # <form>            INSCOPE: for (reverse @{$self->{open_elements}}) {
4452              $token = {type => END_TAG_TOKEN, tag_name => 'p',              if ($_->[1] == P_EL) {
4453                        line => $token->{line}, column => $token->{column}};                !!!cp ('t344');
4454              next B;                !!!back-token; # <form>
4455            } elsif ($_->[1] & SCOPING_EL) {                $token = {type => END_TAG_TOKEN, tag_name => 'p',
4456              !!!cp ('t345');                          line => $token->{line}, column => $token->{column}};
4457              last INSCOPE;                next B;
4458                } elsif ($_->[1] & SCOPING_EL) {
4459                  !!!cp ('t345');
4460                  last INSCOPE;
4461                }
4462              } # INSCOPE
4463            }
4464    
4465            ## 3. Close the opening <hn> element, if any.
4466            if ({h1 => 1, h2 => 1, h3 => 1,
4467                 h4 => 1, h5 => 1, h6 => 1}->{$token->{tag_name}}) {
4468              if ($self->{open_elements}->[-1]->[1] == HEADING_EL) {
4469                !!!parse-error (type => 'not closed',
4470                                text => $self->{open_elements}->[-1]->[0]->manakai_local_name,
4471                                token => $token);
4472                pop @{$self->{open_elements}};
4473            }            }
4474          } # INSCOPE          }
4475              
4476            ## 4. Insertion.
4477          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
4478          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
4479            !!!nack ('t346.1');            !!!nack ('t346.1');
# Line 4466  sub _tree_construction_main ($) { Line 4517  sub _tree_construction_main ($) {
4517        } elsif ($token->{tag_name} eq 'li') {        } elsif ($token->{tag_name} eq 'li') {
4518          ## NOTE: As normal, but imply </li> when there's another <li> ...          ## NOTE: As normal, but imply </li> when there's another <li> ...
4519    
4520          ## NOTE: Special, Scope (<li><foo><li> == <li><foo><li/></foo></li>)          ## NOTE: Special, Scope (<li><foo><li> == <li><foo><li/></foo></li>)::
4521            ## Interpreted as <li><foo/></li><li/> (non-conforming)            ## Interpreted as <li><foo/></li><li/> (non-conforming):
4522            ## blockquote (O9.27), center (O), dd (Fx3, O, S3.1.2, IE7),            ## blockquote (O9.27), center (O), dd (Fx3, O, S3.1.2, IE7),
4523            ## 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),
4524            ## 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),
4525            ## object (Fx)            ## object (Fx)
4526            ## Generate non-tree (non-conforming)            ## Generate non-tree (non-conforming):
4527            ## basefont (IE7 (where basefont is non-void)), center (IE),            ## basefont (IE7 (where basefont is non-void)), center (IE),
4528            ## form (IE), hn (IE)            ## form (IE), hn (IE)
4529          ## address, div, p (<li><foo><li> == <li><foo/></li><li/>)          ## address, div, p (<li><foo><li> == <li><foo/></li><li/>)::
4530            ## Interpreted as <li><foo><li/></foo></li> (non-conforming)            ## Interpreted as <li><foo><li/></foo></li> (non-conforming):
4531            ## div (Fx, S)            ## div (Fx, S)
4532    
4533          my $non_optional;          my $non_optional;
# Line 4823  sub _tree_construction_main ($) { Line 4874  sub _tree_construction_main ($) {
4874            next B;            next B;
4875          }          }
4876        } elsif ($token->{tag_name} eq 'textarea') {        } elsif ($token->{tag_name} eq 'textarea') {
4877          ## Step 1          ## 1. Insert
4878          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
4879                    
4880          ## Step 2          ## Step 2 # XXX
4881          ## TODO: $self->{form_element} if defined          ## TODO: $self->{form_element} if defined
4882    
4883          ## Step 3          ## 2. Drop U+000A LINE FEED
4884          $self->{ignore_newline} = 1;          $self->{ignore_newline} = 1;
4885    
4886          ## Step 4          ## 3. RCDATA
         ## ISSUE: This step is wrong. (r2302 enbugged)  
   
         ## Step 5  
4887          $self->{content_model} = RCDATA_CONTENT_MODEL;          $self->{content_model} = RCDATA_CONTENT_MODEL;
4888          delete $self->{escape}; # MUST          delete $self->{escape}; # MUST
4889    
4890          ## Step 6-7          ## 4., 6. Insertion mode
4891          $self->{insertion_mode} |= IN_CDATA_RCDATA_IM;          $self->{insertion_mode} |= IN_CDATA_RCDATA_IM;
4892    
4893            ## XXX: 5. frameset-ok flag
4894    
4895          !!!nack ('t392.1');          !!!nack ('t392.1');
4896          !!!next-token;          !!!next-token;
4897          next B;          next B;
# Line 5013  sub _tree_construction_main ($) { Line 5063  sub _tree_construction_main ($) {
5063        }        }
5064      } elsif ($token->{type} == END_TAG_TOKEN) {      } elsif ($token->{type} == END_TAG_TOKEN) {
5065        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
5066          ## has a |body| element in scope  
5067            ## 1. If not "have an element in scope":
5068            ## "has a |body| element in scope"
5069          my $i;          my $i;
5070          INSCOPE: {          INSCOPE: {
5071            for (reverse @{$self->{open_elements}}) {            for (reverse @{$self->{open_elements}}) {
# Line 5036  sub _tree_construction_main ($) { Line 5088  sub _tree_construction_main ($) {
5088            next B;            next B;
5089          } # INSCOPE          } # INSCOPE
5090    
5091            ## 2. If unclosed elements:
5092          for (@{$self->{open_elements}}) {          for (@{$self->{open_elements}}) {
5093            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL ||
5094                      $_->[1] == OPTGROUP_EL ||
5095                      $_->[1] == OPTION_EL ||
5096                      $_->[1] == RUBY_COMPONENT_EL) {
5097              !!!cp ('t403');              !!!cp ('t403');
5098              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
5099                              text => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
# Line 5048  sub _tree_construction_main ($) { Line 5104  sub _tree_construction_main ($) {
5104            }            }
5105          }          }
5106    
5107            ## 3. Switch the insertion mode.
5108          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
5109          !!!next-token;          !!!next-token;
5110          next B;          next B;
# Line 5434  sub _tree_construction_main ($) { Line 5491  sub _tree_construction_main ($) {
5491    ## TODO: script stuffs    ## TODO: script stuffs
5492  } # _tree_construct_main  } # _tree_construct_main
5493    
5494    ## XXX: How this method is organized is somewhat out of date, although
5495    ## it still does what the current spec documents.
5496  sub set_inner_html ($$$$;$) {  sub set_inner_html ($$$$;$) {
5497    my $class = shift;    my $class = shift;
5498    my $node = shift;    my $node = shift; # /context/
5499    #my $s = \$_[0];    #my $s = \$_[0];
5500    my $onerror = $_[1];    my $onerror = $_[1];
5501    my $get_wrapper = $_[2] || sub ($) { return $_[0] };    my $get_wrapper = $_[2] || sub ($) { return $_[0] };
# Line 5444  sub set_inner_html ($$$$;$) { Line 5503  sub set_inner_html ($$$$;$) {
5503    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
5504    
5505    my $nt = $node->node_type;    my $nt = $node->node_type;
5506    if ($nt == 9) {    if ($nt == 9) { # Document (invoke the algorithm with no /context/ element)
5507      # MUST      # MUST
5508            
5509      ## Step 1 # MUST      ## Step 1 # MUST
# Line 5459  sub set_inner_html ($$$$;$) { Line 5518  sub set_inner_html ($$$$;$) {
5518    
5519      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
5520      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);
5521    } elsif ($nt == 1) {    } elsif ($nt == 1) { # Element (invoke the algorithm with /context/ element)
5522      ## TODO: If non-html element      ## TODO: If non-html element
5523    
5524      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
5525    
5526  ## TODO: Support for $get_wrapper  ## TODO: Support for $get_wrapper
5527    
5528      ## Step 1 # MUST      ## F1. Create an HTML document.
5529      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
5530      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
5531      $doc->manakai_is_html (1);      $doc->manakai_is_html (1);
5532    
5533        ## F2. Propagate quirkness flag
5534        my $node_doc = $node->owner_document;
5535        $doc->manakai_compat_mode ($node_doc->manakai_compat_mode);
5536    
5537        ## F3. Create an HTML parser
5538      my $p = $class->new;      my $p = $class->new;
5539      $p->{document} = $doc;      $p->{document} = $doc;
5540    
# Line 5597  sub set_inner_html ($$$$;$) { Line 5662  sub set_inner_html ($$$$;$) {
5662      $p->_initialize_tokenizer;      $p->_initialize_tokenizer;
5663      $p->_initialize_tree_constructor;      $p->_initialize_tree_constructor;
5664    
5665      ## Step 2      ## F4. If /context/ is not undef...
5666    
5667        ## F4.1. content model flag
5668      my $node_ln = $node->manakai_local_name;      my $node_ln = $node->manakai_local_name;
5669      $p->{content_model} = {      $p->{content_model} = {
5670        title => RCDATA_CONTENT_MODEL,        title => RCDATA_CONTENT_MODEL,
# Line 5617  sub set_inner_html ($$$$;$) { Line 5684  sub set_inner_html ($$$$;$) {
5684      $p->{inner_html_node} = [$node, $el_category->{$node_ln}];      $p->{inner_html_node} = [$node, $el_category->{$node_ln}];
5685        ## TODO: Foreign element OK?        ## TODO: Foreign element OK?
5686    
5687      ## Step 3      ## F4.2. Root |html| element
5688      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
5689        ('http://www.w3.org/1999/xhtml', [undef, 'html']);        ('http://www.w3.org/1999/xhtml', [undef, 'html']);
5690    
5691      ## Step 4 # MUST      ## F4.3.
5692      $doc->append_child ($root);      $doc->append_child ($root);
5693    
5694      ## Step 5 # MUST      ## F4.4.
5695      push @{$p->{open_elements}}, [$root, $el_category->{html}];      push @{$p->{open_elements}}, [$root, $el_category->{html}];
5696    
5697      undef $p->{head_element};      undef $p->{head_element};
5698      undef $p->{head_element_inserted};      undef $p->{head_element_inserted};
5699    
5700      ## Step 6 # MUST      ## F4.5.
5701      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;
5702    
5703      ## Step 7 # MUST      ## F4.6.
5704      my $anode = $node;      my $anode = $node;
5705      AN: while (defined $anode) {      AN: while (defined $anode) {
5706        if ($anode->node_type == 1) {        if ($anode->node_type == 1) {
# Line 5648  sub set_inner_html ($$$$;$) { Line 5715  sub set_inner_html ($$$$;$) {
5715        }        }
5716        $anode = $anode->parent_node;        $anode = $anode->parent_node;
5717      } # AN      } # AN
5718        
5719      ## Step 9 # MUST      ## F.6. Start the parser.
5720      {      {
5721        my $self = $p;        my $self = $p;
5722        !!!next-token;        !!!next-token;
5723      }      }
5724      $p->_tree_construction_main;      $p->_tree_construction_main;
5725    
5726      ## Step 10 # MUST      ## F.7.
5727      my @cn = @{$node->child_nodes};      my @cn = @{$node->child_nodes};
5728      for (@cn) {      for (@cn) {
5729        $node->remove_child ($_);        $node->remove_child ($_);

Legend:
Removed from v.1.213  
changed lines
  Added in v.1.225

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24