/[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.153 by wakaba, Fri Aug 15 08:32:41 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 47  sub MISC_SPECIAL_EL () { 0b1000000000000 Line 45  sub MISC_SPECIAL_EL () { 0b1000000000000
45  sub FOREIGN_EL () { 0b10000000000000000000000000 }  sub FOREIGN_EL () { 0b10000000000000000000000000 }
46  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
47  sub MML_AXML_EL () { 0b1000000000000000000000000000 }  sub MML_AXML_EL () { 0b1000000000000000000000000000 }
48    sub RUBY_EL () { 0b10000000000000000000000000000 }
49    sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 }
50    
51  sub TABLE_ROWS_EL () {  sub TABLE_ROWS_EL () {
52    TABLE_EL |    TABLE_EL |
# Line 54  sub TABLE_ROWS_EL () { Line 54  sub TABLE_ROWS_EL () {
54    TABLE_ROW_GROUP_EL    TABLE_ROW_GROUP_EL
55  }  }
56    
57    ## NOTE: Used in "generate implied end tags" algorithm.
58    ## NOTE: There is a code where a modified version of END_TAG_OPTIONAL_EL
59    ## is used in "generate implied end tags" implementation (search for the
60    ## function mae).
61  sub END_TAG_OPTIONAL_EL () {  sub END_TAG_OPTIONAL_EL () {
62    DD_EL |    DD_EL |
63    DT_EL |    DT_EL |
64    LI_EL |    LI_EL |
65    P_EL    P_EL |
66      RUBY_COMPONENT_EL
67  }  }
68    
69    ## NOTE: Used in </body> and EOF algorithms.
70  sub ALL_END_TAG_OPTIONAL_EL () {  sub ALL_END_TAG_OPTIONAL_EL () {
71    END_TAG_OPTIONAL_EL |    DD_EL |
72      DT_EL |
73      LI_EL |
74      P_EL |
75    
76    BODY_EL |    BODY_EL |
77    HTML_EL |    HTML_EL |
78    TABLE_CELL_EL |    TABLE_CELL_EL |
# Line 98  sub SPECIAL_EL () { Line 108  sub SPECIAL_EL () {
108    ADDRESS_EL |    ADDRESS_EL |
109    BODY_EL |    BODY_EL |
110    DIV_EL |    DIV_EL |
111    END_TAG_OPTIONAL_EL |  
112      DD_EL |
113      DT_EL |
114      LI_EL |
115      P_EL |
116    
117    FORM_EL |    FORM_EL |
118    FRAMESET_EL |    FRAMESET_EL |
119    HEADING_EL |    HEADING_EL |
# Line 172  my $el_category = { Line 187  my $el_category = {
187    param => MISC_SPECIAL_EL,    param => MISC_SPECIAL_EL,
188    plaintext => MISC_SPECIAL_EL,    plaintext => MISC_SPECIAL_EL,
189    pre => MISC_SPECIAL_EL,    pre => MISC_SPECIAL_EL,
190      rp => RUBY_COMPONENT_EL,
191      rt => RUBY_COMPONENT_EL,
192      ruby => RUBY_EL,
193    s => FORMATTING_EL,    s => FORMATTING_EL,
194    script => MISC_SPECIAL_EL,    script => MISC_SPECIAL_EL,
195    select => SELECT_EL,    select => SELECT_EL,
# Line 205  my $el_category_f = { Line 223  my $el_category_f = {
223      mtext => FOREIGN_FLOW_CONTENT_EL,      mtext => FOREIGN_FLOW_CONTENT_EL,
224    },    },
225    $SVG_NS => {    $SVG_NS => {
226      foreignobject => FOREIGN_FLOW_CONTENT_EL, ## TODO: case      foreignObject => FOREIGN_FLOW_CONTENT_EL,
227      desc => FOREIGN_FLOW_CONTENT_EL,      desc => FOREIGN_FLOW_CONTENT_EL,
228      title => FOREIGN_FLOW_CONTENT_EL,      title => FOREIGN_FLOW_CONTENT_EL,
229    },    },
230    ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.    ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.
231  };  };
232    
233    my $svg_attr_name = {
234      attributename => 'attributeName',
235      attributetype => 'attributeType',
236      basefrequency => 'baseFrequency',
237      baseprofile => 'baseProfile',
238      calcmode => 'calcMode',
239      clippathunits => 'clipPathUnits',
240      contentscripttype => 'contentScriptType',
241      contentstyletype => 'contentStyleType',
242      diffuseconstant => 'diffuseConstant',
243      edgemode => 'edgeMode',
244      externalresourcesrequired => 'externalResourcesRequired',
245      filterres => 'filterRes',
246      filterunits => 'filterUnits',
247      glyphref => 'glyphRef',
248      gradienttransform => 'gradientTransform',
249      gradientunits => 'gradientUnits',
250      kernelmatrix => 'kernelMatrix',
251      kernelunitlength => 'kernelUnitLength',
252      keypoints => 'keyPoints',
253      keysplines => 'keySplines',
254      keytimes => 'keyTimes',
255      lengthadjust => 'lengthAdjust',
256      limitingconeangle => 'limitingConeAngle',
257      markerheight => 'markerHeight',
258      markerunits => 'markerUnits',
259      markerwidth => 'markerWidth',
260      maskcontentunits => 'maskContentUnits',
261      maskunits => 'maskUnits',
262      numoctaves => 'numOctaves',
263      pathlength => 'pathLength',
264      patterncontentunits => 'patternContentUnits',
265      patterntransform => 'patternTransform',
266      patternunits => 'patternUnits',
267      pointsatx => 'pointsAtX',
268      pointsaty => 'pointsAtY',
269      pointsatz => 'pointsAtZ',
270      preservealpha => 'preserveAlpha',
271      preserveaspectratio => 'preserveAspectRatio',
272      primitiveunits => 'primitiveUnits',
273      refx => 'refX',
274      refy => 'refY',
275      repeatcount => 'repeatCount',
276      repeatdur => 'repeatDur',
277      requiredextensions => 'requiredExtensions',
278      requiredfeatures => 'requiredFeatures',
279      specularconstant => 'specularConstant',
280      specularexponent => 'specularExponent',
281      spreadmethod => 'spreadMethod',
282      startoffset => 'startOffset',
283      stddeviation => 'stdDeviation',
284      stitchtiles => 'stitchTiles',
285      surfacescale => 'surfaceScale',
286      systemlanguage => 'systemLanguage',
287      tablevalues => 'tableValues',
288      targetx => 'targetX',
289      targety => 'targetY',
290      textlength => 'textLength',
291      viewbox => 'viewBox',
292      viewtarget => 'viewTarget',
293      xchannelselector => 'xChannelSelector',
294      ychannelselector => 'yChannelSelector',
295      zoomandpan => 'zoomAndPan',
296    };
297    
298    my $foreign_attr_xname = {
299      'xlink:actuate' => [$XLINK_NS, ['xlink', 'actuate']],
300      'xlink:arcrole' => [$XLINK_NS, ['xlink', 'arcrole']],
301      'xlink:href' => [$XLINK_NS, ['xlink', 'href']],
302      'xlink:role' => [$XLINK_NS, ['xlink', 'role']],
303      'xlink:show' => [$XLINK_NS, ['xlink', 'show']],
304      'xlink:title' => [$XLINK_NS, ['xlink', 'title']],
305      'xlink:type' => [$XLINK_NS, ['xlink', 'type']],
306      'xml:base' => [$XML_NS, ['xml', 'base']],
307      'xml:lang' => [$XML_NS, ['xml', 'lang']],
308      'xml:space' => [$XML_NS, ['xml', 'space']],
309      'xmlns' => [$XMLNS_NS, [undef, 'xmlns']],
310      'xmlns:xlink' => [$XMLNS_NS, ['xmlns', 'xlink']],
311    };
312    
313    ## ISSUE: xmlns:xlink="non-xlink-ns" is not an error.
314    
315  my $c1_entity_char = {  my $c1_entity_char = {
316    0x80 => 0x20AC,    0x80 => 0x20AC,
317    0x81 => 0xFFFD,    0x81 => 0xFFFD,
# Line 248  my $c1_entity_char = { Line 348  my $c1_entity_char = {
348  }; # $c1_entity_char  }; # $c1_entity_char
349    
350  sub parse_byte_string ($$$$;$) {  sub parse_byte_string ($$$$;$) {
351      my $self = shift;
352      my $charset_name = shift;
353      open my $input, '<', ref $_[0] ? $_[0] : \($_[0]);
354      return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
355    } # parse_byte_string
356    
357    sub parse_byte_stream ($$$$;$) {
358    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
359    my $charset = shift;    my $charset_name = shift;
360    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;  
   }  
361    
362    $self->{change_encoding} = sub {    my $onerror = $_[2] || sub {
363      my $self = shift;      my (%opt) = @_;
364      my $charset = lc shift;      warn "Parse error ($opt{type})\n";
365      my $token = shift;    };
366      ## TODO: if $charset is supported    $self->{parse_error} = $onerror; # updated later by parse_char_string
367      ## TODO: normalize charset name  
368      ## HTML5 encoding sniffing algorithm
369      require Message::Charset::Info;
370      my $charset;
371      my $buffer;
372      my ($char_stream, $e_status);
373    
374      ## "Change the encoding" algorithm:    SNIFFING: {
375    
376      ## Step 1          ## Step 1
377      if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?      if (defined $charset_name) {
378        $charset = 'utf-8';        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
379    
380          ## ISSUE: Unsupported encoding is not ignored according to the spec.
381          ($char_stream, $e_status) = $charset->get_decode_handle
382              ($byte_stream, allow_error_reporting => 1,
383               allow_fallback => 1);
384          if ($char_stream) {
385            $self->{confident} = 1;
386            last SNIFFING;
387          } else {
388            ## TODO: unsupported error
389          }
390      }      }
391    
392      ## Step 2      ## Step 2
393      if (defined $self->{input_encoding} and      my $byte_buffer = '';
394          $self->{input_encoding} eq $charset) {      for (1..1024) {
395          my $char = $byte_stream->getc;
396          last unless defined $char;
397          $byte_buffer .= $char;
398        } ## TODO: timeout
399    
400        ## Step 3
401        if ($byte_buffer =~ /^\xFE\xFF/) {
402          $charset = Message::Charset::Info->get_by_iana_name ('utf-16be');
403          ($char_stream, $e_status) = $charset->get_decode_handle
404              ($byte_stream, allow_error_reporting => 1,
405               allow_fallback => 1, byte_buffer => \$byte_buffer);
406        $self->{confident} = 1;        $self->{confident} = 1;
407        return;        last SNIFFING;
408        } elsif ($byte_buffer =~ /^\xFF\xFE/) {
409          $charset = Message::Charset::Info->get_by_iana_name ('utf-16le');
410          ($char_stream, $e_status) = $charset->get_decode_handle
411              ($byte_stream, allow_error_reporting => 1,
412               allow_fallback => 1, byte_buffer => \$byte_buffer);
413          $self->{confident} = 1;
414          last SNIFFING;
415        } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
416          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
417          ($char_stream, $e_status) = $charset->get_decode_handle
418              ($byte_stream, allow_error_reporting => 1,
419               allow_fallback => 1, byte_buffer => \$byte_buffer);
420          $self->{confident} = 1;
421          last SNIFFING;
422      }      }
423    
424      !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.      ## Step 4
425          ':'.$charset, level => 'w', token => $token);      ## TODO: <meta charset>
426    
427      ## Step 3      ## Step 5
428      # if (can) {      ## TODO: from history
       ## change the encoding on the fly.  
       #$self->{confident} = 1;  
       #return;  
     # }  
429    
430      ## Step 4      ## Step 6
431      throw Whatpm::HTML::RestartParser (charset => $charset);      require Whatpm::Charset::UniversalCharDet;
432        $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
433            ($byte_buffer);
434        if (defined $charset_name) {
435          $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
436    
437          ## ISSUE: Unsupported encoding is not ignored according to the spec.
438          require Whatpm::Charset::DecodeHandle;
439          $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
440              ($byte_stream);
441          ($char_stream, $e_status) = $charset->get_decode_handle
442              ($buffer, allow_error_reporting => 1,
443               allow_fallback => 1, byte_buffer => \$byte_buffer);
444          if ($char_stream) {
445            $buffer->{buffer} = $byte_buffer;
446            !!!parse-error (type => 'sniffing:chardet',
447                            text => $charset_name,
448                            level => $self->{level}->{info},
449                            layer => 'encode',
450                            line => 1, column => 1);
451            $self->{confident} = 0;
452            last SNIFFING;
453          }
454        }
455    
456        ## Step 7: default
457        ## TODO: Make this configurable.
458        $charset = Message::Charset::Info->get_by_iana_name ('windows-1252');
459            ## NOTE: We choose |windows-1252| here, since |utf-8| should be
460            ## detectable in the step 6.
461        require Whatpm::Charset::DecodeHandle;
462        $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
463            ($byte_stream);
464        ($char_stream, $e_status)
465            = $charset->get_decode_handle ($buffer,
466                                           allow_error_reporting => 1,
467                                           allow_fallback => 1,
468                                           byte_buffer => \$byte_buffer);
469        $buffer->{buffer} = $byte_buffer;
470        !!!parse-error (type => 'sniffing:default',
471                        text => 'windows-1252',
472                        level => $self->{level}->{info},
473                        line => 1, column => 1,
474                        layer => 'encode');
475        $self->{confident} = 0;
476      } # SNIFFING
477    
478      $self->{input_encoding} = $charset->get_iana_name;
479      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
480        !!!parse-error (type => 'chardecode:fallback',
481                        text => $self->{input_encoding},
482                        level => $self->{level}->{uncertain},
483                        line => 1, column => 1,
484                        layer => 'encode');
485      } elsif (not ($e_status &
486                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
487        !!!parse-error (type => 'chardecode:no error',
488                        text => $self->{input_encoding},
489                        level => $self->{level}->{uncertain},
490                        line => 1, column => 1,
491                        layer => 'encode');
492      }
493    
494      $self->{change_encoding} = sub {
495        my $self = shift;
496        $charset_name = shift;
497        my $token = shift;
498    
499        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
500        ($char_stream, $e_status) = $charset->get_decode_handle
501            ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
502             byte_buffer => \ $buffer->{buffer});
503        
504        if ($char_stream) { # if supported
505          ## "Change the encoding" algorithm:
506    
507          ## Step 1    
508          if ($charset->{category} &
509              Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
510            $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
511            ($char_stream, $e_status) = $charset->get_decode_handle
512                ($byte_stream,
513                 byte_buffer => \ $buffer->{buffer});
514          }
515          $charset_name = $charset->get_iana_name;
516          
517          ## Step 2
518          if (defined $self->{input_encoding} and
519              $self->{input_encoding} eq $charset_name) {
520            !!!parse-error (type => 'charset label:matching',
521                            text => $charset_name,
522                            level => $self->{level}->{info});
523            $self->{confident} = 1;
524            return;
525          }
526    
527          !!!parse-error (type => 'charset label detected',
528                          text => $self->{input_encoding},
529                          value => $charset_name,
530                          level => $self->{level}->{warn},
531                          token => $token);
532          
533          ## Step 3
534          # if (can) {
535            ## change the encoding on the fly.
536            #$self->{confident} = 1;
537            #return;
538          # }
539          
540          ## Step 4
541          throw Whatpm::HTML::RestartParser ();
542        }
543    }; # $self->{change_encoding}    }; # $self->{change_encoding}
544    
545      my $char_onerror = sub {
546        my (undef, $type, %opt) = @_;
547        !!!parse-error (layer => 'encode',
548                        %opt, type => $type,
549                        line => $self->{line}, column => $self->{column} + 1);
550        if ($opt{octets}) {
551          ${$opt{octets}} = "\x{FFFD}"; # relacement character
552        }
553      };
554      $char_stream->onerror ($char_onerror);
555    
556    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
557    my $return;    my $return;
558    try {    try {
559      $return = $self->parse_char_string ($s, @args);        $return = $self->parse_char_stream ($char_stream, @args);  
560    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
561      my $charset = shift->{charset};      ## NOTE: Invoked after {change_encoding}.
562      $s = \ (Encode::decode ($charset, $$bytes_s));      
563      $self->{input_encoding} = $charset; ## TODO: normalize      $self->{input_encoding} = $charset->get_iana_name;
564        if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
565          !!!parse-error (type => 'chardecode:fallback',
566                          text => $self->{input_encoding},
567                          level => $self->{level}->{uncertain},
568                          line => 1, column => 1,
569                          layer => 'encode');
570        } elsif (not ($e_status &
571                      Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
572          !!!parse-error (type => 'chardecode:no error',
573                          text => $self->{input_encoding},
574                          level => $self->{level}->{uncertain},
575                          line => 1, column => 1,
576                          layer => 'encode');
577        }
578      $self->{confident} = 1;      $self->{confident} = 1;
579      $return = $self->parse_char_string ($s, @args);      $char_stream->onerror ($char_onerror);
580        $return = $self->parse_char_stream ($char_stream, @args);
581    };    };
582    return $return;    return $return;
583  } # parse_byte_string  } # parse_byte_stream
584    
585  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM
586  ## 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 591  sub parse_byte_string ($$$$;$) {
591  ## 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
592  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
593    
594  *parse_char_string = \&parse_string;  sub parse_char_string ($$$;$) {
595      my $self = shift;
596      require utf8;
597      my $s = ref $_[0] ? $_[0] : \($_[0]);
598      open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
599      return $self->parse_char_stream ($input, @_[1..$#_]);
600    } # parse_char_string
601    *parse_string = \&parse_char_string;
602    
603  sub parse_string ($$$;$) {  sub parse_char_stream ($$$;$) {
604    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
605    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $input = $_[0];
606    $self->{document} = $_[1];    $self->{document} = $_[1];
607    @{$self->{document}->child_nodes} = ();    @{$self->{document}->child_nodes} = ();
608    
# Line 350  sub parse_string ($$$;$) { Line 621  sub parse_string ($$$;$) {
621      pop @{$self->{prev_char}};      pop @{$self->{prev_char}};
622      unshift @{$self->{prev_char}}, $self->{next_char};      unshift @{$self->{prev_char}}, $self->{next_char};
623    
624      $self->{next_char} = -1 and return if $i >= length $$s;      my $char;
625      $self->{next_char} = ord substr $$s, $i++, 1;      if (defined $self->{next_next_char}) {
626          $char = $self->{next_next_char};
627          delete $self->{next_next_char};
628        } else {
629          $char = $input->getc;
630        }
631        $self->{next_char} = -1 and return unless defined $char;
632        $self->{next_char} = ord $char;
633    
634      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
635          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
636      $self->{column}++;      $self->{column}++;
637            
638      if ($self->{next_char} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
639          !!!cp ('j1');
640        $self->{line}++;        $self->{line}++;
641        $self->{column} = 0;        $self->{column} = 0;
642      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
643        $i++ if substr ($$s, $i, 1) eq "\x0A";        !!!cp ('j2');
644          my $next = $input->getc;
645          if (defined $next and $next ne "\x0A") {
646            $self->{next_next_char} = $next;
647          }
648        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
649        $self->{line}++;        $self->{line}++;
650        $self->{column} = 0;        $self->{column} = 0;
651      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
652          !!!cp ('j3');
653        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
654      } elsif ($self->{next_char} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
655          !!!cp ('j4');
656        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
657        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
658        } elsif ($self->{next_char} <= 0x0008 or
659                 (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or
660                 (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or
661                 (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or
662                 (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or
663                 {
664                  0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
665                  0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
666                  0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
667                  0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
668                  0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
669                  0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
670                  0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
671                  0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
672                  0x10FFFE => 1, 0x10FFFF => 1,
673                 }->{$self->{next_char}}) {
674          !!!cp ('j5');
675          if ($self->{next_char} < 0x10000) {
676            !!!parse-error (type => 'control char',
677                            text => (sprintf 'U+%04X', $self->{next_char}));
678          } else {
679            !!!parse-error (type => 'control char',
680                            text => (sprintf 'U-%08X', $self->{next_char}));
681          }
682      }      }
683    };    };
684    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 393  sub parse_string ($$$;$) { Line 702  sub parse_string ($$$;$) {
702    delete $self->{parse_error}; # remove loop    delete $self->{parse_error}; # remove loop
703    
704    return $self->{document};    return $self->{document};
705  } # parse_string  } # parse_char_stream
706    
707  sub new ($) {  sub new ($) {
708    my $class = shift;    my $class = shift;
709    my $self = bless {}, $class;    my $self = bless {
710        level => {must => 'm',
711                  warn => 'w',
712                  info => 'i',
713                  uncertain => 'u'},
714      }, $class;
715    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
716      $self->{next_char} = -1;      $self->{next_char} = -1;
717    };    };
# Line 543  sub _initialize_tokenizer ($) { Line 857  sub _initialize_tokenizer ($) {
857  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
858  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
859    
 ## ISSUE: "When a DOCTYPE token is created, its  
 ## <i>self-closing flag</i> must be unset (its other state is that it  
 ## be set), and its attributes list must be empty.": Wrong subject?  
   
860  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
861    
862  ## Before each step, UA MAY check to see if either one of the scripts in  ## Before each step, UA MAY check to see if either one of the scripts in
# Line 762  sub _get_next_token ($) { Line 1072  sub _get_next_token ($) {
1072            redo A;            redo A;
1073          } else {          } else {
1074            !!!cp (23);            !!!cp (23);
1075            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago',
1076                              line => $self->{line_prev},
1077                              column => $self->{column_prev});
1078            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1079            ## reconsume            ## reconsume
1080    
# Line 1057  sub _get_next_token ($) { Line 1369  sub _get_next_token ($) {
1369          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1370              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1371            !!!cp (57);            !!!cp (57);
1372            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});            !!!parse-error (type => 'duplicate attribute', text => $self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});
1373            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1374          } else {          } else {
1375            !!!cp (58);            !!!cp (58);
# Line 1539  sub _get_next_token ($) { Line 1851  sub _get_next_token ($) {
1851          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1852          !!!next-input-character;          !!!next-input-character;
1853          redo A;          redo A;
1854          } elsif ($self->{next_char} == -1) {
1855            !!!parse-error (type => 'unclosed tag');
1856            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1857              !!!cp (122.3);
1858              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1859            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1860              if ($self->{current_token}->{attributes}) {
1861                !!!cp (122.1);
1862                !!!parse-error (type => 'end tag attribute');
1863              } else {
1864                ## NOTE: This state should never be reached.
1865                !!!cp (122.2);
1866              }
1867            } else {
1868              die "$0: $self->{current_token}->{type}: Unknown token type";
1869            }
1870            $self->{state} = DATA_STATE;
1871            ## Reconsume.
1872            !!!emit ($self->{current_token}); # start tag or end tag
1873            redo A;
1874        } else {        } else {
1875          !!!cp ('124.1');          !!!cp ('124.1');
1876          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1571  sub _get_next_token ($) { Line 1903  sub _get_next_token ($) {
1903          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1904    
1905          redo A;          redo A;
1906          } elsif ($self->{next_char} == -1) {
1907            !!!parse-error (type => 'unclosed tag');
1908            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1909              !!!cp (124.7);
1910              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1911            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1912              if ($self->{current_token}->{attributes}) {
1913                !!!cp (124.5);
1914                !!!parse-error (type => 'end tag attribute');
1915              } else {
1916                ## NOTE: This state should never be reached.
1917                !!!cp (124.6);
1918              }
1919            } else {
1920              die "$0: $self->{current_token}->{type}: Unknown token type";
1921            }
1922            $self->{state} = DATA_STATE;
1923            ## Reconsume.
1924            !!!emit ($self->{current_token}); # start tag or end tag
1925            redo A;
1926        } else {        } else {
1927          !!!cp ('124.4');          !!!cp ('124.4');
1928          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 2328  sub _get_next_token ($) { Line 2680  sub _get_next_token ($) {
2680          redo A;          redo A;
2681        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2682          !!!cp (208);          !!!cp (208);
2683          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2684    
2685          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2686          !!!next-input-character;          !!!next-input-character;
# Line 2364  sub _get_next_token ($) { Line 2716  sub _get_next_token ($) {
2716          redo A;          redo A;
2717        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2718          !!!cp (212);          !!!cp (212);
2719          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2720    
2721          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2722          !!!next-input-character;          !!!next-input-character;
# Line 2412  sub _get_next_token ($) { Line 2764  sub _get_next_token ($) {
2764        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2765          !!!cp (217);          !!!cp (217);
2766          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2767          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2768          ## reconsume          ## reconsume
2769    
# Line 2574  sub _tokenize_attempt_to_consume_an_enti Line 2925  sub _tokenize_attempt_to_consume_an_enti
2925    
2926          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2927            !!!cp (1008);            !!!cp (1008);
2928            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2929                              text => (sprintf 'U+%04X', $code),
2930                              line => $l, column => $c);
2931            $code = 0xFFFD;            $code = 0xFFFD;
2932          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2933            !!!cp (1009);            !!!cp (1009);
2934            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2935                              text => (sprintf 'U-%08X', $code),
2936                              line => $l, column => $c);
2937            $code = 0xFFFD;            $code = 0xFFFD;
2938          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2939            !!!cp (1010);            !!!cp (1010);
# Line 2586  sub _tokenize_attempt_to_consume_an_enti Line 2941  sub _tokenize_attempt_to_consume_an_enti
2941            $code = 0x000A;            $code = 0x000A;
2942          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2943            !!!cp (1011);            !!!cp (1011);
2944            !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
2945            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2946          }          }
2947    
# Line 2619  sub _tokenize_attempt_to_consume_an_enti Line 2974  sub _tokenize_attempt_to_consume_an_enti
2974    
2975        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2976          !!!cp (1015);          !!!cp (1015);
2977          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
2978                            text => (sprintf 'U+%04X', $code),
2979                            line => $l, column => $c);
2980          $code = 0xFFFD;          $code = 0xFFFD;
2981        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
2982          !!!cp (1016);          !!!cp (1016);
2983          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
2984                            text => (sprintf 'U-%08X', $code),
2985                            line => $l, column => $c);
2986          $code = 0xFFFD;          $code = 0xFFFD;
2987        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
2988          !!!cp (1017);          !!!cp (1017);
2989          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
2990                            line => $l, column => $c);
2991          $code = 0x000A;          $code = 0x000A;
2992        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
2993          !!!cp (1018);          !!!cp (1018);
2994          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
2995                            text => (sprintf 'U+%04X', $code),
2996                            line => $l, column => $c);
2997          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
2998        }        }
2999                
# Line 2657  sub _tokenize_attempt_to_consume_an_enti Line 3019  sub _tokenize_attempt_to_consume_an_enti
3019      require Whatpm::_NamedEntityList;      require Whatpm::_NamedEntityList;
3020      our $EntityChar;      our $EntityChar;
3021    
3022      while (length $entity_name < 10 and      while (length $entity_name < 30 and
3023             ## NOTE: Some number greater than the maximum length of entity name             ## NOTE: Some number greater than the maximum length of entity name
3024             ((0x0041 <= $self->{next_char} and # a             ((0x0041 <= $self->{next_char} and # a
3025               $self->{next_char} <= 0x005A) or # x               $self->{next_char} <= 0x005A) or # x
# Line 2815  sub _tree_construction_initial ($) { Line 3177  sub _tree_construction_initial ($) {
3177        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3178          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3179          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3180          if ({          my $prefix = [
3181            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3182            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3183            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3184            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3185            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3186            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3187            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3188            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3189            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3190            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3191            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3192            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3193            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3194            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3195            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3196            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3197            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3198            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3199            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3200            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3201            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3202            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3203            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3204            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3205            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3206            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3207            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3208            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3209            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3210            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3211            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3212            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3213            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3214            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3215            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3216            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3217            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3218            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3219            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3220            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3221            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3222            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3223            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3224            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3225            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3226            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3227            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3228            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3229            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3230            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3231            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3232            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3233            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3234            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3235            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3236            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3237            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3238            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3239            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3240            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3241            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3242            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3243            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3244            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3245            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3246            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3247            "-//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}) {  
3248            !!!cp ('t5');            !!!cp ('t5');
3249            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3250          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3251                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3252            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3253              !!!cp ('t6');              !!!cp ('t6');
3254              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 2900  sub _tree_construction_initial ($) { Line 3256  sub _tree_construction_initial ($) {
3256              !!!cp ('t7');              !!!cp ('t7');
3257              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3258            }            }
3259          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3260                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3261            !!!cp ('t8');            !!!cp ('t8');
3262            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3263          } else {          } else {
# Line 2914  sub _tree_construction_initial ($) { Line 3270  sub _tree_construction_initial ($) {
3270          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3271          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3272          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") {
3273            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3274              ## marked as quirks.
3275            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3276            !!!cp ('t11');            !!!cp ('t11');
3277          } else {          } else {
# Line 3086  sub _reset_insertion_mode ($) { Line 3443  sub _reset_insertion_mode ($) {
3443        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3444          $last = 1;          $last = 1;
3445          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3446            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3447              !!!cp ('t27');            $node = $self->{inner_html_node};
3448              #          } else {
3449            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3450          }          }
3451        }        }
3452              
3453      ## Step 4..14        ## Step 4..14
3454      my $new_mode;        my $new_mode;
3455      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3456        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3457        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3458        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3459        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3460        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3461      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3462        $new_mode = {          if ($last) {
3463              !!!cp ('t28.2');
3464              #
3465            } else {
3466              !!!cp ('t28.3');
3467              $new_mode = IN_CELL_IM;
3468            }
3469          } else {
3470            !!!cp ('t28.4');
3471            $new_mode = {
3472                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3473                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3474                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3475                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3476                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3477                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3122  sub _reset_insertion_mode ($) { Line 3483  sub _reset_insertion_mode ($) {
3483                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3484                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3485                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3486      }        }
3487      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3488                
3489        ## Step 15        ## Step 15
3490        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3297  sub _tree_construction_main ($) { Line 3658  sub _tree_construction_main ($) {
3658        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3659        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3660          !!!cp ('t43');          !!!cp ('t43');
3661          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3662        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3663          !!!cp ('t44');          !!!cp ('t44');
3664          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3665        } else {        } else {
3666          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3667        }        }
# Line 3337  sub _tree_construction_main ($) { Line 3698  sub _tree_construction_main ($) {
3698        ## Ignore the token        ## Ignore the token
3699      } else {      } else {
3700        !!!cp ('t48');        !!!cp ('t48');
3701        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3702        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3703        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3704      }      }
# Line 3388  sub _tree_construction_main ($) { Line 3749  sub _tree_construction_main ($) {
3749        } # AFE        } # AFE
3750        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3751          !!!cp ('t53');          !!!cp ('t53');
3752          !!!parse-error (type => 'unmatched end tag:'.$tag_name, token => $end_tag_token);          !!!parse-error (type => 'unmatched end tag', text => $tag_name, token => $end_tag_token);
3753          ## Ignore the token          ## Ignore the token
3754          !!!next-token;          !!!next-token;
3755          return;          return;
# Line 3405  sub _tree_construction_main ($) { Line 3766  sub _tree_construction_main ($) {
3766              last INSCOPE;              last INSCOPE;
3767            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3768              !!!cp ('t55');              !!!cp ('t55');
3769              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3770                                text => $token->{tag_name},
3771                              token => $end_tag_token);                              token => $end_tag_token);
3772              ## Ignore the token              ## Ignore the token
3773              !!!next-token;              !!!next-token;
# Line 3418  sub _tree_construction_main ($) { Line 3780  sub _tree_construction_main ($) {
3780        } # INSCOPE        } # INSCOPE
3781        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3782          !!!cp ('t57');          !!!cp ('t57');
3783          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3784                            text => $token->{tag_name},
3785                          token => $end_tag_token);                          token => $end_tag_token);
3786          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3787          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3427  sub _tree_construction_main ($) { Line 3790  sub _tree_construction_main ($) {
3790        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3791          !!!cp ('t58');          !!!cp ('t58');
3792          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3793                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3794                              ->manakai_local_name,                              ->manakai_local_name,
3795                          token => $end_tag_token);                          token => $end_tag_token);
3796        }        }
# Line 3636  sub _tree_construction_main ($) { Line 3999  sub _tree_construction_main ($) {
3999    B: while (1) {    B: while (1) {
4000      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4001        !!!cp ('t73');        !!!cp ('t73');
4002        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4003        ## Ignore the token        ## Ignore the token
4004        ## Stay in the phase        ## Stay in the phase
4005        !!!next-token;        !!!next-token;
# Line 3645  sub _tree_construction_main ($) { Line 4008  sub _tree_construction_main ($) {
4008               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4009        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4010          !!!cp ('t79');          !!!cp ('t79');
4011          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4012          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4013        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4014          !!!cp ('t80');          !!!cp ('t80');
4015          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4016          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4017        } else {        } else {
4018          !!!cp ('t81');          !!!cp ('t81');
# Line 3690  sub _tree_construction_main ($) { Line 4053  sub _tree_construction_main ($) {
4053          !!!next-token;          !!!next-token;
4054          next B;          next B;
4055        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4056          if ($self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL or          if ((not {mglyph => 1, malignmark => 1}->{$token->{tag_name}} and
4057                 $self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL) or
4058              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or
4059              ($token->{tag_name} eq 'svg' and              ($token->{tag_name} eq 'svg' and
4060               $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {               $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {
# Line 3698  sub _tree_construction_main ($) { Line 4062  sub _tree_construction_main ($) {
4062            !!!cp ('t87.2');            !!!cp ('t87.2');
4063            #            #
4064          } elsif ({          } elsif ({
4065    ## TODO:                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4066                      center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4067                      em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4068                      h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4069                      img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4070                      nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4071                      small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4072                      sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4073                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4074            !!!cp ('t87.2');            !!!cp ('t87.2');
4075            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4076                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4077                                ->manakai_local_name,                                ->manakai_local_name,
4078                            token => $token);                            token => $token);
4079    
4080            pop @{$self->{open_elements}}            pop @{$self->{open_elements}}
4081                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4082    
4083            $self->{insertion_mode} &= ~ $self->{insertion_mode};            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4084            ## Reprocess.            ## Reprocess.
4085            next B;            next B;
4086          } else {          } else {
4087            ## TODO: case fixup            my $nsuri = $self->{open_elements}->[-1]->[0]->namespace_uri;
4088              my $tag_name = $token->{tag_name};
4089              if ($nsuri eq $SVG_NS) {
4090                $tag_name = {
4091                   altglyph => 'altGlyph',
4092                   altglyphdef => 'altGlyphDef',
4093                   altglyphitem => 'altGlyphItem',
4094                   animatecolor => 'animateColor',
4095                   animatemotion => 'animateMotion',
4096                   animatetransform => 'animateTransform',
4097                   clippath => 'clipPath',
4098                   feblend => 'feBlend',
4099                   fecolormatrix => 'feColorMatrix',
4100                   fecomponenttransfer => 'feComponentTransfer',
4101                   fecomposite => 'feComposite',
4102                   feconvolvematrix => 'feConvolveMatrix',
4103                   fediffuselighting => 'feDiffuseLighting',
4104                   fedisplacementmap => 'feDisplacementMap',
4105                   fedistantlight => 'feDistantLight',
4106                   feflood => 'feFlood',
4107                   fefunca => 'feFuncA',
4108                   fefuncb => 'feFuncB',
4109                   fefuncg => 'feFuncG',
4110                   fefuncr => 'feFuncR',
4111                   fegaussianblur => 'feGaussianBlur',
4112                   feimage => 'feImage',
4113                   femerge => 'feMerge',
4114                   femergenode => 'feMergeNode',
4115                   femorphology => 'feMorphology',
4116                   feoffset => 'feOffset',
4117                   fepointlight => 'fePointLight',
4118                   fespecularlighting => 'feSpecularLighting',
4119                   fespotlight => 'feSpotLight',
4120                   fetile => 'feTile',
4121                   feturbulence => 'feTurbulence',
4122                   foreignobject => 'foreignObject',
4123                   glyphref => 'glyphRef',
4124                   lineargradient => 'linearGradient',
4125                   radialgradient => 'radialGradient',
4126                   #solidcolor => 'solidColor', ## NOTE: Commented in spec (SVG1.2)
4127                   textpath => 'textPath',  
4128                }->{$tag_name} || $tag_name;
4129              }
4130    
4131              ## "adjust SVG attributes" (SVG only) - done in insert-element-f
4132    
4133            !!!insert-element-f ($self->{open_elements}->[-1]->[0]->namespace_uri, $token);            ## "adjust foreign attributes" - done in insert-element-f
4134    
4135              !!!insert-element-f ($nsuri, $tag_name, $token->{attributes}, $token);
4136    
4137            if ($self->{self_closing}) {            if ($self->{self_closing}) {
4138              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 3732  sub _tree_construction_main ($) { Line 4149  sub _tree_construction_main ($) {
4149          !!!cp ('t87.5');          !!!cp ('t87.5');
4150          #          #
4151        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4152          !!!cp ('t87.6');          !!!cp ('t87.6');
4153          #          !!!parse-error (type => 'not closed',
4154          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4155                                ->manakai_local_name,
4156                            token => $token);
4157    
4158            pop @{$self->{open_elements}}
4159                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4160    
4161            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4162            ## Reprocess.
4163            next B;
4164        } else {        } else {
4165          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4166        }        }
# Line 3776  sub _tree_construction_main ($) { Line 4201  sub _tree_construction_main ($) {
4201            !!!cp ('t90');            !!!cp ('t90');
4202            ## As if </noscript>            ## As if </noscript>
4203            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4204            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4205                        
4206            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4207            ## As if </head>            ## As if </head>
# Line 3812  sub _tree_construction_main ($) { Line 4237  sub _tree_construction_main ($) {
4237              !!!next-token;              !!!next-token;
4238              next B;              next B;
4239            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4240              !!!cp ('t94');              !!!cp ('t93.2');
4241              #              !!!parse-error (type => 'after head', text => 'head',
4242                                token => $token);
4243                ## Ignore the token
4244                !!!nack ('t93.3');
4245                !!!next-token;
4246                next B;
4247            } else {            } else {
4248              !!!cp ('t95');              !!!cp ('t95');
4249              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4250                                token => $token); # or in head noscript
4251              ## Ignore the token              ## Ignore the token
4252              !!!nack ('t95.1');              !!!nack ('t95.1');
4253              !!!next-token;              !!!next-token;
# Line 3841  sub _tree_construction_main ($) { Line 4272  sub _tree_construction_main ($) {
4272                  !!!cp ('t98');                  !!!cp ('t98');
4273                  ## As if </noscript>                  ## As if </noscript>
4274                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4275                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4276                                    token => $token);
4277                                
4278                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4279                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 3852  sub _tree_construction_main ($) { Line 4284  sub _tree_construction_main ($) {
4284                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4285                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4286                  !!!cp ('t100');                  !!!cp ('t100');
4287                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4288                                    text => $token->{tag_name}, token => $token);
4289                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4290                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4291                } else {                } else {
# Line 3869  sub _tree_construction_main ($) { Line 4302  sub _tree_construction_main ($) {
4302                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4303                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4304                  !!!cp ('t102');                  !!!cp ('t102');
4305                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4306                                    text => $token->{tag_name}, token => $token);
4307                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4308                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4309                } else {                } else {
# Line 3886  sub _tree_construction_main ($) { Line 4320  sub _tree_construction_main ($) {
4320                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4321                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4322                  !!!cp ('t104');                  !!!cp ('t104');
4323                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4324                                    text => $token->{tag_name}, token => $token);
4325                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4326                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4327                } else {                } else {
# Line 3896  sub _tree_construction_main ($) { Line 4331  sub _tree_construction_main ($) {
4331                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.
4332    
4333                unless ($self->{confident}) {                unless ($self->{confident}) {
4334                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) {
4335                    !!!cp ('t106');                    !!!cp ('t106');
4336                      ## NOTE: Whether the encoding is supported or not is handled
4337                      ## in the {change_encoding} callback.
4338                    $self->{change_encoding}                    $self->{change_encoding}
4339                        ->($self, $token->{attributes}->{charset}->{value},                        ->($self, $token->{attributes}->{charset}->{value},
4340                           $token);                           $token);
# Line 3907  sub _tree_construction_main ($) { Line 4344  sub _tree_construction_main ($) {
4344                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
4345                                                 ->{has_reference});                                                 ->{has_reference});
4346                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
                   ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
4347                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4348                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4349                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4350                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4351                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4352                      !!!cp ('t107');                      !!!cp ('t107');
4353                        ## NOTE: Whether the encoding is supported or not is handled
4354                        ## in the {change_encoding} callback.
4355                      $self->{change_encoding}                      $self->{change_encoding}
4356                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,
4357                             $token);                             $token);
# Line 3952  sub _tree_construction_main ($) { Line 4390  sub _tree_construction_main ($) {
4390                  !!!cp ('t111');                  !!!cp ('t111');
4391                  ## As if </noscript>                  ## As if </noscript>
4392                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4393                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4394                                    token => $token);
4395                                
4396                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4397                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4398                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4399                  !!!cp ('t112');                  !!!cp ('t112');
4400                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4401                                    text => $token->{tag_name}, token => $token);
4402                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4403                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4404                } else {                } else {
# Line 3972  sub _tree_construction_main ($) { Line 4412  sub _tree_construction_main ($) {
4412                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4413                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4414                next B;                next B;
4415              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4416                         $token->{tag_name} eq 'noframes') {
4417                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4418                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4419                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4420                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4421                  !!!cp ('t114');                  !!!cp ('t114');
4422                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4423                                    text => $token->{tag_name}, token => $token);
4424                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4425                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4426                } else {                } else {
# Line 3999  sub _tree_construction_main ($) { Line 4441  sub _tree_construction_main ($) {
4441                  next B;                  next B;
4442                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4443                  !!!cp ('t117');                  !!!cp ('t117');
4444                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4445                                    token => $token);
4446                  ## Ignore the token                  ## Ignore the token
4447                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4448                  !!!next-token;                  !!!next-token;
# Line 4013  sub _tree_construction_main ($) { Line 4456  sub _tree_construction_main ($) {
4456                  !!!cp ('t119');                  !!!cp ('t119');
4457                  ## As if </noscript>                  ## As if </noscript>
4458                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4459                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4460                                    token => $token);
4461                                
4462                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4463                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4464                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4465                  !!!cp ('t120');                  !!!cp ('t120');
4466                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4467                                    text => $token->{tag_name}, token => $token);
4468                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4469                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4470                } else {                } else {
# Line 4037  sub _tree_construction_main ($) { Line 4482  sub _tree_construction_main ($) {
4482                  !!!cp ('t122');                  !!!cp ('t122');
4483                  ## As if </noscript>                  ## As if </noscript>
4484                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4485                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4486                                    text => $token->{tag_name}, token => $token);
4487                                    
4488                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4489                  ## As if </head>                  ## As if </head>
# Line 4076  sub _tree_construction_main ($) { Line 4522  sub _tree_construction_main ($) {
4522                !!!cp ('t129');                !!!cp ('t129');
4523                ## As if </noscript>                ## As if </noscript>
4524                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4525                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4526                                  text => $token->{tag_name}, token => $token);
4527                                
4528                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4529                ## As if </head>                ## As if </head>
# Line 4119  sub _tree_construction_main ($) { Line 4566  sub _tree_construction_main ($) {
4566                  !!!cp ('t133');                  !!!cp ('t133');
4567                  ## As if </noscript>                  ## As if </noscript>
4568                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4569                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4570                                    text => 'head', token => $token);
4571                                    
4572                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4573                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4132  sub _tree_construction_main ($) { Line 4580  sub _tree_construction_main ($) {
4580                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4581                  !!!next-token;                  !!!next-token;
4582                  next B;                  next B;
4583                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4584                    !!!cp ('t134.1');
4585                    !!!parse-error (type => 'unmatched end tag', text => 'head',
4586                                    token => $token);
4587                    ## Ignore the token
4588                    !!!next-token;
4589                    next B;
4590                } else {                } else {
4591                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4592                }                }
4593              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4594                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4143  sub _tree_construction_main ($) { Line 4597  sub _tree_construction_main ($) {
4597                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4598                  !!!next-token;                  !!!next-token;
4599                  next B;                  next B;
4600                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4601                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4602                  !!!cp ('t137');                  !!!cp ('t137');
4603                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4604                                    text => 'noscript', token => $token);
4605                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4606                  !!!next-token;                  !!!next-token;
4607                  next B;                  next B;
# Line 4156  sub _tree_construction_main ($) { Line 4612  sub _tree_construction_main ($) {
4612              } elsif ({              } elsif ({
4613                        body => 1, html => 1,                        body => 1, html => 1,
4614                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4615                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4616                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4617                  ## 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) {  
4618                  !!!cp ('t140');                  !!!cp ('t140');
4619                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4620                                    text => $token->{tag_name}, token => $token);
4621                    ## Ignore the token
4622                    !!!next-token;
4623                    next B;
4624                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4625                    !!!cp ('t140.1');
4626                    !!!parse-error (type => 'unmatched end tag',
4627                                    text => $token->{tag_name}, token => $token);
4628                  ## Ignore the token                  ## Ignore the token
4629                  !!!next-token;                  !!!next-token;
4630                  next B;                  next B;
4631                } else {                } else {
4632                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4633                }                }
4634                              } elsif ($token->{tag_name} eq 'p') {
4635                #                !!!cp ('t142');
4636              } elsif ({                !!!parse-error (type => 'unmatched end tag',
4637                        p => 1, br => 1,                                text => $token->{tag_name}, token => $token);
4638                       }->{$token->{tag_name}}) {                ## Ignore the token
4639                  !!!next-token;
4640                  next B;
4641                } elsif ($token->{tag_name} eq 'br') {
4642                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4643                  !!!cp ('t142');                  !!!cp ('t142.2');
4644                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4645                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4646                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4647                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4648                      [$self->{head_element}, $el_category->{head}];    
4649                    ## Reprocess in the "after head" insertion mode...
4650                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4651                    !!!cp ('t143.2');
4652                    ## As if </head>
4653                    pop @{$self->{open_elements}};
4654                    $self->{insertion_mode} = AFTER_HEAD_IM;
4655      
4656                    ## Reprocess in the "after head" insertion mode...
4657                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4658                    !!!cp ('t143.3');
4659                    ## ISSUE: Two parse errors for <head><noscript></br>
4660                    !!!parse-error (type => 'unmatched end tag',
4661                                    text => 'br', token => $token);
4662                    ## As if </noscript>
4663                    pop @{$self->{open_elements}};
4664                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4665    
4666                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4667                } else {                  ## As if </head>
4668                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4669                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4670    
4671                #                  ## Reprocess in the "after head" insertion mode...
4672              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4673                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4674                  #                  #
4675                } else {                } else {
4676                  !!!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;  
4677                }                }
4678    
4679                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4680                  !!!parse-error (type => 'unmatched end tag',
4681                                  text => 'br', token => $token);
4682                  ## Ignore the token
4683                  !!!next-token;
4684                  next B;
4685                } else {
4686                  !!!cp ('t145');
4687                  !!!parse-error (type => 'unmatched end tag',
4688                                  text => $token->{tag_name}, token => $token);
4689                  ## Ignore the token
4690                  !!!next-token;
4691                  next B;
4692              }              }
4693    
4694              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4695                !!!cp ('t146');                !!!cp ('t146');
4696                ## As if </noscript>                ## As if </noscript>
4697                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4698                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4699                                  text => $token->{tag_name}, token => $token);
4700                                
4701                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4702                ## As if </head>                ## As if </head>
# Line 4228  sub _tree_construction_main ($) { Line 4712  sub _tree_construction_main ($) {
4712              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4713  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4714                !!!cp ('t148');                !!!cp ('t148');
4715                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4716                                  text => $token->{tag_name}, token => $token);
4717                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4718                !!!next-token;                !!!next-token;
4719                next B;                next B;
# Line 4339  sub _tree_construction_main ($) { Line 4824  sub _tree_construction_main ($) {
4824    
4825                  !!!cp ('t153');                  !!!cp ('t153');
4826                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4827                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4828                  ## Ignore the token                  ## Ignore the token
4829                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4830                  !!!next-token;                  !!!next-token;
4831                  next B;                  next B;
4832                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4833                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4834                                    token => $token);
4835                                    
4836                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4837                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4365  sub _tree_construction_main ($) { Line 4851  sub _tree_construction_main ($) {
4851    
4852                    !!!cp ('t157');                    !!!cp ('t157');
4853                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4854                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4855                    ## Ignore the token                    ## Ignore the token
4856                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4857                    !!!next-token;                    !!!next-token;
# Line 4382  sub _tree_construction_main ($) { Line 4868  sub _tree_construction_main ($) {
4868                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4869                    !!!cp ('t159');                    !!!cp ('t159');
4870                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4871                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4872                                        ->manakai_local_name,                                        ->manakai_local_name,
4873                                    token => $token);                                    token => $token);
4874                  } else {                  } else {
# Line 4424  sub _tree_construction_main ($) { Line 4910  sub _tree_construction_main ($) {
4910                  } # INSCOPE                  } # INSCOPE
4911                    unless (defined $i) {                    unless (defined $i) {
4912                      !!!cp ('t165');                      !!!cp ('t165');
4913                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
4914                                        text => $token->{tag_name},
4915                                        token => $token);
4916                      ## Ignore the token                      ## Ignore the token
4917                      !!!next-token;                      !!!next-token;
4918                      next B;                      next B;
# Line 4441  sub _tree_construction_main ($) { Line 4929  sub _tree_construction_main ($) {
4929                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
4930                    !!!cp ('t167');                    !!!cp ('t167');
4931                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4932                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4933                                        ->manakai_local_name,                                        ->manakai_local_name,
4934                                    token => $token);                                    token => $token);
4935                  } else {                  } else {
# Line 4458  sub _tree_construction_main ($) { Line 4946  sub _tree_construction_main ($) {
4946                  next B;                  next B;
4947                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4948                  !!!cp ('t169');                  !!!cp ('t169');
4949                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4950                                    text => $token->{tag_name}, token => $token);
4951                  ## Ignore the token                  ## Ignore the token
4952                  !!!next-token;                  !!!next-token;
4953                  next B;                  next B;
# Line 4485  sub _tree_construction_main ($) { Line 4974  sub _tree_construction_main ($) {
4974    
4975                    !!!cp ('t173');                    !!!cp ('t173');
4976                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
4977                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4978                    ## Ignore the token                    ## Ignore the token
4979                    !!!next-token;                    !!!next-token;
4980                    next B;                    next B;
# Line 4501  sub _tree_construction_main ($) { Line 4990  sub _tree_construction_main ($) {
4990                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4991                    !!!cp ('t175');                    !!!cp ('t175');
4992                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4993                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4994                                        ->manakai_local_name,                                        ->manakai_local_name,
4995                                    token => $token);                                    token => $token);
4996                  } else {                  } else {
# Line 4518  sub _tree_construction_main ($) { Line 5007  sub _tree_construction_main ($) {
5007                  next B;                  next B;
5008                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5009                  !!!cp ('t177');                  !!!cp ('t177');
5010                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5011                                    text => $token->{tag_name}, token => $token);
5012                  ## Ignore the token                  ## Ignore the token
5013                  !!!next-token;                  !!!next-token;
5014                  next B;                  next B;
# Line 4561  sub _tree_construction_main ($) { Line 5051  sub _tree_construction_main ($) {
5051    
5052                  !!!cp ('t182');                  !!!cp ('t182');
5053                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5054                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5055                  ## Ignore the token                  ## Ignore the token
5056                  !!!next-token;                  !!!next-token;
5057                  next B;                  next B;
5058                } # INSCOPE                } # INSCOPE
5059              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5060                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5061                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5062                                  token => $token);
5063    
5064                ## As if </caption>                ## As if </caption>
5065                ## have a table element in table scope                ## have a table element in table scope
# Line 4586  sub _tree_construction_main ($) { Line 5077  sub _tree_construction_main ($) {
5077                } # INSCOPE                } # INSCOPE
5078                unless (defined $i) {                unless (defined $i) {
5079                  !!!cp ('t186');                  !!!cp ('t186');
5080                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5081                                    text => 'caption', token => $token);
5082                  ## Ignore the token                  ## Ignore the token
5083                  !!!next-token;                  !!!next-token;
5084                  next B;                  next B;
# Line 4601  sub _tree_construction_main ($) { Line 5093  sub _tree_construction_main ($) {
5093                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5094                  !!!cp ('t188');                  !!!cp ('t188');
5095                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5096                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5097                                      ->manakai_local_name,                                      ->manakai_local_name,
5098                                  token => $token);                                  token => $token);
5099                } else {                } else {
# Line 4621  sub _tree_construction_main ($) { Line 5113  sub _tree_construction_main ($) {
5113                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5114                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5115                  !!!cp ('t190');                  !!!cp ('t190');
5116                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5117                                    text => $token->{tag_name}, token => $token);
5118                  ## Ignore the token                  ## Ignore the token
5119                  !!!next-token;                  !!!next-token;
5120                  next B;                  next B;
# Line 4635  sub _tree_construction_main ($) { Line 5128  sub _tree_construction_main ($) {
5128                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5129                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5130                !!!cp ('t192');                !!!cp ('t192');
5131                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5132                                  text => $token->{tag_name}, token => $token);
5133                ## Ignore the token                ## Ignore the token
5134                !!!next-token;                !!!next-token;
5135                next B;                next B;
# Line 4675  sub _tree_construction_main ($) { Line 5169  sub _tree_construction_main ($) {
5169            }            }
5170          }          }
5171    
5172              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5173    
5174              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5175              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 4726  sub _tree_construction_main ($) { Line 5220  sub _tree_construction_main ($) {
5220          !!!next-token;          !!!next-token;
5221          next B;          next B;
5222        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5223              if ({          if ({
5224                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5225                   th => 1, td => 1,               th => 1, td => 1,
5226                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5227                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5228                  ## Clear back to table context              ## Clear back to table context
5229                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5230                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5231                    !!!cp ('t201');                !!!cp ('t201');
5232                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5233                  }              }
5234                                
5235                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5236                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5237                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5238                }            }
5239              
5240                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5241                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5242                    !!!cp ('t202');                !!!cp ('t202');
5243                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5244                  }              }
5245                                    
5246                  ## Clear back to table body context              ## Clear back to table body context
5247                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5248                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5249                    !!!cp ('t203');                !!!cp ('t203');
5250                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5251                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5252                  }              }
5253                                    
5254                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5255                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 4811  sub _tree_construction_main ($) { Line 5305  sub _tree_construction_main ($) {
5305                  unless (defined $i) {                  unless (defined $i) {
5306                    !!!cp ('t210');                    !!!cp ('t210');
5307  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5308                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5309                                      text => $token->{tag_name}, token => $token);
5310                    ## Ignore the token                    ## Ignore the token
5311                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5312                    !!!next-token;                    !!!next-token;
# Line 4855  sub _tree_construction_main ($) { Line 5350  sub _tree_construction_main ($) {
5350                  } # INSCOPE                  } # INSCOPE
5351                  unless (defined $i) {                  unless (defined $i) {
5352                    !!!cp ('t216');                    !!!cp ('t216');
5353  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5354                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5355                                      text => $token->{tag_name}, token => $token);
5356                    ## Ignore the token                    ## Ignore the token
5357                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5358                    !!!next-token;                    !!!next-token;
# Line 4931  sub _tree_construction_main ($) { Line 5427  sub _tree_construction_main ($) {
5427                }                }
5428              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5429                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5430                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5431                                    ->manakai_local_name,                                    ->manakai_local_name,
5432                                token => $token);                                token => $token);
5433    
# Line 4952  sub _tree_construction_main ($) { Line 5448  sub _tree_construction_main ($) {
5448                unless (defined $i) {                unless (defined $i) {
5449                  !!!cp ('t223');                  !!!cp ('t223');
5450  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5451                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5452                                    token => $token);
5453                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5454                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5455                  !!!next-token;                  !!!next-token;
5456                  next B;                  next B;
5457                }                }
5458                                
5459  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5460                ## generate implied end tags                ## generate implied end tags
5461                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5462                  !!!cp ('t224');                  !!!cp ('t224');
# Line 4970  sub _tree_construction_main ($) { Line 5467  sub _tree_construction_main ($) {
5467                  !!!cp ('t225');                  !!!cp ('t225');
5468                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5469                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5470                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5471                                      ->manakai_local_name,                                      ->manakai_local_name,
5472                                  token => $token);                                  token => $token);
5473                } else {                } else {
# Line 5011  sub _tree_construction_main ($) { Line 5508  sub _tree_construction_main ($) {
5508                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5509                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5510                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5511                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5512                                    text => $token->{tag_name}, token => $token);
5513    
5514                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5515    
# Line 5039  sub _tree_construction_main ($) { Line 5537  sub _tree_construction_main ($) {
5537            #            #
5538          }          }
5539    
5540          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5541                            token => $token);
5542    
5543          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5544          #          #
# Line 5061  sub _tree_construction_main ($) { Line 5560  sub _tree_construction_main ($) {
5560                } # INSCOPE                } # INSCOPE
5561                unless (defined $i) {                unless (defined $i) {
5562                  !!!cp ('t230');                  !!!cp ('t230');
5563                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5564                                    text => $token->{tag_name}, token => $token);
5565                  ## Ignore the token                  ## Ignore the token
5566                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5567                  !!!next-token;                  !!!next-token;
# Line 5102  sub _tree_construction_main ($) { Line 5602  sub _tree_construction_main ($) {
5602                  unless (defined $i) {                  unless (defined $i) {
5603                    !!!cp ('t235');                    !!!cp ('t235');
5604  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5605                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5606                                      text => $token->{type}, token => $token);
5607                    ## Ignore the token                    ## Ignore the token
5608                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5609                    !!!next-token;                    !!!next-token;
# Line 5138  sub _tree_construction_main ($) { Line 5639  sub _tree_construction_main ($) {
5639                  } # INSCOPE                  } # INSCOPE
5640                  unless (defined $i) {                  unless (defined $i) {
5641                    !!!cp ('t239');                    !!!cp ('t239');
5642                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5643                                      text => $token->{tag_name}, token => $token);
5644                    ## Ignore the token                    ## Ignore the token
5645                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5646                    !!!next-token;                    !!!next-token;
# Line 5184  sub _tree_construction_main ($) { Line 5686  sub _tree_construction_main ($) {
5686                } # INSCOPE                } # INSCOPE
5687                unless (defined $i) {                unless (defined $i) {
5688                  !!!cp ('t243');                  !!!cp ('t243');
5689                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5690                                    text => $token->{tag_name}, token => $token);
5691                  ## Ignore the token                  ## Ignore the token
5692                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5693                  !!!next-token;                  !!!next-token;
# Line 5218  sub _tree_construction_main ($) { Line 5721  sub _tree_construction_main ($) {
5721                  } # INSCOPE                  } # INSCOPE
5722                    unless (defined $i) {                    unless (defined $i) {
5723                      !!!cp ('t249');                      !!!cp ('t249');
5724                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5725                                        text => $token->{tag_name}, token => $token);
5726                      ## Ignore the token                      ## Ignore the token
5727                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5728                      !!!next-token;                      !!!next-token;
# Line 5241  sub _tree_construction_main ($) { Line 5745  sub _tree_construction_main ($) {
5745                  } # INSCOPE                  } # INSCOPE
5746                    unless (defined $i) {                    unless (defined $i) {
5747                      !!!cp ('t252');                      !!!cp ('t252');
5748                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5749                                        text => 'tr', token => $token);
5750                      ## Ignore the token                      ## Ignore the token
5751                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5752                      !!!next-token;                      !!!next-token;
# Line 5276  sub _tree_construction_main ($) { Line 5781  sub _tree_construction_main ($) {
5781                } # INSCOPE                } # INSCOPE
5782                unless (defined $i) {                unless (defined $i) {
5783                  !!!cp ('t256');                  !!!cp ('t256');
5784                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5785                                    text => $token->{tag_name}, token => $token);
5786                  ## Ignore the token                  ## Ignore the token
5787                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5788                  !!!next-token;                  !!!next-token;
# Line 5303  sub _tree_construction_main ($) { Line 5809  sub _tree_construction_main ($) {
5809                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5810                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5811            !!!cp ('t258');            !!!cp ('t258');
5812            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5813                              text => $token->{tag_name}, token => $token);
5814            ## Ignore the token            ## Ignore the token
5815            !!!nack ('t258.1');            !!!nack ('t258.1');
5816             !!!next-token;             !!!next-token;
5817            next B;            next B;
5818          } else {          } else {
5819            !!!cp ('t259');            !!!cp ('t259');
5820            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5821                              text => $token->{tag_name}, token => $token);
5822    
5823            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5824            #            #
# Line 5360  sub _tree_construction_main ($) { Line 5868  sub _tree_construction_main ($) {
5868              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5869                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5870                  !!!cp ('t264');                  !!!cp ('t264');
5871                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5872                                    text => 'colgroup', token => $token);
5873                  ## Ignore the token                  ## Ignore the token
5874                  !!!next-token;                  !!!next-token;
5875                  next B;                  next B;
# Line 5373  sub _tree_construction_main ($) { Line 5882  sub _tree_construction_main ($) {
5882                }                }
5883              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5884                !!!cp ('t266');                !!!cp ('t266');
5885                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
5886                                  text => 'col', token => $token);
5887                ## Ignore the token                ## Ignore the token
5888                !!!next-token;                !!!next-token;
5889                next B;                next B;
# Line 5403  sub _tree_construction_main ($) { Line 5913  sub _tree_construction_main ($) {
5913            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5914              !!!cp ('t269');              !!!cp ('t269');
5915  ## TODO: Wrong error type?  ## TODO: Wrong error type?
5916              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
5917                                text => 'colgroup', token => $token);
5918              ## Ignore the token              ## Ignore the token
5919              !!!nack ('t269.1');              !!!nack ('t269.1');
5920              !!!next-token;              !!!next-token;
# Line 5457  sub _tree_construction_main ($) { Line 5968  sub _tree_construction_main ($) {
5968            !!!nack ('t277.1');            !!!nack ('t277.1');
5969            !!!next-token;            !!!next-token;
5970            next B;            next B;
5971          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
5972                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
5973                     }->{$token->{tag_name}} or
5974                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5975                    {                    {
5976                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5466  sub _tree_construction_main ($) { Line 5978  sub _tree_construction_main ($) {
5978                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
5979                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
5980            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
5981            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
5982                              token => $token);
5983            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
5984            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
5985            ## have an element in table scope            ## have an element in table scope
# Line 5484  sub _tree_construction_main ($) { Line 5997  sub _tree_construction_main ($) {
5997            } # INSCOPE            } # INSCOPE
5998            unless (defined $i) {            unless (defined $i) {
5999              !!!cp ('t280');              !!!cp ('t280');
6000              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6001                                text => 'select', token => $token);
6002              ## Ignore the token              ## Ignore the token
6003              !!!nack ('t280.1');              !!!nack ('t280.1');
6004              !!!next-token;              !!!next-token;
# Line 5508  sub _tree_construction_main ($) { Line 6022  sub _tree_construction_main ($) {
6022            }            }
6023          } else {          } else {
6024            !!!cp ('t282');            !!!cp ('t282');
6025            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6026                              text => $token->{tag_name}, token => $token);
6027            ## Ignore the token            ## Ignore the token
6028            !!!nack ('t282.1');            !!!nack ('t282.1');
6029            !!!next-token;            !!!next-token;
# Line 5526  sub _tree_construction_main ($) { Line 6041  sub _tree_construction_main ($) {
6041              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6042            } else {            } else {
6043              !!!cp ('t285');              !!!cp ('t285');
6044              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6045                                text => $token->{tag_name}, token => $token);
6046              ## Ignore the token              ## Ignore the token
6047            }            }
6048            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5538  sub _tree_construction_main ($) { Line 6054  sub _tree_construction_main ($) {
6054              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6055            } else {            } else {
6056              !!!cp ('t287');              !!!cp ('t287');
6057              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6058                                text => $token->{tag_name}, token => $token);
6059              ## Ignore the token              ## Ignore the token
6060            }            }
6061            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5560  sub _tree_construction_main ($) { Line 6077  sub _tree_construction_main ($) {
6077            } # INSCOPE            } # INSCOPE
6078            unless (defined $i) {            unless (defined $i) {
6079              !!!cp ('t290');              !!!cp ('t290');
6080              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6081                                text => $token->{tag_name}, token => $token);
6082              ## Ignore the token              ## Ignore the token
6083              !!!nack ('t290.1');              !!!nack ('t290.1');
6084              !!!next-token;              !!!next-token;
# Line 5581  sub _tree_construction_main ($) { Line 6099  sub _tree_construction_main ($) {
6099                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6100                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6101  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6102            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6103                              text => $token->{tag_name}, token => $token);
6104                                
6105            ## have an element in table scope            ## have an element in table scope
6106            my $i;            my $i;
# Line 5622  sub _tree_construction_main ($) { Line 6141  sub _tree_construction_main ($) {
6141            unless (defined $i) {            unless (defined $i) {
6142              !!!cp ('t297');              !!!cp ('t297');
6143  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6144              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6145                                text => 'select', token => $token);
6146              ## Ignore the </select> token              ## Ignore the </select> token
6147              !!!nack ('t297.1');              !!!nack ('t297.1');
6148              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 5639  sub _tree_construction_main ($) { Line 6159  sub _tree_construction_main ($) {
6159            next B;            next B;
6160          } else {          } else {
6161            !!!cp ('t299');            !!!cp ('t299');
6162            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6163                              text => $token->{tag_name}, token => $token);
6164            ## Ignore the token            ## Ignore the token
6165            !!!nack ('t299.3');            !!!nack ('t299.3');
6166            !!!next-token;            !!!next-token;
# Line 5677  sub _tree_construction_main ($) { Line 6198  sub _tree_construction_main ($) {
6198                    
6199          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6200            !!!cp ('t301');            !!!cp ('t301');
6201            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6202    
6203            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6204          } else {          } else {
# Line 5685  sub _tree_construction_main ($) { Line 6206  sub _tree_construction_main ($) {
6206          }          }
6207                    
6208          ## "after body" insertion mode          ## "after body" insertion mode
6209          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6210    
6211          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6212          ## reprocess          ## reprocess
# Line 5693  sub _tree_construction_main ($) { Line 6214  sub _tree_construction_main ($) {
6214        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6215          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6216            !!!cp ('t303');            !!!cp ('t303');
6217            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6218                              text => $token->{tag_name}, token => $token);
6219                        
6220            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6221          } else {          } else {
# Line 5701  sub _tree_construction_main ($) { Line 6223  sub _tree_construction_main ($) {
6223          }          }
6224    
6225          ## "after body" insertion mode          ## "after body" insertion mode
6226          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6227                            text => $token->{tag_name}, token => $token);
6228    
6229          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6230          !!!ack-later;          !!!ack-later;
# Line 5710  sub _tree_construction_main ($) { Line 6233  sub _tree_construction_main ($) {
6233        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6234          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6235            !!!cp ('t305');            !!!cp ('t305');
6236            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6237                              text => $token->{tag_name}, token => $token);
6238                        
6239            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6240            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 5722  sub _tree_construction_main ($) { Line 6246  sub _tree_construction_main ($) {
6246          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6247            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6248              !!!cp ('t307');              !!!cp ('t307');
6249              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6250                                text => 'html', token => $token);
6251              ## Ignore the token              ## Ignore the token
6252              !!!next-token;              !!!next-token;
6253              next B;              next B;
# Line 5734  sub _tree_construction_main ($) { Line 6259  sub _tree_construction_main ($) {
6259            }            }
6260          } else {          } else {
6261            !!!cp ('t309');            !!!cp ('t309');
6262            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6263                              text => $token->{tag_name}, token => $token);
6264    
6265            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6266            ## reprocess            ## reprocess
# Line 5762  sub _tree_construction_main ($) { Line 6288  sub _tree_construction_main ($) {
6288          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6289            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6290              !!!cp ('t311');              !!!cp ('t311');
6291              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6292            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6293              !!!cp ('t312');              !!!cp ('t312');
6294              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6295            } else { # "after html frameset"            } else { # "after html frameset"
6296              !!!cp ('t313');              !!!cp ('t313');
6297              !!!parse-error (type => 'after html:#character', token => $token);              !!!parse-error (type => 'after html:#text', token => $token);
6298    
6299              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
6300              ## Reprocess in the "after frameset" insertion mode.              ## Reprocess in the "after frameset" insertion mode.
6301              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6302            }            }
6303                        
6304            ## Ignore the token.            ## Ignore the token.
# Line 5790  sub _tree_construction_main ($) { Line 6316  sub _tree_construction_main ($) {
6316        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6317          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
6318            !!!cp ('t316');            !!!cp ('t316');
6319            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6320                              text => $token->{tag_name}, token => $token);
6321    
6322            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
6323            ## Process in the "after frameset" insertion mode.            ## Process in the "after frameset" insertion mode.
# Line 5815  sub _tree_construction_main ($) { Line 6342  sub _tree_construction_main ($) {
6342            next B;            next B;
6343          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6344            !!!cp ('t320');            !!!cp ('t320');
6345            ## NOTE: As if in body.            ## NOTE: As if in head.
6346            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6347            next B;            next B;
6348          } else {          } else {
6349            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6350              !!!cp ('t321');              !!!cp ('t321');
6351              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6352                                text => $token->{tag_name}, token => $token);
6353            } else {            } else {
6354              !!!cp ('t322');              !!!cp ('t322');
6355              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6356                                text => $token->{tag_name}, token => $token);
6357            }            }
6358            ## Ignore the token            ## Ignore the token
6359            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 5834  sub _tree_construction_main ($) { Line 6363  sub _tree_construction_main ($) {
6363        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6364          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
6365            !!!cp ('t323');            !!!cp ('t323');
6366            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6367                              text => $token->{tag_name}, token => $token);
6368    
6369            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
6370            ## Process in the "after frameset" insertion mode.            ## Process in the "after frameset" insertion mode.
# Line 5847  sub _tree_construction_main ($) { Line 6377  sub _tree_construction_main ($) {
6377            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6378                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6379              !!!cp ('t325');              !!!cp ('t325');
6380              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6381                                text => $token->{tag_name}, token => $token);
6382              ## Ignore the token              ## Ignore the token
6383              !!!next-token;              !!!next-token;
6384            } else {            } else {
# Line 5873  sub _tree_construction_main ($) { Line 6404  sub _tree_construction_main ($) {
6404          } else {          } else {
6405            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6406              !!!cp ('t330');              !!!cp ('t330');
6407              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6408                                text => $token->{tag_name}, token => $token);
6409            } else {            } else {
6410              !!!cp ('t331');              !!!cp ('t331');
6411              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset:/',
6412                                text => $token->{tag_name}, token => $token);
6413            }            }
6414            ## Ignore the token            ## Ignore the token
6415            !!!next-token;            !!!next-token;
# Line 5930  sub _tree_construction_main ($) { Line 6463  sub _tree_construction_main ($) {
6463          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.
6464    
6465          unless ($self->{confident}) {          unless ($self->{confident}) {
6466            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) {
6467              !!!cp ('t335');              !!!cp ('t335');
6468                ## NOTE: Whether the encoding is supported or not is handled
6469                ## in the {change_encoding} callback.
6470              $self->{change_encoding}              $self->{change_encoding}
6471                  ->($self, $token->{attributes}->{charset}->{value}, $token);                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6472                            
# Line 5940  sub _tree_construction_main ($) { Line 6475  sub _tree_construction_main ($) {
6475                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
6476                                           ->{has_reference});                                           ->{has_reference});
6477            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
6478              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6479                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6480                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6481                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6482                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6483                !!!cp ('t336');                !!!cp ('t336');
6484                  ## NOTE: Whether the encoding is supported or not is handled
6485                  ## in the {change_encoding} callback.
6486                $self->{change_encoding}                $self->{change_encoding}
6487                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6488                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 5981  sub _tree_construction_main ($) { Line 6517  sub _tree_construction_main ($) {
6517          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6518          next B;          next B;
6519        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6520          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6521                                
6522          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6523              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6101  sub _tree_construction_main ($) { Line 6637  sub _tree_construction_main ($) {
6637              if ($i != -1) {              if ($i != -1) {
6638                !!!cp ('t355');                !!!cp ('t355');
6639                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6640                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6641                                    ->manakai_local_name,                                    ->manakai_local_name,
6642                                token => $token);                                token => $token);
6643              } else {              } else {
# Line 6255  sub _tree_construction_main ($) { Line 6791  sub _tree_construction_main ($) {
6791                  xmp => 1,                  xmp => 1,
6792                  iframe => 1,                  iframe => 1,
6793                  noembed => 1,                  noembed => 1,
6794                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6795                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6796                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6797          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6277  sub _tree_construction_main ($) { Line 6813  sub _tree_construction_main ($) {
6813            !!!next-token;            !!!next-token;
6814            next B;            next B;
6815          } else {          } else {
6816              !!!ack ('t391.1');
6817    
6818            my $at = $token->{attributes};            my $at = $token->{attributes};
6819            my $form_attrs;            my $form_attrs;
6820            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6320  sub _tree_construction_main ($) { Line 6858  sub _tree_construction_main ($) {
6858                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6859                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6860                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6861            !!!back-token (@tokens);            !!!back-token (@tokens);
6862            !!!next-token;            !!!next-token;
6863            next B;            next B;
# Line 6368  sub _tree_construction_main ($) { Line 6905  sub _tree_construction_main ($) {
6905            ## Ignore the token            ## Ignore the token
6906          } else {          } else {
6907            !!!cp ('t398');            !!!cp ('t398');
6908            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
6909          }          }
6910          !!!next-token;          !!!next-token;
6911          next B;          next B;
6912          } elsif ($token->{tag_name} eq 'rt' or
6913                   $token->{tag_name} eq 'rp') {
6914            ## has a |ruby| element in scope
6915            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6916              my $node = $self->{open_elements}->[$_];
6917              if ($node->[1] & RUBY_EL) {
6918                !!!cp ('t398.1');
6919                ## generate implied end tags
6920                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
6921                  !!!cp ('t398.2');
6922                  pop @{$self->{open_elements}};
6923                }
6924                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
6925                  !!!cp ('t398.3');
6926                  !!!parse-error (type => 'not closed',
6927                                  text => $self->{open_elements}->[-1]->[0]
6928                                      ->manakai_local_name,
6929                                  token => $token);
6930                  pop @{$self->{open_elements}}
6931                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
6932                }
6933                last INSCOPE;
6934              } elsif ($node->[1] & SCOPING_EL) {
6935                !!!cp ('t398.4');
6936                last INSCOPE;
6937              }
6938            } # INSCOPE
6939    
6940            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6941    
6942            !!!nack ('t398.5');
6943            !!!next-token;
6944            redo B;
6945        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
6946                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6947          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6948    
6949            ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6950    
6951            ## "adjust foreign attributes" - done in insert-element-f
6952                    
6953          !!!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);
6954                    
6955          if ($self->{self_closing}) {          if ($self->{self_closing}) {
6956            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
# Line 6398  sub _tree_construction_main ($) { Line 6972  sub _tree_construction_main ($) {
6972                  thead => 1, tr => 1,                  thead => 1, tr => 1,
6973                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6974          !!!cp ('t401');          !!!cp ('t401');
6975          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
6976                            text => $token->{tag_name}, token => $token);
6977          ## Ignore the token          ## Ignore the token
6978          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
6979          !!!next-token;          !!!next-token;
# Line 6483  sub _tree_construction_main ($) { Line 7058  sub _tree_construction_main ($) {
7058            }            }
7059    
7060            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7061                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7062            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7063            !!!next-token;            !!!next-token;
7064            next B;            next B;
# Line 6493  sub _tree_construction_main ($) { Line 7068  sub _tree_construction_main ($) {
7068            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7069              !!!cp ('t403');              !!!cp ('t403');
7070              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7071                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7072                              token => $token);                              token => $token);
7073              last;              last;
7074            } else {            } else {
# Line 6513  sub _tree_construction_main ($) { Line 7088  sub _tree_construction_main ($) {
7088            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7089              !!!cp ('t406');              !!!cp ('t406');
7090              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7091                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7092                                  ->manakai_local_name,                                  ->manakai_local_name,
7093                              token => $token);                              token => $token);
7094            } else {            } else {
# Line 6524  sub _tree_construction_main ($) { Line 7099  sub _tree_construction_main ($) {
7099            next B;            next B;
7100          } else {          } else {
7101            !!!cp ('t408');            !!!cp ('t408');
7102            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7103                              text => $token->{tag_name}, token => $token);
7104            ## Ignore the token            ## Ignore the token
7105            !!!next-token;            !!!next-token;
7106            next B;            next B;
# Line 6552  sub _tree_construction_main ($) { Line 7128  sub _tree_construction_main ($) {
7128    
7129          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7130            !!!cp ('t413');            !!!cp ('t413');
7131            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7132                              text => $token->{tag_name}, token => $token);
7133          } else {          } else {
7134            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7135            while ({            while ({
7136                      ## END_TAG_OPTIONAL_EL
7137                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7138                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7139                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7140                    p => 1,                    p => 1,
7141                      rt => 1,
7142                      rp => 1,
7143                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7144              !!!cp ('t409');              !!!cp ('t409');
7145              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6570  sub _tree_construction_main ($) { Line 7150  sub _tree_construction_main ($) {
7150                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7151              !!!cp ('t412');              !!!cp ('t412');
7152              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7153                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7154                                  ->manakai_local_name,                                  ->manakai_local_name,
7155                              token => $token);                              token => $token);
7156            } else {            } else {
# Line 6607  sub _tree_construction_main ($) { Line 7187  sub _tree_construction_main ($) {
7187    
7188          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7189            !!!cp ('t421');            !!!cp ('t421');
7190            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7191                              text => $token->{tag_name}, token => $token);
7192          } else {          } else {
7193            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7194            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6620  sub _tree_construction_main ($) { Line 7201  sub _tree_construction_main ($) {
7201                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7202              !!!cp ('t417.1');              !!!cp ('t417.1');
7203              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7204                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7205                                  ->manakai_local_name,                                  ->manakai_local_name,
7206                              token => $token);                              token => $token);
7207            } else {            } else {
# Line 6652  sub _tree_construction_main ($) { Line 7233  sub _tree_construction_main ($) {
7233    
7234          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7235            !!!cp ('t425.1');            !!!cp ('t425.1');
7236            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7237                              text => $token->{tag_name}, token => $token);
7238          } else {          } else {
7239            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7240            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6664  sub _tree_construction_main ($) { Line 7246  sub _tree_construction_main ($) {
7246            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7247                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7248              !!!cp ('t425');              !!!cp ('t425');
7249              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7250                                text => $token->{tag_name}, token => $token);
7251            } else {            } else {
7252              !!!cp ('t426');              !!!cp ('t426');
7253            }            }
# Line 6695  sub _tree_construction_main ($) { Line 7278  sub _tree_construction_main ($) {
7278                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7279              !!!cp ('t412.1');              !!!cp ('t412.1');
7280              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7281                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7282                                  ->manakai_local_name,                                  ->manakai_local_name,
7283                              token => $token);                              token => $token);
7284            } else {            } else {
# Line 6705  sub _tree_construction_main ($) { Line 7288  sub _tree_construction_main ($) {
7288            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7289          } else {          } else {
7290            !!!cp ('t413.1');            !!!cp ('t413.1');
7291            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7292                              text => $token->{tag_name}, token => $token);
7293    
7294            !!!cp ('t415.1');            !!!cp ('t415.1');
7295            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 6728  sub _tree_construction_main ($) { Line 7312  sub _tree_construction_main ($) {
7312          next B;          next B;
7313        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7314          !!!cp ('t428');          !!!cp ('t428');
7315          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7316                            text => 'br', token => $token);
7317    
7318          ## As if <br>          ## As if <br>
7319          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 6753  sub _tree_construction_main ($) { Line 7338  sub _tree_construction_main ($) {
7338                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7339                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7340          !!!cp ('t429');          !!!cp ('t429');
7341          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7342                            text => $token->{tag_name}, token => $token);
7343          ## Ignore the token          ## Ignore the token
7344          !!!next-token;          !!!next-token;
7345          next B;          next B;
# Line 6772  sub _tree_construction_main ($) { Line 7358  sub _tree_construction_main ($) {
7358              ## generate implied end tags              ## generate implied end tags
7359              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7360                !!!cp ('t430');                !!!cp ('t430');
7361                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7362                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7363                  ## which seems wrong.
7364                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7365                  $node_i++;
7366              }              }
7367                    
7368              ## Step 2              ## Step 2
# Line 6782  sub _tree_construction_main ($) { Line 7371  sub _tree_construction_main ($) {
7371                !!!cp ('t431');                !!!cp ('t431');
7372                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7373                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7374                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7375                                    ->manakai_local_name,                                    ->manakai_local_name,
7376                                token => $token);                                token => $token);
7377              } else {              } else {
# Line 6790  sub _tree_construction_main ($) { Line 7379  sub _tree_construction_main ($) {
7379              }              }
7380                            
7381              ## Step 3              ## Step 3
7382              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7383    
7384              !!!next-token;              !!!next-token;
7385              last S2;              last S2;
# Line 6801  sub _tree_construction_main ($) { Line 7390  sub _tree_construction_main ($) {
7390                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7391                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7392                !!!cp ('t433');                !!!cp ('t433');
7393                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7394                                  text => $token->{tag_name}, token => $token);
7395                ## Ignore the token                ## Ignore the token
7396                !!!next-token;                !!!next-token;
7397                last S2;                last S2;
# Line 6916  sub set_inner_html ($$$) { Line 7506  sub set_inner_html ($$$) {
7506          !!!cp ('i4');          !!!cp ('i4');
7507          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7508          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
7509          } elsif ($self->{next_char} <= 0x0008 or
7510                   (0x000E <= $self->{next_char} and
7511                    $self->{next_char} <= 0x001F) or
7512                   (0x007F <= $self->{next_char} and
7513                    $self->{next_char} <= 0x009F) or
7514                   (0xD800 <= $self->{next_char} and
7515                    $self->{next_char} <= 0xDFFF) or
7516                   (0xFDD0 <= $self->{next_char} and
7517                    $self->{next_char} <= 0xFDDF) or
7518                   {
7519                    0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
7520                    0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
7521                    0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
7522                    0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
7523                    0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
7524                    0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
7525                    0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
7526                    0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
7527                    0x10FFFE => 1, 0x10FFFF => 1,
7528                   }->{$self->{next_char}}) {
7529            !!!cp ('i4.1');
7530            if ($self->{next_char} < 0x10000) {
7531              !!!parse-error (type => 'control char',
7532                              text => (sprintf 'U+%04X', $self->{next_char}));
7533            } else {
7534              !!!parse-error (type => 'control char',
7535                              text => (sprintf 'U-%08X', $self->{next_char}));
7536            }
7537        }        }
7538      };      };
7539      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24