/[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.129 by wakaba, Sat Apr 12 15:37:33 2008 UTC revision 1.149 by wakaba, Sun May 25 08:53:49 2008 UTC
# Line 8  use Error qw(:try); Line 8  use Error qw(:try);
8  ## doc.write ('');  ## doc.write ('');
9  ## alert (doc.compatMode);  ## alert (doc.compatMode);
10    
11  ## TODO: Control charcters and noncharacters are not allowed (HTML5 revision 1263)  require IO::Handle;
 ## TODO: 1252 parse error (revision 1264)  
 ## TODO: 8859-11 = 874 (revision 1271)  
12    
13  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
14  my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;  my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;
# Line 205  my $el_category_f = { Line 203  my $el_category_f = {
203      mtext => FOREIGN_FLOW_CONTENT_EL,      mtext => FOREIGN_FLOW_CONTENT_EL,
204    },    },
205    $SVG_NS => {    $SVG_NS => {
206      foreignobject => FOREIGN_FLOW_CONTENT_EL, ## TODO: case      foreignObject => FOREIGN_FLOW_CONTENT_EL,
207      desc => FOREIGN_FLOW_CONTENT_EL,      desc => FOREIGN_FLOW_CONTENT_EL,
208      title => FOREIGN_FLOW_CONTENT_EL,      title => FOREIGN_FLOW_CONTENT_EL,
209    },    },
210    ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.    ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.
211  };  };
212    
213    my $svg_attr_name = {
214      attributename => 'attributeName',
215      attributetype => 'attributeType',
216      basefrequency => 'baseFrequency',
217      baseprofile => 'baseProfile',
218      calcmode => 'calcMode',
219      clippathunits => 'clipPathUnits',
220      contentscripttype => 'contentScriptType',
221      contentstyletype => 'contentStyleType',
222      diffuseconstant => 'diffuseConstant',
223      edgemode => 'edgeMode',
224      externalresourcesrequired => 'externalResourcesRequired',
225      filterres => 'filterRes',
226      filterunits => 'filterUnits',
227      glyphref => 'glyphRef',
228      gradienttransform => 'gradientTransform',
229      gradientunits => 'gradientUnits',
230      kernelmatrix => 'kernelMatrix',
231      kernelunitlength => 'kernelUnitLength',
232      keypoints => 'keyPoints',
233      keysplines => 'keySplines',
234      keytimes => 'keyTimes',
235      lengthadjust => 'lengthAdjust',
236      limitingconeangle => 'limitingConeAngle',
237      markerheight => 'markerHeight',
238      markerunits => 'markerUnits',
239      markerwidth => 'markerWidth',
240      maskcontentunits => 'maskContentUnits',
241      maskunits => 'maskUnits',
242      numoctaves => 'numOctaves',
243      pathlength => 'pathLength',
244      patterncontentunits => 'patternContentUnits',
245      patterntransform => 'patternTransform',
246      patternunits => 'patternUnits',
247      pointsatx => 'pointsAtX',
248      pointsaty => 'pointsAtY',
249      pointsatz => 'pointsAtZ',
250      preservealpha => 'preserveAlpha',
251      preserveaspectratio => 'preserveAspectRatio',
252      primitiveunits => 'primitiveUnits',
253      refx => 'refX',
254      refy => 'refY',
255      repeatcount => 'repeatCount',
256      repeatdur => 'repeatDur',
257      requiredextensions => 'requiredExtensions',
258      requiredfeatures => 'requiredFeatures',
259      specularconstant => 'specularConstant',
260      specularexponent => 'specularExponent',
261      spreadmethod => 'spreadMethod',
262      startoffset => 'startOffset',
263      stddeviation => 'stdDeviation',
264      stitchtiles => 'stitchTiles',
265      surfacescale => 'surfaceScale',
266      systemlanguage => 'systemLanguage',
267      tablevalues => 'tableValues',
268      targetx => 'targetX',
269      targety => 'targetY',
270      textlength => 'textLength',
271      viewbox => 'viewBox',
272      viewtarget => 'viewTarget',
273      xchannelselector => 'xChannelSelector',
274      ychannelselector => 'yChannelSelector',
275      zoomandpan => 'zoomAndPan',
276    };
277    
278    my $foreign_attr_xname = {
279      'xlink:actuate' => [$XLINK_NS, ['xlink', 'actuate']],
280      'xlink:arcrole' => [$XLINK_NS, ['xlink', 'arcrole']],
281      'xlink:href' => [$XLINK_NS, ['xlink', 'href']],
282      'xlink:role' => [$XLINK_NS, ['xlink', 'role']],
283      'xlink:show' => [$XLINK_NS, ['xlink', 'show']],
284      'xlink:title' => [$XLINK_NS, ['xlink', 'title']],
285      'xlink:type' => [$XLINK_NS, ['xlink', 'type']],
286      'xml:base' => [$XML_NS, ['xml', 'base']],
287      'xml:lang' => [$XML_NS, ['xml', 'lang']],
288      'xml:space' => [$XML_NS, ['xml', 'space']],
289      'xmlns' => [$XMLNS_NS, [undef, 'xmlns']],
290      'xmlns:xlink' => [$XMLNS_NS, ['xmlns', 'xlink']],
291    };
292    
293    ## ISSUE: xmlns:xlink="non-xlink-ns" is not an error.
294    
295  my $c1_entity_char = {  my $c1_entity_char = {
296    0x80 => 0x20AC,    0x80 => 0x20AC,
297    0x81 => 0xFFFD,    0x81 => 0xFFFD,
# Line 248  my $c1_entity_char = { Line 328  my $c1_entity_char = {
328  }; # $c1_entity_char  }; # $c1_entity_char
329    
330  sub parse_byte_string ($$$$;$) {  sub parse_byte_string ($$$$;$) {
331      my $self = shift;
332      my $charset_name = shift;
333      open my $input, '<', ref $_[0] ? $_[0] : \($_[0]);
334      return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
335    } # parse_byte_string
336    
337    sub parse_byte_stream ($$$$;$) {
338    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
339    my $charset = shift;    my $charset_name = shift;
340    my $bytes_s = ref $_[0] ? $_[0] : \($_[0]);    my $byte_stream = $_[0];
   my $s;  
     
   if (defined $charset) {  
     require Encode; ## TODO: decode(utf8) don't delete BOM  
     $s = \ (Encode::decode ($charset, $$bytes_s));  
     $self->{input_encoding} = lc $charset; ## TODO: normalize name  
     $self->{confident} = 1;  
   } else {  
     ## TODO: Implement HTML5 detection algorithm  
     require Whatpm::Charset::UniversalCharDet;  
     $charset = Whatpm::Charset::UniversalCharDet->detect_byte_string  
         (substr ($$bytes_s, 0, 1024));  
     $charset ||= 'windows-1252';  
     $s = \ (Encode::decode ($charset, $$bytes_s));  
     $self->{input_encoding} = $charset;  
     $self->{confident} = 0;  
   }  
341    
342    $self->{change_encoding} = sub {    my $onerror = $_[2] || sub {
343      my $self = shift;      my (%opt) = @_;
344      my $charset = lc shift;      warn "Parse error ($opt{type})\n";
345      my $token = shift;    };
346      ## TODO: if $charset is supported    $self->{parse_error} = $onerror; # updated later by parse_char_string
347      ## TODO: normalize charset name  
348      ## HTML5 encoding sniffing algorithm
349      require Message::Charset::Info;
350      my $charset;
351      my $buffer;
352      my ($char_stream, $e_status);
353    
354      ## "Change the encoding" algorithm:    SNIFFING: {
355    
356      ## Step 1          ## Step 1
357      if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?      if (defined $charset_name) {
358        $charset = 'utf-8';        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
359    
360          ## ISSUE: Unsupported encoding is not ignored according to the spec.
361          ($char_stream, $e_status) = $charset->get_decode_handle
362              ($byte_stream, allow_error_reporting => 1,
363               allow_fallback => 1);
364          if ($char_stream) {
365            $self->{confident} = 1;
366            last SNIFFING;
367          } else {
368            ## TODO: unsupported error
369          }
370      }      }
371    
372      ## Step 2      ## Step 2
373      if (defined $self->{input_encoding} and      my $byte_buffer = '';
374          $self->{input_encoding} eq $charset) {      for (1..1024) {
375          my $char = $byte_stream->getc;
376          last unless defined $char;
377          $byte_buffer .= $char;
378        } ## TODO: timeout
379    
380        ## Step 3
381        if ($byte_buffer =~ /^\xFE\xFF/) {
382          $charset = Message::Charset::Info->get_by_iana_name ('utf-16be');
383          ($char_stream, $e_status) = $charset->get_decode_handle
384              ($byte_stream, allow_error_reporting => 1,
385               allow_fallback => 1, byte_buffer => \$byte_buffer);
386        $self->{confident} = 1;        $self->{confident} = 1;
387        return;        last SNIFFING;
388        } elsif ($byte_buffer =~ /^\xFF\xFE/) {
389          $charset = Message::Charset::Info->get_by_iana_name ('utf-16le');
390          ($char_stream, $e_status) = $charset->get_decode_handle
391              ($byte_stream, allow_error_reporting => 1,
392               allow_fallback => 1, byte_buffer => \$byte_buffer);
393          $self->{confident} = 1;
394          last SNIFFING;
395        } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
396          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
397          ($char_stream, $e_status) = $charset->get_decode_handle
398              ($byte_stream, allow_error_reporting => 1,
399               allow_fallback => 1, byte_buffer => \$byte_buffer);
400          $self->{confident} = 1;
401          last SNIFFING;
402      }      }
403    
404      !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.      ## Step 4
405          ':'.$charset, level => 'w', token => $token);      ## TODO: <meta charset>
406    
407      ## Step 3      ## Step 5
408      # if (can) {      ## TODO: from history
       ## change the encoding on the fly.  
       #$self->{confident} = 1;  
       #return;  
     # }  
409    
410      ## Step 4      ## Step 6
411      throw Whatpm::HTML::RestartParser (charset => $charset);      require Whatpm::Charset::UniversalCharDet;
412        $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
413            ($byte_buffer);
414        if (defined $charset_name) {
415          $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
416    
417          ## ISSUE: Unsupported encoding is not ignored according to the spec.
418          require Whatpm::Charset::DecodeHandle;
419          $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
420              ($byte_stream);
421          ($char_stream, $e_status) = $charset->get_decode_handle
422              ($buffer, allow_error_reporting => 1,
423               allow_fallback => 1, byte_buffer => \$byte_buffer);
424          if ($char_stream) {
425            $buffer->{buffer} = $byte_buffer;
426            !!!parse-error (type => 'sniffing:chardet', ## TODO: type name
427                            value => $charset_name,
428                            level => $self->{info_level},
429                            line => 1, column => 1);
430            $self->{confident} = 0;
431            last SNIFFING;
432          }
433        }
434    
435        ## Step 7: default
436        ## TODO: Make this configurable.
437        $charset = Message::Charset::Info->get_by_iana_name ('windows-1252');
438            ## NOTE: We choose |windows-1252| here, since |utf-8| should be
439            ## detectable in the step 6.
440        require Whatpm::Charset::DecodeHandle;
441        $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
442            ($byte_stream);
443        ($char_stream, $e_status)
444            = $charset->get_decode_handle ($buffer,
445                                           allow_error_reporting => 1,
446                                           allow_fallback => 1,
447                                           byte_buffer => \$byte_buffer);
448        $buffer->{buffer} = $byte_buffer;
449        !!!parse-error (type => 'sniffing:default', ## TODO: type name
450                        value => 'windows-1252',
451                        level => $self->{info_level},
452                        line => 1, column => 1);
453        $self->{confident} = 0;
454      } # SNIFFING
455    
456      $self->{input_encoding} = $charset->get_iana_name;
457      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
458        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name
459                        value => $self->{input_encoding},
460                        level => $self->{unsupported_level},
461                        line => 1, column => 1);
462      } elsif (not ($e_status &
463                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
464        !!!parse-error (type => 'chardecode:no error', ## TODO: type name
465                        value => $self->{input_encoding},
466                        level => $self->{unsupported_level},
467                        line => 1, column => 1);
468      }
469    
470      $self->{change_encoding} = sub {
471        my $self = shift;
472        $charset_name = shift;
473        my $token = shift;
474    
475        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
476        ($char_stream, $e_status) = $charset->get_decode_handle
477            ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
478             byte_buffer => \ $buffer->{buffer});
479        
480        if ($char_stream) { # if supported
481          ## "Change the encoding" algorithm:
482    
483          ## Step 1    
484          if ($charset->{category} &
485              Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
486            $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
487            ($char_stream, $e_status) = $charset->get_decode_handle
488                ($byte_stream,
489                 byte_buffer => \ $buffer->{buffer});
490          }
491          $charset_name = $charset->get_iana_name;
492          
493          ## Step 2
494          if (defined $self->{input_encoding} and
495              $self->{input_encoding} eq $charset_name) {
496            !!!parse-error (type => 'charset label:matching', ## TODO: type
497                            value => $charset_name,
498                            level => $self->{info_level});
499            $self->{confident} = 1;
500            return;
501          }
502    
503          !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.
504              ':'.$charset_name, level => 'w', token => $token);
505          
506          ## Step 3
507          # if (can) {
508            ## change the encoding on the fly.
509            #$self->{confident} = 1;
510            #return;
511          # }
512          
513          ## Step 4
514          throw Whatpm::HTML::RestartParser ();
515        }
516    }; # $self->{change_encoding}    }; # $self->{change_encoding}
517    
518      my $char_onerror = sub {
519        my (undef, $type, %opt) = @_;
520        !!!parse-error (%opt, type => $type,
521                        line => $self->{line}, column => $self->{column} + 1);
522        if ($opt{octets}) {
523          ${$opt{octets}} = "\x{FFFD}"; # relacement character
524        }
525      };
526      $char_stream->onerror ($char_onerror);
527    
528    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
529    my $return;    my $return;
530    try {    try {
531      $return = $self->parse_char_string ($s, @args);        $return = $self->parse_char_stream ($char_stream, @args);  
532    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
533      my $charset = shift->{charset};      ## NOTE: Invoked after {change_encoding}.
534      $s = \ (Encode::decode ($charset, $$bytes_s));      
535      $self->{input_encoding} = $charset; ## TODO: normalize      $self->{input_encoding} = $charset->get_iana_name;
536        if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
537          !!!parse-error (type => 'chardecode:fallback', ## TODO: type name
538                          value => $self->{input_encoding},
539                          level => $self->{unsupported_level},
540                          line => 1, column => 1);
541        } elsif (not ($e_status &
542                      Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
543          !!!parse-error (type => 'chardecode:no error', ## TODO: type name
544                          value => $self->{input_encoding},
545                          level => $self->{unsupported_level},
546                          line => 1, column => 1);
547        }
548      $self->{confident} = 1;      $self->{confident} = 1;
549      $return = $self->parse_char_string ($s, @args);      $char_stream->onerror ($char_onerror);
550        $return = $self->parse_char_stream ($char_stream, @args);
551    };    };
552    return $return;    return $return;
553  } # parse_byte_string  } # parse_byte_stream
554    
555  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM
556  ## and the HTML layer MUST ignore it.  However, we does strip BOM in  ## and the HTML layer MUST ignore it.  However, we does strip BOM in
# Line 327  sub parse_byte_string ($$$$;$) { Line 561  sub parse_byte_string ($$$$;$) {
561  ## such as |parse_byte_string| in this module, must ensure that it does  ## such as |parse_byte_string| in this module, must ensure that it does
562  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
563    
564  *parse_char_string = \&parse_string;  sub parse_char_string ($$$;$) {
565      my $self = shift;
566      require utf8;
567      my $s = ref $_[0] ? $_[0] : \($_[0]);
568      open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
569      return $self->parse_char_stream ($input, @_[1..$#_]);
570    } # parse_char_string
571    *parse_string = \&parse_char_string;
572    
573  sub parse_string ($$$;$) {  sub parse_char_stream ($$$;$) {
574    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
575    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $input = $_[0];
576    $self->{document} = $_[1];    $self->{document} = $_[1];
577    @{$self->{document}->child_nodes} = ();    @{$self->{document}->child_nodes} = ();
578    
# Line 350  sub parse_string ($$$;$) { Line 591  sub parse_string ($$$;$) {
591      pop @{$self->{prev_char}};      pop @{$self->{prev_char}};
592      unshift @{$self->{prev_char}}, $self->{next_char};      unshift @{$self->{prev_char}}, $self->{next_char};
593    
594      $self->{next_char} = -1 and return if $i >= length $$s;      my $char;
595      $self->{next_char} = ord substr $$s, $i++, 1;      if (defined $self->{next_next_char}) {
596          $char = $self->{next_next_char};
597          delete $self->{next_next_char};
598        } else {
599          $char = $input->getc;
600        }
601        $self->{next_char} = -1 and return unless defined $char;
602        $self->{next_char} = ord $char;
603    
604      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
605          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
606      $self->{column}++;      $self->{column}++;
607            
608      if ($self->{next_char} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
609          !!!cp ('j1');
610        $self->{line}++;        $self->{line}++;
611        $self->{column} = 0;        $self->{column} = 0;
612      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
613        $i++ if substr ($$s, $i, 1) eq "\x0A";        !!!cp ('j2');
614          my $next = $input->getc;
615          if (defined $next and $next ne "\x0A") {
616            $self->{next_next_char} = $next;
617          }
618        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
619        $self->{line}++;        $self->{line}++;
620        $self->{column} = 0;        $self->{column} = 0;
621      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
622          !!!cp ('j3');
623        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
624      } elsif ($self->{next_char} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
625          !!!cp ('j4');
626        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
627        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
628        } elsif ($self->{next_char} <= 0x0008 or
629                 (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or
630                 (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or
631                 (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or
632                 (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or
633                 {
634                  0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
635                  0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
636                  0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
637                  0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
638                  0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
639                  0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
640                  0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
641                  0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
642                  0x10FFFE => 1, 0x10FFFF => 1,
643                 }->{$self->{next_char}}) {
644          !!!cp ('j5');
645          !!!parse-error (type => 'control char', level => $self->{must_level});
646    ## TODO: error type documentation
647      }      }
648    };    };
649    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 393  sub parse_string ($$$;$) { Line 667  sub parse_string ($$$;$) {
667    delete $self->{parse_error}; # remove loop    delete $self->{parse_error}; # remove loop
668    
669    return $self->{document};    return $self->{document};
670  } # parse_string  } # parse_char_stream
671    
672  sub new ($) {  sub new ($) {
673    my $class = shift;    my $class = shift;
674    my $self = bless {}, $class;    my $self = bless {
675        must_level => 'm',
676        should_level => 's',
677        good_level => 'w',
678        warn_level => 'w',
679        info_level => 'i',
680        unsupported_level => 'u',
681      }, $class;
682    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
683      $self->{next_char} = -1;      $self->{next_char} = -1;
684    };    };
# Line 762  sub _get_next_token ($) { Line 1043  sub _get_next_token ($) {
1043            redo A;            redo A;
1044          } else {          } else {
1045            !!!cp (23);            !!!cp (23);
1046            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago',
1047                              line => $self->{line_prev},
1048                              column => $self->{column_prev});
1049            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1050            ## reconsume            ## reconsume
1051    
# Line 1539  sub _get_next_token ($) { Line 1822  sub _get_next_token ($) {
1822          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1823          !!!next-input-character;          !!!next-input-character;
1824          redo A;          redo A;
1825          } elsif ($self->{next_char} == -1) {
1826            !!!parse-error (type => 'unclosed tag');
1827            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1828              !!!cp (122.3);
1829              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1830            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1831              if ($self->{current_token}->{attributes}) {
1832                !!!cp (122.1);
1833                !!!parse-error (type => 'end tag attribute');
1834              } else {
1835                ## NOTE: This state should never be reached.
1836                !!!cp (122.2);
1837              }
1838            } else {
1839              die "$0: $self->{current_token}->{type}: Unknown token type";
1840            }
1841            $self->{state} = DATA_STATE;
1842            ## Reconsume.
1843            !!!emit ($self->{current_token}); # start tag or end tag
1844            redo A;
1845        } else {        } else {
1846          !!!cp ('124.1');          !!!cp ('124.1');
1847          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1571  sub _get_next_token ($) { Line 1874  sub _get_next_token ($) {
1874          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1875    
1876          redo A;          redo A;
1877          } elsif ($self->{next_char} == -1) {
1878            !!!parse-error (type => 'unclosed tag');
1879            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1880              !!!cp (124.7);
1881              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1882            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1883              if ($self->{current_token}->{attributes}) {
1884                !!!cp (124.5);
1885                !!!parse-error (type => 'end tag attribute');
1886              } else {
1887                ## NOTE: This state should never be reached.
1888                !!!cp (124.6);
1889              }
1890            } else {
1891              die "$0: $self->{current_token}->{type}: Unknown token type";
1892            }
1893            $self->{state} = DATA_STATE;
1894            ## Reconsume.
1895            !!!emit ($self->{current_token}); # start tag or end tag
1896            redo A;
1897        } else {        } else {
1898          !!!cp ('124.4');          !!!cp ('124.4');
1899          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 2411  sub _get_next_token ($) { Line 2734  sub _get_next_token ($) {
2734          redo A;          redo A;
2735        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2736          !!!cp (217);          !!!cp (217);
         !!!parse-error (type => 'unclosed DOCTYPE');  
2737    
2738          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2739          ## reconsume          ## reconsume
# Line 2815  sub _tree_construction_initial ($) { Line 3137  sub _tree_construction_initial ($) {
3137        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3138          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3139          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3140          if ({          my $prefix = [
3141            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3142            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3143            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3144            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3145            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3146            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3147            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3148            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3149            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3150            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3151            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3152            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3153            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3154            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3155            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3156            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3157            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3158            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3159            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3160            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3161            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3162            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3163            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3164            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3165            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3166            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3167            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3168            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3169            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3170            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3171            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3172            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3173            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3174            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3175            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3176            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3177            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3178            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3179            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3180            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3181            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3182            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3183            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3184            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3185            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3186            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3187            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3188            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3189            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3190            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3191            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3192            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3193            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3194            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3195            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3196            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3197            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3198            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3199            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3200            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3201            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3202            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3203            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3204            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3205            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3206            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3207            "-//W3O//DTD W3 HTML 3.0//EN//" => 1,              $pubid eq "HTML") {
           "-//W3O//DTD W3 HTML STRICT 3.0//EN//" => 1,  
           "-//WEBTECHS//DTD MOZILLA HTML 2.0//EN" => 1,  
           "-//WEBTECHS//DTD MOZILLA HTML//EN" => 1,  
           "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,  
           "HTML" => 1,  
         }->{$pubid}) {  
3208            !!!cp ('t5');            !!!cp ('t5');
3209            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3210          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3211                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3212            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3213              !!!cp ('t6');              !!!cp ('t6');
3214              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 2900  sub _tree_construction_initial ($) { Line 3216  sub _tree_construction_initial ($) {
3216              !!!cp ('t7');              !!!cp ('t7');
3217              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3218            }            }
3219          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3220                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3221            !!!cp ('t8');            !!!cp ('t8');
3222            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3223          } else {          } else {
# Line 2914  sub _tree_construction_initial ($) { Line 3230  sub _tree_construction_initial ($) {
3230          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3231          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3232          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {
3233            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3234              ## marked as quirks.
3235            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3236            !!!cp ('t11');            !!!cp ('t11');
3237          } else {          } else {
# Line 3086  sub _reset_insertion_mode ($) { Line 3403  sub _reset_insertion_mode ($) {
3403        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3404          $last = 1;          $last = 1;
3405          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3406            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3407              !!!cp ('t27');            $node = $self->{inner_html_node};
3408              #          } else {
3409            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3410          }          }
3411        }        }
3412              
3413      ## Step 4..14        ## Step 4..14
3414      my $new_mode;        my $new_mode;
3415      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3416        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3417        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3418        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3419        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3420        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3421      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3422        $new_mode = {          if ($last) {
3423              !!!cp ('t28.2');
3424              #
3425            } else {
3426              !!!cp ('t28.3');
3427              $new_mode = IN_CELL_IM;
3428            }
3429          } else {
3430            !!!cp ('t28.4');
3431            $new_mode = {
3432                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3433                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3434                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3435                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3436                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3437                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3122  sub _reset_insertion_mode ($) { Line 3443  sub _reset_insertion_mode ($) {
3443                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3444                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3445                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3446      }        }
3447      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3448                
3449        ## Step 15        ## Step 15
3450        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3699  sub _tree_construction_main ($) { Line 4020  sub _tree_construction_main ($) {
4020            !!!cp ('t87.2');            !!!cp ('t87.2');
4021            #            #
4022          } elsif ({          } elsif ({
4023    ## TODO:                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4024                      center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4025                      em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4026                      h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4027                      img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4028                      nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4029                      small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4030                      sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4031                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4032            !!!cp ('t87.2');            !!!cp ('t87.2');
4033            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
# Line 3710  sub _tree_construction_main ($) { Line 4038  sub _tree_construction_main ($) {
4038            pop @{$self->{open_elements}}            pop @{$self->{open_elements}}
4039                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4040    
4041            $self->{insertion_mode} &= ~ $self->{insertion_mode};            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4042            ## Reprocess.            ## Reprocess.
4043            next B;            next B;
4044          } else {          } else {
4045            ## TODO: case fixup            my $nsuri = $self->{open_elements}->[-1]->[0]->namespace_uri;
4046              my $tag_name = $token->{tag_name};
4047              if ($nsuri eq $SVG_NS) {
4048                $tag_name = {
4049                   altglyph => 'altGlyph',
4050                   altglyphdef => 'altGlyphDef',
4051                   altglyphitem => 'altGlyphItem',
4052                   animatecolor => 'animateColor',
4053                   animatemotion => 'animateMotion',
4054                   animatetransform => 'animateTransform',
4055                   clippath => 'clipPath',
4056                   feblend => 'feBlend',
4057                   fecolormatrix => 'feColorMatrix',
4058                   fecomponenttransfer => 'feComponentTransfer',
4059                   fecomposite => 'feComposite',
4060                   feconvolvematrix => 'feConvolveMatrix',
4061                   fediffuselighting => 'feDiffuseLighting',
4062                   fedisplacementmap => 'feDisplacementMap',
4063                   fedistantlight => 'feDistantLight',
4064                   feflood => 'feFlood',
4065                   fefunca => 'feFuncA',
4066                   fefuncb => 'feFuncB',
4067                   fefuncg => 'feFuncG',
4068                   fefuncr => 'feFuncR',
4069                   fegaussianblur => 'feGaussianBlur',
4070                   feimage => 'feImage',
4071                   femerge => 'feMerge',
4072                   femergenode => 'feMergeNode',
4073                   femorphology => 'feMorphology',
4074                   feoffset => 'feOffset',
4075                   fepointlight => 'fePointLight',
4076                   fespecularlighting => 'feSpecularLighting',
4077                   fespotlight => 'feSpotLight',
4078                   fetile => 'feTile',
4079                   feturbulence => 'feTurbulence',
4080                   foreignobject => 'foreignObject',
4081                   glyphref => 'glyphRef',
4082                   lineargradient => 'linearGradient',
4083                   radialgradient => 'radialGradient',
4084                   #solidcolor => 'solidColor', ## NOTE: Commented in spec (SVG1.2)
4085                   textpath => 'textPath',  
4086                }->{$tag_name} || $tag_name;
4087              }
4088    
4089              ## "adjust SVG attributes" (SVG only) - done in insert-element-f
4090    
4091            !!!insert-element-f ($self->{open_elements}->[-1]->[0]->namespace_uri, $token);            ## "adjust foreign attributes" - done in insert-element-f
4092    
4093              !!!insert-element-f ($nsuri, $tag_name, $token->{attributes}, $token);
4094    
4095            if ($self->{self_closing}) {            if ($self->{self_closing}) {
4096              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 3733  sub _tree_construction_main ($) { Line 4107  sub _tree_construction_main ($) {
4107          !!!cp ('t87.5');          !!!cp ('t87.5');
4108          #          #
4109        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4110          !!!cp ('t87.6');          !!!cp ('t87.6');
4111          #          !!!parse-error (type => 'not closed',
4112          ## TODO: ...                          value => $self->{open_elements}->[-1]->[0]
4113                                ->manakai_local_name,
4114                            token => $token);
4115    
4116            pop @{$self->{open_elements}}
4117                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4118    
4119            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4120            ## Reprocess.
4121            next B;
4122        } else {        } else {
4123          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4124        }        }
# Line 3813  sub _tree_construction_main ($) { Line 4195  sub _tree_construction_main ($) {
4195              !!!next-token;              !!!next-token;
4196              next B;              next B;
4197            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4198              !!!cp ('t94');              !!!cp ('t93.2');
4199              #              !!!parse-error (type => 'after head:head', token => $token); ## TODO: error type
4200                ## Ignore the token
4201                !!!nack ('t93.3');
4202                !!!next-token;
4203                next B;
4204            } else {            } else {
4205              !!!cp ('t95');              !!!cp ('t95');
4206              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript
# Line 3897  sub _tree_construction_main ($) { Line 4283  sub _tree_construction_main ($) {
4283                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4284    
4285                unless ($self->{confident}) {                unless ($self->{confident}) {
4286                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) {
4287                    !!!cp ('t106');                    !!!cp ('t106');
4288                      ## NOTE: Whether the encoding is supported or not is handled
4289                      ## in the {change_encoding} callback.
4290                    $self->{change_encoding}                    $self->{change_encoding}
4291                        ->($self, $token->{attributes}->{charset}->{value},                        ->($self, $token->{attributes}->{charset}->{value},
4292                           $token);                           $token);
# Line 3908  sub _tree_construction_main ($) { Line 4296  sub _tree_construction_main ($) {
4296                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
4297                                                 ->{has_reference});                                                 ->{has_reference});
4298                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
                   ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
4299                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4300                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4301                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4302                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4303                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4304                      !!!cp ('t107');                      !!!cp ('t107');
4305                        ## NOTE: Whether the encoding is supported or not is handled
4306                        ## in the {change_encoding} callback.
4307                      $self->{change_encoding}                      $self->{change_encoding}
4308                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,
4309                             $token);                             $token);
# Line 3973  sub _tree_construction_main ($) { Line 4362  sub _tree_construction_main ($) {
4362                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4363                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4364                next B;                next B;
4365              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4366                         $token->{tag_name} eq 'noframes') {
4367                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4368                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4369                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
# Line 4133  sub _tree_construction_main ($) { Line 4523  sub _tree_construction_main ($) {
4523                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4524                  !!!next-token;                  !!!next-token;
4525                  next B;                  next B;
4526                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4527                    !!!cp ('t134.1');
4528                    !!!parse-error (type => 'unmatched end tag:head', token => $token);
4529                    ## Ignore the token
4530                    !!!next-token;
4531                    next B;
4532                } else {                } else {
4533                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4534                }                }
4535              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4536                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4144  sub _tree_construction_main ($) { Line 4539  sub _tree_construction_main ($) {
4539                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4540                  !!!next-token;                  !!!next-token;
4541                  next B;                  next B;
4542                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4543                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4544                  !!!cp ('t137');                  !!!cp ('t137');
4545                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);
4546                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
# Line 4157  sub _tree_construction_main ($) { Line 4553  sub _tree_construction_main ($) {
4553              } elsif ({              } elsif ({
4554                        body => 1, html => 1,                        body => 1, html => 1,
4555                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4556                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4557                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4558                  ## As if <head>                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
                 !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);  
                 $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});  
                 push @{$self->{open_elements}},  
                     [$self->{head_element}, $el_category->{head}];  
   
                 $self->{insertion_mode} = IN_HEAD_IM;  
                 ## Reprocess in the "in head" insertion mode...  
               } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {  
4559                  !!!cp ('t140');                  !!!cp ('t140');
4560                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4561                  ## Ignore the token                  ## Ignore the token
4562                  !!!next-token;                  !!!next-token;
4563                  next B;                  next B;
4564                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4565                    !!!cp ('t140.1');
4566                    !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);
4567                    ## Ignore the token
4568                    !!!next-token;
4569                    next B;
4570                } else {                } else {
4571                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4572                }                }
4573                              } elsif ($token->{tag_name} eq 'p') {
4574                #                !!!cp ('t142');
4575              } elsif ({                !!!parse-error (type => 'unmatched end tag:p', token => $token);
4576                        p => 1, br => 1,                ## Ignore the token
4577                       }->{$token->{tag_name}}) {                !!!next-token;
4578                  next B;
4579                } elsif ($token->{tag_name} eq 'br') {
4580                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4581                  !!!cp ('t142');                  !!!cp ('t142.2');
4582                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4583                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4584                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4585                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4586                      [$self->{head_element}, $el_category->{head}];    
4587                    ## Reprocess in the "after head" insertion mode...
4588                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4589                    !!!cp ('t143.2');
4590                    ## As if </head>
4591                    pop @{$self->{open_elements}};
4592                    $self->{insertion_mode} = AFTER_HEAD_IM;
4593      
4594                    ## Reprocess in the "after head" insertion mode...
4595                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4596                    !!!cp ('t143.3');
4597                    ## ISSUE: Two parse errors for <head><noscript></br>
4598                    !!!parse-error (type => 'unmatched end tag:br', token => $token);
4599                    ## As if </noscript>
4600                    pop @{$self->{open_elements}};
4601                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4602    
4603                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4604                } else {                  ## As if </head>
4605                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4606                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4607    
4608                #                  ## Reprocess in the "after head" insertion mode...
4609              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4610                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4611                  #                  #
4612                } else {                } else {
4613                  !!!cp ('t145');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);  
                 ## Ignore the token  
                 !!!next-token;  
                 next B;  
4614                }                }
4615    
4616                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4617                  !!!parse-error (type => 'unmatched end tag:br', token => $token);
4618                  ## Ignore the token
4619                  !!!next-token;
4620                  next B;
4621                } else {
4622                  !!!cp ('t145');
4623                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4624                  ## Ignore the token
4625                  !!!next-token;
4626                  next B;
4627              }              }
4628    
4629              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 5458  sub _tree_construction_main ($) { Line 5875  sub _tree_construction_main ($) {
5875            !!!nack ('t277.1');            !!!nack ('t277.1');
5876            !!!next-token;            !!!next-token;
5877            next B;            next B;
5878          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
5879                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
5880                     }->{$token->{tag_name}} or
5881                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5882                    {                    {
5883                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5816  sub _tree_construction_main ($) { Line 6234  sub _tree_construction_main ($) {
6234            next B;            next B;
6235          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6236            !!!cp ('t320');            !!!cp ('t320');
6237            ## NOTE: As if in body.            ## NOTE: As if in head.
6238            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6239            next B;            next B;
6240          } else {          } else {
# Line 5931  sub _tree_construction_main ($) { Line 6349  sub _tree_construction_main ($) {
6349          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
6350    
6351          unless ($self->{confident}) {          unless ($self->{confident}) {
6352            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) {
6353              !!!cp ('t335');              !!!cp ('t335');
6354                ## NOTE: Whether the encoding is supported or not is handled
6355                ## in the {change_encoding} callback.
6356              $self->{change_encoding}              $self->{change_encoding}
6357                  ->($self, $token->{attributes}->{charset}->{value}, $token);                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6358                            
# Line 5941  sub _tree_construction_main ($) { Line 6361  sub _tree_construction_main ($) {
6361                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
6362                                           ->{has_reference});                                           ->{has_reference});
6363            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
6364              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6365                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6366                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6367                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6368                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6369                !!!cp ('t336');                !!!cp ('t336');
6370                  ## NOTE: Whether the encoding is supported or not is handled
6371                  ## in the {change_encoding} callback.
6372                $self->{change_encoding}                $self->{change_encoding}
6373                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6374                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 6256  sub _tree_construction_main ($) { Line 6677  sub _tree_construction_main ($) {
6677                  xmp => 1,                  xmp => 1,
6678                  iframe => 1,                  iframe => 1,
6679                  noembed => 1,                  noembed => 1,
6680                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6681                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6682                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6683          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6278  sub _tree_construction_main ($) { Line 6699  sub _tree_construction_main ($) {
6699            !!!next-token;            !!!next-token;
6700            next B;            next B;
6701          } else {          } else {
6702              !!!ack ('t391.1');
6703    
6704            my $at = $token->{attributes};            my $at = $token->{attributes};
6705            my $form_attrs;            my $form_attrs;
6706            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6321  sub _tree_construction_main ($) { Line 6744  sub _tree_construction_main ($) {
6744                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6745                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6746                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6747            !!!back-token (@tokens);            !!!back-token (@tokens);
6748            !!!next-token;            !!!next-token;
6749            next B;            next B;
# Line 6376  sub _tree_construction_main ($) { Line 6798  sub _tree_construction_main ($) {
6798        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
6799                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6800          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6801    
6802            ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6803    
6804            ## "adjust foreign attributes" - done in insert-element-f
6805                    
6806          !!!insert-element-f ($token->{tag_name} eq 'math' ? $MML_NS : $SVG_NS, $token);          !!!insert-element-f ($token->{tag_name} eq 'math' ? $MML_NS : $SVG_NS, $token->{tag_name}, $token->{attributes}, $token);
6807                    
6808          if ($self->{self_closing}) {          if ($self->{self_closing}) {
6809            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
# Line 6917  sub set_inner_html ($$$) { Line 7343  sub set_inner_html ($$$) {
7343          !!!cp ('i4');          !!!cp ('i4');
7344          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7345          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
7346          } elsif ($self->{next_char} <= 0x0008 or
7347                   (0x000E <= $self->{next_char} and
7348                    $self->{next_char} <= 0x001F) or
7349                   (0x007F <= $self->{next_char} and
7350                    $self->{next_char} <= 0x009F) or
7351                   (0xD800 <= $self->{next_char} and
7352                    $self->{next_char} <= 0xDFFF) or
7353                   (0xFDD0 <= $self->{next_char} and
7354                    $self->{next_char} <= 0xFDDF) or
7355                   {
7356                    0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
7357                    0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
7358                    0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
7359                    0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
7360                    0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
7361                    0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
7362                    0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
7363                    0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
7364                    0x10FFFE => 1, 0x10FFFF => 1,
7365                   }->{$self->{next_char}}) {
7366            !!!cp ('i4.1');
7367            !!!parse-error (type => 'control char', level => $self->{must_level});
7368    ## TODO: error type documentation
7369        }        }
7370      };      };
7371      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.129  
changed lines
  Added in v.1.149

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24