/[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.11 by wakaba, Sat Jun 23 03:53:35 2007 UTC revision 1.15 by wakaba, Sat Jun 23 06:48:24 2007 UTC
# Line 349  sub parse_string ($$$;$) { Line 349  sub parse_string ($$$;$) {
349    my $column = 0;    my $column = 0;
350    $self->{set_next_input_character} = sub {    $self->{set_next_input_character} = sub {
351      my $self = shift;      my $self = shift;
352    
353        pop @{$self->{prev_input_character}};
354        unshift @{$self->{prev_input_character}}, $self->{next_input_character};
355    
356      $self->{next_input_character} = -1 and return if $i >= length $$s;      $self->{next_input_character} = -1 and return if $i >= length $$s;
357      $self->{next_input_character} = ord substr $$s, $i++, 1;      $self->{next_input_character} = ord substr $$s, $i++, 1;
358      $column++;      $column++;
# Line 357  sub parse_string ($$$;$) { Line 361  sub parse_string ($$$;$) {
361        $line++;        $line++;
362        $column = 0;        $column = 0;
363      } elsif ($self->{next_input_character} == 0x000D) { # CR      } elsif ($self->{next_input_character} == 0x000D) { # CR
364        if ($i >= length $$s) {        $i++ if substr ($$s, $i, 1) eq "\x0A";
         #  
       } else {  
         my $next_char = ord substr $$s, $i++, 1;  
         if ($next_char == 0x000A) { # LF  
           #  
         } else {  
           push @{$self->{char}}, $next_char;  
         }  
       }  
365        $self->{next_input_character} = 0x000A; # LF # MUST        $self->{next_input_character} = 0x000A; # LF # MUST
366        $line++;        $line++;
367        $column = 0;        $column = 0;
# Line 377  sub parse_string ($$$;$) { Line 372  sub parse_string ($$$;$) {
372        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
373      }      }
374    };    };
375      $self->{prev_input_character} = [-1, -1, -1];
376      $self->{next_input_character} = -1;
377    
378    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
379      my (%opt) = @_;      my (%opt) = @_;
# Line 461  sub _get_next_token ($) { Line 458  sub _get_next_token ($) {
458          } else {          } else {
459            #            #
460          }          }
461          } elsif ($self->{next_input_character} == 0x002D) { # -
462            if ($self->{content_model_flag} eq 'RCDATA' or
463                $self->{content_model_flag} eq 'CDATA') {
464              unless ($self->{escape}) {
465                if ($self->{prev_input_character}->[0] == 0x002D and # -
466                    $self->{prev_input_character}->[1] == 0x0021 and # !
467                    $self->{prev_input_character}->[2] == 0x003C) { # <
468                  $self->{escape} = 1;
469                }
470              }
471            }
472            
473            #
474        } elsif ($self->{next_input_character} == 0x003C) { # <        } elsif ($self->{next_input_character} == 0x003C) { # <
475          if ($self->{content_model_flag} ne 'PLAINTEXT') {          if ($self->{content_model_flag} eq 'PCDATA' or
476                (($self->{content_model_flag} eq 'CDATA' or
477                  $self->{content_model_flag} eq 'RCDATA') and
478                 not $self->{escape})) {
479            $self->{state} = 'tag open';            $self->{state} = 'tag open';
480            !!!next-input-character;            !!!next-input-character;
481            redo A;            redo A;
482          } else {          } else {
483            #            #
484          }          }
485          } elsif ($self->{next_input_character} == 0x003E) { # >
486            if ($self->{escape} and
487                ($self->{content_model_flag} eq 'RCDATA' or
488                 $self->{content_model_flag} eq 'CDATA')) {
489              if ($self->{prev_input_character}->[0] == 0x002D and # -
490                  $self->{prev_input_character}->[1] == 0x002D) { # -
491                delete $self->{escape};
492              }
493            }
494            
495            #
496        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
497          !!!emit ({type => 'end-of-file'});          !!!emit ({type => 'end-of-file'});
498          last A; ## TODO: ok?          last A; ## TODO: ok?
# Line 1924  sub _tree_construction_main ($) { Line 1948  sub _tree_construction_main ($) {
1948       ? $self->{head_element} : $self->{open_elements}->[-1]->[0])       ? $self->{head_element} : $self->{open_elements}->[-1]->[0])
1949        ->append_child ($style_el);        ->append_child ($style_el);
1950      $self->{content_model_flag} = 'CDATA';      $self->{content_model_flag} = 'CDATA';
1951        delete $self->{escape}; # MUST
1952                                
1953      my $text = '';      my $text = '';
1954      !!!next-token;      !!!next-token;
# Line 1952  sub _tree_construction_main ($) { Line 1977  sub _tree_construction_main ($) {
1977      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
1978    
1979      $self->{content_model_flag} = 'CDATA';      $self->{content_model_flag} = 'CDATA';
1980        delete $self->{escape}; # MUST
1981            
1982      my $text = '';      my $text = '';
1983      !!!next-token;      !!!next-token;
# Line 2241  sub _tree_construction_main ($) { Line 2267  sub _tree_construction_main ($) {
2267          (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])          (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])
2268            ->append_child ($title_el);            ->append_child ($title_el);
2269          $self->{content_model_flag} = 'RCDATA';          $self->{content_model_flag} = 'RCDATA';
2270            delete $self->{escape}; # MUST
2271                    
2272          my $text = '';          my $text = '';
2273          !!!next-token;          !!!next-token;
# Line 2587  sub _tree_construction_main ($) { Line 2614  sub _tree_construction_main ($) {
2614          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2615                    
2616          $self->{content_model_flag} = 'CDATA';          $self->{content_model_flag} = 'CDATA';
2617            delete $self->{escape}; # MUST
2618                    
2619          !!!next-token;          !!!next-token;
2620          return;          return;
# Line 2703  sub _tree_construction_main ($) { Line 2731  sub _tree_construction_main ($) {
2731          } else {          } else {
2732            $self->{content_model_flag} = 'CDATA';            $self->{content_model_flag} = 'CDATA';
2733          }          }
2734            delete $self->{escape}; # MUST
2735                    
2736          $insert->($el);          $insert->($el);
2737                    
# Line 2804  sub _tree_construction_main ($) { Line 2833  sub _tree_construction_main ($) {
2833                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
2834                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
2835                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 form => 1,  
2836                  p => 1,                  p => 1,
2837                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
2838                  button => 1, marquee => 1, object => 1,                  button => 1, marquee => 1, object => 1,
# Line 2842  sub _tree_construction_main ($) { Line 2870  sub _tree_construction_main ($) {
2870          }          }
2871                    
2872          splice @{$self->{open_elements}}, $i if defined $i;          splice @{$self->{open_elements}}, $i if defined $i;
         undef $self->{form_element} if $token->{tag_name} eq 'form';  
2873          $clear_up_to_marker->()          $clear_up_to_marker->()
2874            if {            if {
2875              button => 1, marquee => 1, object => 1,              button => 1, marquee => 1, object => 1,
2876            }->{$token->{tag_name}};            }->{$token->{tag_name}};
2877          !!!next-token;          !!!next-token;
2878          return;          return;
2879          } elsif ($token->{tag_name} eq 'form') {
2880            ## has an element in scope
2881            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2882              my $node = $self->{open_elements}->[$_];
2883              if ($node->[1] eq $token->{tag_name}) {
2884                ## generate implied end tags
2885                if ({
2886                     dd => 1, dt => 1, li => 1, p => 1,
2887                     td => 1, th => 1, tr => 1,
2888                    }->{$self->{open_elements}->[-1]->[1]}) {
2889                  !!!back-token;
2890                  $token = {type => 'end tag',
2891                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
2892                  return;
2893                }
2894                last INSCOPE;
2895              } elsif ({
2896                        table => 1, caption => 1, td => 1, th => 1,
2897                        button => 1, marquee => 1, object => 1, html => 1,
2898                       }->{$node->[1]}) {
2899                last INSCOPE;
2900              }
2901            } # INSCOPE
2902            
2903            if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {
2904              pop @{$self->{open_elements}};
2905            } else {
2906              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
2907            }
2908    
2909            undef $self->{form_element};
2910            !!!next-token;
2911            return;
2912        } elsif ({        } elsif ({
2913                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
2914                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 3094  sub _tree_construction_main ($) { Line 3154  sub _tree_construction_main ($) {
3154                (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])                (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])
3155                  ->append_child ($title_el);                  ->append_child ($title_el);
3156                $self->{content_model_flag} = 'RCDATA';                $self->{content_model_flag} = 'RCDATA';
3157                  delete $self->{escape}; # MUST
3158    
3159                my $text = '';                my $text = '';
3160                !!!next-token;                !!!next-token;
# Line 4865  sub set_inner_html ($$$) { Line 4926  sub set_inner_html ($$$) {
4926      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
4927    
4928      ## Step 1 # MUST      ## Step 1 # MUST
4929      my $doc = $node->owner_document->implementation->create_document;      my $this_doc = $node->owner_document;
4930        my $doc = $this_doc->implementation->create_document;
4931      ## TODO: Mark as HTML document      ## TODO: Mark as HTML document
4932      my $p = $class->new;      my $p = $class->new;
4933      $p->{document} = $doc;      $p->{document} = $doc;
# Line 4876  sub set_inner_html ($$$) { Line 4938  sub set_inner_html ($$$) {
4938      my $column = 0;      my $column = 0;
4939      $p->{set_next_input_character} = sub {      $p->{set_next_input_character} = sub {
4940        my $self = shift;        my $self = shift;
4941    
4942          pop @{$self->{prev_input_character}};
4943          unshift @{$self->{prev_input_character}}, $self->{next_input_character};
4944    
4945        $self->{next_input_character} = -1 and return if $i >= length $$s;        $self->{next_input_character} = -1 and return if $i >= length $$s;
4946        $self->{next_input_character} = ord substr $$s, $i++, 1;        $self->{next_input_character} = ord substr $$s, $i++, 1;
4947        $column++;        $column++;
# Line 4884  sub set_inner_html ($$$) { Line 4950  sub set_inner_html ($$$) {
4950          $line++;          $line++;
4951          $column = 0;          $column = 0;
4952        } elsif ($self->{next_input_character} == 0x000D) { # CR        } elsif ($self->{next_input_character} == 0x000D) { # CR
4953          if ($i >= length $$s) {          $i++ if substr ($$s, $i, 1) eq "\x0A";
           #  
         } else {  
           my $next_char = ord substr $$s, $i++, 1;  
           if ($next_char == 0x000A) { # LF  
             #  
           } else {  
             push @{$self->{char}}, $next_char;  
           }  
         }  
4954          $self->{next_input_character} = 0x000A; # LF # MUST          $self->{next_input_character} = 0x000A; # LF # MUST
4955          $line++;          $line++;
4956          $column = 0;          $column = 0;
4957        } elsif ($self->{next_input_character} > 0x10FFFF) {        } elsif ($self->{next_input_character} > 0x10FFFF) {
4958          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
4959        } elsif ($self->{next_input_character} == 0x0000) { # NULL        } elsif ($self->{next_input_character} == 0x0000) { # NULL
4960            !!!parse-error (type => 'NULL');
4961          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
4962        }        }
4963      };      };
4964        $p->{prev_input_character} = [-1, -1, -1];
4965        $p->{next_input_character} = -1;
4966            
4967      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
4968        my (%opt) = @_;        my (%opt) = @_;
# Line 4981  sub set_inner_html ($$$) { Line 5041  sub set_inner_html ($$$) {
5041      ## Step 12 # MUST      ## Step 12 # MUST
5042      @cn = @{$root->child_nodes};      @cn = @{$root->child_nodes};
5043      for (@cn) {      for (@cn) {
5044          $this_doc->adopt_node ($_);
5045        $node->append_child ($_);        $node->append_child ($_);
5046      }      }
5047      ## ISSUE: adopt_node? mutation events?      ## ISSUE: mutation events?
5048    
5049      $p->_terminate_tree_constructor;      $p->_terminate_tree_constructor;
5050    } else {    } else {

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.15

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24