/[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.162 by wakaba, Thu Sep 11 09:12:27 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, $charset_name, $byte_stream, $doc, $onerror, $get_wrapper) = @_;
359    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
360    my $charset = shift;    my $charset_name = shift;
361    my $bytes_s = ref $_[0] ? $_[0] : \($_[0]);    my $byte_stream = $_[0];
362    my $s;  
363        my $onerror = $_[2] || sub {
364    if (defined $charset) {      my (%opt) = @_;
365      require Encode; ## TODO: decode(utf8) don't delete BOM      warn "Parse error ($opt{type})\n";
366      $s = \ (Encode::decode ($charset, $$bytes_s));    };
367      $self->{input_encoding} = lc $charset; ## TODO: normalize name    $self->{parse_error} = $onerror; # updated later by parse_char_string
368      $self->{confident} = 1;  
369    } else {    my $get_wrapper = $_[3] || sub ($) {
370      ## TODO: Implement HTML5 detection algorithm      return $_[0]; # $_[0] = byte stream handle, returned = arg to char handle
371      };
372    
373      ## HTML5 encoding sniffing algorithm
374      require Message::Charset::Info;
375      my $charset;
376      my $buffer;
377      my ($char_stream, $e_status);
378    
379      SNIFFING: {
380        ## NOTE: By setting |allow_fallback| option true when the
381        ## |get_decode_handle| method is invoked, we ignore what the HTML5
382        ## spec requires, i.e. unsupported encoding should be ignored.
383          ## TODO: We should not do this unless the parser is invoked
384          ## in the conformance checking mode, in which this behavior
385          ## would be useful.
386    
387        ## Step 1
388        if (defined $charset_name) {
389          $charset = Message::Charset::Info->get_by_html_name ($charset_name);
390              ## TODO: Is this ok?  Transfer protocol's parameter should be
391              ## interpreted in its semantics?
392    
393          ## ISSUE: Unsupported encoding is not ignored according to the spec.
394          ($char_stream, $e_status) = $charset->get_decode_handle
395              ($byte_stream, allow_error_reporting => 1,
396               allow_fallback => 1);
397          if ($char_stream) {
398            $self->{confident} = 1;
399            last SNIFFING;
400          } else {
401            ## TODO: unsupported error
402          }
403        }
404    
405        ## Step 2
406        my $byte_buffer = '';
407        for (1..1024) {
408          my $char = $byte_stream->getc;
409          last unless defined $char;
410          $byte_buffer .= $char;
411        } ## TODO: timeout
412    
413        ## Step 3
414        if ($byte_buffer =~ /^\xFE\xFF/) {
415          $charset = Message::Charset::Info->get_by_html_name ('utf-16be');
416          ($char_stream, $e_status) = $charset->get_decode_handle
417              ($byte_stream, allow_error_reporting => 1,
418               allow_fallback => 1, byte_buffer => \$byte_buffer);
419          $self->{confident} = 1;
420          last SNIFFING;
421        } elsif ($byte_buffer =~ /^\xFF\xFE/) {
422          $charset = Message::Charset::Info->get_by_html_name ('utf-16le');
423          ($char_stream, $e_status) = $charset->get_decode_handle
424              ($byte_stream, allow_error_reporting => 1,
425               allow_fallback => 1, byte_buffer => \$byte_buffer);
426          $self->{confident} = 1;
427          last SNIFFING;
428        } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
429          $charset = Message::Charset::Info->get_by_html_name ('utf-8');
430          ($char_stream, $e_status) = $charset->get_decode_handle
431              ($byte_stream, allow_error_reporting => 1,
432               allow_fallback => 1, byte_buffer => \$byte_buffer);
433          $self->{confident} = 1;
434          last SNIFFING;
435        }
436    
437        ## Step 4
438        ## TODO: <meta charset>
439    
440        ## Step 5
441        ## TODO: from history
442    
443        ## Step 6
444      require Whatpm::Charset::UniversalCharDet;      require Whatpm::Charset::UniversalCharDet;
445      $charset = Whatpm::Charset::UniversalCharDet->detect_byte_string      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
446          (substr ($$bytes_s, 0, 1024));          ($byte_buffer);
447      $charset ||= 'windows-1252';      if (defined $charset_name) {
448      $s = \ (Encode::decode ($charset, $$bytes_s));        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
449      $self->{input_encoding} = $charset;  
450          ## ISSUE: Unsupported encoding is not ignored according to the spec.
451          require Whatpm::Charset::DecodeHandle;
452          $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
453              ($byte_stream);
454          ($char_stream, $e_status) = $charset->get_decode_handle
455              ($buffer, allow_error_reporting => 1,
456               allow_fallback => 1, byte_buffer => \$byte_buffer);
457          if ($char_stream) {
458            $buffer->{buffer} = $byte_buffer;
459            !!!parse-error (type => 'sniffing:chardet',
460                            text => $charset_name,
461                            level => $self->{level}->{info},
462                            layer => 'encode',
463                            line => 1, column => 1);
464            $self->{confident} = 0;
465            last SNIFFING;
466          }
467        }
468    
469        ## Step 7: default
470        ## TODO: Make this configurable.
471        $charset = Message::Charset::Info->get_by_html_name ('windows-1252');
472            ## NOTE: We choose |windows-1252| here, since |utf-8| should be
473            ## detectable in the step 6.
474        require Whatpm::Charset::DecodeHandle;
475        $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
476            ($byte_stream);
477        ($char_stream, $e_status)
478            = $charset->get_decode_handle ($buffer,
479                                           allow_error_reporting => 1,
480                                           allow_fallback => 1,
481                                           byte_buffer => \$byte_buffer);
482        $buffer->{buffer} = $byte_buffer;
483        !!!parse-error (type => 'sniffing:default',
484                        text => 'windows-1252',
485                        level => $self->{level}->{info},
486                        line => 1, column => 1,
487                        layer => 'encode');
488      $self->{confident} = 0;      $self->{confident} = 0;
489      } # SNIFFING
490    
491      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
492        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
493        !!!parse-error (type => 'chardecode:fallback',
494                        #text => $self->{input_encoding},
495                        level => $self->{level}->{uncertain},
496                        line => 1, column => 1,
497                        layer => 'encode');
498      } elsif (not ($e_status &
499                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
500        $self->{input_encoding} = $charset->get_iana_name;
501        !!!parse-error (type => 'chardecode:no error',
502                        text => $self->{input_encoding},
503                        level => $self->{level}->{uncertain},
504                        line => 1, column => 1,
505                        layer => 'encode');
506      } else {
507        $self->{input_encoding} = $charset->get_iana_name;
508    }    }
509    
510    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
511      my $self = shift;      my $self = shift;
512      my $charset = lc shift;      $charset_name = shift;
513      my $token = shift;      my $token = shift;
     ## TODO: if $charset is supported  
     ## TODO: normalize charset name  
514    
515      ## "Change the encoding" algorithm:      $charset = Message::Charset::Info->get_by_html_name ($charset_name);
516        ($char_stream, $e_status) = $charset->get_decode_handle
517            ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
518             byte_buffer => \ $buffer->{buffer});
519        
520        if ($char_stream) { # if supported
521          ## "Change the encoding" algorithm:
522    
523      ## Step 1            ## Step 1    
524      if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
525        $charset = 'utf-8';            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
526      }          $charset = Message::Charset::Info->get_by_html_name ('utf-8');
527            ($char_stream, $e_status) = $charset->get_decode_handle
528                ($byte_stream,
529                 byte_buffer => \ $buffer->{buffer});
530          }
531          $charset_name = $charset->get_iana_name;
532          
533          ## Step 2
534          if (defined $self->{input_encoding} and
535              $self->{input_encoding} eq $charset_name) {
536            !!!parse-error (type => 'charset label:matching',
537                            text => $charset_name,
538                            level => $self->{level}->{info});
539            $self->{confident} = 1;
540            return;
541          }
542    
543      ## Step 2        !!!parse-error (type => 'charset label detected',
544      if (defined $self->{input_encoding} and                        text => $self->{input_encoding},
545          $self->{input_encoding} eq $charset) {                        value => $charset_name,
546        $self->{confident} = 1;                        level => $self->{level}->{warn},
547        return;                        token => $token);
548          
549          ## Step 3
550          # if (can) {
551            ## change the encoding on the fly.
552            #$self->{confident} = 1;
553            #return;
554          # }
555          
556          ## Step 4
557          throw Whatpm::HTML::RestartParser ();
558      }      }
559      }; # $self->{change_encoding}
560    
561      !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.    my $char_onerror = sub {
562          ':'.$charset, level => 'w', token => $token);      my (undef, $type, %opt) = @_;
563        !!!parse-error (layer => 'encode',
564      ## Step 3                      %opt, type => $type,
565      # if (can) {                      line => $self->{line}, column => $self->{column} + 1);
566        ## change the encoding on the fly.      if ($opt{octets}) {
567        #$self->{confident} = 1;        ${$opt{octets}} = "\x{FFFD}"; # relacement character
568        #return;      }
569      # }    };
570    
571      ## Step 4    my $wrapped_char_stream = $get_wrapper->($char_stream);
572      throw Whatpm::HTML::RestartParser (charset => $charset);    $wrapped_char_stream->onerror ($char_onerror);
   }; # $self->{change_encoding}  
573    
574    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
575    my $return;    my $return;
576    try {    try {
577      $return = $self->parse_char_string ($s, @args);        $return = $self->parse_char_stream ($wrapped_char_stream, @args);  
578    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
579      my $charset = shift->{charset};      ## NOTE: Invoked after {change_encoding}.
580      $s = \ (Encode::decode ($charset, $$bytes_s));      
581      $self->{input_encoding} = $charset; ## TODO: normalize      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
582          $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
583          !!!parse-error (type => 'chardecode:fallback',
584                          level => $self->{level}->{uncertain},
585                          #text => $self->{input_encoding},
586                          line => 1, column => 1,
587                          layer => 'encode');
588        } elsif (not ($e_status &
589                      Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
590          $self->{input_encoding} = $charset->get_iana_name;
591          !!!parse-error (type => 'chardecode:no error',
592                          text => $self->{input_encoding},
593                          level => $self->{level}->{uncertain},
594                          line => 1, column => 1,
595                          layer => 'encode');
596        } else {
597          $self->{input_encoding} = $charset->get_iana_name;
598        }
599      $self->{confident} = 1;      $self->{confident} = 1;
600      $return = $self->parse_char_string ($s, @args);  
601        $wrapped_char_stream = $get_wrapper->($char_stream);
602        $wrapped_char_stream->onerror ($char_onerror);
603    
604        $return = $self->parse_char_stream ($wrapped_char_stream, @args);
605    };    };
606    return $return;    return $return;
607  } # parse_byte_string  } # parse_byte_stream
608    
609  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM
610  ## 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 615  sub parse_byte_string ($$$$;$) {
615  ## 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
616  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
617    
618  *parse_char_string = \&parse_string;  sub parse_char_string ($$$;$$) {
619      #my ($self, $s, $doc, $onerror, $get_wrapper) = @_;
620      my $self = shift;
621      require utf8;
622      my $s = ref $_[0] ? $_[0] : \($_[0]);
623      open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
624      if ($_[3]) {
625        $input = $_[3]->($input);
626      }
627      return $self->parse_char_stream ($input, @_[1..$#_]);
628    } # parse_char_string
629    *parse_string = \&parse_char_string; ## NOTE: Alias for backward compatibility.
630    
631  sub parse_string ($$$;$) {  sub parse_char_stream ($$$;$) {
632    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
633    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $input = $_[0];
634    $self->{document} = $_[1];    $self->{document} = $_[1];
635    @{$self->{document}->child_nodes} = ();    @{$self->{document}->child_nodes} = ();
636    
# Line 350  sub parse_string ($$$;$) { Line 649  sub parse_string ($$$;$) {
649      pop @{$self->{prev_char}};      pop @{$self->{prev_char}};
650      unshift @{$self->{prev_char}}, $self->{next_char};      unshift @{$self->{prev_char}}, $self->{next_char};
651    
652      $self->{next_char} = -1 and return if $i >= length $$s;      my $char;
653      $self->{next_char} = ord substr $$s, $i++, 1;      if (defined $self->{next_next_char}) {
654          $char = $self->{next_next_char};
655          delete $self->{next_next_char};
656        } else {
657          $char = $input->getc;
658        }
659        $self->{next_char} = -1 and return unless defined $char;
660        $self->{next_char} = ord $char;
661    
662      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
663          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
664      $self->{column}++;      $self->{column}++;
665            
666      if ($self->{next_char} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
667          !!!cp ('j1');
668        $self->{line}++;        $self->{line}++;
669        $self->{column} = 0;        $self->{column} = 0;
670      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
671        $i++ if substr ($$s, $i, 1) eq "\x0A";        !!!cp ('j2');
672          my $next = $input->getc;
673          if (defined $next and $next ne "\x0A") {
674            $self->{next_next_char} = $next;
675          }
676        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
677        $self->{line}++;        $self->{line}++;
678        $self->{column} = 0;        $self->{column} = 0;
679      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
680          !!!cp ('j3');
681        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
682      } elsif ($self->{next_char} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
683          !!!cp ('j4');
684        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
685        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
686        } elsif ($self->{next_char} <= 0x0008 or
687                 (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or
688                 (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or
689                 (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or
690                 (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or
691                 {
692                  0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
693                  0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
694                  0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
695                  0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
696                  0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
697                  0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
698                  0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
699                  0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
700                  0x10FFFE => 1, 0x10FFFF => 1,
701                 }->{$self->{next_char}}) {
702          !!!cp ('j5');
703          if ($self->{next_char} < 0x10000) {
704            !!!parse-error (type => 'control char',
705                            text => (sprintf 'U+%04X', $self->{next_char}));
706          } else {
707            !!!parse-error (type => 'control char',
708                            text => (sprintf 'U-%08X', $self->{next_char}));
709          }
710      }      }
711    };    };
712    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 393  sub parse_string ($$$;$) { Line 730  sub parse_string ($$$;$) {
730    delete $self->{parse_error}; # remove loop    delete $self->{parse_error}; # remove loop
731    
732    return $self->{document};    return $self->{document};
733  } # parse_string  } # parse_char_stream
734    
735  sub new ($) {  sub new ($) {
736    my $class = shift;    my $class = shift;
737    my $self = bless {}, $class;    my $self = bless {
738        level => {must => 'm',
739                  should => 's',
740                  warn => 'w',
741                  info => 'i',
742                  uncertain => 'u'},
743      }, $class;
744    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
745      $self->{next_char} = -1;      $self->{next_char} = -1;
746    };    };
# Line 543  sub _initialize_tokenizer ($) { Line 886  sub _initialize_tokenizer ($) {
886  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
887  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
888    
 ## 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?  
   
889  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
890    
891  ## 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 1101  sub _get_next_token ($) {
1101            redo A;            redo A;
1102          } else {          } else {
1103            !!!cp (23);            !!!cp (23);
1104            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago',
1105                              line => $self->{line_prev},
1106                              column => $self->{column_prev});
1107            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1108            ## reconsume            ## reconsume
1109    
# Line 1057  sub _get_next_token ($) { Line 1398  sub _get_next_token ($) {
1398          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1399              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1400            !!!cp (57);            !!!cp (57);
1401            !!!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});
1402            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1403          } else {          } else {
1404            !!!cp (58);            !!!cp (58);
# Line 1228  sub _get_next_token ($) { Line 1569  sub _get_next_token ($) {
1569    
1570          redo A;          redo A;
1571        } else {        } else {
1572          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1573                $self->{next_char} == 0x0027) { # '
1574              !!!cp (78);
1575              !!!parse-error (type => 'bad attribute name');
1576            } else {
1577              !!!cp (82);
1578            }
1579          $self->{current_attribute}          $self->{current_attribute}
1580              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1581                 value => '',                 value => '',
# Line 1263  sub _get_next_token ($) { Line 1610  sub _get_next_token ($) {
1610          !!!next-input-character;          !!!next-input-character;
1611          redo A;          redo A;
1612        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1613            !!!parse-error (type => 'empty unquoted attribute value');
1614          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1615            !!!cp (87);            !!!cp (87);
1616            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1539  sub _get_next_token ($) { Line 1887  sub _get_next_token ($) {
1887          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1888          !!!next-input-character;          !!!next-input-character;
1889          redo A;          redo A;
1890          } elsif ($self->{next_char} == -1) {
1891            !!!parse-error (type => 'unclosed tag');
1892            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1893              !!!cp (122.3);
1894              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1895            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1896              if ($self->{current_token}->{attributes}) {
1897                !!!cp (122.1);
1898                !!!parse-error (type => 'end tag attribute');
1899              } else {
1900                ## NOTE: This state should never be reached.
1901                !!!cp (122.2);
1902              }
1903            } else {
1904              die "$0: $self->{current_token}->{type}: Unknown token type";
1905            }
1906            $self->{state} = DATA_STATE;
1907            ## Reconsume.
1908            !!!emit ($self->{current_token}); # start tag or end tag
1909            redo A;
1910        } else {        } else {
1911          !!!cp ('124.1');          !!!cp ('124.1');
1912          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1571  sub _get_next_token ($) { Line 1939  sub _get_next_token ($) {
1939          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1940    
1941          redo A;          redo A;
1942          } elsif ($self->{next_char} == -1) {
1943            !!!parse-error (type => 'unclosed tag');
1944            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1945              !!!cp (124.7);
1946              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1947            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1948              if ($self->{current_token}->{attributes}) {
1949                !!!cp (124.5);
1950                !!!parse-error (type => 'end tag attribute');
1951              } else {
1952                ## NOTE: This state should never be reached.
1953                !!!cp (124.6);
1954              }
1955            } else {
1956              die "$0: $self->{current_token}->{type}: Unknown token type";
1957            }
1958            $self->{state} = DATA_STATE;
1959            ## Reconsume.
1960            !!!emit ($self->{current_token}); # start tag or end tag
1961            redo A;
1962        } else {        } else {
1963          !!!cp ('124.4');          !!!cp ('124.4');
1964          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 2328  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 (208);          !!!cp (208);
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 2364  sub _get_next_token ($) { Line 2752  sub _get_next_token ($) {
2752          redo A;          redo A;
2753        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2754          !!!cp (212);          !!!cp (212);
2755          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2756    
2757          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2758          !!!next-input-character;          !!!next-input-character;
# Line 2412  sub _get_next_token ($) { Line 2800  sub _get_next_token ($) {
2800        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2801          !!!cp (217);          !!!cp (217);
2802          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2803          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2804          ## reconsume          ## reconsume
2805    
# Line 2574  sub _tokenize_attempt_to_consume_an_enti Line 2961  sub _tokenize_attempt_to_consume_an_enti
2961    
2962          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2963            !!!cp (1008);            !!!cp (1008);
2964            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2965                              text => (sprintf 'U+%04X', $code),
2966                              line => $l, column => $c);
2967            $code = 0xFFFD;            $code = 0xFFFD;
2968          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2969            !!!cp (1009);            !!!cp (1009);
2970            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2971                              text => (sprintf 'U-%08X', $code),
2972                              line => $l, column => $c);
2973            $code = 0xFFFD;            $code = 0xFFFD;
2974          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2975            !!!cp (1010);            !!!cp (1010);
# Line 2586  sub _tokenize_attempt_to_consume_an_enti Line 2977  sub _tokenize_attempt_to_consume_an_enti
2977            $code = 0x000A;            $code = 0x000A;
2978          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2979            !!!cp (1011);            !!!cp (1011);
2980            !!!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);
2981            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2982          }          }
2983    
# Line 2619  sub _tokenize_attempt_to_consume_an_enti Line 3010  sub _tokenize_attempt_to_consume_an_enti
3010    
3011        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
3012          !!!cp (1015);          !!!cp (1015);
3013          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3014                            text => (sprintf 'U+%04X', $code),
3015                            line => $l, column => $c);
3016          $code = 0xFFFD;          $code = 0xFFFD;
3017        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3018          !!!cp (1016);          !!!cp (1016);
3019          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3020                            text => (sprintf 'U-%08X', $code),
3021                            line => $l, column => $c);
3022          $code = 0xFFFD;          $code = 0xFFFD;
3023        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3024          !!!cp (1017);          !!!cp (1017);
3025          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3026                            line => $l, column => $c);
3027          $code = 0x000A;          $code = 0x000A;
3028        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3029          !!!cp (1018);          !!!cp (1018);
3030          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3031                            text => (sprintf 'U+%04X', $code),
3032                            line => $l, column => $c);
3033          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3034        }        }
3035                
# Line 2657  sub _tokenize_attempt_to_consume_an_enti Line 3055  sub _tokenize_attempt_to_consume_an_enti
3055      require Whatpm::_NamedEntityList;      require Whatpm::_NamedEntityList;
3056      our $EntityChar;      our $EntityChar;
3057    
3058      while (length $entity_name < 10 and      while (length $entity_name < 30 and
3059             ## NOTE: Some number greater than the maximum length of entity name             ## NOTE: Some number greater than the maximum length of entity name
3060             ((0x0041 <= $self->{next_char} and # a             ((0x0041 <= $self->{next_char} and # a
3061               $self->{next_char} <= 0x005A) or # x               $self->{next_char} <= 0x005A) or # x
# Line 2729  sub _initialize_tree_constructor ($) { Line 3127  sub _initialize_tree_constructor ($) {
3127    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3128    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3129    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3130      $self->{document}->set_user_data (manakai_source_line => 1);
3131      $self->{document}->set_user_data (manakai_source_column => 1);
3132  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3133    
3134  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 2783  sub _tree_construction_initial ($) { Line 3183  sub _tree_construction_initial ($) {
3183        ## language.        ## language.
3184        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3185        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3186        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3187        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3188            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3189          !!!cp ('t1');          !!!cp ('t1');
3190          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3191        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3192          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3193          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3194          } elsif (defined $token->{public_identifier}) {
3195            if ($token->{public_identifier} eq 'XSLT-compat') {
3196              !!!cp ('t1.2');
3197              !!!parse-error (type => 'XSLT-compat', token => $token,
3198                              level => $self->{level}->{should});
3199            } else {
3200              !!!parse-error (type => 'not HTML5', token => $token);
3201            }
3202        } else {        } else {
3203          !!!cp ('t3');          !!!cp ('t3');
3204            #
3205        }        }
3206                
3207        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 2815  sub _tree_construction_initial ($) { Line 3222  sub _tree_construction_initial ($) {
3222        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3223          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3224          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3225          if ({          my $prefix = [
3226            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3227            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3228            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3229            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3230            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3231            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3232            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3233            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3234            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3235            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3236            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3237            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3238            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3239            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3240            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3241            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3242            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3243            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3244            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3245            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3246            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3247            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3248            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3249            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3250            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3251            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3252            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3253            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3254            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3255            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3256            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3257            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3258            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3259            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3260            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3261            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3262            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3263            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3264            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3265            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3266            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3267            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3268            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3269            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3270            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3271            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3272            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3273            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3274            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3275            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3276            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3277            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3278            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3279            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3280            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3281            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3282            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3283            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3284            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3285            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3286            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3287            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3288            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3289            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3290            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3291            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3292            "-//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}) {  
3293            !!!cp ('t5');            !!!cp ('t5');
3294            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3295          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3296                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3297            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3298              !!!cp ('t6');              !!!cp ('t6');
3299              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 2900  sub _tree_construction_initial ($) { Line 3301  sub _tree_construction_initial ($) {
3301              !!!cp ('t7');              !!!cp ('t7');
3302              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3303            }            }
3304          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3305                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3306            !!!cp ('t8');            !!!cp ('t8');
3307            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3308          } else {          } else {
# Line 2914  sub _tree_construction_initial ($) { Line 3315  sub _tree_construction_initial ($) {
3315          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3316          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3317          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") {
3318            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3319              ## marked as quirks.
3320            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3321            !!!cp ('t11');            !!!cp ('t11');
3322          } else {          } else {
# Line 3086  sub _reset_insertion_mode ($) { Line 3488  sub _reset_insertion_mode ($) {
3488        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3489          $last = 1;          $last = 1;
3490          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3491            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3492              !!!cp ('t27');            $node = $self->{inner_html_node};
3493              #          } else {
3494            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3495          }          }
3496        }        }
3497              
3498      ## Step 4..14        ## Step 4..14
3499      my $new_mode;        my $new_mode;
3500      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3501        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3502        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3503        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3504        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3505        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3506      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3507        $new_mode = {          if ($last) {
3508              !!!cp ('t28.2');
3509              #
3510            } else {
3511              !!!cp ('t28.3');
3512              $new_mode = IN_CELL_IM;
3513            }
3514          } else {
3515            !!!cp ('t28.4');
3516            $new_mode = {
3517                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3518                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3519                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3520                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3521                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3522                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3122  sub _reset_insertion_mode ($) { Line 3528  sub _reset_insertion_mode ($) {
3528                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3529                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3530                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3531      }        }
3532      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3533                
3534        ## Step 15        ## Step 15
3535        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3297  sub _tree_construction_main ($) { Line 3703  sub _tree_construction_main ($) {
3703        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3704        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3705          !!!cp ('t43');          !!!cp ('t43');
3706          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3707        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3708          !!!cp ('t44');          !!!cp ('t44');
3709          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3710        } else {        } else {
3711          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3712        }        }
# Line 3337  sub _tree_construction_main ($) { Line 3743  sub _tree_construction_main ($) {
3743        ## Ignore the token        ## Ignore the token
3744      } else {      } else {
3745        !!!cp ('t48');        !!!cp ('t48');
3746        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3747        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3748        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3749      }      }
# Line 3388  sub _tree_construction_main ($) { Line 3794  sub _tree_construction_main ($) {
3794        } # AFE        } # AFE
3795        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3796          !!!cp ('t53');          !!!cp ('t53');
3797          !!!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);
3798          ## Ignore the token          ## Ignore the token
3799          !!!next-token;          !!!next-token;
3800          return;          return;
# Line 3405  sub _tree_construction_main ($) { Line 3811  sub _tree_construction_main ($) {
3811              last INSCOPE;              last INSCOPE;
3812            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3813              !!!cp ('t55');              !!!cp ('t55');
3814              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3815                                text => $token->{tag_name},
3816                              token => $end_tag_token);                              token => $end_tag_token);
3817              ## Ignore the token              ## Ignore the token
3818              !!!next-token;              !!!next-token;
# Line 3418  sub _tree_construction_main ($) { Line 3825  sub _tree_construction_main ($) {
3825        } # INSCOPE        } # INSCOPE
3826        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3827          !!!cp ('t57');          !!!cp ('t57');
3828          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3829                            text => $token->{tag_name},
3830                          token => $end_tag_token);                          token => $end_tag_token);
3831          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3832          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3427  sub _tree_construction_main ($) { Line 3835  sub _tree_construction_main ($) {
3835        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3836          !!!cp ('t58');          !!!cp ('t58');
3837          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3838                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3839                              ->manakai_local_name,                              ->manakai_local_name,
3840                          token => $end_tag_token);                          token => $end_tag_token);
3841        }        }
# Line 3636  sub _tree_construction_main ($) { Line 4044  sub _tree_construction_main ($) {
4044    B: while (1) {    B: while (1) {
4045      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4046        !!!cp ('t73');        !!!cp ('t73');
4047        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4048        ## Ignore the token        ## Ignore the token
4049        ## Stay in the phase        ## Stay in the phase
4050        !!!next-token;        !!!next-token;
# Line 3645  sub _tree_construction_main ($) { Line 4053  sub _tree_construction_main ($) {
4053               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4054        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4055          !!!cp ('t79');          !!!cp ('t79');
4056          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4057          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4058        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4059          !!!cp ('t80');          !!!cp ('t80');
4060          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4061          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4062        } else {        } else {
4063          !!!cp ('t81');          !!!cp ('t81');
# Line 3690  sub _tree_construction_main ($) { Line 4098  sub _tree_construction_main ($) {
4098          !!!next-token;          !!!next-token;
4099          next B;          next B;
4100        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4101          if ($self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL or          if ((not {mglyph => 1, malignmark => 1}->{$token->{tag_name}} and
4102                 $self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL) or
4103              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or
4104              ($token->{tag_name} eq 'svg' and              ($token->{tag_name} eq 'svg' and
4105               $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {               $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {
# Line 3698  sub _tree_construction_main ($) { Line 4107  sub _tree_construction_main ($) {
4107            !!!cp ('t87.2');            !!!cp ('t87.2');
4108            #            #
4109          } elsif ({          } elsif ({
4110    ## TODO:                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4111                      center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4112                      em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4113                      h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4114                      img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4115                      nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4116                      small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4117                      sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4118                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4119            !!!cp ('t87.2');            !!!cp ('t87.2');
4120            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4121                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4122                                ->manakai_local_name,                                ->manakai_local_name,
4123                            token => $token);                            token => $token);
4124    
4125            pop @{$self->{open_elements}}            pop @{$self->{open_elements}}
4126                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4127    
4128            $self->{insertion_mode} &= ~ $self->{insertion_mode};            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4129            ## Reprocess.            ## Reprocess.
4130            next B;            next B;
4131          } else {          } else {
4132            ## TODO: case fixup            my $nsuri = $self->{open_elements}->[-1]->[0]->namespace_uri;
4133              my $tag_name = $token->{tag_name};
4134              if ($nsuri eq $SVG_NS) {
4135                $tag_name = {
4136                   altglyph => 'altGlyph',
4137                   altglyphdef => 'altGlyphDef',
4138                   altglyphitem => 'altGlyphItem',
4139                   animatecolor => 'animateColor',
4140                   animatemotion => 'animateMotion',
4141                   animatetransform => 'animateTransform',
4142                   clippath => 'clipPath',
4143                   feblend => 'feBlend',
4144                   fecolormatrix => 'feColorMatrix',
4145                   fecomponenttransfer => 'feComponentTransfer',
4146                   fecomposite => 'feComposite',
4147                   feconvolvematrix => 'feConvolveMatrix',
4148                   fediffuselighting => 'feDiffuseLighting',
4149                   fedisplacementmap => 'feDisplacementMap',
4150                   fedistantlight => 'feDistantLight',
4151                   feflood => 'feFlood',
4152                   fefunca => 'feFuncA',
4153                   fefuncb => 'feFuncB',
4154                   fefuncg => 'feFuncG',
4155                   fefuncr => 'feFuncR',
4156                   fegaussianblur => 'feGaussianBlur',
4157                   feimage => 'feImage',
4158                   femerge => 'feMerge',
4159                   femergenode => 'feMergeNode',
4160                   femorphology => 'feMorphology',
4161                   feoffset => 'feOffset',
4162                   fepointlight => 'fePointLight',
4163                   fespecularlighting => 'feSpecularLighting',
4164                   fespotlight => 'feSpotLight',
4165                   fetile => 'feTile',
4166                   feturbulence => 'feTurbulence',
4167                   foreignobject => 'foreignObject',
4168                   glyphref => 'glyphRef',
4169                   lineargradient => 'linearGradient',
4170                   radialgradient => 'radialGradient',
4171                   #solidcolor => 'solidColor', ## NOTE: Commented in spec (SVG1.2)
4172                   textpath => 'textPath',  
4173                }->{$tag_name} || $tag_name;
4174              }
4175    
4176              ## "adjust SVG attributes" (SVG only) - done in insert-element-f
4177    
4178            !!!insert-element-f ($self->{open_elements}->[-1]->[0]->namespace_uri, $token);            ## "adjust foreign attributes" - done in insert-element-f
4179    
4180              !!!insert-element-f ($nsuri, $tag_name, $token->{attributes}, $token);
4181    
4182            if ($self->{self_closing}) {            if ($self->{self_closing}) {
4183              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 3732  sub _tree_construction_main ($) { Line 4194  sub _tree_construction_main ($) {
4194          !!!cp ('t87.5');          !!!cp ('t87.5');
4195          #          #
4196        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4197          !!!cp ('t87.6');          !!!cp ('t87.6');
4198          #          !!!parse-error (type => 'not closed',
4199          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4200                                ->manakai_local_name,
4201                            token => $token);
4202    
4203            pop @{$self->{open_elements}}
4204                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4205    
4206            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4207            ## Reprocess.
4208            next B;
4209        } else {        } else {
4210          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4211        }        }
# Line 3776  sub _tree_construction_main ($) { Line 4246  sub _tree_construction_main ($) {
4246            !!!cp ('t90');            !!!cp ('t90');
4247            ## As if </noscript>            ## As if </noscript>
4248            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4249            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4250                        
4251            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4252            ## As if </head>            ## As if </head>
# Line 3812  sub _tree_construction_main ($) { Line 4282  sub _tree_construction_main ($) {
4282              !!!next-token;              !!!next-token;
4283              next B;              next B;
4284            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4285              !!!cp ('t94');              !!!cp ('t93.2');
4286              #              !!!parse-error (type => 'after head', text => 'head',
4287                                token => $token);
4288                ## Ignore the token
4289                !!!nack ('t93.3');
4290                !!!next-token;
4291                next B;
4292            } else {            } else {
4293              !!!cp ('t95');              !!!cp ('t95');
4294              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4295                                token => $token); # or in head noscript
4296              ## Ignore the token              ## Ignore the token
4297              !!!nack ('t95.1');              !!!nack ('t95.1');
4298              !!!next-token;              !!!next-token;
# Line 3841  sub _tree_construction_main ($) { Line 4317  sub _tree_construction_main ($) {
4317                  !!!cp ('t98');                  !!!cp ('t98');
4318                  ## As if </noscript>                  ## As if </noscript>
4319                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4320                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4321                                    token => $token);
4322                                
4323                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4324                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 3852  sub _tree_construction_main ($) { Line 4329  sub _tree_construction_main ($) {
4329                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4330                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4331                  !!!cp ('t100');                  !!!cp ('t100');
4332                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4333                                    text => $token->{tag_name}, token => $token);
4334                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4335                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4336                } else {                } else {
# Line 3869  sub _tree_construction_main ($) { Line 4347  sub _tree_construction_main ($) {
4347                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4348                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4349                  !!!cp ('t102');                  !!!cp ('t102');
4350                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4351                                    text => $token->{tag_name}, token => $token);
4352                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4353                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4354                } else {                } else {
# Line 3886  sub _tree_construction_main ($) { Line 4365  sub _tree_construction_main ($) {
4365                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4366                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4367                  !!!cp ('t104');                  !!!cp ('t104');
4368                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4369                                    text => $token->{tag_name}, token => $token);
4370                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4371                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4372                } else {                } else {
# Line 3896  sub _tree_construction_main ($) { Line 4376  sub _tree_construction_main ($) {
4376                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.
4377    
4378                unless ($self->{confident}) {                unless ($self->{confident}) {
4379                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) {
4380                    !!!cp ('t106');                    !!!cp ('t106');
4381                      ## NOTE: Whether the encoding is supported or not is handled
4382                      ## in the {change_encoding} callback.
4383                    $self->{change_encoding}                    $self->{change_encoding}
4384                        ->($self, $token->{attributes}->{charset}->{value},                        ->($self, $token->{attributes}->{charset}->{value},
4385                           $token);                           $token);
# Line 3907  sub _tree_construction_main ($) { Line 4389  sub _tree_construction_main ($) {
4389                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
4390                                                 ->{has_reference});                                                 ->{has_reference});
4391                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
                   ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
4392                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4393                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4394                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4395                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4396                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4397                      !!!cp ('t107');                      !!!cp ('t107');
4398                        ## NOTE: Whether the encoding is supported or not is handled
4399                        ## in the {change_encoding} callback.
4400                      $self->{change_encoding}                      $self->{change_encoding}
4401                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,
4402                             $token);                             $token);
# Line 3952  sub _tree_construction_main ($) { Line 4435  sub _tree_construction_main ($) {
4435                  !!!cp ('t111');                  !!!cp ('t111');
4436                  ## As if </noscript>                  ## As if </noscript>
4437                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4438                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4439                                    token => $token);
4440                                
4441                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4442                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4443                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4444                  !!!cp ('t112');                  !!!cp ('t112');
4445                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4446                                    text => $token->{tag_name}, token => $token);
4447                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4448                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4449                } else {                } else {
# Line 3972  sub _tree_construction_main ($) { Line 4457  sub _tree_construction_main ($) {
4457                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4458                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4459                next B;                next B;
4460              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4461                         $token->{tag_name} eq 'noframes') {
4462                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4463                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4464                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4465                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4466                  !!!cp ('t114');                  !!!cp ('t114');
4467                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4468                                    text => $token->{tag_name}, token => $token);
4469                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4470                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4471                } else {                } else {
# Line 3999  sub _tree_construction_main ($) { Line 4486  sub _tree_construction_main ($) {
4486                  next B;                  next B;
4487                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4488                  !!!cp ('t117');                  !!!cp ('t117');
4489                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4490                                    token => $token);
4491                  ## Ignore the token                  ## Ignore the token
4492                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4493                  !!!next-token;                  !!!next-token;
# Line 4013  sub _tree_construction_main ($) { Line 4501  sub _tree_construction_main ($) {
4501                  !!!cp ('t119');                  !!!cp ('t119');
4502                  ## As if </noscript>                  ## As if </noscript>
4503                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4504                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4505                                    token => $token);
4506                                
4507                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4508                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4509                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4510                  !!!cp ('t120');                  !!!cp ('t120');
4511                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4512                                    text => $token->{tag_name}, token => $token);
4513                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4514                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4515                } else {                } else {
# Line 4037  sub _tree_construction_main ($) { Line 4527  sub _tree_construction_main ($) {
4527                  !!!cp ('t122');                  !!!cp ('t122');
4528                  ## As if </noscript>                  ## As if </noscript>
4529                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4530                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4531                                    text => $token->{tag_name}, token => $token);
4532                                    
4533                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4534                  ## As if </head>                  ## As if </head>
# Line 4076  sub _tree_construction_main ($) { Line 4567  sub _tree_construction_main ($) {
4567                !!!cp ('t129');                !!!cp ('t129');
4568                ## As if </noscript>                ## As if </noscript>
4569                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4570                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4571                                  text => $token->{tag_name}, token => $token);
4572                                
4573                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4574                ## As if </head>                ## As if </head>
# Line 4119  sub _tree_construction_main ($) { Line 4611  sub _tree_construction_main ($) {
4611                  !!!cp ('t133');                  !!!cp ('t133');
4612                  ## As if </noscript>                  ## As if </noscript>
4613                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4614                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4615                                    text => 'head', token => $token);
4616                                    
4617                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4618                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4132  sub _tree_construction_main ($) { Line 4625  sub _tree_construction_main ($) {
4625                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4626                  !!!next-token;                  !!!next-token;
4627                  next B;                  next B;
4628                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4629                    !!!cp ('t134.1');
4630                    !!!parse-error (type => 'unmatched end tag', text => 'head',
4631                                    token => $token);
4632                    ## Ignore the token
4633                    !!!next-token;
4634                    next B;
4635                } else {                } else {
4636                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4637                }                }
4638              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4639                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4143  sub _tree_construction_main ($) { Line 4642  sub _tree_construction_main ($) {
4642                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4643                  !!!next-token;                  !!!next-token;
4644                  next B;                  next B;
4645                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4646                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4647                  !!!cp ('t137');                  !!!cp ('t137');
4648                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4649                                    text => 'noscript', token => $token);
4650                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4651                  !!!next-token;                  !!!next-token;
4652                  next B;                  next B;
# Line 4156  sub _tree_construction_main ($) { Line 4657  sub _tree_construction_main ($) {
4657              } elsif ({              } elsif ({
4658                        body => 1, html => 1,                        body => 1, html => 1,
4659                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4660                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4661                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4662                  ## 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) {  
4663                  !!!cp ('t140');                  !!!cp ('t140');
4664                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4665                                    text => $token->{tag_name}, token => $token);
4666                    ## Ignore the token
4667                    !!!next-token;
4668                    next B;
4669                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4670                    !!!cp ('t140.1');
4671                    !!!parse-error (type => 'unmatched end tag',
4672                                    text => $token->{tag_name}, token => $token);
4673                  ## Ignore the token                  ## Ignore the token
4674                  !!!next-token;                  !!!next-token;
4675                  next B;                  next B;
4676                } else {                } else {
4677                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4678                }                }
4679                              } elsif ($token->{tag_name} eq 'p') {
4680                #                !!!cp ('t142');
4681              } elsif ({                !!!parse-error (type => 'unmatched end tag',
4682                        p => 1, br => 1,                                text => $token->{tag_name}, token => $token);
4683                       }->{$token->{tag_name}}) {                ## Ignore the token
4684                  !!!next-token;
4685                  next B;
4686                } elsif ($token->{tag_name} eq 'br') {
4687                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4688                  !!!cp ('t142');                  !!!cp ('t142.2');
4689                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4690                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4691                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4692                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4693                      [$self->{head_element}, $el_category->{head}];    
4694                    ## Reprocess in the "after head" insertion mode...
4695                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4696                    !!!cp ('t143.2');
4697                    ## As if </head>
4698                    pop @{$self->{open_elements}};
4699                    $self->{insertion_mode} = AFTER_HEAD_IM;
4700      
4701                    ## Reprocess in the "after head" insertion mode...
4702                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4703                    !!!cp ('t143.3');
4704                    ## ISSUE: Two parse errors for <head><noscript></br>
4705                    !!!parse-error (type => 'unmatched end tag',
4706                                    text => 'br', token => $token);
4707                    ## As if </noscript>
4708                    pop @{$self->{open_elements}};
4709                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4710    
4711                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4712                } else {                  ## As if </head>
4713                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4714                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4715    
4716                #                  ## Reprocess in the "after head" insertion mode...
4717              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4718                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4719                  #                  #
4720                } else {                } else {
4721                  !!!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;  
4722                }                }
4723    
4724                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4725                  !!!parse-error (type => 'unmatched end tag',
4726                                  text => 'br', token => $token);
4727                  ## Ignore the token
4728                  !!!next-token;
4729                  next B;
4730                } else {
4731                  !!!cp ('t145');
4732                  !!!parse-error (type => 'unmatched end tag',
4733                                  text => $token->{tag_name}, token => $token);
4734                  ## Ignore the token
4735                  !!!next-token;
4736                  next B;
4737              }              }
4738    
4739              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4740                !!!cp ('t146');                !!!cp ('t146');
4741                ## As if </noscript>                ## As if </noscript>
4742                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4743                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4744                                  text => $token->{tag_name}, token => $token);
4745                                
4746                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4747                ## As if </head>                ## As if </head>
# Line 4228  sub _tree_construction_main ($) { Line 4757  sub _tree_construction_main ($) {
4757              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4758  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4759                !!!cp ('t148');                !!!cp ('t148');
4760                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4761                                  text => $token->{tag_name}, token => $token);
4762                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4763                !!!next-token;                !!!next-token;
4764                next B;                next B;
# Line 4339  sub _tree_construction_main ($) { Line 4869  sub _tree_construction_main ($) {
4869    
4870                  !!!cp ('t153');                  !!!cp ('t153');
4871                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4872                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4873                  ## Ignore the token                  ## Ignore the token
4874                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4875                  !!!next-token;                  !!!next-token;
4876                  next B;                  next B;
4877                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4878                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4879                                    token => $token);
4880                                    
4881                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4882                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4365  sub _tree_construction_main ($) { Line 4896  sub _tree_construction_main ($) {
4896    
4897                    !!!cp ('t157');                    !!!cp ('t157');
4898                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4899                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4900                    ## Ignore the token                    ## Ignore the token
4901                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4902                    !!!next-token;                    !!!next-token;
# Line 4382  sub _tree_construction_main ($) { Line 4913  sub _tree_construction_main ($) {
4913                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4914                    !!!cp ('t159');                    !!!cp ('t159');
4915                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4916                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4917                                        ->manakai_local_name,                                        ->manakai_local_name,
4918                                    token => $token);                                    token => $token);
4919                  } else {                  } else {
# Line 4424  sub _tree_construction_main ($) { Line 4955  sub _tree_construction_main ($) {
4955                  } # INSCOPE                  } # INSCOPE
4956                    unless (defined $i) {                    unless (defined $i) {
4957                      !!!cp ('t165');                      !!!cp ('t165');
4958                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
4959                                        text => $token->{tag_name},
4960                                        token => $token);
4961                      ## Ignore the token                      ## Ignore the token
4962                      !!!next-token;                      !!!next-token;
4963                      next B;                      next B;
# Line 4441  sub _tree_construction_main ($) { Line 4974  sub _tree_construction_main ($) {
4974                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
4975                    !!!cp ('t167');                    !!!cp ('t167');
4976                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4977                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4978                                        ->manakai_local_name,                                        ->manakai_local_name,
4979                                    token => $token);                                    token => $token);
4980                  } else {                  } else {
# Line 4458  sub _tree_construction_main ($) { Line 4991  sub _tree_construction_main ($) {
4991                  next B;                  next B;
4992                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4993                  !!!cp ('t169');                  !!!cp ('t169');
4994                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4995                                    text => $token->{tag_name}, token => $token);
4996                  ## Ignore the token                  ## Ignore the token
4997                  !!!next-token;                  !!!next-token;
4998                  next B;                  next B;
# Line 4485  sub _tree_construction_main ($) { Line 5019  sub _tree_construction_main ($) {
5019    
5020                    !!!cp ('t173');                    !!!cp ('t173');
5021                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5022                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5023                    ## Ignore the token                    ## Ignore the token
5024                    !!!next-token;                    !!!next-token;
5025                    next B;                    next B;
# Line 4501  sub _tree_construction_main ($) { Line 5035  sub _tree_construction_main ($) {
5035                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5036                    !!!cp ('t175');                    !!!cp ('t175');
5037                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5038                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5039                                        ->manakai_local_name,                                        ->manakai_local_name,
5040                                    token => $token);                                    token => $token);
5041                  } else {                  } else {
# Line 4518  sub _tree_construction_main ($) { Line 5052  sub _tree_construction_main ($) {
5052                  next B;                  next B;
5053                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5054                  !!!cp ('t177');                  !!!cp ('t177');
5055                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5056                                    text => $token->{tag_name}, token => $token);
5057                  ## Ignore the token                  ## Ignore the token
5058                  !!!next-token;                  !!!next-token;
5059                  next B;                  next B;
# Line 4561  sub _tree_construction_main ($) { Line 5096  sub _tree_construction_main ($) {
5096    
5097                  !!!cp ('t182');                  !!!cp ('t182');
5098                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5099                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5100                  ## Ignore the token                  ## Ignore the token
5101                  !!!next-token;                  !!!next-token;
5102                  next B;                  next B;
5103                } # INSCOPE                } # INSCOPE
5104              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5105                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5106                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5107                                  token => $token);
5108    
5109                ## As if </caption>                ## As if </caption>
5110                ## have a table element in table scope                ## have a table element in table scope
# Line 4586  sub _tree_construction_main ($) { Line 5122  sub _tree_construction_main ($) {
5122                } # INSCOPE                } # INSCOPE
5123                unless (defined $i) {                unless (defined $i) {
5124                  !!!cp ('t186');                  !!!cp ('t186');
5125                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5126                                    text => 'caption', token => $token);
5127                  ## Ignore the token                  ## Ignore the token
5128                  !!!next-token;                  !!!next-token;
5129                  next B;                  next B;
# Line 4601  sub _tree_construction_main ($) { Line 5138  sub _tree_construction_main ($) {
5138                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5139                  !!!cp ('t188');                  !!!cp ('t188');
5140                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5141                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5142                                      ->manakai_local_name,                                      ->manakai_local_name,
5143                                  token => $token);                                  token => $token);
5144                } else {                } else {
# Line 4621  sub _tree_construction_main ($) { Line 5158  sub _tree_construction_main ($) {
5158                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5159                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5160                  !!!cp ('t190');                  !!!cp ('t190');
5161                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5162                                    text => $token->{tag_name}, token => $token);
5163                  ## Ignore the token                  ## Ignore the token
5164                  !!!next-token;                  !!!next-token;
5165                  next B;                  next B;
# Line 4635  sub _tree_construction_main ($) { Line 5173  sub _tree_construction_main ($) {
5173                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5174                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5175                !!!cp ('t192');                !!!cp ('t192');
5176                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5177                                  text => $token->{tag_name}, token => $token);
5178                ## Ignore the token                ## Ignore the token
5179                !!!next-token;                !!!next-token;
5180                next B;                next B;
# Line 4675  sub _tree_construction_main ($) { Line 5214  sub _tree_construction_main ($) {
5214            }            }
5215          }          }
5216    
5217              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5218    
5219              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5220              ## 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 5265  sub _tree_construction_main ($) {
5265          !!!next-token;          !!!next-token;
5266          next B;          next B;
5267        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5268              if ({          if ({
5269                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5270                   th => 1, td => 1,               th => 1, td => 1,
5271                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5272                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5273                  ## Clear back to table context              ## Clear back to table context
5274                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5275                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5276                    !!!cp ('t201');                !!!cp ('t201');
5277                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5278                  }              }
5279                                
5280                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5281                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5282                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5283                }            }
5284              
5285                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5286                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5287                    !!!cp ('t202');                !!!cp ('t202');
5288                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5289                  }              }
5290                                    
5291                  ## Clear back to table body context              ## Clear back to table body context
5292                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5293                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5294                    !!!cp ('t203');                !!!cp ('t203');
5295                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5296                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5297                  }              }
5298                                    
5299                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5300                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 4811  sub _tree_construction_main ($) { Line 5350  sub _tree_construction_main ($) {
5350                  unless (defined $i) {                  unless (defined $i) {
5351                    !!!cp ('t210');                    !!!cp ('t210');
5352  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5353                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5354                                      text => $token->{tag_name}, token => $token);
5355                    ## Ignore the token                    ## Ignore the token
5356                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5357                    !!!next-token;                    !!!next-token;
# Line 4855  sub _tree_construction_main ($) { Line 5395  sub _tree_construction_main ($) {
5395                  } # INSCOPE                  } # INSCOPE
5396                  unless (defined $i) {                  unless (defined $i) {
5397                    !!!cp ('t216');                    !!!cp ('t216');
5398  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5399                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5400                                      text => $token->{tag_name}, token => $token);
5401                    ## Ignore the token                    ## Ignore the token
5402                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5403                    !!!next-token;                    !!!next-token;
# Line 4931  sub _tree_construction_main ($) { Line 5472  sub _tree_construction_main ($) {
5472                }                }
5473              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5474                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5475                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5476                                    ->manakai_local_name,                                    ->manakai_local_name,
5477                                token => $token);                                token => $token);
5478    
# Line 4952  sub _tree_construction_main ($) { Line 5493  sub _tree_construction_main ($) {
5493                unless (defined $i) {                unless (defined $i) {
5494                  !!!cp ('t223');                  !!!cp ('t223');
5495  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5496                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5497                                    token => $token);
5498                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5499                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5500                  !!!next-token;                  !!!next-token;
5501                  next B;                  next B;
5502                }                }
5503                                
5504  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5505                ## generate implied end tags                ## generate implied end tags
5506                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5507                  !!!cp ('t224');                  !!!cp ('t224');
# Line 4970  sub _tree_construction_main ($) { Line 5512  sub _tree_construction_main ($) {
5512                  !!!cp ('t225');                  !!!cp ('t225');
5513                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5514                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5515                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5516                                      ->manakai_local_name,                                      ->manakai_local_name,
5517                                  token => $token);                                  token => $token);
5518                } else {                } else {
# Line 5011  sub _tree_construction_main ($) { Line 5553  sub _tree_construction_main ($) {
5553                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5554                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5555                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5556                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5557                                    text => $token->{tag_name}, token => $token);
5558    
5559                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5560    
# Line 5039  sub _tree_construction_main ($) { Line 5582  sub _tree_construction_main ($) {
5582            #            #
5583          }          }
5584    
5585          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5586                            token => $token);
5587    
5588          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5589          #          #
# Line 5061  sub _tree_construction_main ($) { Line 5605  sub _tree_construction_main ($) {
5605                } # INSCOPE                } # INSCOPE
5606                unless (defined $i) {                unless (defined $i) {
5607                  !!!cp ('t230');                  !!!cp ('t230');
5608                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5609                                    text => $token->{tag_name}, token => $token);
5610                  ## Ignore the token                  ## Ignore the token
5611                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5612                  !!!next-token;                  !!!next-token;
# Line 5102  sub _tree_construction_main ($) { Line 5647  sub _tree_construction_main ($) {
5647                  unless (defined $i) {                  unless (defined $i) {
5648                    !!!cp ('t235');                    !!!cp ('t235');
5649  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5650                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5651                                      text => $token->{type}, token => $token);
5652                    ## Ignore the token                    ## Ignore the token
5653                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5654                    !!!next-token;                    !!!next-token;
# Line 5138  sub _tree_construction_main ($) { Line 5684  sub _tree_construction_main ($) {
5684                  } # INSCOPE                  } # INSCOPE
5685                  unless (defined $i) {                  unless (defined $i) {
5686                    !!!cp ('t239');                    !!!cp ('t239');
5687                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5688                                      text => $token->{tag_name}, token => $token);
5689                    ## Ignore the token                    ## Ignore the token
5690                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5691                    !!!next-token;                    !!!next-token;
# Line 5184  sub _tree_construction_main ($) { Line 5731  sub _tree_construction_main ($) {
5731                } # INSCOPE                } # INSCOPE
5732                unless (defined $i) {                unless (defined $i) {
5733                  !!!cp ('t243');                  !!!cp ('t243');
5734                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5735                                    text => $token->{tag_name}, token => $token);
5736                  ## Ignore the token                  ## Ignore the token
5737                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5738                  !!!next-token;                  !!!next-token;
# Line 5218  sub _tree_construction_main ($) { Line 5766  sub _tree_construction_main ($) {
5766                  } # INSCOPE                  } # INSCOPE
5767                    unless (defined $i) {                    unless (defined $i) {
5768                      !!!cp ('t249');                      !!!cp ('t249');
5769                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5770                                        text => $token->{tag_name}, token => $token);
5771                      ## Ignore the token                      ## Ignore the token
5772                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5773                      !!!next-token;                      !!!next-token;
# Line 5241  sub _tree_construction_main ($) { Line 5790  sub _tree_construction_main ($) {
5790                  } # INSCOPE                  } # INSCOPE
5791                    unless (defined $i) {                    unless (defined $i) {
5792                      !!!cp ('t252');                      !!!cp ('t252');
5793                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5794                                        text => 'tr', token => $token);
5795                      ## Ignore the token                      ## Ignore the token
5796                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5797                      !!!next-token;                      !!!next-token;
# Line 5276  sub _tree_construction_main ($) { Line 5826  sub _tree_construction_main ($) {
5826                } # INSCOPE                } # INSCOPE
5827                unless (defined $i) {                unless (defined $i) {
5828                  !!!cp ('t256');                  !!!cp ('t256');
5829                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5830                                    text => $token->{tag_name}, token => $token);
5831                  ## Ignore the token                  ## Ignore the token
5832                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5833                  !!!next-token;                  !!!next-token;
# Line 5303  sub _tree_construction_main ($) { Line 5854  sub _tree_construction_main ($) {
5854                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5855                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5856            !!!cp ('t258');            !!!cp ('t258');
5857            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5858                              text => $token->{tag_name}, token => $token);
5859            ## Ignore the token            ## Ignore the token
5860            !!!nack ('t258.1');            !!!nack ('t258.1');
5861             !!!next-token;             !!!next-token;
5862            next B;            next B;
5863          } else {          } else {
5864            !!!cp ('t259');            !!!cp ('t259');
5865            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5866                              text => $token->{tag_name}, token => $token);
5867    
5868            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5869            #            #
# Line 5360  sub _tree_construction_main ($) { Line 5913  sub _tree_construction_main ($) {
5913              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5914                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5915                  !!!cp ('t264');                  !!!cp ('t264');
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                  !!!next-token;                  !!!next-token;
5920                  next B;                  next B;
# Line 5373  sub _tree_construction_main ($) { Line 5927  sub _tree_construction_main ($) {
5927                }                }
5928              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5929                !!!cp ('t266');                !!!cp ('t266');
5930                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
5931                                  text => 'col', token => $token);
5932                ## Ignore the token                ## Ignore the token
5933                !!!next-token;                !!!next-token;
5934                next B;                next B;
# Line 5403  sub _tree_construction_main ($) { Line 5958  sub _tree_construction_main ($) {
5958            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5959              !!!cp ('t269');              !!!cp ('t269');
5960  ## TODO: Wrong error type?  ## TODO: Wrong error type?
5961              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
5962                                text => 'colgroup', token => $token);
5963              ## Ignore the token              ## Ignore the token
5964              !!!nack ('t269.1');              !!!nack ('t269.1');
5965              !!!next-token;              !!!next-token;
# Line 5457  sub _tree_construction_main ($) { Line 6013  sub _tree_construction_main ($) {
6013            !!!nack ('t277.1');            !!!nack ('t277.1');
6014            !!!next-token;            !!!next-token;
6015            next B;            next B;
6016          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
6017                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
6018                     }->{$token->{tag_name}} or
6019                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
6020                    {                    {
6021                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5466  sub _tree_construction_main ($) { Line 6023  sub _tree_construction_main ($) {
6023                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6024                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6025            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6026            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6027                              token => $token);
6028            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6029            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6030            ## have an element in table scope            ## have an element in table scope
# Line 5484  sub _tree_construction_main ($) { Line 6042  sub _tree_construction_main ($) {
6042            } # INSCOPE            } # INSCOPE
6043            unless (defined $i) {            unless (defined $i) {
6044              !!!cp ('t280');              !!!cp ('t280');
6045              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6046                                text => 'select', token => $token);
6047              ## Ignore the token              ## Ignore the token
6048              !!!nack ('t280.1');              !!!nack ('t280.1');
6049              !!!next-token;              !!!next-token;
# Line 5508  sub _tree_construction_main ($) { Line 6067  sub _tree_construction_main ($) {
6067            }            }
6068          } else {          } else {
6069            !!!cp ('t282');            !!!cp ('t282');
6070            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6071                              text => $token->{tag_name}, token => $token);
6072            ## Ignore the token            ## Ignore the token
6073            !!!nack ('t282.1');            !!!nack ('t282.1');
6074            !!!next-token;            !!!next-token;
# Line 5526  sub _tree_construction_main ($) { Line 6086  sub _tree_construction_main ($) {
6086              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6087            } else {            } else {
6088              !!!cp ('t285');              !!!cp ('t285');
6089              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6090                                text => $token->{tag_name}, token => $token);
6091              ## Ignore the token              ## Ignore the token
6092            }            }
6093            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5538  sub _tree_construction_main ($) { Line 6099  sub _tree_construction_main ($) {
6099              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6100            } else {            } else {
6101              !!!cp ('t287');              !!!cp ('t287');
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              ## Ignore the token              ## Ignore the token
6105            }            }
6106            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5560  sub _tree_construction_main ($) { Line 6122  sub _tree_construction_main ($) {
6122            } # INSCOPE            } # INSCOPE
6123            unless (defined $i) {            unless (defined $i) {
6124              !!!cp ('t290');              !!!cp ('t290');
6125              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6126                                text => $token->{tag_name}, token => $token);
6127              ## Ignore the token              ## Ignore the token
6128              !!!nack ('t290.1');              !!!nack ('t290.1');
6129              !!!next-token;              !!!next-token;
# Line 5581  sub _tree_construction_main ($) { Line 6144  sub _tree_construction_main ($) {
6144                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6145                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6146  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6147            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6148                              text => $token->{tag_name}, token => $token);
6149                                
6150            ## have an element in table scope            ## have an element in table scope
6151            my $i;            my $i;
# Line 5622  sub _tree_construction_main ($) { Line 6186  sub _tree_construction_main ($) {
6186            unless (defined $i) {            unless (defined $i) {
6187              !!!cp ('t297');              !!!cp ('t297');
6188  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6189              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6190                                text => 'select', token => $token);
6191              ## Ignore the </select> token              ## Ignore the </select> token
6192              !!!nack ('t297.1');              !!!nack ('t297.1');
6193              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 5639  sub _tree_construction_main ($) { Line 6204  sub _tree_construction_main ($) {
6204            next B;            next B;
6205          } else {          } else {
6206            !!!cp ('t299');            !!!cp ('t299');
6207            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6208                              text => $token->{tag_name}, token => $token);
6209            ## Ignore the token            ## Ignore the token
6210            !!!nack ('t299.3');            !!!nack ('t299.3');
6211            !!!next-token;            !!!next-token;
# Line 5677  sub _tree_construction_main ($) { Line 6243  sub _tree_construction_main ($) {
6243                    
6244          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6245            !!!cp ('t301');            !!!cp ('t301');
6246            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6247    
6248            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6249          } else {          } else {
# Line 5685  sub _tree_construction_main ($) { Line 6251  sub _tree_construction_main ($) {
6251          }          }
6252                    
6253          ## "after body" insertion mode          ## "after body" insertion mode
6254          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6255    
6256          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6257          ## reprocess          ## reprocess
# Line 5693  sub _tree_construction_main ($) { Line 6259  sub _tree_construction_main ($) {
6259        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6260          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6261            !!!cp ('t303');            !!!cp ('t303');
6262            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6263                              text => $token->{tag_name}, token => $token);
6264                        
6265            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6266          } else {          } else {
# Line 5701  sub _tree_construction_main ($) { Line 6268  sub _tree_construction_main ($) {
6268          }          }
6269    
6270          ## "after body" insertion mode          ## "after body" insertion mode
6271          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6272                            text => $token->{tag_name}, token => $token);
6273    
6274          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6275          !!!ack-later;          !!!ack-later;
# Line 5710  sub _tree_construction_main ($) { Line 6278  sub _tree_construction_main ($) {
6278        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6279          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6280            !!!cp ('t305');            !!!cp ('t305');
6281            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6282                              text => $token->{tag_name}, token => $token);
6283                        
6284            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6285            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 5722  sub _tree_construction_main ($) { Line 6291  sub _tree_construction_main ($) {
6291          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6292            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6293              !!!cp ('t307');              !!!cp ('t307');
6294              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6295                                text => 'html', token => $token);
6296              ## Ignore the token              ## Ignore the token
6297              !!!next-token;              !!!next-token;
6298              next B;              next B;
# Line 5734  sub _tree_construction_main ($) { Line 6304  sub _tree_construction_main ($) {
6304            }            }
6305          } else {          } else {
6306            !!!cp ('t309');            !!!cp ('t309');
6307            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6308                              text => $token->{tag_name}, token => $token);
6309    
6310            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6311            ## reprocess            ## reprocess
# Line 5762  sub _tree_construction_main ($) { Line 6333  sub _tree_construction_main ($) {
6333          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6334            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6335              !!!cp ('t311');              !!!cp ('t311');
6336              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6337            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6338              !!!cp ('t312');              !!!cp ('t312');
6339              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6340            } else { # "after html frameset"            } else { # "after after frameset"
6341              !!!cp ('t313');              !!!cp ('t313');
6342              !!!parse-error (type => 'after html:#character', token => $token);              !!!parse-error (type => 'after html:#text', token => $token);
   
             $self->{insertion_mode} = AFTER_FRAMESET_IM;  
             ## Reprocess in the "after frameset" insertion mode.  
             !!!parse-error (type => 'after frameset:#character', token => $token);  
6343            }            }
6344                        
6345            ## Ignore the token.            ## Ignore the token.
# Line 5788  sub _tree_construction_main ($) { Line 6355  sub _tree_construction_main ($) {
6355                    
6356          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6357        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
         if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
           !!!cp ('t316');  
           !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t317');  
         }  
   
6358          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6359              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6360            !!!cp ('t318');            !!!cp ('t318');
# Line 5815  sub _tree_construction_main ($) { Line 6372  sub _tree_construction_main ($) {
6372            next B;            next B;
6373          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6374            !!!cp ('t320');            !!!cp ('t320');
6375            ## NOTE: As if in body.            ## NOTE: As if in head.
6376            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6377            next B;            next B;
6378    
6379              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6380              ## has no parse error.
6381          } else {          } else {
6382            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6383              !!!cp ('t321');              !!!cp ('t321');
6384              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6385            } else {                              text => $token->{tag_name}, token => $token);
6386              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6387              !!!cp ('t322');              !!!cp ('t322');
6388              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6389                                text => $token->{tag_name}, token => $token);
6390              } else { # "after after frameset"
6391                !!!cp ('t322.2');
6392                !!!parse-error (type => 'after after frameset',
6393                                text => $token->{tag_name}, token => $token);
6394            }            }
6395            ## Ignore the token            ## Ignore the token
6396            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 5832  sub _tree_construction_main ($) { Line 6398  sub _tree_construction_main ($) {
6398            next B;            next B;
6399          }          }
6400        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
         if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
           !!!cp ('t323');  
           !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t324');  
         }  
   
6401          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6402              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6403            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6404                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6405              !!!cp ('t325');              !!!cp ('t325');
6406              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6407                                text => $token->{tag_name}, token => $token);
6408              ## Ignore the token              ## Ignore the token
6409              !!!next-token;              !!!next-token;
6410            } else {            } else {
# Line 5873  sub _tree_construction_main ($) { Line 6430  sub _tree_construction_main ($) {
6430          } else {          } else {
6431            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6432              !!!cp ('t330');              !!!cp ('t330');
6433              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6434            } else {                              text => $token->{tag_name}, token => $token);
6435              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6436                !!!cp ('t330.1');
6437                !!!parse-error (type => 'after frameset:/',
6438                                text => $token->{tag_name}, token => $token);
6439              } else { # "after after html"
6440              !!!cp ('t331');              !!!cp ('t331');
6441              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6442                                text => $token->{tag_name}, token => $token);
6443            }            }
6444            ## Ignore the token            ## Ignore the token
6445            !!!next-token;            !!!next-token;
# Line 5930  sub _tree_construction_main ($) { Line 6493  sub _tree_construction_main ($) {
6493          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.
6494    
6495          unless ($self->{confident}) {          unless ($self->{confident}) {
6496            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) {
6497              !!!cp ('t335');              !!!cp ('t335');
6498                ## NOTE: Whether the encoding is supported or not is handled
6499                ## in the {change_encoding} callback.
6500              $self->{change_encoding}              $self->{change_encoding}
6501                  ->($self, $token->{attributes}->{charset}->{value}, $token);                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6502                            
# Line 5940  sub _tree_construction_main ($) { Line 6505  sub _tree_construction_main ($) {
6505                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
6506                                           ->{has_reference});                                           ->{has_reference});
6507            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
6508              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6509                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6510                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6511                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6512                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6513                !!!cp ('t336');                !!!cp ('t336');
6514                  ## NOTE: Whether the encoding is supported or not is handled
6515                  ## in the {change_encoding} callback.
6516                $self->{change_encoding}                $self->{change_encoding}
6517                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6518                $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 6547  sub _tree_construction_main ($) {
6547          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6548          next B;          next B;
6549        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6550          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6551                                
6552          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6553              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6101  sub _tree_construction_main ($) { Line 6667  sub _tree_construction_main ($) {
6667              if ($i != -1) {              if ($i != -1) {
6668                !!!cp ('t355');                !!!cp ('t355');
6669                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6670                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6671                                    ->manakai_local_name,                                    ->manakai_local_name,
6672                                token => $token);                                token => $token);
6673              } else {              } else {
# Line 6255  sub _tree_construction_main ($) { Line 6821  sub _tree_construction_main ($) {
6821                  xmp => 1,                  xmp => 1,
6822                  iframe => 1,                  iframe => 1,
6823                  noembed => 1,                  noembed => 1,
6824                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6825                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6826                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6827          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6277  sub _tree_construction_main ($) { Line 6843  sub _tree_construction_main ($) {
6843            !!!next-token;            !!!next-token;
6844            next B;            next B;
6845          } else {          } else {
6846              !!!ack ('t391.1');
6847    
6848            my $at = $token->{attributes};            my $at = $token->{attributes};
6849            my $form_attrs;            my $form_attrs;
6850            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6320  sub _tree_construction_main ($) { Line 6888  sub _tree_construction_main ($) {
6888                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6889                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6890                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6891            !!!back-token (@tokens);            !!!back-token (@tokens);
6892            !!!next-token;            !!!next-token;
6893            next B;            next B;
# Line 6368  sub _tree_construction_main ($) { Line 6935  sub _tree_construction_main ($) {
6935            ## Ignore the token            ## Ignore the token
6936          } else {          } else {
6937            !!!cp ('t398');            !!!cp ('t398');
6938            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
6939          }          }
6940          !!!next-token;          !!!next-token;
6941          next B;          next B;
6942          } elsif ($token->{tag_name} eq 'rt' or
6943                   $token->{tag_name} eq 'rp') {
6944            ## has a |ruby| element in scope
6945            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6946              my $node = $self->{open_elements}->[$_];
6947              if ($node->[1] & RUBY_EL) {
6948                !!!cp ('t398.1');
6949                ## generate implied end tags
6950                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
6951                  !!!cp ('t398.2');
6952                  pop @{$self->{open_elements}};
6953                }
6954                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
6955                  !!!cp ('t398.3');
6956                  !!!parse-error (type => 'not closed',
6957                                  text => $self->{open_elements}->[-1]->[0]
6958                                      ->manakai_local_name,
6959                                  token => $token);
6960                  pop @{$self->{open_elements}}
6961                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
6962                }
6963                last INSCOPE;
6964              } elsif ($node->[1] & SCOPING_EL) {
6965                !!!cp ('t398.4');
6966                last INSCOPE;
6967              }
6968            } # INSCOPE
6969    
6970            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6971    
6972            !!!nack ('t398.5');
6973            !!!next-token;
6974            redo B;
6975        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
6976                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6977          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6978    
6979            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
6980    
6981            ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6982    
6983            ## "adjust foreign attributes" - done in insert-element-f
6984                    
6985          !!!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);
6986                    
6987          if ($self->{self_closing}) {          if ($self->{self_closing}) {
6988            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
# Line 6398  sub _tree_construction_main ($) { Line 7004  sub _tree_construction_main ($) {
7004                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7005                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7006          !!!cp ('t401');          !!!cp ('t401');
7007          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
7008                            text => $token->{tag_name}, token => $token);
7009          ## Ignore the token          ## Ignore the token
7010          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
7011          !!!next-token;          !!!next-token;
# Line 6483  sub _tree_construction_main ($) { Line 7090  sub _tree_construction_main ($) {
7090            }            }
7091    
7092            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7093                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7094            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7095            !!!next-token;            !!!next-token;
7096            next B;            next B;
# Line 6493  sub _tree_construction_main ($) { Line 7100  sub _tree_construction_main ($) {
7100            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7101              !!!cp ('t403');              !!!cp ('t403');
7102              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7103                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7104                              token => $token);                              token => $token);
7105              last;              last;
7106            } else {            } else {
# Line 6513  sub _tree_construction_main ($) { Line 7120  sub _tree_construction_main ($) {
7120            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7121              !!!cp ('t406');              !!!cp ('t406');
7122              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7123                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7124                                  ->manakai_local_name,                                  ->manakai_local_name,
7125                              token => $token);                              token => $token);
7126            } else {            } else {
# Line 6524  sub _tree_construction_main ($) { Line 7131  sub _tree_construction_main ($) {
7131            next B;            next B;
7132          } else {          } else {
7133            !!!cp ('t408');            !!!cp ('t408');
7134            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7135                              text => $token->{tag_name}, token => $token);
7136            ## Ignore the token            ## Ignore the token
7137            !!!next-token;            !!!next-token;
7138            next B;            next B;
# Line 6552  sub _tree_construction_main ($) { Line 7160  sub _tree_construction_main ($) {
7160    
7161          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7162            !!!cp ('t413');            !!!cp ('t413');
7163            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7164                              text => $token->{tag_name}, token => $token);
7165              ## NOTE: Ignore the token.
7166          } else {          } else {
7167            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7168            while ({            while ({
7169                      ## END_TAG_OPTIONAL_EL
7170                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7171                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7172                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7173                    p => 1,                    p => 1,
7174                      rt => 1,
7175                      rp => 1,
7176                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7177              !!!cp ('t409');              !!!cp ('t409');
7178              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6570  sub _tree_construction_main ($) { Line 7183  sub _tree_construction_main ($) {
7183                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7184              !!!cp ('t412');              !!!cp ('t412');
7185              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7186                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7187                                  ->manakai_local_name,                                  ->manakai_local_name,
7188                              token => $token);                              token => $token);
7189            } else {            } else {
# Line 6607  sub _tree_construction_main ($) { Line 7220  sub _tree_construction_main ($) {
7220    
7221          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7222            !!!cp ('t421');            !!!cp ('t421');
7223            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7224                              text => $token->{tag_name}, token => $token);
7225              ## NOTE: Ignore the token.
7226          } else {          } else {
7227            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7228            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 7235  sub _tree_construction_main ($) {
7235                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7236              !!!cp ('t417.1');              !!!cp ('t417.1');
7237              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7238                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7239                                  ->manakai_local_name,                                  ->manakai_local_name,
7240                              token => $token);                              token => $token);
7241            } else {            } else {
# Line 6652  sub _tree_construction_main ($) { Line 7267  sub _tree_construction_main ($) {
7267    
7268          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7269            !!!cp ('t425.1');            !!!cp ('t425.1');
7270            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7271                              text => $token->{tag_name}, token => $token);
7272              ## NOTE: Ignore the token.
7273          } else {          } else {
7274            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7275            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 7281  sub _tree_construction_main ($) {
7281            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7282                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7283              !!!cp ('t425');              !!!cp ('t425');
7284              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7285                                text => $token->{tag_name}, token => $token);
7286            } else {            } else {
7287              !!!cp ('t426');              !!!cp ('t426');
7288            }            }
# Line 6695  sub _tree_construction_main ($) { Line 7313  sub _tree_construction_main ($) {
7313                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7314              !!!cp ('t412.1');              !!!cp ('t412.1');
7315              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7316                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7317                                  ->manakai_local_name,                                  ->manakai_local_name,
7318                              token => $token);                              token => $token);
7319            } else {            } else {
# Line 6705  sub _tree_construction_main ($) { Line 7323  sub _tree_construction_main ($) {
7323            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7324          } else {          } else {
7325            !!!cp ('t413.1');            !!!cp ('t413.1');
7326            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7327                              text => $token->{tag_name}, token => $token);
7328    
7329            !!!cp ('t415.1');            !!!cp ('t415.1');
7330            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 6728  sub _tree_construction_main ($) { Line 7347  sub _tree_construction_main ($) {
7347          next B;          next B;
7348        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7349          !!!cp ('t428');          !!!cp ('t428');
7350          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7351                            text => 'br', token => $token);
7352    
7353          ## As if <br>          ## As if <br>
7354          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 6753  sub _tree_construction_main ($) { Line 7373  sub _tree_construction_main ($) {
7373                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7374                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7375          !!!cp ('t429');          !!!cp ('t429');
7376          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7377                            text => $token->{tag_name}, token => $token);
7378          ## Ignore the token          ## Ignore the token
7379          !!!next-token;          !!!next-token;
7380          next B;          next B;
# Line 6772  sub _tree_construction_main ($) { Line 7393  sub _tree_construction_main ($) {
7393              ## generate implied end tags              ## generate implied end tags
7394              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7395                !!!cp ('t430');                !!!cp ('t430');
7396                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7397                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7398                  ## which seems wrong.
7399                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7400                  $node_i++;
7401              }              }
7402                    
7403              ## Step 2              ## Step 2
# Line 6782  sub _tree_construction_main ($) { Line 7406  sub _tree_construction_main ($) {
7406                !!!cp ('t431');                !!!cp ('t431');
7407                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7408                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7409                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7410                                    ->manakai_local_name,                                    ->manakai_local_name,
7411                                token => $token);                                token => $token);
7412              } else {              } else {
# Line 6790  sub _tree_construction_main ($) { Line 7414  sub _tree_construction_main ($) {
7414              }              }
7415                            
7416              ## Step 3              ## Step 3
7417              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7418    
7419              !!!next-token;              !!!next-token;
7420              last S2;              last S2;
# Line 6801  sub _tree_construction_main ($) { Line 7425  sub _tree_construction_main ($) {
7425                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7426                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7427                !!!cp ('t433');                !!!cp ('t433');
7428                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7429                                  text => $token->{tag_name}, token => $token);
7430                ## Ignore the token                ## Ignore the token
7431                !!!next-token;                !!!next-token;
7432                last S2;                last S2;
# Line 6847  sub _tree_construction_main ($) { Line 7472  sub _tree_construction_main ($) {
7472    ## TODO: script stuffs    ## TODO: script stuffs
7473  } # _tree_construct_main  } # _tree_construct_main
7474    
7475  sub set_inner_html ($$$) {  sub set_inner_html ($$$;$) {
7476    my $class = shift;    my $class = shift;
7477    my $node = shift;    my $node = shift;
7478    my $s = \$_[0];    my $s = \$_[0];
7479    my $onerror = $_[1];    my $onerror = $_[1];
7480      my $get_wrapper = $_[2] || sub ($) { return $_[0] };
7481    
7482    ## ISSUE: Should {confident} be true?    ## ISSUE: Should {confident} be true?
7483    
# Line 6870  sub set_inner_html ($$$) { Line 7496  sub set_inner_html ($$$) {
7496      }      }
7497    
7498      ## Step 3, 4, 5 # MUST      ## Step 3, 4, 5 # MUST
7499      $class->parse_string ($$s => $node, $onerror);      $class->parse_char_string ($$s => $node, $onerror, $get_wrapper);
7500    } elsif ($nt == 1) {    } elsif ($nt == 1) {
7501      ## TODO: If non-html element      ## TODO: If non-html element
7502    
7503      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
7504    
7505    ## TODO: Support for $get_wrapper
7506    
7507      ## Step 1 # MUST      ## Step 1 # MUST
7508      my $this_doc = $node->owner_document;      my $this_doc = $node->owner_document;
7509      my $doc = $this_doc->implementation->create_document;      my $doc = $this_doc->implementation->create_document;
# Line 6916  sub set_inner_html ($$$) { Line 7544  sub set_inner_html ($$$) {
7544          !!!cp ('i4');          !!!cp ('i4');
7545          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7546          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
7547          } elsif ($self->{next_char} <= 0x0008 or
7548                   (0x000E <= $self->{next_char} and
7549                    $self->{next_char} <= 0x001F) or
7550                   (0x007F <= $self->{next_char} and
7551                    $self->{next_char} <= 0x009F) or
7552                   (0xD800 <= $self->{next_char} and
7553                    $self->{next_char} <= 0xDFFF) or
7554                   (0xFDD0 <= $self->{next_char} and
7555                    $self->{next_char} <= 0xFDDF) or
7556                   {
7557                    0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
7558                    0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
7559                    0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
7560                    0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
7561                    0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
7562                    0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
7563                    0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
7564                    0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
7565                    0x10FFFE => 1, 0x10FFFF => 1,
7566                   }->{$self->{next_char}}) {
7567            !!!cp ('i4.1');
7568            if ($self->{next_char} < 0x10000) {
7569              !!!parse-error (type => 'control char',
7570                              text => (sprintf 'U+%04X', $self->{next_char}));
7571            } else {
7572              !!!parse-error (type => 'control char',
7573                              text => (sprintf 'U-%08X', $self->{next_char}));
7574            }
7575        }        }
7576      };      };
7577      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24