/[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.127 by wakaba, Sat Apr 12 15:25:52 2008 UTC revision 1.146 by wakaba, Sat May 24 14:19:55 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->{iana_names}->{'utf-16'}) { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?
485            $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
486            ($char_stream, $e_status) = $charset->get_decode_handle
487                ($byte_stream,
488                 byte_buffer => \ $buffer->{buffer});
489          }
490          $charset_name = $charset->get_iana_name;
491          
492          ## Step 2
493          if (defined $self->{input_encoding} and
494              $self->{input_encoding} eq $charset_name) {
495            !!!parse-error (type => 'charset label:matching', ## TODO: type
496                            value => $charset_name,
497                            level => $self->{info_level});
498            $self->{confident} = 1;
499            return;
500          }
501    
502          !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.
503              ':'.$charset_name, level => 'w', token => $token);
504          
505          ## Step 3
506          # if (can) {
507            ## change the encoding on the fly.
508            #$self->{confident} = 1;
509            #return;
510          # }
511          
512          ## Step 4
513          throw Whatpm::HTML::RestartParser ();
514        }
515    }; # $self->{change_encoding}    }; # $self->{change_encoding}
516    
517      my $char_onerror = sub {
518        my (undef, $type, %opt) = @_;
519        !!!parse-error (%opt, type => $type,
520                        line => $self->{line}, column => $self->{column} + 1);
521        if ($opt{octets}) {
522          ${$opt{octets}} = "\x{FFFD}"; # relacement character
523        }
524      };
525      $char_stream->onerror ($char_onerror);
526    
527    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
528    my $return;    my $return;
529    try {    try {
530      $return = $self->parse_char_string ($s, @args);        $return = $self->parse_char_stream ($char_stream, @args);  
531    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
532      my $charset = shift->{charset};      ## NOTE: Invoked after {change_encoding}.
533      $s = \ (Encode::decode ($charset, $$bytes_s));      
534      $self->{input_encoding} = $charset; ## TODO: normalize      $self->{input_encoding} = $charset->get_iana_name;
535        if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
536          !!!parse-error (type => 'chardecode:fallback', ## TODO: type name
537                          value => $self->{input_encoding},
538                          level => $self->{unsupported_level},
539                          line => 1, column => 1);
540        } elsif (not ($e_status &
541                      Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
542          !!!parse-error (type => 'chardecode:no error', ## TODO: type name
543                          value => $self->{input_encoding},
544                          level => $self->{unsupported_level},
545                          line => 1, column => 1);
546        }
547      $self->{confident} = 1;      $self->{confident} = 1;
548      $return = $self->parse_char_string ($s, @args);      $char_stream->onerror ($char_onerror);
549        $return = $self->parse_char_stream ($char_stream, @args);
550    };    };
551    return $return;    return $return;
552  } # parse_byte_string  } # parse_byte_stream
553    
554  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM
555  ## 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 560  sub parse_byte_string ($$$$;$) {
560  ## 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
561  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
562    
563  *parse_char_string = \&parse_string;  sub parse_char_string ($$$;$) {
564      my $self = shift;
565      require utf8;
566      my $s = ref $_[0] ? $_[0] : \($_[0]);
567      open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
568      return $self->parse_char_stream ($input, @_[1..$#_]);
569    } # parse_char_string
570    *parse_string = \&parse_char_string;
571    
572  sub parse_string ($$$;$) {  sub parse_char_stream ($$$;$) {
573    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
574    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $input = $_[0];
575    $self->{document} = $_[1];    $self->{document} = $_[1];
576    @{$self->{document}->child_nodes} = ();    @{$self->{document}->child_nodes} = ();
577    
# Line 350  sub parse_string ($$$;$) { Line 590  sub parse_string ($$$;$) {
590      pop @{$self->{prev_char}};      pop @{$self->{prev_char}};
591      unshift @{$self->{prev_char}}, $self->{next_char};      unshift @{$self->{prev_char}}, $self->{next_char};
592    
593      $self->{next_char} = -1 and return if $i >= length $$s;      my $char;
594      $self->{next_char} = ord substr $$s, $i++, 1;      if (defined $self->{next_next_char}) {
595          $char = $self->{next_next_char};
596          delete $self->{next_next_char};
597        } else {
598          $char = $input->getc;
599        }
600        $self->{next_char} = -1 and return unless defined $char;
601        $self->{next_char} = ord $char;
602    
603      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
604          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
605      $self->{column}++;      $self->{column}++;
606            
607      if ($self->{next_char} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
608          !!!cp ('j1');
609        $self->{line}++;        $self->{line}++;
610        $self->{column} = 0;        $self->{column} = 0;
611      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
612        $i++ if substr ($$s, $i, 1) eq "\x0A";        !!!cp ('j2');
613          my $next = $input->getc;
614          if (defined $next and $next ne "\x0A") {
615            $self->{next_next_char} = $next;
616          }
617        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
618        $self->{line}++;        $self->{line}++;
619        $self->{column} = 0;        $self->{column} = 0;
620      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
621          !!!cp ('j3');
622        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
623      } elsif ($self->{next_char} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
624          !!!cp ('j4');
625        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
626        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
627        } elsif ($self->{next_char} <= 0x0008 or
628                 (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or
629                 (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or
630                 (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or
631                 (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or
632                 {
633                  0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
634                  0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
635                  0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
636                  0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
637                  0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
638                  0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
639                  0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
640                  0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
641                  0x10FFFE => 1, 0x10FFFF => 1,
642                 }->{$self->{next_char}}) {
643          !!!cp ('j5');
644          !!!parse-error (type => 'control char', level => $self->{must_level});
645    ## TODO: error type documentation
646      }      }
647    };    };
648    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 393  sub parse_string ($$$;$) { Line 666  sub parse_string ($$$;$) {
666    delete $self->{parse_error}; # remove loop    delete $self->{parse_error}; # remove loop
667    
668    return $self->{document};    return $self->{document};
669  } # parse_string  } # parse_char_stream
670    
671  sub new ($) {  sub new ($) {
672    my $class = shift;    my $class = shift;
673    my $self = bless {}, $class;    my $self = bless {
674        must_level => 'm',
675        should_level => 's',
676        good_level => 'w',
677        warn_level => 'w',
678        info_level => 'i',
679        unsupported_level => 'u',
680      }, $class;
681    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
682      $self->{next_char} = -1;      $self->{next_char} = -1;
683    };    };
# Line 762  sub _get_next_token ($) { Line 1042  sub _get_next_token ($) {
1042            redo A;            redo A;
1043          } else {          } else {
1044            !!!cp (23);            !!!cp (23);
1045            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago',
1046                              line => $self->{line_prev},
1047                              column => $self->{column_prev});
1048            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1049            ## reconsume            ## reconsume
1050    
# Line 1539  sub _get_next_token ($) { Line 1821  sub _get_next_token ($) {
1821          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1822          !!!next-input-character;          !!!next-input-character;
1823          redo A;          redo A;
1824          } elsif ($self->{next_char} == -1) {
1825            !!!parse-error (type => 'unclosed tag');
1826            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1827              !!!cp (122.3);
1828              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1829            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1830              if ($self->{current_token}->{attributes}) {
1831                !!!cp (122.1);
1832                !!!parse-error (type => 'end tag attribute');
1833              } else {
1834                ## NOTE: This state should never be reached.
1835                !!!cp (122.2);
1836              }
1837            } else {
1838              die "$0: $self->{current_token}->{type}: Unknown token type";
1839            }
1840            $self->{state} = DATA_STATE;
1841            ## Reconsume.
1842            !!!emit ($self->{current_token}); # start tag or end tag
1843            redo A;
1844        } else {        } else {
1845          !!!cp ('124.1');          !!!cp ('124.1');
1846          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1571  sub _get_next_token ($) { Line 1873  sub _get_next_token ($) {
1873          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1874    
1875          redo A;          redo A;
1876          } elsif ($self->{next_char} == -1) {
1877            !!!parse-error (type => 'unclosed tag');
1878            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1879              !!!cp (124.7);
1880              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1881            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1882              if ($self->{current_token}->{attributes}) {
1883                !!!cp (124.5);
1884                !!!parse-error (type => 'end tag attribute');
1885              } else {
1886                ## NOTE: This state should never be reached.
1887                !!!cp (124.6);
1888              }
1889            } else {
1890              die "$0: $self->{current_token}->{type}: Unknown token type";
1891            }
1892            $self->{state} = DATA_STATE;
1893            ## Reconsume.
1894            !!!emit ($self->{current_token}); # start tag or end tag
1895            redo A;
1896        } else {        } else {
1897          !!!cp ('124.4');          !!!cp ('124.4');
1898          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 2411  sub _get_next_token ($) { Line 2733  sub _get_next_token ($) {
2733          redo A;          redo A;
2734        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2735          !!!cp (217);          !!!cp (217);
         !!!parse-error (type => 'unclosed DOCTYPE');  
2736    
2737          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2738          ## reconsume          ## reconsume
# Line 2657  sub _tokenize_attempt_to_consume_an_enti Line 2978  sub _tokenize_attempt_to_consume_an_enti
2978      require Whatpm::_NamedEntityList;      require Whatpm::_NamedEntityList;
2979      our $EntityChar;      our $EntityChar;
2980    
2981      while (length $entity_name < 10 and      while (length $entity_name < 30 and
2982             ## NOTE: Some number greater than the maximum length of entity name             ## NOTE: Some number greater than the maximum length of entity name
2983             ((0x0041 <= $self->{next_char} and # a             ((0x0041 <= $self->{next_char} and # a
2984               $self->{next_char} <= 0x005A) or # x               $self->{next_char} <= 0x005A) or # x
# Line 2815  sub _tree_construction_initial ($) { Line 3136  sub _tree_construction_initial ($) {
3136        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3137          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3138          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3139          if ({          my $prefix = [
3140            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3141            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3142            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3143            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3144            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3145            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3146            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3147            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3148            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3149            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3150            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3151            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3152            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3153            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3154            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3155            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3156            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3157            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3158            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3159            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3160            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3161            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3162            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3163            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3164            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3165            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3166            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3167            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3168            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3169            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3170            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3171            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3172            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3173            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3174            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3175            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3176            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3177            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3178            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3179            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3180            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3181            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3182            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3183            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3184            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3185            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3186            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3187            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3188            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3189            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3190            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3191            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3192            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3193            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3194            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3195            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3196            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3197            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3198            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3199            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3200            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3201            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3202            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3203            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3204            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3205            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3206            "-//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}) {  
3207            !!!cp ('t5');            !!!cp ('t5');
3208            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3209          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3210                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3211            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3212              !!!cp ('t6');              !!!cp ('t6');
3213              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 2900  sub _tree_construction_initial ($) { Line 3215  sub _tree_construction_initial ($) {
3215              !!!cp ('t7');              !!!cp ('t7');
3216              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3217            }            }
3218          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3219                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3220            !!!cp ('t8');            !!!cp ('t8');
3221            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3222          } else {          } else {
# Line 2914  sub _tree_construction_initial ($) { Line 3229  sub _tree_construction_initial ($) {
3229          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3230          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3231          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") {
3232            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3233              ## marked as quirks.
3234            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3235            !!!cp ('t11');            !!!cp ('t11');
3236          } else {          } else {
# Line 3086  sub _reset_insertion_mode ($) { Line 3402  sub _reset_insertion_mode ($) {
3402        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3403          $last = 1;          $last = 1;
3404          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3405            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3406              !!!cp ('t27');            $node = $self->{inner_html_node};
3407              #          } else {
3408            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3409          }          }
3410        }        }
3411              
3412      ## Step 4..14        ## Step 4..14
3413      my $new_mode;        my $new_mode;
3414      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3415        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3416        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3417        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3418        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3419        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;
3420      } else {          ## ISSUE: What is set as the secondary insertion mode?
3421        $new_mode = {        } elsif ($node->[1] & TABLE_CELL_EL) {
3422            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 3690  sub _tree_construction_main ($) { Line 4011  sub _tree_construction_main ($) {
4011          !!!next-token;          !!!next-token;
4012          next B;          next B;
4013        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4014          if ($self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL or          if ((not {mglyph => 1, malignmark => 1}->{$token->{tag_name}} and
4015                 $self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL) or
4016              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or
4017              ($token->{tag_name} eq 'svg' and              ($token->{tag_name} eq 'svg' and
4018               $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {               $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {
# Line 3698  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 3709  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            !!!insert-element-f ($self->{open_elements}->[-1]->[0]->namespace_uri, $token);            ## "adjust SVG attributes" (SVG only) - done in insert-element-f
4090    
4091              ## "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 3732  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 3812  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 3896  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 3907  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 4132  sub _tree_construction_main ($) { Line 4522  sub _tree_construction_main ($) {
4522                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4523                  !!!next-token;                  !!!next-token;
4524                  next B;                  next B;
4525                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4526                    !!!cp ('t134.1');
4527                    !!!parse-error (type => 'unmatched end tag:head', token => $token);
4528                    ## Ignore the token
4529                    !!!next-token;
4530                    next B;
4531                } else {                } else {
4532                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4533                }                }
4534              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4535                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4143  sub _tree_construction_main ($) { Line 4538  sub _tree_construction_main ($) {
4538                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4539                  !!!next-token;                  !!!next-token;
4540                  next B;                  next B;
4541                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4542                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4543                  !!!cp ('t137');                  !!!cp ('t137');
4544                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);
4545                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
# Line 4156  sub _tree_construction_main ($) { Line 4552  sub _tree_construction_main ($) {
4552              } elsif ({              } elsif ({
4553                        body => 1, html => 1,                        body => 1, html => 1,
4554                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4555                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4556                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4557                  ## 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) {  
4558                  !!!cp ('t140');                  !!!cp ('t140');
4559                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4560                  ## Ignore the token                  ## Ignore the token
4561                  !!!next-token;                  !!!next-token;
4562                  next B;                  next B;
4563                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4564                    !!!cp ('t140.1');
4565                    !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);
4566                    ## Ignore the token
4567                    !!!next-token;
4568                    next B;
4569                } else {                } else {
4570                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4571                }                }
4572                              } elsif ($token->{tag_name} eq 'p') {
4573                #                !!!cp ('t142');
4574              } elsif ({                !!!parse-error (type => 'unmatched end tag:p', token => $token);
4575                        p => 1, br => 1,                ## Ignore the token
4576                       }->{$token->{tag_name}}) {                !!!next-token;
4577                  next B;
4578                } elsif ($token->{tag_name} eq 'br') {
4579                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4580                  !!!cp ('t142');                  !!!cp ('t142.2');
4581                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4582                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4583                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4584                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4585                      [$self->{head_element}, $el_category->{head}];    
4586                    ## Reprocess in the "after head" insertion mode...
4587                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4588                    !!!cp ('t143.2');
4589                    ## As if </head>
4590                    pop @{$self->{open_elements}};
4591                    $self->{insertion_mode} = AFTER_HEAD_IM;
4592      
4593                    ## Reprocess in the "after head" insertion mode...
4594                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4595                    !!!cp ('t143.3');
4596                    ## ISSUE: Two parse errors for <head><noscript></br>
4597                    !!!parse-error (type => 'unmatched end tag:br', token => $token);
4598                    ## As if </noscript>
4599                    pop @{$self->{open_elements}};
4600                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4601    
4602                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4603                } else {                  ## As if </head>
4604                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4605                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4606    
4607                #                  ## Reprocess in the "after head" insertion mode...
4608              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4609                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4610                  #                  #
4611                } else {                } else {
4612                  !!!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;  
4613                }                }
4614    
4615                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4616                  !!!parse-error (type => 'unmatched end tag:br', token => $token);
4617                  ## Ignore the token
4618                  !!!next-token;
4619                  next B;
4620                } else {
4621                  !!!cp ('t145');
4622                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4623                  ## Ignore the token
4624                  !!!next-token;
4625                  next B;
4626              }              }
4627    
4628              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 5457  sub _tree_construction_main ($) { Line 5874  sub _tree_construction_main ($) {
5874            !!!nack ('t277.1');            !!!nack ('t277.1');
5875            !!!next-token;            !!!next-token;
5876            next B;            next B;
5877          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
5878                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
5879                     }->{$token->{tag_name}} or
5880                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5881                    {                    {
5882                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5930  sub _tree_construction_main ($) { Line 6348  sub _tree_construction_main ($) {
6348          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.
6349    
6350          unless ($self->{confident}) {          unless ($self->{confident}) {
6351            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) {
6352              !!!cp ('t335');              !!!cp ('t335');
6353                ## NOTE: Whether the encoding is supported or not is handled
6354                ## in the {change_encoding} callback.
6355              $self->{change_encoding}              $self->{change_encoding}
6356                  ->($self, $token->{attributes}->{charset}->{value}, $token);                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6357                            
# Line 5940  sub _tree_construction_main ($) { Line 6360  sub _tree_construction_main ($) {
6360                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
6361                                           ->{has_reference});                                           ->{has_reference});
6362            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
6363              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6364                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6365                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6366                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6367                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6368                !!!cp ('t336');                !!!cp ('t336');
6369                  ## NOTE: Whether the encoding is supported or not is handled
6370                  ## in the {change_encoding} callback.
6371                $self->{change_encoding}                $self->{change_encoding}
6372                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6373                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 6375  sub _tree_construction_main ($) { Line 6796  sub _tree_construction_main ($) {
6796        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
6797                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6798          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6799    
6800            ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6801    
6802            ## "adjust foreign attributes" - done in insert-element-f
6803                    
6804          !!!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);
6805                    
6806          if ($self->{self_closing}) {          if ($self->{self_closing}) {
6807            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
# Line 6916  sub set_inner_html ($$$) { Line 7341  sub set_inner_html ($$$) {
7341          !!!cp ('i4');          !!!cp ('i4');
7342          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7343          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
7344          } elsif ($self->{next_char} <= 0x0008 or
7345                   (0x000E <= $self->{next_char} and
7346                    $self->{next_char} <= 0x001F) or
7347                   (0x007F <= $self->{next_char} and
7348                    $self->{next_char} <= 0x009F) or
7349                   (0xD800 <= $self->{next_char} and
7350                    $self->{next_char} <= 0xDFFF) or
7351                   (0xFDD0 <= $self->{next_char} and
7352                    $self->{next_char} <= 0xFDDF) or
7353                   {
7354                    0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
7355                    0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
7356                    0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
7357                    0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
7358                    0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
7359                    0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
7360                    0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
7361                    0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
7362                    0x10FFFE => 1, 0x10FFFF => 1,
7363                   }->{$self->{next_char}}) {
7364            !!!cp ('i4.1');
7365            !!!parse-error (type => 'control char', level => $self->{must_level});
7366    ## TODO: error type documentation
7367        }        }
7368      };      };
7369      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.127  
changed lines
  Added in v.1.146

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24