/[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.137 by wakaba, Sun May 18 03:46:27 2008 UTC revision 1.161 by wakaba, Wed Sep 10 10:46:50 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: 1252 parse error (revision 1264)  require IO::Handle;
 ## TODO: 8859-11 = 874 (revision 1271)  
12    
13  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
14  my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;  my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;
# Line 46  sub MISC_SPECIAL_EL () { 0b1000000000000 Line 45  sub MISC_SPECIAL_EL () { 0b1000000000000
45  sub FOREIGN_EL () { 0b10000000000000000000000000 }  sub FOREIGN_EL () { 0b10000000000000000000000000 }
46  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }  sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
47  sub MML_AXML_EL () { 0b1000000000000000000000000000 }  sub MML_AXML_EL () { 0b1000000000000000000000000000 }
48    sub RUBY_EL () { 0b10000000000000000000000000000 }
49    sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 }
50    
51  sub TABLE_ROWS_EL () {  sub TABLE_ROWS_EL () {
52    TABLE_EL |    TABLE_EL |
# Line 53  sub TABLE_ROWS_EL () { Line 54  sub TABLE_ROWS_EL () {
54    TABLE_ROW_GROUP_EL    TABLE_ROW_GROUP_EL
55  }  }
56    
57    ## NOTE: Used in "generate implied end tags" algorithm.
58    ## NOTE: There is a code where a modified version of END_TAG_OPTIONAL_EL
59    ## is used in "generate implied end tags" implementation (search for the
60    ## function mae).
61  sub END_TAG_OPTIONAL_EL () {  sub END_TAG_OPTIONAL_EL () {
62    DD_EL |    DD_EL |
63    DT_EL |    DT_EL |
64    LI_EL |    LI_EL |
65    P_EL    P_EL |
66      RUBY_COMPONENT_EL
67  }  }
68    
69    ## NOTE: Used in </body> and EOF algorithms.
70  sub ALL_END_TAG_OPTIONAL_EL () {  sub ALL_END_TAG_OPTIONAL_EL () {
71    END_TAG_OPTIONAL_EL |    DD_EL |
72      DT_EL |
73      LI_EL |
74      P_EL |
75    
76    BODY_EL |    BODY_EL |
77    HTML_EL |    HTML_EL |
78    TABLE_CELL_EL |    TABLE_CELL_EL |
# Line 97  sub SPECIAL_EL () { Line 108  sub SPECIAL_EL () {
108    ADDRESS_EL |    ADDRESS_EL |
109    BODY_EL |    BODY_EL |
110    DIV_EL |    DIV_EL |
111    END_TAG_OPTIONAL_EL |  
112      DD_EL |
113      DT_EL |
114      LI_EL |
115      P_EL |
116    
117    FORM_EL |    FORM_EL |
118    FRAMESET_EL |    FRAMESET_EL |
119    HEADING_EL |    HEADING_EL |
# Line 171  my $el_category = { Line 187  my $el_category = {
187    param => MISC_SPECIAL_EL,    param => MISC_SPECIAL_EL,
188    plaintext => MISC_SPECIAL_EL,    plaintext => MISC_SPECIAL_EL,
189    pre => MISC_SPECIAL_EL,    pre => MISC_SPECIAL_EL,
190      rp => RUBY_COMPONENT_EL,
191      rt => RUBY_COMPONENT_EL,
192      ruby => RUBY_EL,
193    s => FORMATTING_EL,    s => FORMATTING_EL,
194    script => MISC_SPECIAL_EL,    script => MISC_SPECIAL_EL,
195    select => SELECT_EL,    select => SELECT_EL,
# Line 212  my $el_category_f = { Line 231  my $el_category_f = {
231  };  };
232    
233  my $svg_attr_name = {  my $svg_attr_name = {
234      attributename => 'attributeName',
235    attributetype => 'attributeType',    attributetype => 'attributeType',
236    basefrequency => 'baseFrequency',    basefrequency => 'baseFrequency',
237    baseprofile => 'baseProfile',    baseprofile => 'baseProfile',
# Line 222  my $svg_attr_name = { Line 242  my $svg_attr_name = {
242    diffuseconstant => 'diffuseConstant',    diffuseconstant => 'diffuseConstant',
243    edgemode => 'edgeMode',    edgemode => 'edgeMode',
244    externalresourcesrequired => 'externalResourcesRequired',    externalresourcesrequired => 'externalResourcesRequired',
   fecolormatrix => 'feColorMatrix',  
   fecomposite => 'feComposite',  
   fegaussianblur => 'feGaussianBlur',  
   femorphology => 'feMorphology',  
   fetile => 'feTile',  
245    filterres => 'filterRes',    filterres => 'filterRes',
246    filterunits => 'filterUnits',    filterunits => 'filterUnits',
247    glyphref => 'glyphRef',    glyphref => 'glyphRef',
# Line 260  my $svg_attr_name = { Line 275  my $svg_attr_name = {
275    repeatcount => 'repeatCount',    repeatcount => 'repeatCount',
276    repeatdur => 'repeatDur',    repeatdur => 'repeatDur',
277    requiredextensions => 'requiredExtensions',    requiredextensions => 'requiredExtensions',
278      requiredfeatures => 'requiredFeatures',
279    specularconstant => 'specularConstant',    specularconstant => 'specularConstant',
280    specularexponent => 'specularExponent',    specularexponent => 'specularExponent',
281    spreadmethod => 'spreadMethod',    spreadmethod => 'spreadMethod',
# Line 332  my $c1_entity_char = { Line 348  my $c1_entity_char = {
348  }; # $c1_entity_char  }; # $c1_entity_char
349    
350  sub parse_byte_string ($$$$;$) {  sub parse_byte_string ($$$$;$) {
351      my $self = shift;
352      my $charset_name = shift;
353      open my $input, '<', ref $_[0] ? $_[0] : \($_[0]);
354      return $self->parse_byte_stream ($charset_name, $input, @_[1..$#_]);
355    } # parse_byte_string
356    
357    sub parse_byte_stream ($$$$;$) {
358    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
359    my $charset_name = shift;    my $charset_name = shift;
360    open my $byte_stream, '<', ref $_[0] ? $_[0] : \($_[0]);    my $byte_stream = $_[0];
361    
362    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
363      my (%opt) = @_;      my (%opt) = @_;
# Line 349  sub parse_byte_string ($$$$;$) { Line 372  sub parse_byte_string ($$$$;$) {
372    my ($char_stream, $e_status);    my ($char_stream, $e_status);
373    
374    SNIFFING: {    SNIFFING: {
375        ## NOTE: By setting |allow_fallback| option true when the
376        ## |get_decode_handle| method is invoked, we ignore what the HTML5
377        ## spec requires, i.e. unsupported encoding should be ignored.
378          ## TODO: We should not do this unless the parser is invoked
379          ## in the conformance checking mode, in which this behavior
380          ## would be useful.
381    
382      ## Step 1      ## Step 1
383      if (defined $charset_name) {      if (defined $charset_name) {
384        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
385              ## TODO: Is this ok?  Transfer protocol's parameter should be
386              ## interpreted in its semantics?
387    
388        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
389        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
# Line 376  sub parse_byte_string ($$$$;$) { Line 407  sub parse_byte_string ($$$$;$) {
407    
408      ## Step 3      ## Step 3
409      if ($byte_buffer =~ /^\xFE\xFF/) {      if ($byte_buffer =~ /^\xFE\xFF/) {
410        $charset = Message::Charset::Info->get_by_iana_name ('utf-16be');        $charset = Message::Charset::Info->get_by_html_name ('utf-16be');
411        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
412            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
413             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
414        $self->{confident} = 1;        $self->{confident} = 1;
415        last SNIFFING;        last SNIFFING;
416      } elsif ($byte_buffer =~ /^\xFF\xFE/) {      } elsif ($byte_buffer =~ /^\xFF\xFE/) {
417        $charset = Message::Charset::Info->get_by_iana_name ('utf-16le');        $charset = Message::Charset::Info->get_by_html_name ('utf-16le');
418        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
419            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
420             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
421        $self->{confident} = 1;        $self->{confident} = 1;
422        last SNIFFING;        last SNIFFING;
423      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {      } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
424        $charset = Message::Charset::Info->get_by_iana_name ('utf-8');        $charset = Message::Charset::Info->get_by_html_name ('utf-8');
425        ($char_stream, $e_status) = $charset->get_decode_handle        ($char_stream, $e_status) = $charset->get_decode_handle
426            ($byte_stream, allow_error_reporting => 1,            ($byte_stream, allow_error_reporting => 1,
427             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
# Line 409  sub parse_byte_string ($$$$;$) { Line 440  sub parse_byte_string ($$$$;$) {
440      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string      $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
441          ($byte_buffer);          ($byte_buffer);
442      if (defined $charset_name) {      if (defined $charset_name) {
443        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);        $charset = Message::Charset::Info->get_by_html_name ($charset_name);
444    
445        ## ISSUE: Unsupported encoding is not ignored according to the spec.        ## ISSUE: Unsupported encoding is not ignored according to the spec.
446        require Whatpm::Charset::DecodeHandle;        require Whatpm::Charset::DecodeHandle;
# Line 420  sub parse_byte_string ($$$$;$) { Line 451  sub parse_byte_string ($$$$;$) {
451             allow_fallback => 1, byte_buffer => \$byte_buffer);             allow_fallback => 1, byte_buffer => \$byte_buffer);
452        if ($char_stream) {        if ($char_stream) {
453          $buffer->{buffer} = $byte_buffer;          $buffer->{buffer} = $byte_buffer;
454          !!!parse-error (type => 'sniffing:chardet', ## TODO: type name          !!!parse-error (type => 'sniffing:chardet',
455                          value => $charset_name,                          text => $charset_name,
456                          level => $self->{info_level},                          level => $self->{level}->{info},
457                            layer => 'encode',
458                          line => 1, column => 1);                          line => 1, column => 1);
459          $self->{confident} = 0;          $self->{confident} = 0;
460          last SNIFFING;          last SNIFFING;
# Line 431  sub parse_byte_string ($$$$;$) { Line 463  sub parse_byte_string ($$$$;$) {
463    
464      ## Step 7: default      ## Step 7: default
465      ## TODO: Make this configurable.      ## TODO: Make this configurable.
466      $charset = Message::Charset::Info->get_by_iana_name ('windows-1252');      $charset = Message::Charset::Info->get_by_html_name ('windows-1252');
467          ## NOTE: We choose |windows-1252| here, since |utf-8| should be          ## NOTE: We choose |windows-1252| here, since |utf-8| should be
468          ## detectable in the step 6.          ## detectable in the step 6.
469      require Whatpm::Charset::DecodeHandle;      require Whatpm::Charset::DecodeHandle;
# Line 443  sub parse_byte_string ($$$$;$) { Line 475  sub parse_byte_string ($$$$;$) {
475                                         allow_fallback => 1,                                         allow_fallback => 1,
476                                         byte_buffer => \$byte_buffer);                                         byte_buffer => \$byte_buffer);
477      $buffer->{buffer} = $byte_buffer;      $buffer->{buffer} = $byte_buffer;
478      !!!parse-error (type => 'sniffing:default', ## TODO: type name      !!!parse-error (type => 'sniffing:default',
479                      value => 'windows-1252',                      text => 'windows-1252',
480                      level => $self->{info_level},                      level => $self->{level}->{info},
481                      line => 1, column => 1);                      line => 1, column => 1,
482                        layer => 'encode');
483      $self->{confident} = 0;      $self->{confident} = 0;
484    } # SNIFFING    } # SNIFFING
485    
   $self->{input_encoding} = $charset->get_iana_name;  
486    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {    if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
487      !!!parse-error (type => 'chardecode:fallback', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
488                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:fallback',
489                      level => $self->{unsupported_level},                      #text => $self->{input_encoding},
490                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
491                        line => 1, column => 1,
492                        layer => 'encode');
493    } elsif (not ($e_status &    } elsif (not ($e_status &
494                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                  Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
495      !!!parse-error (type => 'chardecode:no error', ## TODO: type name      $self->{input_encoding} = $charset->get_iana_name;
496                      value => $self->{input_encoding},      !!!parse-error (type => 'chardecode:no error',
497                      level => $self->{unsupported_level},                      text => $self->{input_encoding},
498                      line => 1, column => 1);                      level => $self->{level}->{uncertain},
499                        line => 1, column => 1,
500                        layer => 'encode');
501      } else {
502        $self->{input_encoding} = $charset->get_iana_name;
503    }    }
504    
505    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
# Line 469  sub parse_byte_string ($$$$;$) { Line 507  sub parse_byte_string ($$$$;$) {
507      $charset_name = shift;      $charset_name = shift;
508      my $token = shift;      my $token = shift;
509    
510      $charset = Message::Charset::Info->get_by_iana_name ($charset_name);      $charset = Message::Charset::Info->get_by_html_name ($charset_name);
511      ($char_stream, $e_status) = $charset->get_decode_handle      ($char_stream, $e_status) = $charset->get_decode_handle
512          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,          ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
513           byte_buffer => \ $buffer->{buffer});           byte_buffer => \ $buffer->{buffer});
# Line 478  sub parse_byte_string ($$$$;$) { Line 516  sub parse_byte_string ($$$$;$) {
516        ## "Change the encoding" algorithm:        ## "Change the encoding" algorithm:
517    
518        ## Step 1            ## Step 1    
519        if ($charset->{iana_names}->{'utf-16'}) { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?        if ($charset->{category} &
520          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');            Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
521            $charset = Message::Charset::Info->get_by_html_name ('utf-8');
522          ($char_stream, $e_status) = $charset->get_decode_handle          ($char_stream, $e_status) = $charset->get_decode_handle
523              ($byte_stream,              ($byte_stream,
524               byte_buffer => \ $buffer->{buffer});               byte_buffer => \ $buffer->{buffer});
# Line 489  sub parse_byte_string ($$$$;$) { Line 528  sub parse_byte_string ($$$$;$) {
528        ## Step 2        ## Step 2
529        if (defined $self->{input_encoding} and        if (defined $self->{input_encoding} and
530            $self->{input_encoding} eq $charset_name) {            $self->{input_encoding} eq $charset_name) {
531          !!!parse-error (type => 'charset label:matching', ## TODO: type          !!!parse-error (type => 'charset label:matching',
532                          value => $charset_name,                          text => $charset_name,
533                          level => $self->{info_level});                          level => $self->{level}->{info});
534          $self->{confident} = 1;          $self->{confident} = 1;
535          return;          return;
536        }        }
537    
538        !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.        !!!parse-error (type => 'charset label detected',
539            ':'.$charset_name, level => 'w', token => $token);                        text => $self->{input_encoding},
540                          value => $charset_name,
541                          level => $self->{level}->{warn},
542                          token => $token);
543                
544        ## Step 3        ## Step 3
545        # if (can) {        # if (can) {
# Line 513  sub parse_byte_string ($$$$;$) { Line 555  sub parse_byte_string ($$$$;$) {
555    
556    my $char_onerror = sub {    my $char_onerror = sub {
557      my (undef, $type, %opt) = @_;      my (undef, $type, %opt) = @_;
558      !!!parse-error (%opt, type => $type,      !!!parse-error (layer => 'encode',
559                        %opt, type => $type,
560                      line => $self->{line}, column => $self->{column} + 1);                      line => $self->{line}, column => $self->{column} + 1);
561      if ($opt{octets}) {      if ($opt{octets}) {
562        ${$opt{octets}} = "\x{FFFD}"; # relacement character        ${$opt{octets}} = "\x{FFFD}"; # relacement character
# Line 528  sub parse_byte_string ($$$$;$) { Line 571  sub parse_byte_string ($$$$;$) {
571    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
572      ## NOTE: Invoked after {change_encoding}.      ## NOTE: Invoked after {change_encoding}.
573    
     $self->{input_encoding} = $charset->get_iana_name;  
574      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
575        !!!parse-error (type => 'chardecode:fallback', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name?
576                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:fallback',
577                        level => $self->{unsupported_level},                        level => $self->{level}->{uncertain},
578                        line => 1, column => 1);                        #text => $self->{input_encoding},
579                          line => 1, column => 1,
580                          layer => 'encode');
581      } elsif (not ($e_status &      } elsif (not ($e_status &
582                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
583        !!!parse-error (type => 'chardecode:no error', ## TODO: type name        $self->{input_encoding} = $charset->get_iana_name;
584                        value => $self->{input_encoding},        !!!parse-error (type => 'chardecode:no error',
585                        level => $self->{unsupported_level},                        text => $self->{input_encoding},
586                        line => 1, column => 1);                        level => $self->{level}->{uncertain},
587                          line => 1, column => 1,
588                          layer => 'encode');
589        } else {
590          $self->{input_encoding} = $charset->get_iana_name;
591      }      }
592      $self->{confident} = 1;      $self->{confident} = 1;
593      $char_stream->onerror ($char_onerror);      $char_stream->onerror ($char_onerror);
594      $return = $self->parse_char_stream ($char_stream, @args);      $return = $self->parse_char_stream ($char_stream, @args);
595    };    };
596    return $return;    return $return;
597  } # parse_byte_string  } # parse_byte_stream
598    
599  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM
600  ## 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 559  sub parse_byte_string ($$$$;$) { Line 607  sub parse_byte_string ($$$$;$) {
607    
608  sub parse_char_string ($$$;$) {  sub parse_char_string ($$$;$) {
609    my $self = shift;    my $self = shift;
610    open my $input, '<:utf8', ref $_[0] ? $_[0] : \($_[0]);    require utf8;
611      my $s = ref $_[0] ? $_[0] : \($_[0]);
612      open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
613    return $self->parse_char_stream ($input, @_[1..$#_]);    return $self->parse_char_stream ($input, @_[1..$#_]);
614  } # parse_char_string  } # parse_char_string
615  *parse_string = \&parse_char_string;  *parse_string = \&parse_char_string;
# Line 585  sub parse_char_stream ($$$;$) { Line 635  sub parse_char_stream ($$$;$) {
635      pop @{$self->{prev_char}};      pop @{$self->{prev_char}};
636      unshift @{$self->{prev_char}}, $self->{next_char};      unshift @{$self->{prev_char}}, $self->{next_char};
637    
638      my $char = $input->getc;      my $char;
639        if (defined $self->{next_next_char}) {
640          $char = $self->{next_next_char};
641          delete $self->{next_next_char};
642        } else {
643          $char = $input->getc;
644        }
645      $self->{next_char} = -1 and return unless defined $char;      $self->{next_char} = -1 and return unless defined $char;
646      $self->{next_char} = ord $char;      $self->{next_char} = ord $char;
647    
# Line 600  sub parse_char_stream ($$$;$) { Line 656  sub parse_char_stream ($$$;$) {
656      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
657        !!!cp ('j2');        !!!cp ('j2');
658        my $next = $input->getc;        my $next = $input->getc;
659        if ($next ne "\x0A") {        if (defined $next and $next ne "\x0A") {
660          $input->ungetc ($next);          $self->{next_next_char} = $next;
661        }        }
662        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
663        $self->{line}++;        $self->{line}++;
# Line 630  sub parse_char_stream ($$$;$) { Line 686  sub parse_char_stream ($$$;$) {
686                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
687               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
688        !!!cp ('j5');        !!!cp ('j5');
689        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
690  ## TODO: error type documentation          !!!parse-error (type => 'control char',
691                            text => (sprintf 'U+%04X', $self->{next_char}));
692          } else {
693            !!!parse-error (type => 'control char',
694                            text => (sprintf 'U-%08X', $self->{next_char}));
695          }
696      }      }
697    };    };
698    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 660  sub parse_char_stream ($$$;$) { Line 721  sub parse_char_stream ($$$;$) {
721  sub new ($) {  sub new ($) {
722    my $class = shift;    my $class = shift;
723    my $self = bless {    my $self = bless {
724      must_level => 'm',      level => {must => 'm',
725      should_level => 's',                should => 's',
726      good_level => 'w',                warn => 'w',
727      warn_level => 'w',                info => 'i',
728      info_level => 'i',                uncertain => 'u'},
     unsupported_level => 'u',  
729    }, $class;    }, $class;
730    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
731      $self->{next_char} = -1;      $self->{next_char} = -1;
# Line 812  sub _initialize_tokenizer ($) { Line 872  sub _initialize_tokenizer ($) {
872  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
873  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
874    
 ## ISSUE: "When a DOCTYPE token is created, its  
 ## <i>self-closing flag</i> must be unset (its other state is that it  
 ## be set), and its attributes list must be empty.": Wrong subject?  
   
875  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
876    
877  ## Before each step, UA MAY check to see if either one of the scripts in  ## Before each step, UA MAY check to see if either one of the scripts in
# Line 1328  sub _get_next_token ($) { Line 1384  sub _get_next_token ($) {
1384          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1385              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1386            !!!cp (57);            !!!cp (57);
1387            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});            !!!parse-error (type => 'duplicate attribute', text => $self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});
1388            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1389          } else {          } else {
1390            !!!cp (58);            !!!cp (58);
# Line 1499  sub _get_next_token ($) { Line 1555  sub _get_next_token ($) {
1555    
1556          redo A;          redo A;
1557        } else {        } else {
1558          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1559                $self->{next_char} == 0x0027) { # '
1560              !!!cp (78);
1561              !!!parse-error (type => 'bad attribute name');
1562            } else {
1563              !!!cp (82);
1564            }
1565          $self->{current_attribute}          $self->{current_attribute}
1566              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1567                 value => '',                 value => '',
# Line 1534  sub _get_next_token ($) { Line 1596  sub _get_next_token ($) {
1596          !!!next-input-character;          !!!next-input-character;
1597          redo A;          redo A;
1598        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1599            !!!parse-error (type => 'empty unquoted attribute value');
1600          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1601            !!!cp (87);            !!!cp (87);
1602            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1810  sub _get_next_token ($) { Line 1873  sub _get_next_token ($) {
1873          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1874          !!!next-input-character;          !!!next-input-character;
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 (122.3);
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 (122.1);
1884                !!!parse-error (type => 'end tag attribute');
1885              } else {
1886                ## NOTE: This state should never be reached.
1887                !!!cp (122.2);
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.1');          !!!cp ('124.1');
1898          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1842  sub _get_next_token ($) { Line 1925  sub _get_next_token ($) {
1925          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1926    
1927          redo A;          redo A;
1928          } elsif ($self->{next_char} == -1) {
1929            !!!parse-error (type => 'unclosed tag');
1930            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1931              !!!cp (124.7);
1932              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1933            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1934              if ($self->{current_token}->{attributes}) {
1935                !!!cp (124.5);
1936                !!!parse-error (type => 'end tag attribute');
1937              } else {
1938                ## NOTE: This state should never be reached.
1939                !!!cp (124.6);
1940              }
1941            } else {
1942              die "$0: $self->{current_token}->{type}: Unknown token type";
1943            }
1944            $self->{state} = DATA_STATE;
1945            ## Reconsume.
1946            !!!emit ($self->{current_token}); # start tag or end tag
1947            redo A;
1948        } else {        } else {
1949          !!!cp ('124.4');          !!!cp ('124.4');
1950          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 2599  sub _get_next_token ($) { Line 2702  sub _get_next_token ($) {
2702          redo A;          redo A;
2703        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2704          !!!cp (208);          !!!cp (208);
2705          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2706    
2707          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2708          !!!next-input-character;          !!!next-input-character;
# Line 2635  sub _get_next_token ($) { Line 2738  sub _get_next_token ($) {
2738          redo A;          redo A;
2739        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2740          !!!cp (212);          !!!cp (212);
2741          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2742    
2743          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2744          !!!next-input-character;          !!!next-input-character;
# Line 2683  sub _get_next_token ($) { Line 2786  sub _get_next_token ($) {
2786        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2787          !!!cp (217);          !!!cp (217);
2788          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2789          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2790          ## reconsume          ## reconsume
2791    
# Line 2845  sub _tokenize_attempt_to_consume_an_enti Line 2947  sub _tokenize_attempt_to_consume_an_enti
2947    
2948          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2949            !!!cp (1008);            !!!cp (1008);
2950            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2951                              text => (sprintf 'U+%04X', $code),
2952                              line => $l, column => $c);
2953            $code = 0xFFFD;            $code = 0xFFFD;
2954          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2955            !!!cp (1009);            !!!cp (1009);
2956            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2957                              text => (sprintf 'U-%08X', $code),
2958                              line => $l, column => $c);
2959            $code = 0xFFFD;            $code = 0xFFFD;
2960          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2961            !!!cp (1010);            !!!cp (1010);
# Line 2857  sub _tokenize_attempt_to_consume_an_enti Line 2963  sub _tokenize_attempt_to_consume_an_enti
2963            $code = 0x000A;            $code = 0x000A;
2964          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2965            !!!cp (1011);            !!!cp (1011);
2966            !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c);
2967            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2968          }          }
2969    
# Line 2890  sub _tokenize_attempt_to_consume_an_enti Line 2996  sub _tokenize_attempt_to_consume_an_enti
2996    
2997        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2998          !!!cp (1015);          !!!cp (1015);
2999          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3000                            text => (sprintf 'U+%04X', $code),
3001                            line => $l, column => $c);
3002          $code = 0xFFFD;          $code = 0xFFFD;
3003        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
3004          !!!cp (1016);          !!!cp (1016);
3005          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
3006                            text => (sprintf 'U-%08X', $code),
3007                            line => $l, column => $c);
3008          $code = 0xFFFD;          $code = 0xFFFD;
3009        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
3010          !!!cp (1017);          !!!cp (1017);
3011          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
3012                            line => $l, column => $c);
3013          $code = 0x000A;          $code = 0x000A;
3014        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3015          !!!cp (1018);          !!!cp (1018);
3016          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3017                            text => (sprintf 'U+%04X', $code),
3018                            line => $l, column => $c);
3019          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3020        }        }
3021                
# Line 3000  sub _initialize_tree_constructor ($) { Line 3113  sub _initialize_tree_constructor ($) {
3113    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3114    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3115    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3116      $self->{document}->set_user_data (manakai_source_line => 1);
3117      $self->{document}->set_user_data (manakai_source_column => 1);
3118  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3119    
3120  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 3054  sub _tree_construction_initial ($) { Line 3169  sub _tree_construction_initial ($) {
3169        ## language.        ## language.
3170        my $doctype_name = $token->{name};        my $doctype_name = $token->{name};
3171        $doctype_name = '' unless defined $doctype_name;        $doctype_name = '' unless defined $doctype_name;
3172        $doctype_name =~ tr/a-z/A-Z/;        $doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive
3173        if (not defined $token->{name} or # <!DOCTYPE>        if (not defined $token->{name} or # <!DOCTYPE>
           defined $token->{public_identifier} or  
3174            defined $token->{system_identifier}) {            defined $token->{system_identifier}) {
3175          !!!cp ('t1');          !!!cp ('t1');
3176          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3177        } elsif ($doctype_name ne 'HTML') {        } elsif ($doctype_name ne 'HTML') {
3178          !!!cp ('t2');          !!!cp ('t2');
         ## ISSUE: ASCII case-insensitive? (in fact it does not matter)  
3179          !!!parse-error (type => 'not HTML5', token => $token);          !!!parse-error (type => 'not HTML5', token => $token);
3180          } elsif (defined $token->{public_identifier}) {
3181            if ($token->{public_identifier} eq 'XSLT-compat') {
3182              !!!cp ('t1.2');
3183              !!!parse-error (type => 'XSLT-compat', token => $token,
3184                              level => $self->{level}->{should});
3185            } else {
3186              !!!parse-error (type => 'not HTML5', token => $token);
3187            }
3188        } else {        } else {
3189          !!!cp ('t3');          !!!cp ('t3');
3190            #
3191        }        }
3192                
3193        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
# Line 3086  sub _tree_construction_initial ($) { Line 3208  sub _tree_construction_initial ($) {
3208        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3209          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3210          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3211          if ({          my $prefix = [
3212            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3213            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3214            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3215            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3216            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3217            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3218            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3219            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3220            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3221            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3222            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3223            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3224            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3225            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3226            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3227            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3228            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3229            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3230            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3231            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3232            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3233            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3234            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3235            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3236            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3237            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3238            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3239            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3240            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3241            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3242            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3243            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3244            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3245            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3246            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3247            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3248            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3249            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3250            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3251            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3252            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3253            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3254            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3255            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3256            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3257            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3258            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3259            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3260            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3261            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3262            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3263            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3264            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3265            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3266            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3267            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3268            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3269            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3270            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3271            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3272            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3273            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3274            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3275            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3276            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3277            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3278            "-//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}) {  
3279            !!!cp ('t5');            !!!cp ('t5');
3280            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3281          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3282                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3283            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3284              !!!cp ('t6');              !!!cp ('t6');
3285              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 3171  sub _tree_construction_initial ($) { Line 3287  sub _tree_construction_initial ($) {
3287              !!!cp ('t7');              !!!cp ('t7');
3288              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3289            }            }
3290          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3291                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3292            !!!cp ('t8');            !!!cp ('t8');
3293            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3294          } else {          } else {
# Line 3185  sub _tree_construction_initial ($) { Line 3301  sub _tree_construction_initial ($) {
3301          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3302          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3303          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") {
3304            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3305              ## marked as quirks.
3306            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3307            !!!cp ('t11');            !!!cp ('t11');
3308          } else {          } else {
# Line 3357  sub _reset_insertion_mode ($) { Line 3474  sub _reset_insertion_mode ($) {
3474        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3475          $last = 1;          $last = 1;
3476          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3477            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3478              !!!cp ('t27');            $node = $self->{inner_html_node};
3479              #          } else {
3480            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3481          }          }
3482        }        }
3483              
3484      ## Step 4..14        ## Step 4..14
3485      my $new_mode;        my $new_mode;
3486      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3487        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3488        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3489        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3490        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3491        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3492      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3493        $new_mode = {          if ($last) {
3494              !!!cp ('t28.2');
3495              #
3496            } else {
3497              !!!cp ('t28.3');
3498              $new_mode = IN_CELL_IM;
3499            }
3500          } else {
3501            !!!cp ('t28.4');
3502            $new_mode = {
3503                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3504                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3505                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3506                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3507                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3508                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3393  sub _reset_insertion_mode ($) { Line 3514  sub _reset_insertion_mode ($) {
3514                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3515                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3516                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3517      }        }
3518      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3519                
3520        ## Step 15        ## Step 15
3521        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3568  sub _tree_construction_main ($) { Line 3689  sub _tree_construction_main ($) {
3689        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3690        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3691          !!!cp ('t43');          !!!cp ('t43');
3692          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3693        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3694          !!!cp ('t44');          !!!cp ('t44');
3695          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3696        } else {        } else {
3697          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3698        }        }
# Line 3608  sub _tree_construction_main ($) { Line 3729  sub _tree_construction_main ($) {
3729        ## Ignore the token        ## Ignore the token
3730      } else {      } else {
3731        !!!cp ('t48');        !!!cp ('t48');
3732        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3733        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3734        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3735      }      }
# Line 3659  sub _tree_construction_main ($) { Line 3780  sub _tree_construction_main ($) {
3780        } # AFE        } # AFE
3781        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3782          !!!cp ('t53');          !!!cp ('t53');
3783          !!!parse-error (type => 'unmatched end tag:'.$tag_name, token => $end_tag_token);          !!!parse-error (type => 'unmatched end tag', text => $tag_name, token => $end_tag_token);
3784          ## Ignore the token          ## Ignore the token
3785          !!!next-token;          !!!next-token;
3786          return;          return;
# Line 3676  sub _tree_construction_main ($) { Line 3797  sub _tree_construction_main ($) {
3797              last INSCOPE;              last INSCOPE;
3798            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3799              !!!cp ('t55');              !!!cp ('t55');
3800              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3801                                text => $token->{tag_name},
3802                              token => $end_tag_token);                              token => $end_tag_token);
3803              ## Ignore the token              ## Ignore the token
3804              !!!next-token;              !!!next-token;
# Line 3689  sub _tree_construction_main ($) { Line 3811  sub _tree_construction_main ($) {
3811        } # INSCOPE        } # INSCOPE
3812        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3813          !!!cp ('t57');          !!!cp ('t57');
3814          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3815                            text => $token->{tag_name},
3816                          token => $end_tag_token);                          token => $end_tag_token);
3817          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3818          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3698  sub _tree_construction_main ($) { Line 3821  sub _tree_construction_main ($) {
3821        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3822          !!!cp ('t58');          !!!cp ('t58');
3823          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3824                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3825                              ->manakai_local_name,                              ->manakai_local_name,
3826                          token => $end_tag_token);                          token => $end_tag_token);
3827        }        }
# Line 3907  sub _tree_construction_main ($) { Line 4030  sub _tree_construction_main ($) {
4030    B: while (1) {    B: while (1) {
4031      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4032        !!!cp ('t73');        !!!cp ('t73');
4033        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4034        ## Ignore the token        ## Ignore the token
4035        ## Stay in the phase        ## Stay in the phase
4036        !!!next-token;        !!!next-token;
# Line 3916  sub _tree_construction_main ($) { Line 4039  sub _tree_construction_main ($) {
4039               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4040        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4041          !!!cp ('t79');          !!!cp ('t79');
4042          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4043          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4044        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4045          !!!cp ('t80');          !!!cp ('t80');
4046          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4047          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4048        } else {        } else {
4049          !!!cp ('t81');          !!!cp ('t81');
# Line 3971  sub _tree_construction_main ($) { Line 4094  sub _tree_construction_main ($) {
4094            #            #
4095          } elsif ({          } elsif ({
4096                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4097                    center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4098                    embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4099                    h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4100                    li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4101                    ruby => 1, s => 1, small => 1, span => 1, strong => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4102                    sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4103                    var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4104                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4105            !!!cp ('t87.2');            !!!cp ('t87.2');
4106            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4107                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4108                                ->manakai_local_name,                                ->manakai_local_name,
4109                            token => $token);                            token => $token);
4110    
# Line 4057  sub _tree_construction_main ($) { Line 4180  sub _tree_construction_main ($) {
4180          !!!cp ('t87.5');          !!!cp ('t87.5');
4181          #          #
4182        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4183          !!!cp ('t87.6');          !!!cp ('t87.6');
4184          #          !!!parse-error (type => 'not closed',
4185          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4186                                ->manakai_local_name,
4187                            token => $token);
4188    
4189            pop @{$self->{open_elements}}
4190                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4191    
4192            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4193            ## Reprocess.
4194            next B;
4195        } else {        } else {
4196          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4197        }        }
# Line 4101  sub _tree_construction_main ($) { Line 4232  sub _tree_construction_main ($) {
4232            !!!cp ('t90');            !!!cp ('t90');
4233            ## As if </noscript>            ## As if </noscript>
4234            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4235            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4236                        
4237            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4238            ## As if </head>            ## As if </head>
# Line 4137  sub _tree_construction_main ($) { Line 4268  sub _tree_construction_main ($) {
4268              !!!next-token;              !!!next-token;
4269              next B;              next B;
4270            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4271              !!!cp ('t94');              !!!cp ('t93.2');
4272              #              !!!parse-error (type => 'after head', text => 'head',
4273                                token => $token);
4274                ## Ignore the token
4275                !!!nack ('t93.3');
4276                !!!next-token;
4277                next B;
4278            } else {            } else {
4279              !!!cp ('t95');              !!!cp ('t95');
4280              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4281                                token => $token); # or in head noscript
4282              ## Ignore the token              ## Ignore the token
4283              !!!nack ('t95.1');              !!!nack ('t95.1');
4284              !!!next-token;              !!!next-token;
# Line 4166  sub _tree_construction_main ($) { Line 4303  sub _tree_construction_main ($) {
4303                  !!!cp ('t98');                  !!!cp ('t98');
4304                  ## As if </noscript>                  ## As if </noscript>
4305                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4306                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4307                                    token => $token);
4308                                
4309                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4310                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4177  sub _tree_construction_main ($) { Line 4315  sub _tree_construction_main ($) {
4315                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4316                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4317                  !!!cp ('t100');                  !!!cp ('t100');
4318                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4319                                    text => $token->{tag_name}, token => $token);
4320                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4321                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4322                } else {                } else {
# Line 4194  sub _tree_construction_main ($) { Line 4333  sub _tree_construction_main ($) {
4333                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4334                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4335                  !!!cp ('t102');                  !!!cp ('t102');
4336                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4337                                    text => $token->{tag_name}, token => $token);
4338                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4339                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4340                } else {                } else {
# Line 4211  sub _tree_construction_main ($) { Line 4351  sub _tree_construction_main ($) {
4351                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4352                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4353                  !!!cp ('t104');                  !!!cp ('t104');
4354                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4355                                    text => $token->{tag_name}, token => $token);
4356                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4357                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4358                } else {                } else {
# Line 4235  sub _tree_construction_main ($) { Line 4376  sub _tree_construction_main ($) {
4376                                                 ->{has_reference});                                                 ->{has_reference});
4377                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
4378                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4379                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4380                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4381                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4382                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4383                      !!!cp ('t107');                      !!!cp ('t107');
4384                      ## NOTE: Whether the encoding is supported or not is handled                      ## NOTE: Whether the encoding is supported or not is handled
4385                      ## in the {change_encoding} callback.                      ## in the {change_encoding} callback.
# Line 4280  sub _tree_construction_main ($) { Line 4421  sub _tree_construction_main ($) {
4421                  !!!cp ('t111');                  !!!cp ('t111');
4422                  ## As if </noscript>                  ## As if </noscript>
4423                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4424                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4425                                    token => $token);
4426                                
4427                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4428                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4429                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4430                  !!!cp ('t112');                  !!!cp ('t112');
4431                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4432                                    text => $token->{tag_name}, token => $token);
4433                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4434                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4435                } else {                } else {
# Line 4300  sub _tree_construction_main ($) { Line 4443  sub _tree_construction_main ($) {
4443                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4444                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4445                next B;                next B;
4446              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4447                         $token->{tag_name} eq 'noframes') {
4448                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4449                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4450                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4451                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4452                  !!!cp ('t114');                  !!!cp ('t114');
4453                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4454                                    text => $token->{tag_name}, token => $token);
4455                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4456                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4457                } else {                } else {
# Line 4327  sub _tree_construction_main ($) { Line 4472  sub _tree_construction_main ($) {
4472                  next B;                  next B;
4473                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4474                  !!!cp ('t117');                  !!!cp ('t117');
4475                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4476                                    token => $token);
4477                  ## Ignore the token                  ## Ignore the token
4478                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4479                  !!!next-token;                  !!!next-token;
# Line 4341  sub _tree_construction_main ($) { Line 4487  sub _tree_construction_main ($) {
4487                  !!!cp ('t119');                  !!!cp ('t119');
4488                  ## As if </noscript>                  ## As if </noscript>
4489                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4490                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4491                                    token => $token);
4492                                
4493                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4494                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4495                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4496                  !!!cp ('t120');                  !!!cp ('t120');
4497                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4498                                    text => $token->{tag_name}, token => $token);
4499                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4500                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4501                } else {                } else {
# Line 4365  sub _tree_construction_main ($) { Line 4513  sub _tree_construction_main ($) {
4513                  !!!cp ('t122');                  !!!cp ('t122');
4514                  ## As if </noscript>                  ## As if </noscript>
4515                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4516                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4517                                    text => $token->{tag_name}, token => $token);
4518                                    
4519                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4520                  ## As if </head>                  ## As if </head>
# Line 4404  sub _tree_construction_main ($) { Line 4553  sub _tree_construction_main ($) {
4553                !!!cp ('t129');                !!!cp ('t129');
4554                ## As if </noscript>                ## As if </noscript>
4555                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4556                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4557                                  text => $token->{tag_name}, token => $token);
4558                                
4559                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4560                ## As if </head>                ## As if </head>
# Line 4447  sub _tree_construction_main ($) { Line 4597  sub _tree_construction_main ($) {
4597                  !!!cp ('t133');                  !!!cp ('t133');
4598                  ## As if </noscript>                  ## As if </noscript>
4599                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4600                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4601                                    text => 'head', token => $token);
4602                                    
4603                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4604                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4460  sub _tree_construction_main ($) { Line 4611  sub _tree_construction_main ($) {
4611                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4612                  !!!next-token;                  !!!next-token;
4613                  next B;                  next B;
4614                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4615                    !!!cp ('t134.1');
4616                    !!!parse-error (type => 'unmatched end tag', text => 'head',
4617                                    token => $token);
4618                    ## Ignore the token
4619                    !!!next-token;
4620                    next B;
4621                } else {                } else {
4622                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4623                }                }
4624              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4625                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4471  sub _tree_construction_main ($) { Line 4628  sub _tree_construction_main ($) {
4628                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4629                  !!!next-token;                  !!!next-token;
4630                  next B;                  next B;
4631                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4632                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4633                  !!!cp ('t137');                  !!!cp ('t137');
4634                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4635                                    text => 'noscript', token => $token);
4636                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4637                  !!!next-token;                  !!!next-token;
4638                  next B;                  next B;
# Line 4484  sub _tree_construction_main ($) { Line 4643  sub _tree_construction_main ($) {
4643              } elsif ({              } elsif ({
4644                        body => 1, html => 1,                        body => 1, html => 1,
4645                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4646                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4647                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4648                  ## As if <head>                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
                 !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);  
                 $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});  
                 push @{$self->{open_elements}},  
                     [$self->{head_element}, $el_category->{head}];  
   
                 $self->{insertion_mode} = IN_HEAD_IM;  
                 ## Reprocess in the "in head" insertion mode...  
               } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {  
4649                  !!!cp ('t140');                  !!!cp ('t140');
4650                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4651                                    text => $token->{tag_name}, token => $token);
4652                    ## Ignore the token
4653                    !!!next-token;
4654                    next B;
4655                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4656                    !!!cp ('t140.1');
4657                    !!!parse-error (type => 'unmatched end tag',
4658                                    text => $token->{tag_name}, token => $token);
4659                  ## Ignore the token                  ## Ignore the token
4660                  !!!next-token;                  !!!next-token;
4661                  next B;                  next B;
4662                } else {                } else {
4663                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4664                }                }
4665                              } elsif ($token->{tag_name} eq 'p') {
4666                #                !!!cp ('t142');
4667              } elsif ({                !!!parse-error (type => 'unmatched end tag',
4668                        p => 1, br => 1,                                text => $token->{tag_name}, token => $token);
4669                       }->{$token->{tag_name}}) {                ## Ignore the token
4670                  !!!next-token;
4671                  next B;
4672                } elsif ($token->{tag_name} eq 'br') {
4673                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4674                  !!!cp ('t142');                  !!!cp ('t142.2');
4675                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4676                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4677                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4678                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4679                      [$self->{head_element}, $el_category->{head}];    
4680                    ## Reprocess in the "after head" insertion mode...
4681                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4682                    !!!cp ('t143.2');
4683                    ## As if </head>
4684                    pop @{$self->{open_elements}};
4685                    $self->{insertion_mode} = AFTER_HEAD_IM;
4686      
4687                    ## Reprocess in the "after head" insertion mode...
4688                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4689                    !!!cp ('t143.3');
4690                    ## ISSUE: Two parse errors for <head><noscript></br>
4691                    !!!parse-error (type => 'unmatched end tag',
4692                                    text => 'br', token => $token);
4693                    ## As if </noscript>
4694                    pop @{$self->{open_elements}};
4695                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4696    
4697                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4698                } else {                  ## As if </head>
4699                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4700                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4701    
4702                #                  ## Reprocess in the "after head" insertion mode...
4703              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4704                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4705                  #                  #
4706                } else {                } else {
4707                  !!!cp ('t145');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);  
                 ## Ignore the token  
                 !!!next-token;  
                 next B;  
4708                }                }
4709    
4710                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4711                  !!!parse-error (type => 'unmatched end tag',
4712                                  text => 'br', token => $token);
4713                  ## Ignore the token
4714                  !!!next-token;
4715                  next B;
4716                } else {
4717                  !!!cp ('t145');
4718                  !!!parse-error (type => 'unmatched end tag',
4719                                  text => $token->{tag_name}, token => $token);
4720                  ## Ignore the token
4721                  !!!next-token;
4722                  next B;
4723              }              }
4724    
4725              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4726                !!!cp ('t146');                !!!cp ('t146');
4727                ## As if </noscript>                ## As if </noscript>
4728                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4729                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4730                                  text => $token->{tag_name}, token => $token);
4731                                
4732                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4733                ## As if </head>                ## As if </head>
# Line 4556  sub _tree_construction_main ($) { Line 4743  sub _tree_construction_main ($) {
4743              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4744  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4745                !!!cp ('t148');                !!!cp ('t148');
4746                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4747                                  text => $token->{tag_name}, token => $token);
4748                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4749                !!!next-token;                !!!next-token;
4750                next B;                next B;
# Line 4667  sub _tree_construction_main ($) { Line 4855  sub _tree_construction_main ($) {
4855    
4856                  !!!cp ('t153');                  !!!cp ('t153');
4857                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4858                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4859                  ## Ignore the token                  ## Ignore the token
4860                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4861                  !!!next-token;                  !!!next-token;
4862                  next B;                  next B;
4863                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4864                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4865                                    token => $token);
4866                                    
4867                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4868                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4693  sub _tree_construction_main ($) { Line 4882  sub _tree_construction_main ($) {
4882    
4883                    !!!cp ('t157');                    !!!cp ('t157');
4884                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4885                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4886                    ## Ignore the token                    ## Ignore the token
4887                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4888                    !!!next-token;                    !!!next-token;
# Line 4710  sub _tree_construction_main ($) { Line 4899  sub _tree_construction_main ($) {
4899                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4900                    !!!cp ('t159');                    !!!cp ('t159');
4901                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4902                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4903                                        ->manakai_local_name,                                        ->manakai_local_name,
4904                                    token => $token);                                    token => $token);
4905                  } else {                  } else {
# Line 4752  sub _tree_construction_main ($) { Line 4941  sub _tree_construction_main ($) {
4941                  } # INSCOPE                  } # INSCOPE
4942                    unless (defined $i) {                    unless (defined $i) {
4943                      !!!cp ('t165');                      !!!cp ('t165');
4944                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
4945                                        text => $token->{tag_name},
4946                                        token => $token);
4947                      ## Ignore the token                      ## Ignore the token
4948                      !!!next-token;                      !!!next-token;
4949                      next B;                      next B;
# Line 4769  sub _tree_construction_main ($) { Line 4960  sub _tree_construction_main ($) {
4960                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
4961                    !!!cp ('t167');                    !!!cp ('t167');
4962                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4963                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4964                                        ->manakai_local_name,                                        ->manakai_local_name,
4965                                    token => $token);                                    token => $token);
4966                  } else {                  } else {
# Line 4786  sub _tree_construction_main ($) { Line 4977  sub _tree_construction_main ($) {
4977                  next B;                  next B;
4978                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4979                  !!!cp ('t169');                  !!!cp ('t169');
4980                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4981                                    text => $token->{tag_name}, token => $token);
4982                  ## Ignore the token                  ## Ignore the token
4983                  !!!next-token;                  !!!next-token;
4984                  next B;                  next B;
# Line 4813  sub _tree_construction_main ($) { Line 5005  sub _tree_construction_main ($) {
5005    
5006                    !!!cp ('t173');                    !!!cp ('t173');
5007                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
5008                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
5009                    ## Ignore the token                    ## Ignore the token
5010                    !!!next-token;                    !!!next-token;
5011                    next B;                    next B;
# Line 4829  sub _tree_construction_main ($) { Line 5021  sub _tree_construction_main ($) {
5021                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5022                    !!!cp ('t175');                    !!!cp ('t175');
5023                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5024                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5025                                        ->manakai_local_name,                                        ->manakai_local_name,
5026                                    token => $token);                                    token => $token);
5027                  } else {                  } else {
# Line 4846  sub _tree_construction_main ($) { Line 5038  sub _tree_construction_main ($) {
5038                  next B;                  next B;
5039                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5040                  !!!cp ('t177');                  !!!cp ('t177');
5041                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5042                                    text => $token->{tag_name}, token => $token);
5043                  ## Ignore the token                  ## Ignore the token
5044                  !!!next-token;                  !!!next-token;
5045                  next B;                  next B;
# Line 4889  sub _tree_construction_main ($) { Line 5082  sub _tree_construction_main ($) {
5082    
5083                  !!!cp ('t182');                  !!!cp ('t182');
5084                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5085                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5086                  ## Ignore the token                  ## Ignore the token
5087                  !!!next-token;                  !!!next-token;
5088                  next B;                  next B;
5089                } # INSCOPE                } # INSCOPE
5090              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5091                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5092                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5093                                  token => $token);
5094    
5095                ## As if </caption>                ## As if </caption>
5096                ## have a table element in table scope                ## have a table element in table scope
# Line 4914  sub _tree_construction_main ($) { Line 5108  sub _tree_construction_main ($) {
5108                } # INSCOPE                } # INSCOPE
5109                unless (defined $i) {                unless (defined $i) {
5110                  !!!cp ('t186');                  !!!cp ('t186');
5111                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5112                                    text => 'caption', token => $token);
5113                  ## Ignore the token                  ## Ignore the token
5114                  !!!next-token;                  !!!next-token;
5115                  next B;                  next B;
# Line 4929  sub _tree_construction_main ($) { Line 5124  sub _tree_construction_main ($) {
5124                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5125                  !!!cp ('t188');                  !!!cp ('t188');
5126                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5127                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5128                                      ->manakai_local_name,                                      ->manakai_local_name,
5129                                  token => $token);                                  token => $token);
5130                } else {                } else {
# Line 4949  sub _tree_construction_main ($) { Line 5144  sub _tree_construction_main ($) {
5144                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5145                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5146                  !!!cp ('t190');                  !!!cp ('t190');
5147                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5148                                    text => $token->{tag_name}, token => $token);
5149                  ## Ignore the token                  ## Ignore the token
5150                  !!!next-token;                  !!!next-token;
5151                  next B;                  next B;
# Line 4963  sub _tree_construction_main ($) { Line 5159  sub _tree_construction_main ($) {
5159                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5160                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5161                !!!cp ('t192');                !!!cp ('t192');
5162                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5163                                  text => $token->{tag_name}, token => $token);
5164                ## Ignore the token                ## Ignore the token
5165                !!!next-token;                !!!next-token;
5166                next B;                next B;
# Line 5003  sub _tree_construction_main ($) { Line 5200  sub _tree_construction_main ($) {
5200            }            }
5201          }          }
5202    
5203              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5204    
5205              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5206              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 5054  sub _tree_construction_main ($) { Line 5251  sub _tree_construction_main ($) {
5251          !!!next-token;          !!!next-token;
5252          next B;          next B;
5253        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5254              if ({          if ({
5255                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5256                   th => 1, td => 1,               th => 1, td => 1,
5257                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5258                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5259                  ## Clear back to table context              ## Clear back to table context
5260                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5261                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5262                    !!!cp ('t201');                !!!cp ('t201');
5263                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5264                  }              }
5265                                
5266                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5267                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5268                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5269                }            }
5270              
5271                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5272                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5273                    !!!cp ('t202');                !!!cp ('t202');
5274                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5275                  }              }
5276                                    
5277                  ## Clear back to table body context              ## Clear back to table body context
5278                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5279                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5280                    !!!cp ('t203');                !!!cp ('t203');
5281                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5282                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5283                  }              }
5284                                    
5285                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5286                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 5139  sub _tree_construction_main ($) { Line 5336  sub _tree_construction_main ($) {
5336                  unless (defined $i) {                  unless (defined $i) {
5337                    !!!cp ('t210');                    !!!cp ('t210');
5338  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5339                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5340                                      text => $token->{tag_name}, token => $token);
5341                    ## Ignore the token                    ## Ignore the token
5342                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5343                    !!!next-token;                    !!!next-token;
# Line 5183  sub _tree_construction_main ($) { Line 5381  sub _tree_construction_main ($) {
5381                  } # INSCOPE                  } # INSCOPE
5382                  unless (defined $i) {                  unless (defined $i) {
5383                    !!!cp ('t216');                    !!!cp ('t216');
5384  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5385                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5386                                      text => $token->{tag_name}, token => $token);
5387                    ## Ignore the token                    ## Ignore the token
5388                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5389                    !!!next-token;                    !!!next-token;
# Line 5259  sub _tree_construction_main ($) { Line 5458  sub _tree_construction_main ($) {
5458                }                }
5459              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5460                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5461                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5462                                    ->manakai_local_name,                                    ->manakai_local_name,
5463                                token => $token);                                token => $token);
5464    
# Line 5280  sub _tree_construction_main ($) { Line 5479  sub _tree_construction_main ($) {
5479                unless (defined $i) {                unless (defined $i) {
5480                  !!!cp ('t223');                  !!!cp ('t223');
5481  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5482                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5483                                    token => $token);
5484                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5485                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5486                  !!!next-token;                  !!!next-token;
5487                  next B;                  next B;
5488                }                }
5489                                
5490  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5491                ## generate implied end tags                ## generate implied end tags
5492                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5493                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5298  sub _tree_construction_main ($) { Line 5498  sub _tree_construction_main ($) {
5498                  !!!cp ('t225');                  !!!cp ('t225');
5499                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5500                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5501                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5502                                      ->manakai_local_name,                                      ->manakai_local_name,
5503                                  token => $token);                                  token => $token);
5504                } else {                } else {
# Line 5339  sub _tree_construction_main ($) { Line 5539  sub _tree_construction_main ($) {
5539                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5540                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5541                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5542                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5543                                    text => $token->{tag_name}, token => $token);
5544    
5545                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5546    
# Line 5367  sub _tree_construction_main ($) { Line 5568  sub _tree_construction_main ($) {
5568            #            #
5569          }          }
5570    
5571          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5572                            token => $token);
5573    
5574          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5575          #          #
# Line 5389  sub _tree_construction_main ($) { Line 5591  sub _tree_construction_main ($) {
5591                } # INSCOPE                } # INSCOPE
5592                unless (defined $i) {                unless (defined $i) {
5593                  !!!cp ('t230');                  !!!cp ('t230');
5594                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5595                                    text => $token->{tag_name}, token => $token);
5596                  ## Ignore the token                  ## Ignore the token
5597                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5598                  !!!next-token;                  !!!next-token;
# Line 5430  sub _tree_construction_main ($) { Line 5633  sub _tree_construction_main ($) {
5633                  unless (defined $i) {                  unless (defined $i) {
5634                    !!!cp ('t235');                    !!!cp ('t235');
5635  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5636                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5637                                      text => $token->{type}, token => $token);
5638                    ## Ignore the token                    ## Ignore the token
5639                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5640                    !!!next-token;                    !!!next-token;
# Line 5466  sub _tree_construction_main ($) { Line 5670  sub _tree_construction_main ($) {
5670                  } # INSCOPE                  } # INSCOPE
5671                  unless (defined $i) {                  unless (defined $i) {
5672                    !!!cp ('t239');                    !!!cp ('t239');
5673                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5674                                      text => $token->{tag_name}, token => $token);
5675                    ## Ignore the token                    ## Ignore the token
5676                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5677                    !!!next-token;                    !!!next-token;
# Line 5512  sub _tree_construction_main ($) { Line 5717  sub _tree_construction_main ($) {
5717                } # INSCOPE                } # INSCOPE
5718                unless (defined $i) {                unless (defined $i) {
5719                  !!!cp ('t243');                  !!!cp ('t243');
5720                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5721                                    text => $token->{tag_name}, token => $token);
5722                  ## Ignore the token                  ## Ignore the token
5723                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5724                  !!!next-token;                  !!!next-token;
# Line 5546  sub _tree_construction_main ($) { Line 5752  sub _tree_construction_main ($) {
5752                  } # INSCOPE                  } # INSCOPE
5753                    unless (defined $i) {                    unless (defined $i) {
5754                      !!!cp ('t249');                      !!!cp ('t249');
5755                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5756                                        text => $token->{tag_name}, token => $token);
5757                      ## Ignore the token                      ## Ignore the token
5758                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5759                      !!!next-token;                      !!!next-token;
# Line 5569  sub _tree_construction_main ($) { Line 5776  sub _tree_construction_main ($) {
5776                  } # INSCOPE                  } # INSCOPE
5777                    unless (defined $i) {                    unless (defined $i) {
5778                      !!!cp ('t252');                      !!!cp ('t252');
5779                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5780                                        text => 'tr', token => $token);
5781                      ## Ignore the token                      ## Ignore the token
5782                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5783                      !!!next-token;                      !!!next-token;
# Line 5604  sub _tree_construction_main ($) { Line 5812  sub _tree_construction_main ($) {
5812                } # INSCOPE                } # INSCOPE
5813                unless (defined $i) {                unless (defined $i) {
5814                  !!!cp ('t256');                  !!!cp ('t256');
5815                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5816                                    text => $token->{tag_name}, token => $token);
5817                  ## Ignore the token                  ## Ignore the token
5818                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5819                  !!!next-token;                  !!!next-token;
# Line 5631  sub _tree_construction_main ($) { Line 5840  sub _tree_construction_main ($) {
5840                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5841                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5842            !!!cp ('t258');            !!!cp ('t258');
5843            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5844                              text => $token->{tag_name}, token => $token);
5845            ## Ignore the token            ## Ignore the token
5846            !!!nack ('t258.1');            !!!nack ('t258.1');
5847             !!!next-token;             !!!next-token;
5848            next B;            next B;
5849          } else {          } else {
5850            !!!cp ('t259');            !!!cp ('t259');
5851            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5852                              text => $token->{tag_name}, token => $token);
5853    
5854            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5855            #            #
# Line 5688  sub _tree_construction_main ($) { Line 5899  sub _tree_construction_main ($) {
5899              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5900                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5901                  !!!cp ('t264');                  !!!cp ('t264');
5902                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5903                                    text => 'colgroup', token => $token);
5904                  ## Ignore the token                  ## Ignore the token
5905                  !!!next-token;                  !!!next-token;
5906                  next B;                  next B;
# Line 5701  sub _tree_construction_main ($) { Line 5913  sub _tree_construction_main ($) {
5913                }                }
5914              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5915                !!!cp ('t266');                !!!cp ('t266');
5916                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
5917                                  text => 'col', token => $token);
5918                ## Ignore the token                ## Ignore the token
5919                !!!next-token;                !!!next-token;
5920                next B;                next B;
# Line 5731  sub _tree_construction_main ($) { Line 5944  sub _tree_construction_main ($) {
5944            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5945              !!!cp ('t269');              !!!cp ('t269');
5946  ## TODO: Wrong error type?  ## TODO: Wrong error type?
5947              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
5948                                text => 'colgroup', token => $token);
5949              ## Ignore the token              ## Ignore the token
5950              !!!nack ('t269.1');              !!!nack ('t269.1');
5951              !!!next-token;              !!!next-token;
# Line 5785  sub _tree_construction_main ($) { Line 5999  sub _tree_construction_main ($) {
5999            !!!nack ('t277.1');            !!!nack ('t277.1');
6000            !!!next-token;            !!!next-token;
6001            next B;            next B;
6002          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
6003                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
6004                     }->{$token->{tag_name}} or
6005                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
6006                    {                    {
6007                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5794  sub _tree_construction_main ($) { Line 6009  sub _tree_construction_main ($) {
6009                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
6010                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
6011            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
6012            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
6013                              token => $token);
6014            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
6015            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
6016            ## have an element in table scope            ## have an element in table scope
# Line 5812  sub _tree_construction_main ($) { Line 6028  sub _tree_construction_main ($) {
6028            } # INSCOPE            } # INSCOPE
6029            unless (defined $i) {            unless (defined $i) {
6030              !!!cp ('t280');              !!!cp ('t280');
6031              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6032                                text => 'select', token => $token);
6033              ## Ignore the token              ## Ignore the token
6034              !!!nack ('t280.1');              !!!nack ('t280.1');
6035              !!!next-token;              !!!next-token;
# Line 5836  sub _tree_construction_main ($) { Line 6053  sub _tree_construction_main ($) {
6053            }            }
6054          } else {          } else {
6055            !!!cp ('t282');            !!!cp ('t282');
6056            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6057                              text => $token->{tag_name}, token => $token);
6058            ## Ignore the token            ## Ignore the token
6059            !!!nack ('t282.1');            !!!nack ('t282.1');
6060            !!!next-token;            !!!next-token;
# Line 5854  sub _tree_construction_main ($) { Line 6072  sub _tree_construction_main ($) {
6072              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6073            } else {            } else {
6074              !!!cp ('t285');              !!!cp ('t285');
6075              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6076                                text => $token->{tag_name}, token => $token);
6077              ## Ignore the token              ## Ignore the token
6078            }            }
6079            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5866  sub _tree_construction_main ($) { Line 6085  sub _tree_construction_main ($) {
6085              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6086            } else {            } else {
6087              !!!cp ('t287');              !!!cp ('t287');
6088              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6089                                text => $token->{tag_name}, token => $token);
6090              ## Ignore the token              ## Ignore the token
6091            }            }
6092            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5888  sub _tree_construction_main ($) { Line 6108  sub _tree_construction_main ($) {
6108            } # INSCOPE            } # INSCOPE
6109            unless (defined $i) {            unless (defined $i) {
6110              !!!cp ('t290');              !!!cp ('t290');
6111              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6112                                text => $token->{tag_name}, token => $token);
6113              ## Ignore the token              ## Ignore the token
6114              !!!nack ('t290.1');              !!!nack ('t290.1');
6115              !!!next-token;              !!!next-token;
# Line 5909  sub _tree_construction_main ($) { Line 6130  sub _tree_construction_main ($) {
6130                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6131                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6132  ## TODO: The following is wrong?  ## TODO: The following is wrong?
6133            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
6134                              text => $token->{tag_name}, token => $token);
6135                                
6136            ## have an element in table scope            ## have an element in table scope
6137            my $i;            my $i;
# Line 5950  sub _tree_construction_main ($) { Line 6172  sub _tree_construction_main ($) {
6172            unless (defined $i) {            unless (defined $i) {
6173              !!!cp ('t297');              !!!cp ('t297');
6174  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6175              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6176                                text => 'select', token => $token);
6177              ## Ignore the </select> token              ## Ignore the </select> token
6178              !!!nack ('t297.1');              !!!nack ('t297.1');
6179              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 5967  sub _tree_construction_main ($) { Line 6190  sub _tree_construction_main ($) {
6190            next B;            next B;
6191          } else {          } else {
6192            !!!cp ('t299');            !!!cp ('t299');
6193            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6194                              text => $token->{tag_name}, token => $token);
6195            ## Ignore the token            ## Ignore the token
6196            !!!nack ('t299.3');            !!!nack ('t299.3');
6197            !!!next-token;            !!!next-token;
# Line 6005  sub _tree_construction_main ($) { Line 6229  sub _tree_construction_main ($) {
6229                    
6230          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6231            !!!cp ('t301');            !!!cp ('t301');
6232            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6233    
6234            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6235          } else {          } else {
# Line 6013  sub _tree_construction_main ($) { Line 6237  sub _tree_construction_main ($) {
6237          }          }
6238                    
6239          ## "after body" insertion mode          ## "after body" insertion mode
6240          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6241    
6242          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6243          ## reprocess          ## reprocess
# Line 6021  sub _tree_construction_main ($) { Line 6245  sub _tree_construction_main ($) {
6245        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6246          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6247            !!!cp ('t303');            !!!cp ('t303');
6248            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6249                              text => $token->{tag_name}, token => $token);
6250                        
6251            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6252          } else {          } else {
# Line 6029  sub _tree_construction_main ($) { Line 6254  sub _tree_construction_main ($) {
6254          }          }
6255    
6256          ## "after body" insertion mode          ## "after body" insertion mode
6257          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6258                            text => $token->{tag_name}, token => $token);
6259    
6260          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6261          !!!ack-later;          !!!ack-later;
# Line 6038  sub _tree_construction_main ($) { Line 6264  sub _tree_construction_main ($) {
6264        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6265          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6266            !!!cp ('t305');            !!!cp ('t305');
6267            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6268                              text => $token->{tag_name}, token => $token);
6269                        
6270            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6271            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 6050  sub _tree_construction_main ($) { Line 6277  sub _tree_construction_main ($) {
6277          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6278            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6279              !!!cp ('t307');              !!!cp ('t307');
6280              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6281                                text => 'html', token => $token);
6282              ## Ignore the token              ## Ignore the token
6283              !!!next-token;              !!!next-token;
6284              next B;              next B;
# Line 6062  sub _tree_construction_main ($) { Line 6290  sub _tree_construction_main ($) {
6290            }            }
6291          } else {          } else {
6292            !!!cp ('t309');            !!!cp ('t309');
6293            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6294                              text => $token->{tag_name}, token => $token);
6295    
6296            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6297            ## reprocess            ## reprocess
# Line 6090  sub _tree_construction_main ($) { Line 6319  sub _tree_construction_main ($) {
6319          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6320            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6321              !!!cp ('t311');              !!!cp ('t311');
6322              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6323            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6324              !!!cp ('t312');              !!!cp ('t312');
6325              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6326            } else { # "after html frameset"            } else { # "after after frameset"
6327              !!!cp ('t313');              !!!cp ('t313');
6328              !!!parse-error (type => 'after html:#character', token => $token);              !!!parse-error (type => 'after html:#text', token => $token);
   
             $self->{insertion_mode} = AFTER_FRAMESET_IM;  
             ## Reprocess in the "after frameset" insertion mode.  
             !!!parse-error (type => 'after frameset:#character', token => $token);  
6329            }            }
6330                        
6331            ## Ignore the token.            ## Ignore the token.
# Line 6116  sub _tree_construction_main ($) { Line 6341  sub _tree_construction_main ($) {
6341                    
6342          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
6343        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
         if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
           !!!cp ('t316');  
           !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t317');  
         }  
   
6344          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6345              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6346            !!!cp ('t318');            !!!cp ('t318');
# Line 6143  sub _tree_construction_main ($) { Line 6358  sub _tree_construction_main ($) {
6358            next B;            next B;
6359          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6360            !!!cp ('t320');            !!!cp ('t320');
6361            ## NOTE: As if in body.            ## NOTE: As if in head.
6362            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6363            next B;            next B;
6364    
6365              ## NOTE: |<!DOCTYPE HTML><frameset></frameset></html><noframes></noframes>|
6366              ## has no parse error.
6367          } else {          } else {
6368            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6369              !!!cp ('t321');              !!!cp ('t321');
6370              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6371            } else {                              text => $token->{tag_name}, token => $token);
6372              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6373              !!!cp ('t322');              !!!cp ('t322');
6374              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6375                                text => $token->{tag_name}, token => $token);
6376              } else { # "after after frameset"
6377                !!!cp ('t322.2');
6378                !!!parse-error (type => 'after after frameset',
6379                                text => $token->{tag_name}, token => $token);
6380            }            }
6381            ## Ignore the token            ## Ignore the token
6382            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 6160  sub _tree_construction_main ($) { Line 6384  sub _tree_construction_main ($) {
6384            next B;            next B;
6385          }          }
6386        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
         if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {  
           !!!cp ('t323');  
           !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);  
   
           $self->{insertion_mode} = AFTER_FRAMESET_IM;  
           ## Process in the "after frameset" insertion mode.  
         } else {  
           !!!cp ('t324');  
         }  
   
6387          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6388              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6389            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6390                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6391              !!!cp ('t325');              !!!cp ('t325');
6392              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6393                                text => $token->{tag_name}, token => $token);
6394              ## Ignore the token              ## Ignore the token
6395              !!!next-token;              !!!next-token;
6396            } else {            } else {
# Line 6201  sub _tree_construction_main ($) { Line 6416  sub _tree_construction_main ($) {
6416          } else {          } else {
6417            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6418              !!!cp ('t330');              !!!cp ('t330');
6419              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6420            } else {                              text => $token->{tag_name}, token => $token);
6421              } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6422                !!!cp ('t330.1');
6423                !!!parse-error (type => 'after frameset:/',
6424                                text => $token->{tag_name}, token => $token);
6425              } else { # "after after html"
6426              !!!cp ('t331');              !!!cp ('t331');
6427              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after after frameset:/',
6428                                text => $token->{tag_name}, token => $token);
6429            }            }
6430            ## Ignore the token            ## Ignore the token
6431            !!!next-token;            !!!next-token;
# Line 6271  sub _tree_construction_main ($) { Line 6492  sub _tree_construction_main ($) {
6492                                           ->{has_reference});                                           ->{has_reference});
6493            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
6494              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6495                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6496                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6497                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6498                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6499                !!!cp ('t336');                !!!cp ('t336');
6500                ## NOTE: Whether the encoding is supported or not is handled                ## NOTE: Whether the encoding is supported or not is handled
6501                ## in the {change_encoding} callback.                ## in the {change_encoding} callback.
# Line 6312  sub _tree_construction_main ($) { Line 6533  sub _tree_construction_main ($) {
6533          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6534          next B;          next B;
6535        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6536          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6537                                
6538          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6539              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6432  sub _tree_construction_main ($) { Line 6653  sub _tree_construction_main ($) {
6653              if ($i != -1) {              if ($i != -1) {
6654                !!!cp ('t355');                !!!cp ('t355');
6655                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6656                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6657                                    ->manakai_local_name,                                    ->manakai_local_name,
6658                                token => $token);                                token => $token);
6659              } else {              } else {
# Line 6586  sub _tree_construction_main ($) { Line 6807  sub _tree_construction_main ($) {
6807                  xmp => 1,                  xmp => 1,
6808                  iframe => 1,                  iframe => 1,
6809                  noembed => 1,                  noembed => 1,
6810                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6811                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6812                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6813          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6608  sub _tree_construction_main ($) { Line 6829  sub _tree_construction_main ($) {
6829            !!!next-token;            !!!next-token;
6830            next B;            next B;
6831          } else {          } else {
6832              !!!ack ('t391.1');
6833    
6834            my $at = $token->{attributes};            my $at = $token->{attributes};
6835            my $form_attrs;            my $form_attrs;
6836            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6651  sub _tree_construction_main ($) { Line 6874  sub _tree_construction_main ($) {
6874                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6875                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6876                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6877            !!!back-token (@tokens);            !!!back-token (@tokens);
6878            !!!next-token;            !!!next-token;
6879            next B;            next B;
# Line 6699  sub _tree_construction_main ($) { Line 6921  sub _tree_construction_main ($) {
6921            ## Ignore the token            ## Ignore the token
6922          } else {          } else {
6923            !!!cp ('t398');            !!!cp ('t398');
6924            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
6925          }          }
6926          !!!next-token;          !!!next-token;
6927          next B;          next B;
6928          } elsif ($token->{tag_name} eq 'rt' or
6929                   $token->{tag_name} eq 'rp') {
6930            ## has a |ruby| element in scope
6931            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6932              my $node = $self->{open_elements}->[$_];
6933              if ($node->[1] & RUBY_EL) {
6934                !!!cp ('t398.1');
6935                ## generate implied end tags
6936                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
6937                  !!!cp ('t398.2');
6938                  pop @{$self->{open_elements}};
6939                }
6940                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
6941                  !!!cp ('t398.3');
6942                  !!!parse-error (type => 'not closed',
6943                                  text => $self->{open_elements}->[-1]->[0]
6944                                      ->manakai_local_name,
6945                                  token => $token);
6946                  pop @{$self->{open_elements}}
6947                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
6948                }
6949                last INSCOPE;
6950              } elsif ($node->[1] & SCOPING_EL) {
6951                !!!cp ('t398.4');
6952                last INSCOPE;
6953              }
6954            } # INSCOPE
6955    
6956            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6957    
6958            !!!nack ('t398.5');
6959            !!!next-token;
6960            redo B;
6961        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
6962                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6963          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6964    
6965            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
6966    
6967          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6968    
6969          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6733  sub _tree_construction_main ($) { Line 6990  sub _tree_construction_main ($) {
6990                  thead => 1, tr => 1,                  thead => 1, tr => 1,
6991                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6992          !!!cp ('t401');          !!!cp ('t401');
6993          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
6994                            text => $token->{tag_name}, token => $token);
6995          ## Ignore the token          ## Ignore the token
6996          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
6997          !!!next-token;          !!!next-token;
# Line 6818  sub _tree_construction_main ($) { Line 7076  sub _tree_construction_main ($) {
7076            }            }
7077    
7078            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7079                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7080            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7081            !!!next-token;            !!!next-token;
7082            next B;            next B;
# Line 6828  sub _tree_construction_main ($) { Line 7086  sub _tree_construction_main ($) {
7086            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7087              !!!cp ('t403');              !!!cp ('t403');
7088              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7089                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7090                              token => $token);                              token => $token);
7091              last;              last;
7092            } else {            } else {
# Line 6848  sub _tree_construction_main ($) { Line 7106  sub _tree_construction_main ($) {
7106            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7107              !!!cp ('t406');              !!!cp ('t406');
7108              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7109                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7110                                  ->manakai_local_name,                                  ->manakai_local_name,
7111                              token => $token);                              token => $token);
7112            } else {            } else {
# Line 6859  sub _tree_construction_main ($) { Line 7117  sub _tree_construction_main ($) {
7117            next B;            next B;
7118          } else {          } else {
7119            !!!cp ('t408');            !!!cp ('t408');
7120            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7121                              text => $token->{tag_name}, token => $token);
7122            ## Ignore the token            ## Ignore the token
7123            !!!next-token;            !!!next-token;
7124            next B;            next B;
# Line 6887  sub _tree_construction_main ($) { Line 7146  sub _tree_construction_main ($) {
7146    
7147          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7148            !!!cp ('t413');            !!!cp ('t413');
7149            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7150                              text => $token->{tag_name}, token => $token);
7151              ## NOTE: Ignore the token.
7152          } else {          } else {
7153            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7154            while ({            while ({
7155                      ## END_TAG_OPTIONAL_EL
7156                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7157                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7158                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7159                    p => 1,                    p => 1,
7160                      rt => 1,
7161                      rp => 1,
7162                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7163              !!!cp ('t409');              !!!cp ('t409');
7164              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6905  sub _tree_construction_main ($) { Line 7169  sub _tree_construction_main ($) {
7169                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7170              !!!cp ('t412');              !!!cp ('t412');
7171              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7172                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7173                                  ->manakai_local_name,                                  ->manakai_local_name,
7174                              token => $token);                              token => $token);
7175            } else {            } else {
# Line 6942  sub _tree_construction_main ($) { Line 7206  sub _tree_construction_main ($) {
7206    
7207          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7208            !!!cp ('t421');            !!!cp ('t421');
7209            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7210                              text => $token->{tag_name}, token => $token);
7211              ## NOTE: Ignore the token.
7212          } else {          } else {
7213            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7214            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6955  sub _tree_construction_main ($) { Line 7221  sub _tree_construction_main ($) {
7221                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7222              !!!cp ('t417.1');              !!!cp ('t417.1');
7223              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7224                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7225                                  ->manakai_local_name,                                  ->manakai_local_name,
7226                              token => $token);                              token => $token);
7227            } else {            } else {
# Line 6987  sub _tree_construction_main ($) { Line 7253  sub _tree_construction_main ($) {
7253    
7254          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7255            !!!cp ('t425.1');            !!!cp ('t425.1');
7256            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7257                              text => $token->{tag_name}, token => $token);
7258              ## NOTE: Ignore the token.
7259          } else {          } else {
7260            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7261            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6999  sub _tree_construction_main ($) { Line 7267  sub _tree_construction_main ($) {
7267            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7268                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7269              !!!cp ('t425');              !!!cp ('t425');
7270              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7271                                text => $token->{tag_name}, token => $token);
7272            } else {            } else {
7273              !!!cp ('t426');              !!!cp ('t426');
7274            }            }
# Line 7030  sub _tree_construction_main ($) { Line 7299  sub _tree_construction_main ($) {
7299                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7300              !!!cp ('t412.1');              !!!cp ('t412.1');
7301              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7302                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7303                                  ->manakai_local_name,                                  ->manakai_local_name,
7304                              token => $token);                              token => $token);
7305            } else {            } else {
# Line 7040  sub _tree_construction_main ($) { Line 7309  sub _tree_construction_main ($) {
7309            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7310          } else {          } else {
7311            !!!cp ('t413.1');            !!!cp ('t413.1');
7312            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7313                              text => $token->{tag_name}, token => $token);
7314    
7315            !!!cp ('t415.1');            !!!cp ('t415.1');
7316            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 7063  sub _tree_construction_main ($) { Line 7333  sub _tree_construction_main ($) {
7333          next B;          next B;
7334        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7335          !!!cp ('t428');          !!!cp ('t428');
7336          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7337                            text => 'br', token => $token);
7338    
7339          ## As if <br>          ## As if <br>
7340          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 7088  sub _tree_construction_main ($) { Line 7359  sub _tree_construction_main ($) {
7359                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7360                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7361          !!!cp ('t429');          !!!cp ('t429');
7362          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7363                            text => $token->{tag_name}, token => $token);
7364          ## Ignore the token          ## Ignore the token
7365          !!!next-token;          !!!next-token;
7366          next B;          next B;
# Line 7107  sub _tree_construction_main ($) { Line 7379  sub _tree_construction_main ($) {
7379              ## generate implied end tags              ## generate implied end tags
7380              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7381                !!!cp ('t430');                !!!cp ('t430');
7382                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7383                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7384                  ## which seems wrong.
7385                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7386                  $node_i++;
7387              }              }
7388                    
7389              ## Step 2              ## Step 2
# Line 7117  sub _tree_construction_main ($) { Line 7392  sub _tree_construction_main ($) {
7392                !!!cp ('t431');                !!!cp ('t431');
7393                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7394                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7395                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7396                                    ->manakai_local_name,                                    ->manakai_local_name,
7397                                token => $token);                                token => $token);
7398              } else {              } else {
# Line 7125  sub _tree_construction_main ($) { Line 7400  sub _tree_construction_main ($) {
7400              }              }
7401                            
7402              ## Step 3              ## Step 3
7403              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7404    
7405              !!!next-token;              !!!next-token;
7406              last S2;              last S2;
# Line 7136  sub _tree_construction_main ($) { Line 7411  sub _tree_construction_main ($) {
7411                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7412                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7413                !!!cp ('t433');                !!!cp ('t433');
7414                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7415                                  text => $token->{tag_name}, token => $token);
7416                ## Ignore the token                ## Ignore the token
7417                !!!next-token;                !!!next-token;
7418                last S2;                last S2;
# Line 7272  sub set_inner_html ($$$) { Line 7548  sub set_inner_html ($$$) {
7548                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7549                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7550          !!!cp ('i4.1');          !!!cp ('i4.1');
7551          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7552  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7553                              text => (sprintf 'U+%04X', $self->{next_char}));
7554            } else {
7555              !!!parse-error (type => 'control char',
7556                              text => (sprintf 'U-%08X', $self->{next_char}));
7557            }
7558        }        }
7559      };      };
7560      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.137  
changed lines
  Added in v.1.161

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24