/[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.208 by wakaba, Tue Oct 14 02:27:55 2008 UTC revision 1.218 by wakaba, Sat Jul 25 03:38:42 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 820  sub IN_CDATA_RCDATA_IM () { 0b1000000000 Line 828  sub IN_CDATA_RCDATA_IM () { 0b1000000000
828      ## combined with the original insertion mode.  In thie parser,      ## combined with the original insertion mode.  In thie parser,
829      ## they are stored together in the bit-or'ed form.      ## they are stored together in the bit-or'ed form.
830    
831    sub IM_MASK () { 0b11111111111 }
832    
833  ## NOTE: "initial" and "before html" insertion modes have no constants.  ## NOTE: "initial" and "before html" insertion modes have no constants.
834    
835  ## NOTE: "after after body" insertion mode.  ## NOTE: "after after body" insertion mode.
# Line 934  sub _tree_construction_initial ($) { Line 944  sub _tree_construction_initial ($) {
944        $doctype->public_id ($token->{pubid}) if defined $token->{pubid};        $doctype->public_id ($token->{pubid}) if defined $token->{pubid};
945        $doctype->system_id ($token->{sysid}) if defined $token->{sysid};        $doctype->system_id ($token->{sysid}) if defined $token->{sysid};
946        ## NOTE: Other DocumentType attributes are null or empty lists.        ## NOTE: Other DocumentType attributes are null or empty lists.
947        ## ISSUE: internalSubset = null??        ## In Firefox3, |internalSubset| attribute is set to the empty
948          ## string, while |null| is an allowed value for the attribute
949          ## according to DOM3 Core.
950        $self->{document}->append_child ($doctype);        $self->{document}->append_child ($doctype);
951                
952        if ($token->{quirks} or $doctype_name ne 'HTML') {        if ($token->{quirks} or $doctype_name ne 'HTML') {
# Line 2247  sub _tree_construction_main ($) { Line 2259  sub _tree_construction_main ($) {
2259            $parse_rcdata->(RCDATA_CONTENT_MODEL);            $parse_rcdata->(RCDATA_CONTENT_MODEL);
2260            ## ISSUE: A spec bug [Bug 6038]            ## ISSUE: A spec bug [Bug 6038]
2261            splice @{$self->{open_elements}}, -2, 1, () # <head>            splice @{$self->{open_elements}}, -2, 1, () # <head>
2262                if ($self->{insertion_mode} & AFTER_HEAD_IM) == AFTER_HEAD_IM;                if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM;
2263            next B;            next B;
2264          } elsif ($token->{tag_name} eq 'style' or          } elsif ($token->{tag_name} eq 'style' or
2265                   $token->{tag_name} eq 'noframes') {                   $token->{tag_name} eq 'noframes') {
# Line 2267  sub _tree_construction_main ($) { Line 2279  sub _tree_construction_main ($) {
2279            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
2280            ## ISSUE: A spec bug [Bug 6038]            ## ISSUE: A spec bug [Bug 6038]
2281            splice @{$self->{open_elements}}, -2, 1, () # <head>            splice @{$self->{open_elements}}, -2, 1, () # <head>
2282                if ($self->{insertion_mode} & AFTER_HEAD_IM) == AFTER_HEAD_IM;                if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM;
2283            next B;            next B;
2284          } elsif ($token->{tag_name} eq 'noscript') {          } elsif ($token->{tag_name} eq 'noscript') {
2285                if ($self->{insertion_mode} == IN_HEAD_IM) {                if ($self->{insertion_mode} == IN_HEAD_IM) {
# Line 2315  sub _tree_construction_main ($) { Line 2327  sub _tree_construction_main ($) {
2327            $script_start_tag->();            $script_start_tag->();
2328            ## ISSUE: A spec bug  [Bug 6038]            ## ISSUE: A spec bug  [Bug 6038]
2329            splice @{$self->{open_elements}}, -2, 1 # <head>            splice @{$self->{open_elements}}, -2, 1 # <head>
2330                if ($self->{insertion_mode} & AFTER_HEAD_IM) == AFTER_HEAD_IM;                if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM;
2331            next B;            next B;
2332          } elsif ($token->{tag_name} eq 'body' or          } elsif ($token->{tag_name} eq 'body' or
2333                   $token->{tag_name} eq 'frameset') {                   $token->{tag_name} eq 'frameset') {
# Line 2498  sub _tree_construction_main ($) { Line 2510  sub _tree_construction_main ($) {
2510                  ## Reprocess in the "after head" insertion mode...                  ## Reprocess in the "after head" insertion mode...
2511                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
2512                  !!!cp ('t143.3');                  !!!cp ('t143.3');
2513                  ## ISSUE: Two parse errors for <head><noscript></br>                  ## NOTE: Two parse errors for <head><noscript></br>
2514                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
2515                                  text => 'br', token => $token);                                  text => 'br', token => $token);
2516                  ## As if </noscript>                  ## As if </noscript>
# Line 2641  sub _tree_construction_main ($) { Line 2653  sub _tree_construction_main ($) {
2653                   caption => 1, col => 1, colgroup => 1, tbody => 1,                   caption => 1, col => 1, colgroup => 1, tbody => 1,
2654                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,                   td => 1, tfoot => 1, th => 1, thead => 1, tr => 1,
2655                  }->{$token->{tag_name}}) {                  }->{$token->{tag_name}}) {
2656                if ($self->{insertion_mode} == IN_CELL_IM) {                if (($self->{insertion_mode} & IM_MASK) == IN_CELL_IM) {
2657                  ## have an element in table scope                  ## have an element in table scope
2658                  for (reverse 0..$#{$self->{open_elements}}) {                  for (reverse 0..$#{$self->{open_elements}}) {
2659                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
# Line 2669  sub _tree_construction_main ($) { Line 2681  sub _tree_construction_main ($) {
2681                  !!!nack ('t153.1');                  !!!nack ('t153.1');
2682                  !!!next-token;                  !!!next-token;
2683                  next B;                  next B;
2684                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif (($self->{insertion_mode} & IM_MASK) == IN_CAPTION_IM) {
2685                  !!!parse-error (type => 'not closed', text => 'caption',                  !!!parse-error (type => 'not closed', text => 'caption',
2686                                  token => $token);                                  token => $token);
2687                                    
# Line 2734  sub _tree_construction_main ($) { Line 2746  sub _tree_construction_main ($) {
2746              }              }
2747            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
2748              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {              if ($token->{tag_name} eq 'td' or $token->{tag_name} eq 'th') {
2749                if ($self->{insertion_mode} == IN_CELL_IM) {                if (($self->{insertion_mode} & IM_MASK) == IN_CELL_IM) {
2750                  ## have an element in table scope                  ## have an element in table scope
2751                  my $i;                  my $i;
2752                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 2784  sub _tree_construction_main ($) { Line 2796  sub _tree_construction_main ($) {
2796                                    
2797                  !!!next-token;                  !!!next-token;
2798                  next B;                  next B;
2799                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif (($self->{insertion_mode} & IM_MASK) == IN_CAPTION_IM) {
2800                  !!!cp ('t169');                  !!!cp ('t169');
2801                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
2802                                  text => $token->{tag_name}, token => $token);                                  text => $token->{tag_name}, token => $token);
# Line 2796  sub _tree_construction_main ($) { Line 2808  sub _tree_construction_main ($) {
2808                  #                  #
2809                }                }
2810              } elsif ($token->{tag_name} eq 'caption') {              } elsif ($token->{tag_name} eq 'caption') {
2811                if ($self->{insertion_mode} == IN_CAPTION_IM) {                if (($self->{insertion_mode} & IM_MASK) == IN_CAPTION_IM) {
2812                  ## have a table element in table scope                  ## have a table element in table scope
2813                  my $i;                  my $i;
2814                  INSCOPE: {                  INSCOPE: {
# Line 2845  sub _tree_construction_main ($) { Line 2857  sub _tree_construction_main ($) {
2857                                    
2858                  !!!next-token;                  !!!next-token;
2859                  next B;                  next B;
2860                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif (($self->{insertion_mode} & IM_MASK) == IN_CELL_IM) {
2861                  !!!cp ('t177');                  !!!cp ('t177');
2862                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
2863                                  text => $token->{tag_name}, token => $token);                                  text => $token->{tag_name}, token => $token);
# Line 2860  sub _tree_construction_main ($) { Line 2872  sub _tree_construction_main ($) {
2872                        table => 1, tbody => 1, tfoot => 1,                        table => 1, tbody => 1, tfoot => 1,
2873                        thead => 1, tr => 1,                        thead => 1, tr => 1,
2874                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
2875                       $self->{insertion_mode} == IN_CELL_IM) {                       ($self->{insertion_mode} & IM_MASK) == IN_CELL_IM) {
2876                ## have an element in table scope                ## have an element in table scope
2877                my $i;                my $i;
2878                my $tn;                my $tn;
# Line 2897  sub _tree_construction_main ($) { Line 2909  sub _tree_construction_main ($) {
2909                  next B;                  next B;
2910                } # INSCOPE                } # INSCOPE
2911              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
2912                       $self->{insertion_mode} == IN_CAPTION_IM) {                       ($self->{insertion_mode} & IM_MASK) == IN_CAPTION_IM) {
2913                !!!parse-error (type => 'not closed', text => 'caption',                !!!parse-error (type => 'not closed', text => 'caption',
2914                                token => $token);                                token => $token);
2915    
# Line 2917  sub _tree_construction_main ($) { Line 2929  sub _tree_construction_main ($) {
2929                } # INSCOPE                } # INSCOPE
2930                unless (defined $i) {                unless (defined $i) {
2931                  !!!cp ('t186');                  !!!cp ('t186');
2932            ## TODO: Wrong error type?
2933                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
2934                                  text => 'caption', token => $token);                                  text => 'caption', token => $token);
2935                  ## Ignore the token                  ## Ignore the token
# Line 2962  sub _tree_construction_main ($) { Line 2975  sub _tree_construction_main ($) {
2975                  !!!cp ('t191');                  !!!cp ('t191');
2976                  #                  #
2977                }                }
2978              } elsif ({          } elsif ({
2979                        tbody => 1, tfoot => 1,                    tbody => 1, tfoot => 1,
2980                        thead => 1, tr => 1,                    thead => 1, tr => 1,
2981                       }->{$token->{tag_name}} and                   }->{$token->{tag_name}} and
2982                       $self->{insertion_mode} == IN_CAPTION_IM) {                   ($self->{insertion_mode} & IM_MASK) == IN_CAPTION_IM) {
2983                !!!cp ('t192');            !!!cp ('t192');
2984                !!!parse-error (type => 'unmatched end tag',            !!!parse-error (type => 'unmatched end tag',
2985                                text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
2986                ## Ignore the token            ## Ignore the token
2987                !!!next-token;            !!!next-token;
2988                next B;            next B;
2989              } else {          } else {
2990                !!!cp ('t193');            !!!cp ('t193');
2991                #            #
2992              }          }
2993        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
2994          for my $entry (@{$self->{open_elements}}) {          for my $entry (@{$self->{open_elements}}) {
2995            unless ($entry->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($entry->[1] & ALL_END_TAG_OPTIONAL_EL) {
# Line 3069  sub _tree_construction_main ($) { Line 3082  sub _tree_construction_main ($) {
3082          next B;          next B;
3083        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
3084          if ({          if ({
3085               tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => (($self->{insertion_mode} & IM_MASK) != IN_ROW_IM),
3086               th => 1, td => 1,               th => 1, td => 1,
3087              }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
3088            if ($self->{insertion_mode} == IN_TABLE_IM) {            if (($self->{insertion_mode} & IM_MASK) == IN_TABLE_IM) {
3089              ## Clear back to table context              ## Clear back to table context
3090              while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
3091                              & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
# Line 3085  sub _tree_construction_main ($) { Line 3098  sub _tree_construction_main ($) {
3098              ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
3099            }            }
3100                        
3101            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if (($self->{insertion_mode} & IM_MASK) == IN_TABLE_BODY_IM) {
3102              unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
3103                !!!cp ('t202');                !!!cp ('t202');
3104                !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
# Line 3137  sub _tree_construction_main ($) { Line 3150  sub _tree_construction_main ($) {
3150                    tbody => 1, tfoot => 1, thead => 1,                    tbody => 1, tfoot => 1, thead => 1,
3151                    tr => 1, # $self->{insertion_mode} == IN_ROW_IM                    tr => 1, # $self->{insertion_mode} == IN_ROW_IM
3152                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
3153            if ($self->{insertion_mode} == IN_ROW_IM) {            if (($self->{insertion_mode} & IM_MASK) == IN_ROW_IM) {
3154              ## As if </tr>              ## As if </tr>
3155              ## have an element in table scope              ## have an element in table scope
3156              my $i;              my $i;
# Line 3184  sub _tree_construction_main ($) { Line 3197  sub _tree_construction_main ($) {
3197                  }                  }
3198                }                }
3199    
3200                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {                if (($self->{insertion_mode} & IM_MASK) == IN_TABLE_BODY_IM) {
3201                  ## have an element in table scope                  ## have an element in table scope
3202                  my $i;                  my $i;
3203                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 3398  sub _tree_construction_main ($) { Line 3411  sub _tree_construction_main ($) {
3411          $insert = $insert_to_foster;          $insert = $insert_to_foster;
3412          #          #
3413        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
3414              if ($token->{tag_name} eq 'tr' and          if ($token->{tag_name} eq 'tr' and
3415                  $self->{insertion_mode} == IN_ROW_IM) {              ($self->{insertion_mode} & IM_MASK) == IN_ROW_IM) {
3416                ## have an element in table scope            ## have an element in table scope
3417                my $i;                my $i;
3418                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3419                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
# Line 3439  sub _tree_construction_main ($) { Line 3452  sub _tree_construction_main ($) {
3452                !!!nack ('t231.1');                !!!nack ('t231.1');
3453                next B;                next B;
3454              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
3455                if ($self->{insertion_mode} == IN_ROW_IM) {                if (($self->{insertion_mode} & IM_MASK) == IN_ROW_IM) {
3456                  ## As if </tr>                  ## As if </tr>
3457                  ## have an element in table scope                  ## have an element in table scope
3458                  my $i;                  my $i;
# Line 3478  sub _tree_construction_main ($) { Line 3491  sub _tree_construction_main ($) {
3491                  ## reprocess in the "in table body" insertion mode...                  ## reprocess in the "in table body" insertion mode...
3492                }                }
3493    
3494                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {                if (($self->{insertion_mode} & IM_MASK) == IN_TABLE_BODY_IM) {
3495                  ## have an element in table scope                  ## have an element in table scope
3496                  my $i;                  my $i;
3497                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 3560  sub _tree_construction_main ($) { Line 3573  sub _tree_construction_main ($) {
3573                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
3574                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
3575                       $self->{insertion_mode} & ROW_IMS) {                       $self->{insertion_mode} & ROW_IMS) {
3576                if ($self->{insertion_mode} == IN_ROW_IM) {                if (($self->{insertion_mode} & IM_MASK) == IN_ROW_IM) {
3577                  ## have an element in table scope                  ## have an element in table scope
3578                  my $i;                  my $i;
3579                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 3694  sub _tree_construction_main ($) { Line 3707  sub _tree_construction_main ($) {
3707        } else {        } else {
3708          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
3709        }        }
3710      } elsif ($self->{insertion_mode} == IN_COLUMN_GROUP_IM) {      } elsif (($self->{insertion_mode} & IM_MASK) == IN_COLUMN_GROUP_IM) {
3711            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
3712              if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
3713                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
# Line 3824  sub _tree_construction_main ($) { Line 3837  sub _tree_construction_main ($) {
3837            !!!next-token;            !!!next-token;
3838            next B;            next B;
3839          } elsif ({          } elsif ({
3840                     select => 1, input => 1, textarea => 1,                     select => 1, input => 1, textarea => 1, keygen => 1,
3841                   }->{$token->{tag_name}} or                   }->{$token->{tag_name}} or
3842                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   (($self->{insertion_mode} & IM_MASK)
3843                          == IN_SELECT_IN_TABLE_IM and
3844                    {                    {
3845                     caption => 1, table => 1,                     caption => 1, table => 1,
3846                     tbody => 1, tfoot => 1, thead => 1,                     tbody => 1, tfoot => 1, thead => 1,
# Line 3948  sub _tree_construction_main ($) { Line 3962  sub _tree_construction_main ($) {
3962            !!!nack ('t291.1');            !!!nack ('t291.1');
3963            !!!next-token;            !!!next-token;
3964            next B;            next B;
3965          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and          } elsif (($self->{insertion_mode} & IM_MASK)
3966                         == IN_SELECT_IN_TABLE_IM and
3967                   {                   {
3968                    caption => 1, table => 1, tbody => 1,                    caption => 1, table => 1, tbody => 1,
3969                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
# Line 4402  sub _tree_construction_main ($) { Line 4417  sub _tree_construction_main ($) {
4417            next B;            next B;
4418          }          }
4419    
4420          ## has a p element in scope          if ($token->{tag_name} ne 'table' or # The Hixie Quirk
4421          INSCOPE: for (reverse @{$self->{open_elements}}) {              $self->{document}->manakai_compat_mode ne 'quirks') {
4422            if ($_->[1] == P_EL) {            ## has a p element in scope
4423              !!!cp ('t344');            INSCOPE: for (reverse @{$self->{open_elements}}) {
4424              !!!back-token; # <form>              if ($_->[1] == P_EL) {
4425              $token = {type => END_TAG_TOKEN, tag_name => 'p',                !!!cp ('t344');
4426                        line => $token->{line}, column => $token->{column}};                !!!back-token; # <form>
4427              next B;                $token = {type => END_TAG_TOKEN, tag_name => 'p',
4428            } elsif ($_->[1] & SCOPING_EL) {                          line => $token->{line}, column => $token->{column}};
4429              !!!cp ('t345');                next B;
4430              last INSCOPE;              } elsif ($_->[1] & SCOPING_EL) {
4431            }                !!!cp ('t345');
4432          } # INSCOPE                last INSCOPE;
4433                }
4434              } # INSCOPE
4435            }
4436                        
4437          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
4438          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
# Line 4785  sub _tree_construction_main ($) { Line 4803  sub _tree_construction_main ($) {
4803                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
4804                          {type => START_TAG_TOKEN, tag_name => 'hr',                          {type => START_TAG_TOKEN, tag_name => 'hr',
4805                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
                         {type => START_TAG_TOKEN, tag_name => 'p',  
                          line => $token->{line}, column => $token->{column}},  
4806                          {type => START_TAG_TOKEN, tag_name => 'label',                          {type => START_TAG_TOKEN, tag_name => 'label',
4807                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
4808                         );                         );
# Line 4809  sub _tree_construction_main ($) { Line 4825  sub _tree_construction_main ($) {
4825                          #{type => CHARACTER_TOKEN, data => ''}, # SHOULD                          #{type => CHARACTER_TOKEN, data => ''}, # SHOULD
4826                          {type => END_TAG_TOKEN, tag_name => 'label',                          {type => END_TAG_TOKEN, tag_name => 'label',
4827                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
                         {type => END_TAG_TOKEN, tag_name => 'p',  
                          line => $token->{line}, column => $token->{column}},  
4828                          {type => START_TAG_TOKEN, tag_name => 'hr',                          {type => START_TAG_TOKEN, tag_name => 'hr',
4829                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
4830                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
# Line 4894  sub _tree_construction_main ($) { Line 4908  sub _tree_construction_main ($) {
4908              last INSCOPE;              last INSCOPE;
4909            }            }
4910          } # INSCOPE          } # INSCOPE
4911              
4912            ## TODO: <non-ruby><rt> is not allowed.
4913    
4914          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
4915    
# Line 4991  sub _tree_construction_main ($) { Line 5007  sub _tree_construction_main ($) {
5007                    
5008            if ($self->{insertion_mode} & TABLE_IMS or            if ($self->{insertion_mode} & TABLE_IMS or
5009                $self->{insertion_mode} & BODY_TABLE_IMS or                $self->{insertion_mode} & BODY_TABLE_IMS or
5010                $self->{insertion_mode} == IN_COLUMN_GROUP_IM) {                ($self->{insertion_mode} & IM_MASK) == IN_COLUMN_GROUP_IM) {
5011              !!!cp ('t400.1');              !!!cp ('t400.1');
5012              $self->{insertion_mode} = IN_SELECT_IN_TABLE_IM;              $self->{insertion_mode} = IN_SELECT_IN_TABLE_IM;
5013            } else {            } else {
# Line 5429  sub _tree_construction_main ($) { Line 5445  sub _tree_construction_main ($) {
5445    ## TODO: script stuffs    ## TODO: script stuffs
5446  } # _tree_construct_main  } # _tree_construct_main
5447    
5448    ## XXX: How this method is organized is somewhat out of date, although
5449    ## it still does what the current spec documents.
5450  sub set_inner_html ($$$$;$) {  sub set_inner_html ($$$$;$) {
5451    my $class = shift;    my $class = shift;
5452    my $node = shift;    my $node = shift; # /context/
5453    #my $s = \$_[0];    #my $s = \$_[0];
5454    my $onerror = $_[1];    my $onerror = $_[1];
5455    my $get_wrapper = $_[2] || sub ($) { return $_[0] };    my $get_wrapper = $_[2] || sub ($) { return $_[0] };
# Line 5439  sub set_inner_html ($$$$;$) { Line 5457  sub set_inner_html ($$$$;$) {
5457    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
5458    
5459    my $nt = $node->node_type;    my $nt = $node->node_type;
5460    if ($nt == 9) {    if ($nt == 9) { # Document (invoke the algorithm with no /context/ element)
5461      # MUST      # MUST
5462            
5463      ## Step 1 # MUST      ## Step 1 # MUST
# Line 5454  sub set_inner_html ($$$$;$) { Line 5472  sub set_inner_html ($$$$;$) {
5472    
5473      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
5474      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);      $class->parse_char_string ($_[0] => $node, $onerror, $get_wrapper);
5475    } elsif ($nt == 1) {    } elsif ($nt == 1) { # Element (invoke the algorithm with /context/ element)
5476      ## TODO: If non-html element      ## TODO: If non-html element
5477    
5478      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
5479    
5480  ## TODO: Support for $get_wrapper  ## TODO: Support for $get_wrapper
5481    
5482      ## Step 1 # MUST      ## F1. Create an HTML document.
5483      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
5484      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
5485      $doc->manakai_is_html (1);      $doc->manakai_is_html (1);
5486    
5487        ## F2. Propagate quirkness flag
5488        my $node_doc = $node->owner_document;
5489        $doc->manakai_compat_mode ($node_doc->manakai_compat_mode);
5490    
5491        ## F3. Create an HTML parser
5492      my $p = $class->new;      my $p = $class->new;
5493      $p->{document} = $doc;      $p->{document} = $doc;
5494    
# Line 5592  sub set_inner_html ($$$$;$) { Line 5616  sub set_inner_html ($$$$;$) {
5616      $p->_initialize_tokenizer;      $p->_initialize_tokenizer;
5617      $p->_initialize_tree_constructor;      $p->_initialize_tree_constructor;
5618    
5619      ## Step 2      ## F4. If /context/ is not undef...
5620    
5621        ## F4.1. content model flag
5622      my $node_ln = $node->manakai_local_name;      my $node_ln = $node->manakai_local_name;
5623      $p->{content_model} = {      $p->{content_model} = {
5624        title => RCDATA_CONTENT_MODEL,        title => RCDATA_CONTENT_MODEL,
# Line 5608  sub set_inner_html ($$$$;$) { Line 5634  sub set_inner_html ($$$$;$) {
5634      }->{$node_ln};      }->{$node_ln};
5635      $p->{content_model} = PCDATA_CONTENT_MODEL      $p->{content_model} = PCDATA_CONTENT_MODEL
5636          unless defined $p->{content_model};          unless defined $p->{content_model};
         ## ISSUE: What is "the name of the element"? local name?  
5637    
5638      $p->{inner_html_node} = [$node, $el_category->{$node_ln}];      $p->{inner_html_node} = [$node, $el_category->{$node_ln}];
5639        ## TODO: Foreign element OK?        ## TODO: Foreign element OK?
5640    
5641      ## Step 3      ## F4.2. Root |html| element
5642      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
5643        ('http://www.w3.org/1999/xhtml', [undef, 'html']);        ('http://www.w3.org/1999/xhtml', [undef, 'html']);
5644    
5645      ## Step 4 # MUST      ## F4.3.
5646      $doc->append_child ($root);      $doc->append_child ($root);
5647    
5648      ## Step 5 # MUST      ## F4.4.
5649      push @{$p->{open_elements}}, [$root, $el_category->{html}];      push @{$p->{open_elements}}, [$root, $el_category->{html}];
5650    
5651      undef $p->{head_element};      undef $p->{head_element};
5652      undef $p->{head_element_inserted};      undef $p->{head_element_inserted};
5653    
5654      ## Step 6 # MUST      ## F4.5.
5655      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;
5656    
5657      ## Step 7 # MUST      ## F4.6.
5658      my $anode = $node;      my $anode = $node;
5659      AN: while (defined $anode) {      AN: while (defined $anode) {
5660        if ($anode->node_type == 1) {        if ($anode->node_type == 1) {
# Line 5644  sub set_inner_html ($$$$;$) { Line 5669  sub set_inner_html ($$$$;$) {
5669        }        }
5670        $anode = $anode->parent_node;        $anode = $anode->parent_node;
5671      } # AN      } # AN
5672        
5673      ## Step 9 # MUST      ## F.6. Start the parser.
5674      {      {
5675        my $self = $p;        my $self = $p;
5676        !!!next-token;        !!!next-token;
5677      }      }
5678      $p->_tree_construction_main;      $p->_tree_construction_main;
5679    
5680      ## Step 10 # MUST      ## F.7.
5681      my @cn = @{$node->child_nodes};      my @cn = @{$node->child_nodes};
5682      for (@cn) {      for (@cn) {
5683        $node->remove_child ($_);        $node->remove_child ($_);

Legend:
Removed from v.1.208  
changed lines
  Added in v.1.218

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24