/[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.125 by wakaba, Sat Apr 12 10:41:31 2008 UTC revision 1.146 by wakaba, Sat May 24 14:19:55 2008 UTC
# Line 8  use Error qw(:try); Line 8  use Error qw(:try);
8  ## doc.write ('');  ## doc.write ('');
9  ## alert (doc.compatMode);  ## alert (doc.compatMode);
10    
11  ## TODO: Control charcters and noncharacters are not allowed (HTML5 revision 1263)  require IO::Handle;
12  ## TODO: 1252 parse error (revision 1264)  
13  ## TODO: 8859-11 = 874 (revision 1271)  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
14    my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;
15    my $SVG_NS = q<http://www.w3.org/2000/svg>;
16    my $XLINK_NS = q<http://www.w3.org/1999/xlink>;
17    my $XML_NS = q<http://www.w3.org/XML/1998/namespace>;
18    my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>;
19    
20  sub A_EL () { 0b1 }  sub A_EL () { 0b1 }
21  sub ADDRESS_EL () { 0b10 }  sub ADDRESS_EL () { 0b10 }
# Line 37  sub TABLE_ROW_EL () { 0b1000000000000000 Line 42  sub TABLE_ROW_EL () { 0b1000000000000000
42  sub TABLE_ROW_GROUP_EL () { 0b10000000000000000000000 }  sub TABLE_ROW_GROUP_EL () { 0b10000000000000000000000 }
43  sub MISC_SCOPING_EL () { 0b100000000000000000000000 }  sub MISC_SCOPING_EL () { 0b100000000000000000000000 }
44  sub MISC_SPECIAL_EL () { 0b1000000000000000000000000 }  sub MISC_SPECIAL_EL () { 0b1000000000000000000000000 }
45    sub FOREIGN_EL () { 0b10000000000000000000000000 }
46    sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
47    sub MML_AXML_EL () { 0b1000000000000000000000000000 }
48    
49  sub TABLE_ROWS_EL () {  sub TABLE_ROWS_EL () {
50    TABLE_EL |    TABLE_EL |
# Line 185  my $el_category = { Line 193  my $el_category = {
193    wbr => MISC_SPECIAL_EL,    wbr => MISC_SPECIAL_EL,
194  };  };
195    
196    my $el_category_f = {
197      $MML_NS => {
198        'annotation-xml' => MML_AXML_EL,
199        mi => FOREIGN_FLOW_CONTENT_EL,
200        mo => FOREIGN_FLOW_CONTENT_EL,
201        mn => FOREIGN_FLOW_CONTENT_EL,
202        ms => FOREIGN_FLOW_CONTENT_EL,
203        mtext => FOREIGN_FLOW_CONTENT_EL,
204      },
205      $SVG_NS => {
206        foreignObject => FOREIGN_FLOW_CONTENT_EL,
207        desc => FOREIGN_FLOW_CONTENT_EL,
208        title => FOREIGN_FLOW_CONTENT_EL,
209      },
210      ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.
211    };
212    
213    my $svg_attr_name = {
214      attributename => 'attributeName',
215      attributetype => 'attributeType',
216      basefrequency => 'baseFrequency',
217      baseprofile => 'baseProfile',
218      calcmode => 'calcMode',
219      clippathunits => 'clipPathUnits',
220      contentscripttype => 'contentScriptType',
221      contentstyletype => 'contentStyleType',
222      diffuseconstant => 'diffuseConstant',
223      edgemode => 'edgeMode',
224      externalresourcesrequired => 'externalResourcesRequired',
225      filterres => 'filterRes',
226      filterunits => 'filterUnits',
227      glyphref => 'glyphRef',
228      gradienttransform => 'gradientTransform',
229      gradientunits => 'gradientUnits',
230      kernelmatrix => 'kernelMatrix',
231      kernelunitlength => 'kernelUnitLength',
232      keypoints => 'keyPoints',
233      keysplines => 'keySplines',
234      keytimes => 'keyTimes',
235      lengthadjust => 'lengthAdjust',
236      limitingconeangle => 'limitingConeAngle',
237      markerheight => 'markerHeight',
238      markerunits => 'markerUnits',
239      markerwidth => 'markerWidth',
240      maskcontentunits => 'maskContentUnits',
241      maskunits => 'maskUnits',
242      numoctaves => 'numOctaves',
243      pathlength => 'pathLength',
244      patterncontentunits => 'patternContentUnits',
245      patterntransform => 'patternTransform',
246      patternunits => 'patternUnits',
247      pointsatx => 'pointsAtX',
248      pointsaty => 'pointsAtY',
249      pointsatz => 'pointsAtZ',
250      preservealpha => 'preserveAlpha',
251      preserveaspectratio => 'preserveAspectRatio',
252      primitiveunits => 'primitiveUnits',
253      refx => 'refX',
254      refy => 'refY',
255      repeatcount => 'repeatCount',
256      repeatdur => 'repeatDur',
257      requiredextensions => 'requiredExtensions',
258      requiredfeatures => 'requiredFeatures',
259      specularconstant => 'specularConstant',
260      specularexponent => 'specularExponent',
261      spreadmethod => 'spreadMethod',
262      startoffset => 'startOffset',
263      stddeviation => 'stdDeviation',
264      stitchtiles => 'stitchTiles',
265      surfacescale => 'surfaceScale',
266      systemlanguage => 'systemLanguage',
267      tablevalues => 'tableValues',
268      targetx => 'targetX',
269      targety => 'targetY',
270      textlength => 'textLength',
271      viewbox => 'viewBox',
272      viewtarget => 'viewTarget',
273      xchannelselector => 'xChannelSelector',
274      ychannelselector => 'yChannelSelector',
275      zoomandpan => 'zoomAndPan',
276    };
277    
278    my $foreign_attr_xname = {
279      'xlink:actuate' => [$XLINK_NS, ['xlink', 'actuate']],
280      'xlink:arcrole' => [$XLINK_NS, ['xlink', 'arcrole']],
281      'xlink:href' => [$XLINK_NS, ['xlink', 'href']],
282      'xlink:role' => [$XLINK_NS, ['xlink', 'role']],
283      'xlink:show' => [$XLINK_NS, ['xlink', 'show']],
284      'xlink:title' => [$XLINK_NS, ['xlink', 'title']],
285      'xlink:type' => [$XLINK_NS, ['xlink', 'type']],
286      'xml:base' => [$XML_NS, ['xml', 'base']],
287      'xml:lang' => [$XML_NS, ['xml', 'lang']],
288      'xml:space' => [$XML_NS, ['xml', 'space']],
289      'xmlns' => [$XMLNS_NS, [undef, 'xmlns']],
290      'xmlns:xlink' => [$XMLNS_NS, ['xmlns', 'xlink']],
291    };
292    
293    ## ISSUE: xmlns:xlink="non-xlink-ns" is not an error.
294    
295  my $c1_entity_char = {  my $c1_entity_char = {
296    0x80 => 0x20AC,    0x80 => 0x20AC,
297    0x81 => 0xFFFD,    0x81 => 0xFFFD,
# Line 221  my $c1_entity_char = { Line 328  my $c1_entity_char = {
328  }; # $c1_entity_char  }; # $c1_entity_char
329    
330  sub parse_byte_string ($$$$;$) {  sub parse_byte_string ($$$$;$) {
331      my $self = shift;
332      my $charset_name = shift;
333      open my $input, '<', ref $_[0] ? $_[0] : \($_[0]);
334      return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
335    } # parse_byte_string
336    
337    sub parse_byte_stream ($$$$;$) {
338    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
339    my $charset = shift;    my $charset_name = shift;
340    my $bytes_s = ref $_[0] ? $_[0] : \($_[0]);    my $byte_stream = $_[0];
   my $s;  
     
   if (defined $charset) {  
     require Encode; ## TODO: decode(utf8) don't delete BOM  
     $s = \ (Encode::decode ($charset, $$bytes_s));  
     $self->{input_encoding} = lc $charset; ## TODO: normalize name  
     $self->{confident} = 1;  
   } else {  
     ## TODO: Implement HTML5 detection algorithm  
     require Whatpm::Charset::UniversalCharDet;  
     $charset = Whatpm::Charset::UniversalCharDet->detect_byte_string  
         (substr ($$bytes_s, 0, 1024));  
     $charset ||= 'windows-1252';  
     $s = \ (Encode::decode ($charset, $$bytes_s));  
     $self->{input_encoding} = $charset;  
     $self->{confident} = 0;  
   }  
341    
342    $self->{change_encoding} = sub {    my $onerror = $_[2] || sub {
343      my $self = shift;      my (%opt) = @_;
344      my $charset = lc shift;      warn "Parse error ($opt{type})\n";
345      my $token = shift;    };
346      ## TODO: if $charset is supported    $self->{parse_error} = $onerror; # updated later by parse_char_string
347      ## TODO: normalize charset name  
348      ## HTML5 encoding sniffing algorithm
349      require Message::Charset::Info;
350      my $charset;
351      my $buffer;
352      my ($char_stream, $e_status);
353    
354      ## "Change the encoding" algorithm:    SNIFFING: {
355    
356      ## Step 1          ## Step 1
357      if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?      if (defined $charset_name) {
358        $charset = 'utf-8';        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
359    
360          ## ISSUE: Unsupported encoding is not ignored according to the spec.
361          ($char_stream, $e_status) = $charset->get_decode_handle
362              ($byte_stream, allow_error_reporting => 1,
363               allow_fallback => 1);
364          if ($char_stream) {
365            $self->{confident} = 1;
366            last SNIFFING;
367          } else {
368            ## TODO: unsupported error
369          }
370      }      }
371    
372      ## Step 2      ## Step 2
373      if (defined $self->{input_encoding} and      my $byte_buffer = '';
374          $self->{input_encoding} eq $charset) {      for (1..1024) {
375          my $char = $byte_stream->getc;
376          last unless defined $char;
377          $byte_buffer .= $char;
378        } ## TODO: timeout
379    
380        ## Step 3
381        if ($byte_buffer =~ /^\xFE\xFF/) {
382          $charset = Message::Charset::Info->get_by_iana_name ('utf-16be');
383          ($char_stream, $e_status) = $charset->get_decode_handle
384              ($byte_stream, allow_error_reporting => 1,
385               allow_fallback => 1, byte_buffer => \$byte_buffer);
386        $self->{confident} = 1;        $self->{confident} = 1;
387        return;        last SNIFFING;
388        } elsif ($byte_buffer =~ /^\xFF\xFE/) {
389          $charset = Message::Charset::Info->get_by_iana_name ('utf-16le');
390          ($char_stream, $e_status) = $charset->get_decode_handle
391              ($byte_stream, allow_error_reporting => 1,
392               allow_fallback => 1, byte_buffer => \$byte_buffer);
393          $self->{confident} = 1;
394          last SNIFFING;
395        } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
396          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
397          ($char_stream, $e_status) = $charset->get_decode_handle
398              ($byte_stream, allow_error_reporting => 1,
399               allow_fallback => 1, byte_buffer => \$byte_buffer);
400          $self->{confident} = 1;
401          last SNIFFING;
402      }      }
403    
404      !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.      ## Step 4
405          ':'.$charset, level => 'w', token => $token);      ## TODO: <meta charset>
406    
407      ## Step 3      ## Step 5
408      # if (can) {      ## TODO: from history
       ## change the encoding on the fly.  
       #$self->{confident} = 1;  
       #return;  
     # }  
409    
410      ## Step 4      ## Step 6
411      throw Whatpm::HTML::RestartParser (charset => $charset);      require Whatpm::Charset::UniversalCharDet;
412        $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
413            ($byte_buffer);
414        if (defined $charset_name) {
415          $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
416    
417          ## ISSUE: Unsupported encoding is not ignored according to the spec.
418          require Whatpm::Charset::DecodeHandle;
419          $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
420              ($byte_stream);
421          ($char_stream, $e_status) = $charset->get_decode_handle
422              ($buffer, allow_error_reporting => 1,
423               allow_fallback => 1, byte_buffer => \$byte_buffer);
424          if ($char_stream) {
425            $buffer->{buffer} = $byte_buffer;
426            !!!parse-error (type => 'sniffing:chardet', ## TODO: type name
427                            value => $charset_name,
428                            level => $self->{info_level},
429                            line => 1, column => 1);
430            $self->{confident} = 0;
431            last SNIFFING;
432          }
433        }
434    
435        ## Step 7: default
436        ## TODO: Make this configurable.
437        $charset = Message::Charset::Info->get_by_iana_name ('windows-1252');
438            ## NOTE: We choose |windows-1252| here, since |utf-8| should be
439            ## detectable in the step 6.
440        require Whatpm::Charset::DecodeHandle;
441        $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
442            ($byte_stream);
443        ($char_stream, $e_status)
444            = $charset->get_decode_handle ($buffer,
445                                           allow_error_reporting => 1,
446                                           allow_fallback => 1,
447                                           byte_buffer => \$byte_buffer);
448        $buffer->{buffer} = $byte_buffer;
449        !!!parse-error (type => 'sniffing:default', ## TODO: type name
450                        value => 'windows-1252',
451                        level => $self->{info_level},
452                        line => 1, column => 1);
453        $self->{confident} = 0;
454      } # SNIFFING
455    
456      $self->{input_encoding} = $charset->get_iana_name;
457      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
458        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name
459                        value => $self->{input_encoding},
460                        level => $self->{unsupported_level},
461                        line => 1, column => 1);
462      } elsif (not ($e_status &
463                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
464        !!!parse-error (type => 'chardecode:no error', ## TODO: type name
465                        value => $self->{input_encoding},
466                        level => $self->{unsupported_level},
467                        line => 1, column => 1);
468      }
469    
470      $self->{change_encoding} = sub {
471        my $self = shift;
472        $charset_name = shift;
473        my $token = shift;
474    
475        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
476        ($char_stream, $e_status) = $charset->get_decode_handle
477            ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
478             byte_buffer => \ $buffer->{buffer});
479        
480        if ($char_stream) { # if supported
481          ## "Change the encoding" algorithm:
482    
483          ## Step 1    
484          if ($charset->{iana_names}->{'utf-16'}) { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?
485            $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
486            ($char_stream, $e_status) = $charset->get_decode_handle
487                ($byte_stream,
488                 byte_buffer => \ $buffer->{buffer});
489          }
490          $charset_name = $charset->get_iana_name;
491          
492          ## Step 2
493          if (defined $self->{input_encoding} and
494              $self->{input_encoding} eq $charset_name) {
495            !!!parse-error (type => 'charset label:matching', ## TODO: type
496                            value => $charset_name,
497                            level => $self->{info_level});
498            $self->{confident} = 1;
499            return;
500          }
501    
502          !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.
503              ':'.$charset_name, level => 'w', token => $token);
504          
505          ## Step 3
506          # if (can) {
507            ## change the encoding on the fly.
508            #$self->{confident} = 1;
509            #return;
510          # }
511          
512          ## Step 4
513          throw Whatpm::HTML::RestartParser ();
514        }
515    }; # $self->{change_encoding}    }; # $self->{change_encoding}
516    
517      my $char_onerror = sub {
518        my (undef, $type, %opt) = @_;
519        !!!parse-error (%opt, type => $type,
520                        line => $self->{line}, column => $self->{column} + 1);
521        if ($opt{octets}) {
522          ${$opt{octets}} = "\x{FFFD}"; # relacement character
523        }
524      };
525      $char_stream->onerror ($char_onerror);
526    
527    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
528    my $return;    my $return;
529    try {    try {
530      $return = $self->parse_char_string ($s, @args);        $return = $self->parse_char_stream ($char_stream, @args);  
531    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
532      my $charset = shift->{charset};      ## NOTE: Invoked after {change_encoding}.
533      $s = \ (Encode::decode ($charset, $$bytes_s));      
534      $self->{input_encoding} = $charset; ## TODO: normalize      $self->{input_encoding} = $charset->get_iana_name;
535        if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
536          !!!parse-error (type => 'chardecode:fallback', ## TODO: type name
537                          value => $self->{input_encoding},
538                          level => $self->{unsupported_level},
539                          line => 1, column => 1);
540        } elsif (not ($e_status &
541                      Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
542          !!!parse-error (type => 'chardecode:no error', ## TODO: type name
543                          value => $self->{input_encoding},
544                          level => $self->{unsupported_level},
545                          line => 1, column => 1);
546        }
547      $self->{confident} = 1;      $self->{confident} = 1;
548      $return = $self->parse_char_string ($s, @args);      $char_stream->onerror ($char_onerror);
549        $return = $self->parse_char_stream ($char_stream, @args);
550    };    };
551    return $return;    return $return;
552  } # parse_byte_string  } # parse_byte_stream
553    
554  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM
555  ## and the HTML layer MUST ignore it.  However, we does strip BOM in  ## and the HTML layer MUST ignore it.  However, we does strip BOM in
# Line 300  sub parse_byte_string ($$$$;$) { Line 560  sub parse_byte_string ($$$$;$) {
560  ## such as |parse_byte_string| in this module, must ensure that it does  ## such as |parse_byte_string| in this module, must ensure that it does
561  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
562    
563  *parse_char_string = \&parse_string;  sub parse_char_string ($$$;$) {
564      my $self = shift;
565      require utf8;
566      my $s = ref $_[0] ? $_[0] : \($_[0]);
567      open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
568      return $self->parse_char_stream ($input, @_[1..$#_]);
569    } # parse_char_string
570    *parse_string = \&parse_char_string;
571    
572  sub parse_string ($$$;$) {  sub parse_char_stream ($$$;$) {
573    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
574    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $input = $_[0];
575    $self->{document} = $_[1];    $self->{document} = $_[1];
576    @{$self->{document}->child_nodes} = ();    @{$self->{document}->child_nodes} = ();
577    
# Line 323  sub parse_string ($$$;$) { Line 590  sub parse_string ($$$;$) {
590      pop @{$self->{prev_char}};      pop @{$self->{prev_char}};
591      unshift @{$self->{prev_char}}, $self->{next_char};      unshift @{$self->{prev_char}}, $self->{next_char};
592    
593      $self->{next_char} = -1 and return if $i >= length $$s;      my $char;
594      $self->{next_char} = ord substr $$s, $i++, 1;      if (defined $self->{next_next_char}) {
595          $char = $self->{next_next_char};
596          delete $self->{next_next_char};
597        } else {
598          $char = $input->getc;
599        }
600        $self->{next_char} = -1 and return unless defined $char;
601        $self->{next_char} = ord $char;
602    
603      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
604          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
605      $self->{column}++;      $self->{column}++;
606            
607      if ($self->{next_char} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
608          !!!cp ('j1');
609        $self->{line}++;        $self->{line}++;
610        $self->{column} = 0;        $self->{column} = 0;
611      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
612        $i++ if substr ($$s, $i, 1) eq "\x0A";        !!!cp ('j2');
613          my $next = $input->getc;
614          if (defined $next and $next ne "\x0A") {
615            $self->{next_next_char} = $next;
616          }
617        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
618        $self->{line}++;        $self->{line}++;
619        $self->{column} = 0;        $self->{column} = 0;
620      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
621          !!!cp ('j3');
622        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
623      } elsif ($self->{next_char} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
624          !!!cp ('j4');
625        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
626        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
627        } elsif ($self->{next_char} <= 0x0008 or
628                 (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or
629                 (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or
630                 (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or
631                 (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or
632                 {
633                  0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
634                  0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
635                  0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
636                  0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
637                  0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
638                  0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
639                  0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
640                  0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
641                  0x10FFFE => 1, 0x10FFFF => 1,
642                 }->{$self->{next_char}}) {
643          !!!cp ('j5');
644          !!!parse-error (type => 'control char', level => $self->{must_level});
645    ## TODO: error type documentation
646      }      }
647    };    };
648    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 366  sub parse_string ($$$;$) { Line 666  sub parse_string ($$$;$) {
666    delete $self->{parse_error}; # remove loop    delete $self->{parse_error}; # remove loop
667    
668    return $self->{document};    return $self->{document};
669  } # parse_string  } # parse_char_stream
670    
671  sub new ($) {  sub new ($) {
672    my $class = shift;    my $class = shift;
673    my $self = bless {}, $class;    my $self = bless {
674        must_level => 'm',
675        should_level => 's',
676        good_level => 'w',
677        warn_level => 'w',
678        info_level => 'i',
679        unsupported_level => 'u',
680      }, $class;
681    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
682      $self->{next_char} = -1;      $self->{next_char} = -1;
683    };    };
# Line 433  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT Line 740  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STAT
740  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
741  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
742  sub SELF_CLOSING_START_TAG_STATE () { 34 }  sub SELF_CLOSING_START_TAG_STATE () { 34 }
743    sub CDATA_BLOCK_STATE () { 35 }
744    
745  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
746  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 450  sub ROW_IMS ()        { 0b10000000 } Line 758  sub ROW_IMS ()        { 0b10000000 }
758  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
759  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
760  sub SELECT_IMS ()     { 0b10000000000 }  sub SELECT_IMS ()     { 0b10000000000 }
761    sub IN_FOREIGN_CONTENT_IM () { 0b100000000000 }
762        ## NOTE: "in foreign content" insertion mode is special; it is combined
763        ## with the secondary insertion mode.  In this parser, they are stored
764        ## together in the bit-or'ed form.
765    
766  ## NOTE: "initial" and "before html" insertion modes have no constants.  ## NOTE: "initial" and "before html" insertion modes have no constants.
767    
# Line 730  sub _get_next_token ($) { Line 1042  sub _get_next_token ($) {
1042            redo A;            redo A;
1043          } else {          } else {
1044            !!!cp (23);            !!!cp (23);
1045            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago',
1046                              line => $self->{line_prev},
1047                              column => $self->{column_prev});
1048            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1049            ## reconsume            ## reconsume
1050    
# Line 1507  sub _get_next_token ($) { Line 1821  sub _get_next_token ($) {
1821          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1822          !!!next-input-character;          !!!next-input-character;
1823          redo A;          redo A;
1824          } elsif ($self->{next_char} == -1) {
1825            !!!parse-error (type => 'unclosed tag');
1826            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1827              !!!cp (122.3);
1828              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1829            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1830              if ($self->{current_token}->{attributes}) {
1831                !!!cp (122.1);
1832                !!!parse-error (type => 'end tag attribute');
1833              } else {
1834                ## NOTE: This state should never be reached.
1835                !!!cp (122.2);
1836              }
1837            } else {
1838              die "$0: $self->{current_token}->{type}: Unknown token type";
1839            }
1840            $self->{state} = DATA_STATE;
1841            ## Reconsume.
1842            !!!emit ($self->{current_token}); # start tag or end tag
1843            redo A;
1844        } else {        } else {
1845          !!!cp ('124.1');          !!!cp ('124.1');
1846          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1539  sub _get_next_token ($) { Line 1873  sub _get_next_token ($) {
1873          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1874    
1875          redo A;          redo A;
1876          } elsif ($self->{next_char} == -1) {
1877            !!!parse-error (type => 'unclosed tag');
1878            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1879              !!!cp (124.7);
1880              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1881            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1882              if ($self->{current_token}->{attributes}) {
1883                !!!cp (124.5);
1884                !!!parse-error (type => 'end tag attribute');
1885              } else {
1886                ## NOTE: This state should never be reached.
1887                !!!cp (124.6);
1888              }
1889            } else {
1890              die "$0: $self->{current_token}->{type}: Unknown token type";
1891            }
1892            $self->{state} = DATA_STATE;
1893            ## Reconsume.
1894            !!!emit ($self->{current_token}); # start tag or end tag
1895            redo A;
1896        } else {        } else {
1897          !!!cp ('124.4');          !!!cp ('124.4');
1898          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 1654  sub _get_next_token ($) { Line 2008  sub _get_next_token ($) {
2008          } else {          } else {
2009            !!!cp (135);            !!!cp (135);
2010          }          }
2011          } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
2012                   $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
2013                   $self->{next_char} == 0x005B) { # [
2014            !!!next-input-character;
2015            push @next_char, $self->{next_char};
2016            if ($self->{next_char} == 0x0043) { # C
2017              !!!next-input-character;
2018              push @next_char, $self->{next_char};
2019              if ($self->{next_char} == 0x0044) { # D
2020                !!!next-input-character;
2021                push @next_char, $self->{next_char};
2022                if ($self->{next_char} == 0x0041) { # A
2023                  !!!next-input-character;
2024                  push @next_char, $self->{next_char};
2025                  if ($self->{next_char} == 0x0054) { # T
2026                    !!!next-input-character;
2027                    push @next_char, $self->{next_char};
2028                    if ($self->{next_char} == 0x0041) { # A
2029                      !!!next-input-character;
2030                      push @next_char, $self->{next_char};
2031                      if ($self->{next_char} == 0x005B) { # [
2032                        !!!cp (135.1);
2033                        $self->{state} = CDATA_BLOCK_STATE;
2034                        !!!next-input-character;
2035                        redo A;
2036                      } else {
2037                        !!!cp (135.2);
2038                      }
2039                    } else {
2040                      !!!cp (135.3);
2041                    }
2042                  } else {
2043                    !!!cp (135.4);                
2044                  }
2045                } else {
2046                  !!!cp (135.5);
2047                }
2048              } else {
2049                !!!cp (135.6);
2050              }
2051            } else {
2052              !!!cp (135.7);
2053            }
2054        } else {        } else {
2055          !!!cp (136);          !!!cp (136);
2056        }        }
# Line 2336  sub _get_next_token ($) { Line 2733  sub _get_next_token ($) {
2733          redo A;          redo A;
2734        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2735          !!!cp (217);          !!!cp (217);
         !!!parse-error (type => 'unclosed DOCTYPE');  
2736    
2737          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2738          ## reconsume          ## reconsume
# Line 2378  sub _get_next_token ($) { Line 2774  sub _get_next_token ($) {
2774          !!!next-input-character;          !!!next-input-character;
2775          redo A;          redo A;
2776        }        }
2777        } elsif ($self->{state} == CDATA_BLOCK_STATE) {
2778          my $s = '';
2779          
2780          my ($l, $c) = ($self->{line}, $self->{column});
2781    
2782          CS: while ($self->{next_char} != -1) {
2783            if ($self->{next_char} == 0x005D) { # ]
2784              !!!next-input-character;
2785              if ($self->{next_char} == 0x005D) { # ]
2786                !!!next-input-character;
2787                MDC: {
2788                  if ($self->{next_char} == 0x003E) { # >
2789                    !!!cp (221.1);
2790                    !!!next-input-character;
2791                    last CS;
2792                  } elsif ($self->{next_char} == 0x005D) { # ]
2793                    !!!cp (221.2);
2794                    $s .= ']';
2795                    !!!next-input-character;
2796                    redo MDC;
2797                  } else {
2798                    !!!cp (221.3);
2799                    $s .= ']]';
2800                    #
2801                  }
2802                } # MDC
2803              } else {
2804                !!!cp (221.4);
2805                $s .= ']';
2806                #
2807              }
2808            } else {
2809              !!!cp (221.5);
2810              #
2811            }
2812            $s .= chr $self->{next_char};
2813            !!!next-input-character;
2814          } # CS
2815    
2816          $self->{state} = DATA_STATE;
2817          ## next-input-character done or EOF, which is reconsumed.
2818    
2819          if (length $s) {
2820            !!!cp (221.6);
2821            !!!emit ({type => CHARACTER_TOKEN, data => $s,
2822                      line => $l, column => $c});
2823          } else {
2824            !!!cp (221.7);
2825          }
2826    
2827          redo A;
2828    
2829          ## ISSUE: "text tokens" in spec.
2830          ## TODO: Streaming support
2831      } else {      } else {
2832        die "$0: $self->{state}: Unknown state";        die "$0: $self->{state}: Unknown state";
2833      }      }
# Line 2528  sub _tokenize_attempt_to_consume_an_enti Line 2978  sub _tokenize_attempt_to_consume_an_enti
2978      require Whatpm::_NamedEntityList;      require Whatpm::_NamedEntityList;
2979      our $EntityChar;      our $EntityChar;
2980    
2981      while (length $entity_name < 10 and      while (length $entity_name < 30 and
2982             ## NOTE: Some number greater than the maximum length of entity name             ## NOTE: Some number greater than the maximum length of entity name
2983             ((0x0041 <= $self->{next_char} and # a             ((0x0041 <= $self->{next_char} and # a
2984               $self->{next_char} <= 0x005A) or # x               $self->{next_char} <= 0x005A) or # x
# Line 2686  sub _tree_construction_initial ($) { Line 3136  sub _tree_construction_initial ($) {
3136        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3137          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3138          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3139          if ({          my $prefix = [
3140            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3141            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3142            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3143            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3144            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3145            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3146            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3147            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3148            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3149            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3150            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3151            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3152            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3153            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3154            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3155            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3156            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3157            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3158            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3159            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3160            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3161            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3162            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3163            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3164            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3165            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3166            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3167            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3168            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3169            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3170            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3171            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3172            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3173            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3174            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3175            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3176            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3177            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3178            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3179            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3180            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3181            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3182            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3183            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3184            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3185            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3186            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3187            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3188            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3189            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3190            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3191            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3192            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3193            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3194            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3195            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3196            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3197            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3198            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3199            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3200            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3201            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3202            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3203            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3204            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3205            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3206            "-//W3O//DTD W3 HTML 3.0//EN//" => 1,              $pubid eq "HTML") {
           "-//W3O//DTD W3 HTML STRICT 3.0//EN//" => 1,  
           "-//WEBTECHS//DTD MOZILLA HTML 2.0//EN" => 1,  
           "-//WEBTECHS//DTD MOZILLA HTML//EN" => 1,  
           "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,  
           "HTML" => 1,  
         }->{$pubid}) {  
3207            !!!cp ('t5');            !!!cp ('t5');
3208            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3209          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3210                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3211            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3212              !!!cp ('t6');              !!!cp ('t6');
3213              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 2771  sub _tree_construction_initial ($) { Line 3215  sub _tree_construction_initial ($) {
3215              !!!cp ('t7');              !!!cp ('t7');
3216              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3217            }            }
3218          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3219                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3220            !!!cp ('t8');            !!!cp ('t8');
3221            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3222          } else {          } else {
# Line 2785  sub _tree_construction_initial ($) { Line 3229  sub _tree_construction_initial ($) {
3229          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3230          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3231          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {          if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {
3232            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3233              ## marked as quirks.
3234            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3235            !!!cp ('t11');            !!!cp ('t11');
3236          } else {          } else {
# Line 2889  sub _tree_construction_root_element ($) Line 3334  sub _tree_construction_root_element ($)
3334        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
3335          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
3336            my $root_element;            my $root_element;
3337            !!!create-element ($root_element, $token->{tag_name}, $token->{attributes}, $token);            !!!create-element ($root_element, $HTML_NS, $token->{tag_name}, $token->{attributes}, $token);
3338            $self->{document}->append_child ($root_element);            $self->{document}->append_child ($root_element);
3339            push @{$self->{open_elements}},            push @{$self->{open_elements}},
3340                [$root_element, $el_category->{html}];                [$root_element, $el_category->{html}];
# Line 2925  sub _tree_construction_root_element ($) Line 3370  sub _tree_construction_root_element ($)
3370          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
3371        }        }
3372    
3373      my $root_element; !!!create-element ($root_element, 'html',, $token);      my $root_element;
3374        !!!create-element ($root_element, $HTML_NS, 'html',, $token);
3375      $self->{document}->append_child ($root_element);      $self->{document}->append_child ($root_element);
3376      push @{$self->{open_elements}}, [$root_element, $el_category->{html}];      push @{$self->{open_elements}}, [$root_element, $el_category->{html}];
3377    
# Line 2956  sub _reset_insertion_mode ($) { Line 3402  sub _reset_insertion_mode ($) {
3402        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3403          $last = 1;          $last = 1;
3404          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3405            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3406              !!!cp ('t27');            $node = $self->{inner_html_node};
3407              #          } else {
3408            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3409          }          }
3410        }        }
3411              
3412        ## Step 4..13        ## Step 4..14
3413        my $new_mode = {        my $new_mode;
3414          if ($node->[1] & FOREIGN_EL) {
3415            !!!cp ('t28.1');
3416            ## NOTE: Strictly spaking, the line below only applies to MathML and
3417            ## SVG elements.  Currently the HTML syntax supports only MathML and
3418            ## SVG elements as foreigners.
3419            $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;
3420            ## ISSUE: What is set as the secondary insertion mode?
3421          } elsif ($node->[1] & TABLE_CELL_EL) {
3422            if ($last) {
3423              !!!cp ('t28.2');
3424              #
3425            } else {
3426              !!!cp ('t28.3');
3427              $new_mode = IN_CELL_IM;
3428            }
3429          } else {
3430            !!!cp ('t28.4');
3431            $new_mode = {
3432                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3433                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3434                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3435                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3436                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3437                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 2984  sub _reset_insertion_mode ($) { Line 3443  sub _reset_insertion_mode ($) {
3443                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3444                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3445                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3446                       ## TODO: Foreign namespace case OK?        }
3447        $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3448                
3449        ## Step 14        ## Step 15
3450        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
3451          unless (defined $self->{head_element}) {          unless (defined $self->{head_element}) {
3452            !!!cp ('t29');            !!!cp ('t29');
# Line 3002  sub _reset_insertion_mode ($) { Line 3461  sub _reset_insertion_mode ($) {
3461          !!!cp ('t31');          !!!cp ('t31');
3462        }        }
3463                
3464        ## Step 15        ## Step 16
3465        $self->{insertion_mode} = IN_BODY_IM and return if $last;        $self->{insertion_mode} = IN_BODY_IM and return if $last;
3466                
3467        ## Step 16        ## Step 17
3468        $i--;        $i--;
3469        $node = $self->{open_elements}->[$i];        $node = $self->{open_elements}->[$i];
3470                
3471        ## Step 17        ## Step 18
3472        redo S3;        redo S3;
3473      } # S3      } # S3
3474    
# Line 3121  sub _tree_construction_main ($) { Line 3580  sub _tree_construction_main ($) {
3580      ## Step 1      ## Step 1
3581      my $start_tag_name = $token->{tag_name};      my $start_tag_name = $token->{tag_name};
3582      my $el;      my $el;
3583      !!!create-element ($el, $start_tag_name, $token->{attributes}, $token);      !!!create-element ($el, $HTML_NS, $start_tag_name, $token->{attributes}, $token);
3584    
3585      ## Step 2      ## Step 2
3586      $insert->($el);      $insert->($el);
# Line 3172  sub _tree_construction_main ($) { Line 3631  sub _tree_construction_main ($) {
3631    
3632    my $script_start_tag = sub () {    my $script_start_tag = sub () {
3633      my $script_el;      my $script_el;
3634      !!!create-element ($script_el, 'script', $token->{attributes}, $token);      !!!create-element ($script_el, $HTML_NS, 'script', $token->{attributes}, $token);
3635      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
3636    
3637      $self->{content_model} = CDATA_CONTENT_MODEL;      $self->{content_model} = CDATA_CONTENT_MODEL;
# Line 3495  sub _tree_construction_main ($) { Line 3954  sub _tree_construction_main ($) {
3954      }      }
3955    }; # $insert_to_foster    }; # $insert_to_foster
3956    
3957    B: {    B: while (1) {
3958      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3959        !!!cp ('t73');        !!!cp ('t73');
3960        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);
3961        ## Ignore the token        ## Ignore the token
3962        ## Stay in the phase        ## Stay in the phase
3963        !!!next-token;        !!!next-token;
3964        redo B;        next B;
3965      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3966               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3967        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
# Line 3530  sub _tree_construction_main ($) { Line 3989  sub _tree_construction_main ($) {
3989        }        }
3990        !!!nack ('t84.1');        !!!nack ('t84.1');
3991        !!!next-token;        !!!next-token;
3992        redo B;        next B;
3993      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
3994        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
3995        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
# Line 3544  sub _tree_construction_main ($) { Line 4003  sub _tree_construction_main ($) {
4003          $self->{open_elements}->[-1]->[0]->append_child ($comment);          $self->{open_elements}->[-1]->[0]->append_child ($comment);
4004        }        }
4005        !!!next-token;        !!!next-token;
4006        redo B;        next B;
4007      } elsif ($self->{insertion_mode} & HEAD_IMS) {      } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM) {
4008          if ($token->{type} == CHARACTER_TOKEN) {
4009            !!!cp ('t87.1');
4010            $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4011            !!!next-token;
4012            next B;
4013          } elsif ($token->{type} == START_TAG_TOKEN) {
4014            if ((not {mglyph => 1, malignmark => 1}->{$token->{tag_name}} and
4015                 $self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL) or
4016                not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or
4017                ($token->{tag_name} eq 'svg' and
4018                 $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {
4019              ## NOTE: "using the rules for secondary insertion mode"then"continue"
4020              !!!cp ('t87.2');
4021              #
4022            } elsif ({
4023                      b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4024                      center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4025                      em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4026                      h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4027                      img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4028                      nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4029                      small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4030                      sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4031                     }->{$token->{tag_name}}) {
4032              !!!cp ('t87.2');
4033              !!!parse-error (type => 'not closed',
4034                              value => $self->{open_elements}->[-1]->[0]
4035                                  ->manakai_local_name,
4036                              token => $token);
4037    
4038              pop @{$self->{open_elements}}
4039                  while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4040    
4041              $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4042              ## Reprocess.
4043              next B;
4044            } else {
4045              my $nsuri = $self->{open_elements}->[-1]->[0]->namespace_uri;
4046              my $tag_name = $token->{tag_name};
4047              if ($nsuri eq $SVG_NS) {
4048                $tag_name = {
4049                   altglyph => 'altGlyph',
4050                   altglyphdef => 'altGlyphDef',
4051                   altglyphitem => 'altGlyphItem',
4052                   animatecolor => 'animateColor',
4053                   animatemotion => 'animateMotion',
4054                   animatetransform => 'animateTransform',
4055                   clippath => 'clipPath',
4056                   feblend => 'feBlend',
4057                   fecolormatrix => 'feColorMatrix',
4058                   fecomponenttransfer => 'feComponentTransfer',
4059                   fecomposite => 'feComposite',
4060                   feconvolvematrix => 'feConvolveMatrix',
4061                   fediffuselighting => 'feDiffuseLighting',
4062                   fedisplacementmap => 'feDisplacementMap',
4063                   fedistantlight => 'feDistantLight',
4064                   feflood => 'feFlood',
4065                   fefunca => 'feFuncA',
4066                   fefuncb => 'feFuncB',
4067                   fefuncg => 'feFuncG',
4068                   fefuncr => 'feFuncR',
4069                   fegaussianblur => 'feGaussianBlur',
4070                   feimage => 'feImage',
4071                   femerge => 'feMerge',
4072                   femergenode => 'feMergeNode',
4073                   femorphology => 'feMorphology',
4074                   feoffset => 'feOffset',
4075                   fepointlight => 'fePointLight',
4076                   fespecularlighting => 'feSpecularLighting',
4077                   fespotlight => 'feSpotLight',
4078                   fetile => 'feTile',
4079                   feturbulence => 'feTurbulence',
4080                   foreignobject => 'foreignObject',
4081                   glyphref => 'glyphRef',
4082                   lineargradient => 'linearGradient',
4083                   radialgradient => 'radialGradient',
4084                   #solidcolor => 'solidColor', ## NOTE: Commented in spec (SVG1.2)
4085                   textpath => 'textPath',  
4086                }->{$tag_name} || $tag_name;
4087              }
4088    
4089              ## "adjust SVG attributes" (SVG only) - done in insert-element-f
4090    
4091              ## "adjust foreign attributes" - done in insert-element-f
4092    
4093              !!!insert-element-f ($nsuri, $tag_name, $token->{attributes}, $token);
4094    
4095              if ($self->{self_closing}) {
4096                pop @{$self->{open_elements}};
4097                !!!ack ('t87.3');
4098              } else {
4099                !!!cp ('t87.4');
4100              }
4101    
4102              !!!next-token;
4103              next B;
4104            }
4105          } elsif ($token->{type} == END_TAG_TOKEN) {
4106            ## NOTE: "using the rules for secondary insertion mode" then "continue"
4107            !!!cp ('t87.5');
4108            #
4109          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4110            !!!cp ('t87.6');
4111            !!!parse-error (type => 'not closed',
4112                            value => $self->{open_elements}->[-1]->[0]
4113                                ->manakai_local_name,
4114                            token => $token);
4115    
4116            pop @{$self->{open_elements}}
4117                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4118    
4119            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4120            ## Reprocess.
4121            next B;
4122          } else {
4123            die "$0: $token->{type}: Unknown token type";        
4124          }
4125        }
4126    
4127        if ($self->{insertion_mode} & HEAD_IMS) {
4128        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4129          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
4130            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
# Line 3555  sub _tree_construction_main ($) { Line 4134  sub _tree_construction_main ($) {
4134              !!!cp ('t88.1');              !!!cp ('t88.1');
4135              ## Ignore the token.              ## Ignore the token.
4136              !!!next-token;              !!!next-token;
4137              redo B;              next B;
4138            }            }
4139            unless (length $token->{data}) {            unless (length $token->{data}) {
4140              !!!cp ('t88');              !!!cp ('t88');
4141              !!!next-token;              !!!next-token;
4142              redo B;              next B;
4143            }            }
4144          }          }
4145    
4146          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4147            !!!cp ('t89');            !!!cp ('t89');
4148            ## As if <head>            ## As if <head>
4149            !!!create-element ($self->{head_element}, 'head',, $token);            !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4150            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4151            push @{$self->{open_elements}},            push @{$self->{open_elements}},
4152                [$self->{head_element}, $el_category->{head}];                [$self->{head_element}, $el_category->{head}];
# Line 3601  sub _tree_construction_main ($) { Line 4180  sub _tree_construction_main ($) {
4180          !!!insert-element ('body',, $token);          !!!insert-element ('body',, $token);
4181          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
4182          ## reprocess          ## reprocess
4183          redo B;          next B;
4184        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4185          if ($token->{tag_name} eq 'head') {          if ($token->{tag_name} eq 'head') {
4186            if ($self->{insertion_mode} == BEFORE_HEAD_IM) {            if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4187              !!!cp ('t93');              !!!cp ('t93');
4188              !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes}, $token);              !!!create-element ($self->{head_element}, $HTML_NS, $token->{tag_name}, $token->{attributes}, $token);
4189              $self->{open_elements}->[-1]->[0]->append_child              $self->{open_elements}->[-1]->[0]->append_child
4190                  ($self->{head_element});                  ($self->{head_element});
4191              push @{$self->{open_elements}},              push @{$self->{open_elements}},
# Line 3614  sub _tree_construction_main ($) { Line 4193  sub _tree_construction_main ($) {
4193              $self->{insertion_mode} = IN_HEAD_IM;              $self->{insertion_mode} = IN_HEAD_IM;
4194              !!!nack ('t93.1');              !!!nack ('t93.1');
4195              !!!next-token;              !!!next-token;
4196              redo B;              next B;
4197            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4198              !!!cp ('t94');              !!!cp ('t93.2');
4199              #              !!!parse-error (type => 'after head:head', token => $token); ## TODO: error type
4200                ## Ignore the token
4201                !!!nack ('t93.3');
4202                !!!next-token;
4203                next B;
4204            } else {            } else {
4205              !!!cp ('t95');              !!!cp ('t95');
4206              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript
4207              ## Ignore the token              ## Ignore the token
4208              !!!nack ('t95.1');              !!!nack ('t95.1');
4209              !!!next-token;              !!!next-token;
4210              redo B;              next B;
4211            }            }
4212          } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {          } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4213                !!!cp ('t96');            !!!cp ('t96');
4214                ## As if <head>            ## As if <head>
4215                !!!create-element ($self->{head_element}, 'head',, $token);            !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4216                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4217                push @{$self->{open_elements}},            push @{$self->{open_elements}},
4218                    [$self->{head_element}, $el_category->{head}];                [$self->{head_element}, $el_category->{head}];
4219    
4220                $self->{insertion_mode} = IN_HEAD_IM;            $self->{insertion_mode} = IN_HEAD_IM;
4221                ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4222              } else {          } else {
4223                !!!cp ('t97');            !!!cp ('t97');
4224              }          }
4225    
4226              if ($token->{tag_name} eq 'base') {              if ($token->{tag_name} eq 'base') {
4227                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 3668  sub _tree_construction_main ($) { Line 4251  sub _tree_construction_main ($) {
4251                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4252                !!!nack ('t101.1');                !!!nack ('t101.1');
4253                !!!next-token;                !!!next-token;
4254                redo B;                next B;
4255              } elsif ($token->{tag_name} eq 'link') {              } elsif ($token->{tag_name} eq 'link') {
4256                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4257                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
# Line 3685  sub _tree_construction_main ($) { Line 4268  sub _tree_construction_main ($) {
4268                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4269                !!!ack ('t103.1');                !!!ack ('t103.1');
4270                !!!next-token;                !!!next-token;
4271                redo B;                next B;
4272              } elsif ($token->{tag_name} eq 'meta') {              } elsif ($token->{tag_name} eq 'meta') {
4273                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4274                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
# Line 3700  sub _tree_construction_main ($) { Line 4283  sub _tree_construction_main ($) {
4283                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4284    
4285                unless ($self->{confident}) {                unless ($self->{confident}) {
4286                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) {
4287                    !!!cp ('t106');                    !!!cp ('t106');
4288                      ## NOTE: Whether the encoding is supported or not is handled
4289                      ## in the {change_encoding} callback.
4290                    $self->{change_encoding}                    $self->{change_encoding}
4291                        ->($self, $token->{attributes}->{charset}->{value},                        ->($self, $token->{attributes}->{charset}->{value},
4292                           $token);                           $token);
# Line 3711  sub _tree_construction_main ($) { Line 4296  sub _tree_construction_main ($) {
4296                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
4297                                                 ->{has_reference});                                                 ->{has_reference});
4298                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
                   ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
4299                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4300                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4301                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4302                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4303                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4304                      !!!cp ('t107');                      !!!cp ('t107');
4305                        ## NOTE: Whether the encoding is supported or not is handled
4306                        ## in the {change_encoding} callback.
4307                      $self->{change_encoding}                      $self->{change_encoding}
4308                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,
4309                             $token);                             $token);
# Line 3750  sub _tree_construction_main ($) { Line 4336  sub _tree_construction_main ($) {
4336                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4337                !!!ack ('t110.1');                !!!ack ('t110.1');
4338                !!!next-token;                !!!next-token;
4339                redo B;                next B;
4340              } elsif ($token->{tag_name} eq 'title') {              } elsif ($token->{tag_name} eq 'title') {
4341                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4342                  !!!cp ('t111');                  !!!cp ('t111');
# Line 3775  sub _tree_construction_main ($) { Line 4361  sub _tree_construction_main ($) {
4361                $parse_rcdata->(RCDATA_CONTENT_MODEL);                $parse_rcdata->(RCDATA_CONTENT_MODEL);
4362                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4363                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4364                redo B;                next B;
4365              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style') {
4366                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4367                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
# Line 3791  sub _tree_construction_main ($) { Line 4377  sub _tree_construction_main ($) {
4377                $parse_rcdata->(CDATA_CONTENT_MODEL);                $parse_rcdata->(CDATA_CONTENT_MODEL);
4378                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4379                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4380                redo B;                next B;
4381              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4382                if ($self->{insertion_mode} == IN_HEAD_IM) {                if ($self->{insertion_mode} == IN_HEAD_IM) {
4383                  !!!cp ('t116');                  !!!cp ('t116');
# Line 3800  sub _tree_construction_main ($) { Line 4386  sub _tree_construction_main ($) {
4386                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;
4387                  !!!nack ('t116.1');                  !!!nack ('t116.1');
4388                  !!!next-token;                  !!!next-token;
4389                  redo B;                  next B;
4390                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4391                  !!!cp ('t117');                  !!!cp ('t117');
4392                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript:noscript', token => $token);
4393                  ## Ignore the token                  ## Ignore the token
4394                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4395                  !!!next-token;                  !!!next-token;
4396                  redo B;                  next B;
4397                } else {                } else {
4398                  !!!cp ('t118');                  !!!cp ('t118');
4399                  #                  #
# Line 3834  sub _tree_construction_main ($) { Line 4420  sub _tree_construction_main ($) {
4420                $script_start_tag->();                $script_start_tag->();
4421                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4422                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4423                redo B;                next B;
4424              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
4425                       $token->{tag_name} eq 'frameset') {                       $token->{tag_name} eq 'frameset') {
4426                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 3870  sub _tree_construction_main ($) { Line 4456  sub _tree_construction_main ($) {
4456                }                }
4457                !!!nack ('t127.1');                !!!nack ('t127.1');
4458                !!!next-token;                !!!next-token;
4459                redo B;                next B;
4460              } else {              } else {
4461                !!!cp ('t128');                !!!cp ('t128');
4462                #                #
# Line 3903  sub _tree_construction_main ($) { Line 4489  sub _tree_construction_main ($) {
4489              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
4490              ## reprocess              ## reprocess
4491              !!!ack-later;              !!!ack-later;
4492              redo B;              next B;
4493            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
4494              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
4495                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4496                  !!!cp ('t132');                  !!!cp ('t132');
4497                  ## As if <head>                  ## As if <head>
4498                  !!!create-element ($self->{head_element}, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4499                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4500                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4501                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
# Line 3918  sub _tree_construction_main ($) { Line 4504  sub _tree_construction_main ($) {
4504                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4505                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4506                  !!!next-token;                  !!!next-token;
4507                  redo B;                  next B;
4508                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4509                  !!!cp ('t133');                  !!!cp ('t133');
4510                  ## As if </noscript>                  ## As if </noscript>
# Line 3929  sub _tree_construction_main ($) { Line 4515  sub _tree_construction_main ($) {
4515                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4516                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4517                  !!!next-token;                  !!!next-token;
4518                  redo B;                  next B;
4519                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4520                  !!!cp ('t134');                  !!!cp ('t134');
4521                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4522                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4523                  !!!next-token;                  !!!next-token;
4524                  redo B;                  next B;
4525                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4526                    !!!cp ('t134.1');
4527                    !!!parse-error (type => 'unmatched end tag:head', token => $token);
4528                    ## Ignore the token
4529                    !!!next-token;
4530                    next B;
4531                } else {                } else {
4532                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4533                }                }
4534              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4535                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 3946  sub _tree_construction_main ($) { Line 4537  sub _tree_construction_main ($) {
4537                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4538                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4539                  !!!next-token;                  !!!next-token;
4540                  redo B;                  next B;
4541                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4542                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4543                  !!!cp ('t137');                  !!!cp ('t137');
4544                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);
4545                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4546                  !!!next-token;                  !!!next-token;
4547                  redo B;                  next B;
4548                } else {                } else {
4549                  !!!cp ('t138');                  !!!cp ('t138');
4550                  #                  #
# Line 3960  sub _tree_construction_main ($) { Line 4552  sub _tree_construction_main ($) {
4552              } elsif ({              } elsif ({
4553                        body => 1, html => 1,                        body => 1, html => 1,
4554                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4555                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4556                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4557                  ## As if <head>                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
                 !!!create-element ($self->{head_element}, 'head',, $token);  
                 $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});  
                 push @{$self->{open_elements}},  
                     [$self->{head_element}, $el_category->{head}];  
   
                 $self->{insertion_mode} = IN_HEAD_IM;  
                 ## Reprocess in the "in head" insertion mode...  
               } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {  
4558                  !!!cp ('t140');                  !!!cp ('t140');
4559                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4560                  ## Ignore the token                  ## Ignore the token
4561                  !!!next-token;                  !!!next-token;
4562                  redo B;                  next B;
4563                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4564                    !!!cp ('t140.1');
4565                    !!!parse-error (type => 'unmatched end tag:' . $token->{tag_name}, token => $token);
4566                    ## Ignore the token
4567                    !!!next-token;
4568                    next B;
4569                } else {                } else {
4570                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4571                }                }
4572                              } elsif ($token->{tag_name} eq 'p') {
4573                #                !!!cp ('t142');
4574              } elsif ({                !!!parse-error (type => 'unmatched end tag:p', token => $token);
4575                        p => 1, br => 1,                ## Ignore the token
4576                       }->{$token->{tag_name}}) {                !!!next-token;
4577                  next B;
4578                } elsif ($token->{tag_name} eq 'br') {
4579                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4580                  !!!cp ('t142');                  !!!cp ('t142.2');
4581                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4582                  !!!create-element ($self->{head_element}, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4583                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4584                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4585                      [$self->{head_element}, $el_category->{head}];    
4586                    ## Reprocess in the "after head" insertion mode...
4587                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4588                    !!!cp ('t143.2');
4589                    ## As if </head>
4590                    pop @{$self->{open_elements}};
4591                    $self->{insertion_mode} = AFTER_HEAD_IM;
4592      
4593                    ## Reprocess in the "after head" insertion mode...
4594                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4595                    !!!cp ('t143.3');
4596                    ## ISSUE: Two parse errors for <head><noscript></br>
4597                    !!!parse-error (type => 'unmatched end tag:br', token => $token);
4598                    ## As if </noscript>
4599                    pop @{$self->{open_elements}};
4600                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4601    
4602                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4603                } else {                  ## As if </head>
4604                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4605                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4606    
4607                #                  ## Reprocess in the "after head" insertion mode...
4608              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4609                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4610                  #                  #
4611                } else {                } else {
4612                  !!!cp ('t145');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);  
                 ## Ignore the token  
                 !!!next-token;  
                 redo B;  
4613                }                }
4614    
4615                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4616                  !!!parse-error (type => 'unmatched end tag:br', token => $token);
4617                  ## Ignore the token
4618                  !!!next-token;
4619                  next B;
4620                } else {
4621                  !!!cp ('t145');
4622                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4623                  ## Ignore the token
4624                  !!!next-token;
4625                  next B;
4626              }              }
4627    
4628              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4035  sub _tree_construction_main ($) { Line 4648  sub _tree_construction_main ($) {
4648                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4649                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4650                !!!next-token;                !!!next-token;
4651                redo B;                next B;
4652              } else {              } else {
4653                !!!cp ('t149');                !!!cp ('t149');
4654              }              }
# Line 4045  sub _tree_construction_main ($) { Line 4658  sub _tree_construction_main ($) {
4658              !!!insert-element ('body',, $token);              !!!insert-element ('body',, $token);
4659              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
4660              ## reprocess              ## reprocess
4661              redo B;              next B;
4662        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4663          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4664            !!!cp ('t149.1');            !!!cp ('t149.1');
4665    
4666            ## NOTE: As if <head>            ## NOTE: As if <head>
4667            !!!create-element ($self->{head_element}, 'head',, $token);            !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4668            $self->{open_elements}->[-1]->[0]->append_child            $self->{open_elements}->[-1]->[0]->append_child
4669                ($self->{head_element});                ($self->{head_element});
4670            #push @{$self->{open_elements}},            #push @{$self->{open_elements}},
# Line 4099  sub _tree_construction_main ($) { Line 4712  sub _tree_construction_main ($) {
4712          !!!insert-element ('body',, $token);          !!!insert-element ('body',, $token);
4713          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
4714          ## NOTE: Reprocess.          ## NOTE: Reprocess.
4715          redo B;          next B;
4716        } else {        } else {
4717          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4718        }        }
# Line 4114  sub _tree_construction_main ($) { Line 4727  sub _tree_construction_main ($) {
4727              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4728    
4729              !!!next-token;              !!!next-token;
4730              redo B;              next B;
4731            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
4732              if ({              if ({
4733                   caption => 1, col => 1, colgroup => 1, tbody => 1,                   caption => 1, col => 1, colgroup => 1, tbody => 1,
# Line 4133  sub _tree_construction_main ($) { Line 4746  sub _tree_construction_main ($) {
4746                                tag_name => $node->[0]->manakai_local_name,                                tag_name => $node->[0]->manakai_local_name,
4747                                line => $token->{line},                                line => $token->{line},
4748                                column => $token->{column}};                                column => $token->{column}};
4749                      redo B;                      next B;
4750                    } elsif ($node->[1] & TABLE_SCOPING_EL) {                    } elsif ($node->[1] & TABLE_SCOPING_EL) {
4751                      !!!cp ('t152');                      !!!cp ('t152');
4752                      ## ISSUE: This case can never be reached, maybe.                      ## ISSUE: This case can never be reached, maybe.
# Line 4147  sub _tree_construction_main ($) { Line 4760  sub _tree_construction_main ($) {
4760                  ## Ignore the token                  ## Ignore the token
4761                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4762                  !!!next-token;                  !!!next-token;
4763                  redo B;                  next B;
4764                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4765                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed:caption', token => $token);
4766                                    
# Line 4173  sub _tree_construction_main ($) { Line 4786  sub _tree_construction_main ($) {
4786                    ## Ignore the token                    ## Ignore the token
4787                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4788                    !!!next-token;                    !!!next-token;
4789                    redo B;                    next B;
4790                  } # INSCOPE                  } # INSCOPE
4791                                    
4792                  ## generate implied end tags                  ## generate implied end tags
# Line 4201  sub _tree_construction_main ($) { Line 4814  sub _tree_construction_main ($) {
4814                                    
4815                  ## reprocess                  ## reprocess
4816                  !!!ack-later;                  !!!ack-later;
4817                  redo B;                  next B;
4818                } else {                } else {
4819                  !!!cp ('t161');                  !!!cp ('t161');
4820                  #                  #
# Line 4231  sub _tree_construction_main ($) { Line 4844  sub _tree_construction_main ($) {
4844                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4845                      ## Ignore the token                      ## Ignore the token
4846                      !!!next-token;                      !!!next-token;
4847                      redo B;                      next B;
4848                    }                    }
4849                                    
4850                  ## generate implied end tags                  ## generate implied end tags
# Line 4259  sub _tree_construction_main ($) { Line 4872  sub _tree_construction_main ($) {
4872                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
4873                                    
4874                  !!!next-token;                  !!!next-token;
4875                  redo B;                  next B;
4876                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4877                  !!!cp ('t169');                  !!!cp ('t169');
4878                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4879                  ## Ignore the token                  ## Ignore the token
4880                  !!!next-token;                  !!!next-token;
4881                  redo B;                  next B;
4882                } else {                } else {
4883                  !!!cp ('t170');                  !!!cp ('t170');
4884                  #                  #
# Line 4292  sub _tree_construction_main ($) { Line 4905  sub _tree_construction_main ($) {
4905                                    value => $token->{tag_name}, token => $token);                                    value => $token->{tag_name}, token => $token);
4906                    ## Ignore the token                    ## Ignore the token
4907                    !!!next-token;                    !!!next-token;
4908                    redo B;                    next B;
4909                  } # INSCOPE                  } # INSCOPE
4910                                    
4911                  ## generate implied end tags                  ## generate implied end tags
# Line 4319  sub _tree_construction_main ($) { Line 4932  sub _tree_construction_main ($) {
4932                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4933                                    
4934                  !!!next-token;                  !!!next-token;
4935                  redo B;                  next B;
4936                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
4937                  !!!cp ('t177');                  !!!cp ('t177');
4938                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4939                  ## Ignore the token                  ## Ignore the token
4940                  !!!next-token;                  !!!next-token;
4941                  redo B;                  next B;
4942                } else {                } else {
4943                  !!!cp ('t178');                  !!!cp ('t178');
4944                  #                  #
# Line 4350  sub _tree_construction_main ($) { Line 4963  sub _tree_construction_main ($) {
4963                      $token = {type => END_TAG_TOKEN, tag_name => $tn,                      $token = {type => END_TAG_TOKEN, tag_name => $tn,
4964                                line => $token->{line},                                line => $token->{line},
4965                                column => $token->{column}};                                column => $token->{column}};
4966                      redo B;                      next B;
4967                    } elsif ($node->[1] & TABLE_CELL_EL) {                    } elsif ($node->[1] & TABLE_CELL_EL) {
4968                      !!!cp ('t180');                      !!!cp ('t180');
4969                      $tn = $node->[0]->manakai_local_name;                      $tn = $node->[0]->manakai_local_name;
# Line 4368  sub _tree_construction_main ($) { Line 4981  sub _tree_construction_main ($) {
4981                      value => $token->{tag_name}, token => $token);                      value => $token->{tag_name}, token => $token);
4982                  ## Ignore the token                  ## Ignore the token
4983                  !!!next-token;                  !!!next-token;
4984                  redo B;                  next B;
4985                } # INSCOPE                } # INSCOPE
4986              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
4987                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
# Line 4393  sub _tree_construction_main ($) { Line 5006  sub _tree_construction_main ($) {
5006                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);
5007                  ## Ignore the token                  ## Ignore the token
5008                  !!!next-token;                  !!!next-token;
5009                  redo B;                  next B;
5010                }                }
5011                                
5012                ## generate implied end tags                ## generate implied end tags
# Line 4419  sub _tree_construction_main ($) { Line 5032  sub _tree_construction_main ($) {
5032                $self->{insertion_mode} = IN_TABLE_IM;                $self->{insertion_mode} = IN_TABLE_IM;
5033    
5034                ## reprocess                ## reprocess
5035                redo B;                next B;
5036              } elsif ({              } elsif ({
5037                        body => 1, col => 1, colgroup => 1, html => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
5038                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
# Line 4428  sub _tree_construction_main ($) { Line 5041  sub _tree_construction_main ($) {
5041                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5042                  ## Ignore the token                  ## Ignore the token
5043                  !!!next-token;                  !!!next-token;
5044                  redo B;                  next B;
5045                } else {                } else {
5046                  !!!cp ('t191');                  !!!cp ('t191');
5047                  #                  #
# Line 4442  sub _tree_construction_main ($) { Line 5055  sub _tree_construction_main ($) {
5055                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5056                ## Ignore the token                ## Ignore the token
5057                !!!next-token;                !!!next-token;
5058                redo B;                next B;
5059              } else {              } else {
5060                !!!cp ('t193');                !!!cp ('t193');
5061                #                #
# Line 4473  sub _tree_construction_main ($) { Line 5086  sub _tree_construction_main ($) {
5086            unless (length $token->{data}) {            unless (length $token->{data}) {
5087              !!!cp ('t194');              !!!cp ('t194');
5088              !!!next-token;              !!!next-token;
5089              redo B;              next B;
5090            } else {            } else {
5091              !!!cp ('t195');              !!!cp ('t195');
5092            }            }
# Line 4528  sub _tree_construction_main ($) { Line 5141  sub _tree_construction_main ($) {
5141          }          }
5142                            
5143          !!!next-token;          !!!next-token;
5144          redo B;          next B;
5145        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5146              if ({              if ({
5147                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
# Line 4567  sub _tree_construction_main ($) { Line 5180  sub _tree_construction_main ($) {
5180                    !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                    !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5181                    !!!nack ('t204');                    !!!nack ('t204');
5182                    !!!next-token;                    !!!next-token;
5183                    redo B;                    next B;
5184                  } else {                  } else {
5185                    !!!cp ('t205');                    !!!cp ('t205');
5186                    !!!insert-element ('tr',, $token);                    !!!insert-element ('tr',, $token);
# Line 4591  sub _tree_construction_main ($) { Line 5204  sub _tree_construction_main ($) {
5204                                
5205                !!!nack ('t207.1');                !!!nack ('t207.1');
5206                !!!next-token;                !!!next-token;
5207                redo B;                next B;
5208              } elsif ({              } elsif ({
5209                        caption => 1, col => 1, colgroup => 1,                        caption => 1, col => 1, colgroup => 1,
5210                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
# Line 4619  sub _tree_construction_main ($) { Line 5232  sub _tree_construction_main ($) {
5232                    ## Ignore the token                    ## Ignore the token
5233                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5234                    !!!next-token;                    !!!next-token;
5235                    redo B;                    next B;
5236                  }                  }
5237                                    
5238                  ## Clear back to table row context                  ## Clear back to table row context
# Line 4636  sub _tree_construction_main ($) { Line 5249  sub _tree_construction_main ($) {
5249                    !!!cp ('t212');                    !!!cp ('t212');
5250                    ## reprocess                    ## reprocess
5251                    !!!ack-later;                    !!!ack-later;
5252                    redo B;                    next B;
5253                  } else {                  } else {
5254                    !!!cp ('t213');                    !!!cp ('t213');
5255                    ## reprocess in the "in table body" insertion mode...                    ## reprocess in the "in table body" insertion mode...
# Line 4664  sub _tree_construction_main ($) { Line 5277  sub _tree_construction_main ($) {
5277                    ## Ignore the token                    ## Ignore the token
5278                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5279                    !!!next-token;                    !!!next-token;
5280                    redo B;                    next B;
5281                  }                  }
5282    
5283                  ## Clear back to table body context                  ## Clear back to table body context
# Line 4702  sub _tree_construction_main ($) { Line 5315  sub _tree_construction_main ($) {
5315                  $self->{insertion_mode} = IN_COLUMN_GROUP_IM;                  $self->{insertion_mode} = IN_COLUMN_GROUP_IM;
5316                  ## reprocess                  ## reprocess
5317                  !!!ack-later;                  !!!ack-later;
5318                  redo B;                  next B;
5319                } elsif ({                } elsif ({
5320                          caption => 1,                          caption => 1,
5321                          colgroup => 1,                          colgroup => 1,
# Line 4729  sub _tree_construction_main ($) { Line 5342  sub _tree_construction_main ($) {
5342                                            }->{$token->{tag_name}};                                            }->{$token->{tag_name}};
5343                  !!!next-token;                  !!!next-token;
5344                  !!!nack ('t220.1');                  !!!nack ('t220.1');
5345                  redo B;                  next B;
5346                } else {                } else {
5347                  die "$0: in table: <>: $token->{tag_name}";                  die "$0: in table: <>: $token->{tag_name}";
5348                }                }
# Line 4760  sub _tree_construction_main ($) { Line 5373  sub _tree_construction_main ($) {
5373                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5374                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5375                  !!!next-token;                  !!!next-token;
5376                  redo B;                  next B;
5377                }                }
5378                                
5379  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
# Line 4788  sub _tree_construction_main ($) { Line 5401  sub _tree_construction_main ($) {
5401    
5402            ## reprocess            ## reprocess
5403            !!!ack-later;            !!!ack-later;
5404            redo B;            next B;
5405          } elsif ($token->{tag_name} eq 'style') {          } elsif ($token->{tag_name} eq 'style') {
5406            if (not $open_tables->[-1]->[1]) { # tainted            if (not $open_tables->[-1]->[1]) { # tainted
5407              !!!cp ('t227.8');              !!!cp ('t227.8');
5408              ## NOTE: This is a "as if in head" code clone.              ## NOTE: This is a "as if in head" code clone.
5409              $parse_rcdata->(CDATA_CONTENT_MODEL);              $parse_rcdata->(CDATA_CONTENT_MODEL);
5410              redo B;              next B;
5411            } else {            } else {
5412              !!!cp ('t227.7');              !!!cp ('t227.7');
5413              #              #
# Line 4804  sub _tree_construction_main ($) { Line 5417  sub _tree_construction_main ($) {
5417              !!!cp ('t227.6');              !!!cp ('t227.6');
5418              ## NOTE: This is a "as if in head" code clone.              ## NOTE: This is a "as if in head" code clone.
5419              $script_start_tag->();              $script_start_tag->();
5420              redo B;              next B;
5421            } else {            } else {
5422              !!!cp ('t227.5');              !!!cp ('t227.5');
5423              #              #
# Line 4825  sub _tree_construction_main ($) { Line 5438  sub _tree_construction_main ($) {
5438    
5439                  !!!next-token;                  !!!next-token;
5440                  !!!ack ('t227.2.1');                  !!!ack ('t227.2.1');
5441                  redo B;                  next B;
5442                } else {                } else {
5443                  !!!cp ('t227.2');                  !!!cp ('t227.2');
5444                  #                  #
# Line 4869  sub _tree_construction_main ($) { Line 5482  sub _tree_construction_main ($) {
5482                  ## Ignore the token                  ## Ignore the token
5483                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5484                  !!!next-token;                  !!!next-token;
5485                  redo B;                  next B;
5486                } else {                } else {
5487                  !!!cp ('t232');                  !!!cp ('t232');
5488                }                }
# Line 4886  sub _tree_construction_main ($) { Line 5499  sub _tree_construction_main ($) {
5499                $self->{insertion_mode} = IN_TABLE_BODY_IM;                $self->{insertion_mode} = IN_TABLE_BODY_IM;
5500                !!!next-token;                !!!next-token;
5501                !!!nack ('t231.1');                !!!nack ('t231.1');
5502                redo B;                next B;
5503              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5504                if ($self->{insertion_mode} == IN_ROW_IM) {                if ($self->{insertion_mode} == IN_ROW_IM) {
5505                  ## As if </tr>                  ## As if </tr>
# Line 4910  sub _tree_construction_main ($) { Line 5523  sub _tree_construction_main ($) {
5523                    ## Ignore the token                    ## Ignore the token
5524                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5525                    !!!next-token;                    !!!next-token;
5526                    redo B;                    next B;
5527                  }                  }
5528                                    
5529                  ## Clear back to table row context                  ## Clear back to table row context
# Line 4946  sub _tree_construction_main ($) { Line 5559  sub _tree_construction_main ($) {
5559                    ## Ignore the token                    ## Ignore the token
5560                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5561                    !!!next-token;                    !!!next-token;
5562                    redo B;                    next B;
5563                  }                  }
5564                                    
5565                  ## Clear back to table body context                  ## Clear back to table body context
# Line 4992  sub _tree_construction_main ($) { Line 5605  sub _tree_construction_main ($) {
5605                  ## Ignore the token                  ## Ignore the token
5606                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5607                  !!!next-token;                  !!!next-token;
5608                  redo B;                  next B;
5609                }                }
5610                                    
5611                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 5001  sub _tree_construction_main ($) { Line 5614  sub _tree_construction_main ($) {
5614                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
5615                                
5616                !!!next-token;                !!!next-token;
5617                redo B;                next B;
5618              } elsif ({              } elsif ({
5619                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
5620                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
# Line 5026  sub _tree_construction_main ($) { Line 5639  sub _tree_construction_main ($) {
5639                      ## Ignore the token                      ## Ignore the token
5640                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5641                      !!!next-token;                      !!!next-token;
5642                      redo B;                      next B;
5643                    }                    }
5644                                    
5645                  ## As if </tr>                  ## As if </tr>
# Line 5049  sub _tree_construction_main ($) { Line 5662  sub _tree_construction_main ($) {
5662                      ## Ignore the token                      ## Ignore the token
5663                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5664                      !!!next-token;                      !!!next-token;
5665                      redo B;                      next B;
5666                    }                    }
5667                                    
5668                  ## Clear back to table row context                  ## Clear back to table row context
# Line 5084  sub _tree_construction_main ($) { Line 5697  sub _tree_construction_main ($) {
5697                  ## Ignore the token                  ## Ignore the token
5698                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5699                  !!!next-token;                  !!!next-token;
5700                  redo B;                  next B;
5701                }                }
5702    
5703                ## Clear back to table body context                ## Clear back to table body context
# Line 5099  sub _tree_construction_main ($) { Line 5712  sub _tree_construction_main ($) {
5712                $self->{insertion_mode} = IN_TABLE_IM;                $self->{insertion_mode} = IN_TABLE_IM;
5713                !!!nack ('t257.1');                !!!nack ('t257.1');
5714                !!!next-token;                !!!next-token;
5715                redo B;                next B;
5716              } elsif ({              } elsif ({
5717                        body => 1, caption => 1, col => 1, colgroup => 1,                        body => 1, caption => 1, col => 1, colgroup => 1,
5718                        html => 1, td => 1, th => 1,                        html => 1, td => 1, th => 1,
# Line 5111  sub _tree_construction_main ($) { Line 5724  sub _tree_construction_main ($) {
5724            ## Ignore the token            ## Ignore the token
5725            !!!nack ('t258.1');            !!!nack ('t258.1');
5726             !!!next-token;             !!!next-token;
5727            redo B;            next B;
5728          } else {          } else {
5729            !!!cp ('t259');            !!!cp ('t259');
5730            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);
# Line 5142  sub _tree_construction_main ($) { Line 5755  sub _tree_construction_main ($) {
5755                unless (length $token->{data}) {                unless (length $token->{data}) {
5756                  !!!cp ('t260');                  !!!cp ('t260');
5757                  !!!next-token;                  !!!next-token;
5758                  redo B;                  next B;
5759                }                }
5760              }              }
5761                            
# Line 5155  sub _tree_construction_main ($) { Line 5768  sub _tree_construction_main ($) {
5768                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5769                !!!ack ('t262.1');                !!!ack ('t262.1');
5770                !!!next-token;                !!!next-token;
5771                redo B;                next B;
5772              } else {              } else {
5773                !!!cp ('t263');                !!!cp ('t263');
5774                #                #
# Line 5167  sub _tree_construction_main ($) { Line 5780  sub _tree_construction_main ($) {
5780                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);
5781                  ## Ignore the token                  ## Ignore the token
5782                  !!!next-token;                  !!!next-token;
5783                  redo B;                  next B;
5784                } else {                } else {
5785                  !!!cp ('t265');                  !!!cp ('t265');
5786                  pop @{$self->{open_elements}}; # colgroup                  pop @{$self->{open_elements}}; # colgroup
5787                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
5788                  !!!next-token;                  !!!next-token;
5789                  redo B;                              next B;            
5790                }                }
5791              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5792                !!!cp ('t266');                !!!cp ('t266');
5793                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag:col', token => $token);
5794                ## Ignore the token                ## Ignore the token
5795                !!!next-token;                !!!next-token;
5796                redo B;                next B;
5797              } else {              } else {
5798                !!!cp ('t267');                !!!cp ('t267');
5799                #                #
# Line 5197  sub _tree_construction_main ($) { Line 5810  sub _tree_construction_main ($) {
5810            pop @{$self->{open_elements}}; # colgroup            pop @{$self->{open_elements}}; # colgroup
5811            $self->{insertion_mode} = IN_TABLE_IM;            $self->{insertion_mode} = IN_TABLE_IM;
5812            ## Reprocess.            ## Reprocess.
5813            redo B;            next B;
5814          }          }
5815        } else {        } else {
5816          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
# Line 5211  sub _tree_construction_main ($) { Line 5824  sub _tree_construction_main ($) {
5824              ## Ignore the token              ## Ignore the token
5825              !!!nack ('t269.1');              !!!nack ('t269.1');
5826              !!!next-token;              !!!next-token;
5827              redo B;              next B;
5828            } else {            } else {
5829              !!!cp ('t270');              !!!cp ('t270');
5830              pop @{$self->{open_elements}}; # colgroup              pop @{$self->{open_elements}}; # colgroup
5831              $self->{insertion_mode} = IN_TABLE_IM;              $self->{insertion_mode} = IN_TABLE_IM;
5832              !!!ack-later;              !!!ack-later;
5833              ## reprocess              ## reprocess
5834              redo B;              next B;
5835            }            }
5836      } elsif ($self->{insertion_mode} & SELECT_IMS) {      } elsif ($self->{insertion_mode} & SELECT_IMS) {
5837        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
5838          !!!cp ('t271');          !!!cp ('t271');
5839          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
5840          !!!next-token;          !!!next-token;
5841          redo B;          next B;
5842        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5843          if ($token->{tag_name} eq 'option') {          if ($token->{tag_name} eq 'option') {
5844            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {
# Line 5239  sub _tree_construction_main ($) { Line 5852  sub _tree_construction_main ($) {
5852            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5853            !!!nack ('t273.1');            !!!nack ('t273.1');
5854            !!!next-token;            !!!next-token;
5855            redo B;            next B;
5856          } elsif ($token->{tag_name} eq 'optgroup') {          } elsif ($token->{tag_name} eq 'optgroup') {
5857            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {
5858              !!!cp ('t274');              !!!cp ('t274');
# Line 5260  sub _tree_construction_main ($) { Line 5873  sub _tree_construction_main ($) {
5873            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5874            !!!nack ('t277.1');            !!!nack ('t277.1');
5875            !!!next-token;            !!!next-token;
5876            redo B;            next B;
5877          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
5878                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
5879                     }->{$token->{tag_name}} or
5880                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5881                    {                    {
5882                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5292  sub _tree_construction_main ($) { Line 5906  sub _tree_construction_main ($) {
5906              ## Ignore the token              ## Ignore the token
5907              !!!nack ('t280.1');              !!!nack ('t280.1');
5908              !!!next-token;              !!!next-token;
5909              redo B;              next B;
5910            }            }
5911                                
5912            !!!cp ('t281');            !!!cp ('t281');
# Line 5303  sub _tree_construction_main ($) { Line 5917  sub _tree_construction_main ($) {
5917            if ($token->{tag_name} eq 'select') {            if ($token->{tag_name} eq 'select') {
5918              !!!nack ('t281.2');              !!!nack ('t281.2');
5919              !!!next-token;              !!!next-token;
5920              redo B;              next B;
5921            } else {            } else {
5922              !!!cp ('t281.1');              !!!cp ('t281.1');
5923              !!!ack-later;              !!!ack-later;
5924              ## Reprocess the token.              ## Reprocess the token.
5925              redo B;              next B;
5926            }            }
5927          } else {          } else {
5928            !!!cp ('t282');            !!!cp ('t282');
# Line 5316  sub _tree_construction_main ($) { Line 5930  sub _tree_construction_main ($) {
5930            ## Ignore the token            ## Ignore the token
5931            !!!nack ('t282.1');            !!!nack ('t282.1');
5932            !!!next-token;            !!!next-token;
5933            redo B;            next B;
5934          }          }
5935        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5936          if ($token->{tag_name} eq 'optgroup') {          if ($token->{tag_name} eq 'optgroup') {
# Line 5335  sub _tree_construction_main ($) { Line 5949  sub _tree_construction_main ($) {
5949            }            }
5950            !!!nack ('t285.1');            !!!nack ('t285.1');
5951            !!!next-token;            !!!next-token;
5952            redo B;            next B;
5953          } elsif ($token->{tag_name} eq 'option') {          } elsif ($token->{tag_name} eq 'option') {
5954            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {
5955              !!!cp ('t286');              !!!cp ('t286');
# Line 5347  sub _tree_construction_main ($) { Line 5961  sub _tree_construction_main ($) {
5961            }            }
5962            !!!nack ('t287.1');            !!!nack ('t287.1');
5963            !!!next-token;            !!!next-token;
5964            redo B;            next B;
5965          } elsif ($token->{tag_name} eq 'select') {          } elsif ($token->{tag_name} eq 'select') {
5966            ## have an element in table scope            ## have an element in table scope
5967            my $i;            my $i;
# Line 5368  sub _tree_construction_main ($) { Line 5982  sub _tree_construction_main ($) {
5982              ## Ignore the token              ## Ignore the token
5983              !!!nack ('t290.1');              !!!nack ('t290.1');
5984              !!!next-token;              !!!next-token;
5985              redo B;              next B;
5986            }            }
5987                                
5988            !!!cp ('t291');            !!!cp ('t291');
# Line 5378  sub _tree_construction_main ($) { Line 5992  sub _tree_construction_main ($) {
5992    
5993            !!!nack ('t291.1');            !!!nack ('t291.1');
5994            !!!next-token;            !!!next-token;
5995            redo B;            next B;
5996          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5997                   {                   {
5998                    caption => 1, table => 1, tbody => 1,                    caption => 1, table => 1, tbody => 1,
# Line 5405  sub _tree_construction_main ($) { Line 6019  sub _tree_construction_main ($) {
6019              ## Ignore the token              ## Ignore the token
6020              !!!nack ('t294.1');              !!!nack ('t294.1');
6021              !!!next-token;              !!!next-token;
6022              redo B;              next B;
6023            }            }
6024                                
6025            ## As if </select>            ## As if </select>
# Line 5430  sub _tree_construction_main ($) { Line 6044  sub _tree_construction_main ($) {
6044              ## Ignore the </select> token              ## Ignore the </select> token
6045              !!!nack ('t297.1');              !!!nack ('t297.1');
6046              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
6047              redo B;              next B;
6048            }            }
6049                                
6050            !!!cp ('t298');            !!!cp ('t298');
# Line 5440  sub _tree_construction_main ($) { Line 6054  sub _tree_construction_main ($) {
6054    
6055            !!!ack-later;            !!!ack-later;
6056            ## reprocess            ## reprocess
6057            redo B;            next B;
6058          } else {          } else {
6059            !!!cp ('t299');            !!!cp ('t299');
6060            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);
6061            ## Ignore the token            ## Ignore the token
6062            !!!nack ('t299.3');            !!!nack ('t299.3');
6063            !!!next-token;            !!!next-token;
6064            redo B;            next B;
6065          }          }
6066        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
6067          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and
# Line 5475  sub _tree_construction_main ($) { Line 6089  sub _tree_construction_main ($) {
6089            unless (length $token->{data}) {            unless (length $token->{data}) {
6090              !!!cp ('t300');              !!!cp ('t300');
6091              !!!next-token;              !!!next-token;
6092              redo B;              next B;
6093            }            }
6094          }          }
6095                    
# Line 5493  sub _tree_construction_main ($) { Line 6107  sub _tree_construction_main ($) {
6107    
6108          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6109          ## reprocess          ## reprocess
6110          redo B;          next B;
6111        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6112          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6113            !!!cp ('t303');            !!!cp ('t303');
# Line 5510  sub _tree_construction_main ($) { Line 6124  sub _tree_construction_main ($) {
6124          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6125          !!!ack-later;          !!!ack-later;
6126          ## reprocess          ## reprocess
6127          redo B;          next B;
6128        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6129          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6130            !!!cp ('t305');            !!!cp ('t305');
# Line 5529  sub _tree_construction_main ($) { Line 6143  sub _tree_construction_main ($) {
6143              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag:html', token => $token);
6144              ## Ignore the token              ## Ignore the token
6145              !!!next-token;              !!!next-token;
6146              redo B;              next B;
6147            } else {            } else {
6148              !!!cp ('t308');              !!!cp ('t308');
6149              $self->{insertion_mode} = AFTER_HTML_BODY_IM;              $self->{insertion_mode} = AFTER_HTML_BODY_IM;
6150              !!!next-token;              !!!next-token;
6151              redo B;              next B;
6152            }            }
6153          } else {          } else {
6154            !!!cp ('t309');            !!!cp ('t309');
# Line 5542  sub _tree_construction_main ($) { Line 6156  sub _tree_construction_main ($) {
6156    
6157            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6158            ## reprocess            ## reprocess
6159            redo B;            next B;
6160          }          }
6161        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
6162          !!!cp ('t309.2');          !!!cp ('t309.2');
# Line 5559  sub _tree_construction_main ($) { Line 6173  sub _tree_construction_main ($) {
6173            unless (length $token->{data}) {            unless (length $token->{data}) {
6174              !!!cp ('t310');              !!!cp ('t310');
6175              !!!next-token;              !!!next-token;
6176              redo B;              next B;
6177            }            }
6178          }          }
6179                    
# Line 5587  sub _tree_construction_main ($) { Line 6201  sub _tree_construction_main ($) {
6201              !!!cp ('t315');              !!!cp ('t315');
6202              !!!next-token;              !!!next-token;
6203            }            }
6204            redo B;            next B;
6205          }          }
6206                    
6207          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
# Line 5608  sub _tree_construction_main ($) { Line 6222  sub _tree_construction_main ($) {
6222            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
6223            !!!nack ('t318.1');            !!!nack ('t318.1');
6224            !!!next-token;            !!!next-token;
6225            redo B;            next B;
6226          } elsif ($token->{tag_name} eq 'frame' and          } elsif ($token->{tag_name} eq 'frame' and
6227                   $self->{insertion_mode} == IN_FRAMESET_IM) {                   $self->{insertion_mode} == IN_FRAMESET_IM) {
6228            !!!cp ('t319');            !!!cp ('t319');
# Line 5616  sub _tree_construction_main ($) { Line 6230  sub _tree_construction_main ($) {
6230            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
6231            !!!ack ('t319.1');            !!!ack ('t319.1');
6232            !!!next-token;            !!!next-token;
6233            redo B;            next B;
6234          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6235            !!!cp ('t320');            !!!cp ('t320');
6236            ## NOTE: As if in body.            ## NOTE: As if in body.
6237            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6238            redo B;            next B;
6239          } else {          } else {
6240            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6241              !!!cp ('t321');              !!!cp ('t321');
# Line 5633  sub _tree_construction_main ($) { Line 6247  sub _tree_construction_main ($) {
6247            ## Ignore the token            ## Ignore the token
6248            !!!nack ('t322.1');            !!!nack ('t322.1');
6249            !!!next-token;            !!!next-token;
6250            redo B;            next B;
6251          }          }
6252        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6253          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
# Line 5667  sub _tree_construction_main ($) { Line 6281  sub _tree_construction_main ($) {
6281            } else {            } else {
6282              !!!cp ('t328');              !!!cp ('t328');
6283            }            }
6284            redo B;            next B;
6285          } elsif ($token->{tag_name} eq 'html' and          } elsif ($token->{tag_name} eq 'html' and
6286                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {
6287            !!!cp ('t329');            !!!cp ('t329');
6288            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;
6289            !!!next-token;            !!!next-token;
6290            redo B;            next B;
6291          } else {          } else {
6292            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6293              !!!cp ('t330');              !!!cp ('t330');
# Line 5684  sub _tree_construction_main ($) { Line 6298  sub _tree_construction_main ($) {
6298            }            }
6299            ## Ignore the token            ## Ignore the token
6300            !!!next-token;            !!!next-token;
6301            redo B;            next B;
6302          }          }
6303        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
6304          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and
# Line 5712  sub _tree_construction_main ($) { Line 6326  sub _tree_construction_main ($) {
6326          !!!cp ('t332');          !!!cp ('t332');
6327          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
6328          $script_start_tag->();          $script_start_tag->();
6329          redo B;          next B;
6330        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
6331          !!!cp ('t333');          !!!cp ('t333');
6332          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
6333          $parse_rcdata->(CDATA_CONTENT_MODEL);          $parse_rcdata->(CDATA_CONTENT_MODEL);
6334          redo B;          next B;
6335        } elsif ({        } elsif ({
6336                  base => 1, link => 1,                  base => 1, link => 1,
6337                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 5727  sub _tree_construction_main ($) { Line 6341  sub _tree_construction_main ($) {
6341          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
6342          !!!ack ('t334.1');          !!!ack ('t334.1');
6343          !!!next-token;          !!!next-token;
6344          redo B;          next B;
6345        } elsif ($token->{tag_name} eq 'meta') {        } elsif ($token->{tag_name} eq 'meta') {
6346          ## NOTE: This is an "as if in head" code clone, only "-t" differs          ## NOTE: This is an "as if in head" code clone, only "-t" differs
6347          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6348          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
6349    
6350          unless ($self->{confident}) {          unless ($self->{confident}) {
6351            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) {
6352              !!!cp ('t335');              !!!cp ('t335');
6353                ## NOTE: Whether the encoding is supported or not is handled
6354                ## in the {change_encoding} callback.
6355              $self->{change_encoding}              $self->{change_encoding}
6356                  ->($self, $token->{attributes}->{charset}->{value}, $token);                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6357                            
# Line 5744  sub _tree_construction_main ($) { Line 6360  sub _tree_construction_main ($) {
6360                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
6361                                           ->{has_reference});                                           ->{has_reference});
6362            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
6363              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6364                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6365                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6366                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6367                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6368                !!!cp ('t336');                !!!cp ('t336');
6369                  ## NOTE: Whether the encoding is supported or not is handled
6370                  ## in the {change_encoding} callback.
6371                $self->{change_encoding}                $self->{change_encoding}
6372                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6373                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 5778  sub _tree_construction_main ($) { Line 6395  sub _tree_construction_main ($) {
6395    
6396          !!!ack ('t338.1');          !!!ack ('t338.1');
6397          !!!next-token;          !!!next-token;
6398          redo B;          next B;
6399        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
6400          !!!cp ('t341');          !!!cp ('t341');
6401          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
6402          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6403          redo B;          next B;
6404        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6405          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body:body', token => $token);
6406                                
# Line 5804  sub _tree_construction_main ($) { Line 6421  sub _tree_construction_main ($) {
6421          }          }
6422          !!!nack ('t343.1');          !!!nack ('t343.1');
6423          !!!next-token;          !!!next-token;
6424          redo B;          next B;
6425        } elsif ({        } elsif ({
6426                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
6427                  div => 1, dl => 1, fieldset => 1,                  div => 1, dl => 1, fieldset => 1,
# Line 5821  sub _tree_construction_main ($) { Line 6438  sub _tree_construction_main ($) {
6438            ## Ignore the token            ## Ignore the token
6439            !!!nack ('t350.1');            !!!nack ('t350.1');
6440            !!!next-token;            !!!next-token;
6441            redo B;            next B;
6442          }          }
6443    
6444          ## has a p element in scope          ## has a p element in scope
# Line 5831  sub _tree_construction_main ($) { Line 6448  sub _tree_construction_main ($) {
6448              !!!back-token; # <form>              !!!back-token; # <form>
6449              $token = {type => END_TAG_TOKEN, tag_name => 'p',              $token = {type => END_TAG_TOKEN, tag_name => 'p',
6450                        line => $token->{line}, column => $token->{column}};                        line => $token->{line}, column => $token->{column}};
6451              redo B;              next B;
6452            } elsif ($_->[1] & SCOPING_EL) {            } elsif ($_->[1] & SCOPING_EL) {
6453              !!!cp ('t345');              !!!cp ('t345');
6454              last INSCOPE;              last INSCOPE;
# Line 5877  sub _tree_construction_main ($) { Line 6494  sub _tree_construction_main ($) {
6494            !!!nack ('t347.1');            !!!nack ('t347.1');
6495            !!!next-token;            !!!next-token;
6496          }          }
6497          redo B;          next B;
6498        } elsif ({li => 1, dt => 1, dd => 1}->{$token->{tag_name}}) {        } elsif ({li => 1, dt => 1, dd => 1}->{$token->{tag_name}}) {
6499          ## has a p element in scope          ## has a p element in scope
6500          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
# Line 5886  sub _tree_construction_main ($) { Line 6503  sub _tree_construction_main ($) {
6503              !!!back-token; # <x>              !!!back-token; # <x>
6504              $token = {type => END_TAG_TOKEN, tag_name => 'p',              $token = {type => END_TAG_TOKEN, tag_name => 'p',
6505                        line => $token->{line}, column => $token->{column}};                        line => $token->{line}, column => $token->{column}};
6506              redo B;              next B;
6507            } elsif ($_->[1] & SCOPING_EL) {            } elsif ($_->[1] & SCOPING_EL) {
6508              !!!cp ('t354');              !!!cp ('t354');
6509              last INSCOPE;              last INSCOPE;
# Line 5938  sub _tree_construction_main ($) { Line 6555  sub _tree_construction_main ($) {
6555          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6556          !!!nack ('t359.1');          !!!nack ('t359.1');
6557          !!!next-token;          !!!next-token;
6558          redo B;          next B;
6559        } elsif ($token->{tag_name} eq 'plaintext') {        } elsif ($token->{tag_name} eq 'plaintext') {
6560          ## has a p element in scope          ## has a p element in scope
6561          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
# Line 5947  sub _tree_construction_main ($) { Line 6564  sub _tree_construction_main ($) {
6564              !!!back-token; # <plaintext>              !!!back-token; # <plaintext>
6565              $token = {type => END_TAG_TOKEN, tag_name => 'p',              $token = {type => END_TAG_TOKEN, tag_name => 'p',
6566                        line => $token->{line}, column => $token->{column}};                        line => $token->{line}, column => $token->{column}};
6567              redo B;              next B;
6568            } elsif ($_->[1] & SCOPING_EL) {            } elsif ($_->[1] & SCOPING_EL) {
6569              !!!cp ('t368');              !!!cp ('t368');
6570              last INSCOPE;              last INSCOPE;
# Line 5960  sub _tree_construction_main ($) { Line 6577  sub _tree_construction_main ($) {
6577                        
6578          !!!nack ('t368.1');          !!!nack ('t368.1');
6579          !!!next-token;          !!!next-token;
6580          redo B;          next B;
6581        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
6582          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
6583            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
# Line 6001  sub _tree_construction_main ($) { Line 6618  sub _tree_construction_main ($) {
6618    
6619          !!!nack ('t374.1');          !!!nack ('t374.1');
6620          !!!next-token;          !!!next-token;
6621          redo B;          next B;
6622        } elsif ($token->{tag_name} eq 'nobr') {        } elsif ($token->{tag_name} eq 'nobr') {
6623          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6624    
# Line 6014  sub _tree_construction_main ($) { Line 6631  sub _tree_construction_main ($) {
6631              !!!back-token; # <nobr>              !!!back-token; # <nobr>
6632              $token = {type => END_TAG_TOKEN, tag_name => 'nobr',              $token = {type => END_TAG_TOKEN, tag_name => 'nobr',
6633                        line => $token->{line}, column => $token->{column}};                        line => $token->{line}, column => $token->{column}};
6634              redo B;              next B;
6635            } elsif ($node->[1] & SCOPING_EL) {            } elsif ($node->[1] & SCOPING_EL) {
6636              !!!cp ('t377');              !!!cp ('t377');
6637              last INSCOPE;              last INSCOPE;
# Line 6026  sub _tree_construction_main ($) { Line 6643  sub _tree_construction_main ($) {
6643                    
6644          !!!nack ('t377.1');          !!!nack ('t377.1');
6645          !!!next-token;          !!!next-token;
6646          redo B;          next B;
6647        } elsif ($token->{tag_name} eq 'button') {        } elsif ($token->{tag_name} eq 'button') {
6648          ## has a button element in scope          ## has a button element in scope
6649          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 6037  sub _tree_construction_main ($) { Line 6654  sub _tree_construction_main ($) {
6654              !!!back-token; # <button>              !!!back-token; # <button>
6655              $token = {type => END_TAG_TOKEN, tag_name => 'button',              $token = {type => END_TAG_TOKEN, tag_name => 'button',
6656                        line => $token->{line}, column => $token->{column}};                        line => $token->{line}, column => $token->{column}};
6657              redo B;              next B;
6658            } elsif ($node->[1] & SCOPING_EL) {            } elsif ($node->[1] & SCOPING_EL) {
6659              !!!cp ('t379');              !!!cp ('t379');
6660              last INSCOPE;              last INSCOPE;
# Line 6054  sub _tree_construction_main ($) { Line 6671  sub _tree_construction_main ($) {
6671    
6672          !!!nack ('t379.1');          !!!nack ('t379.1');
6673          !!!next-token;          !!!next-token;
6674          redo B;          next B;
6675        } elsif ({        } elsif ({
6676                  xmp => 1,                  xmp => 1,
6677                  iframe => 1,                  iframe => 1,
# Line 6070  sub _tree_construction_main ($) { Line 6687  sub _tree_construction_main ($) {
6687          }          }
6688          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
6689          $parse_rcdata->(CDATA_CONTENT_MODEL);          $parse_rcdata->(CDATA_CONTENT_MODEL);
6690          redo B;          next B;
6691        } elsif ($token->{tag_name} eq 'isindex') {        } elsif ($token->{tag_name} eq 'isindex') {
6692          !!!parse-error (type => 'isindex', token => $token);          !!!parse-error (type => 'isindex', token => $token);
6693                    
# Line 6079  sub _tree_construction_main ($) { Line 6696  sub _tree_construction_main ($) {
6696            ## Ignore the token            ## Ignore the token
6697            !!!nack ('t389'); ## NOTE: Not acknowledged.            !!!nack ('t389'); ## NOTE: Not acknowledged.
6698            !!!next-token;            !!!next-token;
6699            redo B;            next B;
6700          } else {          } else {
6701            my $at = $token->{attributes};            my $at = $token->{attributes};
6702            my $form_attrs;            my $form_attrs;
# Line 6127  sub _tree_construction_main ($) { Line 6744  sub _tree_construction_main ($) {
6744            !!!nack ('t391.1'); ## NOTE: Not acknowledged.            !!!nack ('t391.1'); ## NOTE: Not acknowledged.
6745            !!!back-token (@tokens);            !!!back-token (@tokens);
6746            !!!next-token;            !!!next-token;
6747            redo B;            next B;
6748          }          }
6749        } elsif ($token->{tag_name} eq 'textarea') {        } elsif ($token->{tag_name} eq 'textarea') {
6750          my $tag_name = $token->{tag_name};          my $tag_name = $token->{tag_name};
6751          my $el;          my $el;
6752          !!!create-element ($el, $token->{tag_name}, $token->{attributes}, $token);          !!!create-element ($el, $HTML_NS, $token->{tag_name}, $token->{attributes}, $token);
6753                    
6754          ## TODO: $self->{form_element} if defined          ## TODO: $self->{form_element} if defined
6755          $self->{content_model} = RCDATA_CONTENT_MODEL;          $self->{content_model} = RCDATA_CONTENT_MODEL;
# Line 6175  sub _tree_construction_main ($) { Line 6792  sub _tree_construction_main ($) {
6792            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);
6793          }          }
6794          !!!next-token;          !!!next-token;
6795          redo B;          next B;
6796          } elsif ($token->{tag_name} eq 'math' or
6797                   $token->{tag_name} eq 'svg') {
6798            $reconstruct_active_formatting_elements->($insert_to_current);
6799    
6800            ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6801    
6802            ## "adjust foreign attributes" - done in insert-element-f
6803            
6804            !!!insert-element-f ($token->{tag_name} eq 'math' ? $MML_NS : $SVG_NS, $token->{tag_name}, $token->{attributes}, $token);
6805            
6806            if ($self->{self_closing}) {
6807              pop @{$self->{open_elements}};
6808              !!!ack ('t398.1');
6809            } else {
6810              !!!cp ('t398.2');
6811              $self->{insertion_mode} |= IN_FOREIGN_CONTENT_IM;
6812              ## NOTE: |<body><math><mi><svg>| -> "in foreign content" insertion
6813              ## mode, "in body" (not "in foreign content") secondary insertion
6814              ## mode, maybe.
6815            }
6816    
6817            !!!next-token;
6818            next B;
6819        } elsif ({        } elsif ({
6820                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
6821                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
# Line 6187  sub _tree_construction_main ($) { Line 6827  sub _tree_construction_main ($) {
6827          ## Ignore the token          ## Ignore the token
6828          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
6829          !!!next-token;          !!!next-token;
6830          redo B;          next B;
6831                    
6832          ## ISSUE: An issue on HTML5 new elements in the spec.          ## ISSUE: An issue on HTML5 new elements in the spec.
6833        } else {        } else {
# Line 6249  sub _tree_construction_main ($) { Line 6889  sub _tree_construction_main ($) {
6889          }          }
6890                    
6891          !!!next-token;          !!!next-token;
6892          redo B;          next B;
6893        }        }
6894      } elsif ($token->{type} == END_TAG_TOKEN) {      } elsif ($token->{type} == END_TAG_TOKEN) {
6895        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
# Line 6271  sub _tree_construction_main ($) { Line 6911  sub _tree_construction_main ($) {
6911                            value => $token->{tag_name}, token => $token);                            value => $token->{tag_name}, token => $token);
6912            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
6913            !!!next-token;            !!!next-token;
6914            redo B;            next B;
6915          } # INSCOPE          } # INSCOPE
6916    
6917          for (@{$self->{open_elements}}) {          for (@{$self->{open_elements}}) {
# Line 6288  sub _tree_construction_main ($) { Line 6928  sub _tree_construction_main ($) {
6928    
6929          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
6930          !!!next-token;          !!!next-token;
6931          redo B;          next B;
6932        } elsif ($token->{tag_name} eq 'html') {        } elsif ($token->{tag_name} eq 'html') {
6933          ## TODO: Update this code.  It seems that the code below is not          ## TODO: Update this code.  It seems that the code below is not
6934          ## up-to-date, though it has same effect as speced.          ## up-to-date, though it has same effect as speced.
# Line 6306  sub _tree_construction_main ($) { Line 6946  sub _tree_construction_main ($) {
6946            }            }
6947            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6948            ## reprocess            ## reprocess
6949            redo B;            next B;
6950          } else {          } else {
6951            !!!cp ('t408');            !!!cp ('t408');
6952            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6953            ## Ignore the token            ## Ignore the token
6954            !!!next-token;            !!!next-token;
6955            redo B;            next B;
6956          }          }
6957        } elsif ({        } elsif ({
6958                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
# Line 6372  sub _tree_construction_main ($) { Line 7012  sub _tree_construction_main ($) {
7012                }->{$token->{tag_name}};                }->{$token->{tag_name}};
7013          }          }
7014          !!!next-token;          !!!next-token;
7015          redo B;          next B;
7016        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
7017          undef $self->{form_element};          undef $self->{form_element};
7018    
# Line 6417  sub _tree_construction_main ($) { Line 7057  sub _tree_construction_main ($) {
7057          }          }
7058    
7059          !!!next-token;          !!!next-token;
7060          redo B;          next B;
7061        } elsif ({        } elsif ({
7062                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
7063                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 6459  sub _tree_construction_main ($) { Line 7099  sub _tree_construction_main ($) {
7099          }          }
7100                    
7101          !!!next-token;          !!!next-token;
7102          redo B;          next B;
7103        } elsif ($token->{tag_name} eq 'p') {        } elsif ($token->{tag_name} eq 'p') {
7104          ## has an element in scope          ## has an element in scope
7105          my $i;          my $i;
# Line 6495  sub _tree_construction_main ($) { Line 7135  sub _tree_construction_main ($) {
7135            !!!cp ('t415.1');            !!!cp ('t415.1');
7136            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
7137            my $el;            my $el;
7138            !!!create-element ($el, 'p',, $token);            !!!create-element ($el, $HTML_NS, 'p',, $token);
7139            $insert->($el);            $insert->($el);
7140            ## NOTE: Not inserted into |$self->{open_elements}|.            ## NOTE: Not inserted into |$self->{open_elements}|.
7141          }          }
7142    
7143          !!!next-token;          !!!next-token;
7144          redo B;          next B;
7145        } elsif ({        } elsif ({
7146                  a => 1,                  a => 1,
7147                  b => 1, big => 1, em => 1, font => 1, i => 1,                  b => 1, big => 1, em => 1, font => 1, i => 1,
# Line 6510  sub _tree_construction_main ($) { Line 7150  sub _tree_construction_main ($) {
7150                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7151          !!!cp ('t427');          !!!cp ('t427');
7152          $formatting_end_tag->($token);          $formatting_end_tag->($token);
7153          redo B;          next B;
7154        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7155          !!!cp ('t428');          !!!cp ('t428');
7156          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag:br', token => $token);
# Line 6519  sub _tree_construction_main ($) { Line 7159  sub _tree_construction_main ($) {
7159          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
7160                    
7161          my $el;          my $el;
7162          !!!create-element ($el, 'br',, $token);          !!!create-element ($el, $HTML_NS, 'br',, $token);
7163          $insert->($el);          $insert->($el);
7164                    
7165          ## Ignore the token.          ## Ignore the token.
7166          !!!next-token;          !!!next-token;
7167          redo B;          next B;
7168        } elsif ({        } elsif ({
7169                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
7170                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
# Line 6541  sub _tree_construction_main ($) { Line 7181  sub _tree_construction_main ($) {
7181          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
7182          ## Ignore the token          ## Ignore the token
7183          !!!next-token;          !!!next-token;
7184          redo B;          next B;
7185                    
7186          ## ISSUE: Issue on HTML5 new elements in spec          ## ISSUE: Issue on HTML5 new elements in spec
7187                    
# Line 6602  sub _tree_construction_main ($) { Line 7242  sub _tree_construction_main ($) {
7242            ## Step 5;            ## Step 5;
7243            redo S2;            redo S2;
7244          } # S2          } # S2
7245          redo B;          next B;
7246        }        }
7247      }      }
7248      redo B;      next B;
7249      } continue { # B
7250        if ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM) {
7251          ## NOTE: The code below is executed in cases where it does not have
7252          ## to be, but it it is harmless even in those cases.
7253          ## has an element in scope
7254          INSCOPE: {
7255            for (reverse 0..$#{$self->{open_elements}}) {
7256              my $node = $self->{open_elements}->[$_];
7257              if ($node->[1] & FOREIGN_EL) {
7258                last INSCOPE;
7259              } elsif ($node->[1] & SCOPING_EL) {
7260                last;
7261              }
7262            }
7263            
7264            ## NOTE: No foreign element in scope.
7265            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
7266          } # INSCOPE
7267        }
7268    } # B    } # B
7269    
7270    ## Stop parsing # MUST    ## Stop parsing # MUST
# Line 6682  sub set_inner_html ($$$) { Line 7341  sub set_inner_html ($$$) {
7341          !!!cp ('i4');          !!!cp ('i4');
7342          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7343          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
7344          } elsif ($self->{next_char} <= 0x0008 or
7345                   (0x000E <= $self->{next_char} and
7346                    $self->{next_char} <= 0x001F) or
7347                   (0x007F <= $self->{next_char} and
7348                    $self->{next_char} <= 0x009F) or
7349                   (0xD800 <= $self->{next_char} and
7350                    $self->{next_char} <= 0xDFFF) or
7351                   (0xFDD0 <= $self->{next_char} and
7352                    $self->{next_char} <= 0xFDDF) or
7353                   {
7354                    0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
7355                    0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
7356                    0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
7357                    0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
7358                    0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
7359                    0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
7360                    0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
7361                    0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
7362                    0x10FFFE => 1, 0x10FFFF => 1,
7363                   }->{$self->{next_char}}) {
7364            !!!cp ('i4.1');
7365            !!!parse-error (type => 'control char', level => $self->{must_level});
7366    ## TODO: error type documentation
7367        }        }
7368      };      };
7369      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24