/[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.132 by wakaba, Sun Apr 13 10:36:40 2008 UTC revision 1.157 by wakaba, Sun Aug 31 09:12:30 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 = shift;    my $charset_name = shift;
360    my $bytes_s = ref $_[0] ? $_[0] : \($_[0]);    my $byte_stream = $_[0];
   my $s;  
     
   if (defined $charset) {  
     require Encode; ## TODO: decode(utf8) don't delete BOM  
     $s = \ (Encode::decode ($charset, $$bytes_s));  
     $self->{input_encoding} = lc $charset; ## TODO: normalize name  
     $self->{confident} = 1;  
   } else {  
     ## TODO: Implement HTML5 detection algorithm  
     require Whatpm::Charset::UniversalCharDet;  
     $charset = Whatpm::Charset::UniversalCharDet->detect_byte_string  
         (substr ($$bytes_s, 0, 1024));  
     $charset ||= 'windows-1252';  
     $s = \ (Encode::decode ($charset, $$bytes_s));  
     $self->{input_encoding} = $charset;  
     $self->{confident} = 0;  
   }  
361    
362    $self->{change_encoding} = sub {    my $onerror = $_[2] || sub {
363      my $self = shift;      my (%opt) = @_;
364      my $charset = lc shift;      warn "Parse error ($opt{type})\n";
365      my $token = shift;    };
366      ## TODO: if $charset is supported    $self->{parse_error} = $onerror; # updated later by parse_char_string
     ## TODO: normalize charset name  
367    
368      ## "Change the encoding" algorithm:    ## HTML5 encoding sniffing algorithm
369      require Message::Charset::Info;
370      my $charset;
371      my $buffer;
372      my ($char_stream, $e_status);
373    
374      ## Step 1        SNIFFING: {
375      if ($charset eq 'utf-16') { ## ISSUE: UTF-16BE -> UTF-8? UTF-16LE -> UTF-8?  
376        $charset = 'utf-8';      ## Step 1
377        if (defined $charset_name) {
378          $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
379    
380          ## ISSUE: Unsupported encoding is not ignored according to the spec.
381          ($char_stream, $e_status) = $charset->get_decode_handle
382              ($byte_stream, allow_error_reporting => 1,
383               allow_fallback => 1);
384          if ($char_stream) {
385            $self->{confident} = 1;
386            last SNIFFING;
387          } else {
388            ## TODO: unsupported error
389          }
390      }      }
391    
392      ## Step 2      ## Step 2
393      if (defined $self->{input_encoding} and      my $byte_buffer = '';
394          $self->{input_encoding} eq $charset) {      for (1..1024) {
395          my $char = $byte_stream->getc;
396          last unless defined $char;
397          $byte_buffer .= $char;
398        } ## TODO: timeout
399    
400        ## Step 3
401        if ($byte_buffer =~ /^\xFE\xFF/) {
402          $charset = Message::Charset::Info->get_by_iana_name ('utf-16be');
403          ($char_stream, $e_status) = $charset->get_decode_handle
404              ($byte_stream, allow_error_reporting => 1,
405               allow_fallback => 1, byte_buffer => \$byte_buffer);
406        $self->{confident} = 1;        $self->{confident} = 1;
407        return;        last SNIFFING;
408        } elsif ($byte_buffer =~ /^\xFF\xFE/) {
409          $charset = Message::Charset::Info->get_by_iana_name ('utf-16le');
410          ($char_stream, $e_status) = $charset->get_decode_handle
411              ($byte_stream, allow_error_reporting => 1,
412               allow_fallback => 1, byte_buffer => \$byte_buffer);
413          $self->{confident} = 1;
414          last SNIFFING;
415        } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) {
416          $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
417          ($char_stream, $e_status) = $charset->get_decode_handle
418              ($byte_stream, allow_error_reporting => 1,
419               allow_fallback => 1, byte_buffer => \$byte_buffer);
420          $self->{confident} = 1;
421          last SNIFFING;
422      }      }
423    
424      !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.      ## Step 4
425          ':'.$charset, level => 'w', token => $token);      ## TODO: <meta charset>
426    
427      ## Step 3      ## Step 5
428      # if (can) {      ## TODO: from history
       ## change the encoding on the fly.  
       #$self->{confident} = 1;  
       #return;  
     # }  
429    
430      ## Step 4      ## Step 6
431      throw Whatpm::HTML::RestartParser (charset => $charset);      require Whatpm::Charset::UniversalCharDet;
432        $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string
433            ($byte_buffer);
434        if (defined $charset_name) {
435          $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
436    
437          ## ISSUE: Unsupported encoding is not ignored according to the spec.
438          require Whatpm::Charset::DecodeHandle;
439          $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
440              ($byte_stream);
441          ($char_stream, $e_status) = $charset->get_decode_handle
442              ($buffer, allow_error_reporting => 1,
443               allow_fallback => 1, byte_buffer => \$byte_buffer);
444          if ($char_stream) {
445            $buffer->{buffer} = $byte_buffer;
446            !!!parse-error (type => 'sniffing:chardet',
447                            text => $charset_name,
448                            level => $self->{level}->{info},
449                            layer => 'encode',
450                            line => 1, column => 1);
451            $self->{confident} = 0;
452            last SNIFFING;
453          }
454        }
455    
456        ## Step 7: default
457        ## TODO: Make this configurable.
458        $charset = Message::Charset::Info->get_by_iana_name ('windows-1252');
459            ## NOTE: We choose |windows-1252| here, since |utf-8| should be
460            ## detectable in the step 6.
461        require Whatpm::Charset::DecodeHandle;
462        $buffer = Whatpm::Charset::DecodeHandle::ByteBuffer->new
463            ($byte_stream);
464        ($char_stream, $e_status)
465            = $charset->get_decode_handle ($buffer,
466                                           allow_error_reporting => 1,
467                                           allow_fallback => 1,
468                                           byte_buffer => \$byte_buffer);
469        $buffer->{buffer} = $byte_buffer;
470        !!!parse-error (type => 'sniffing:default',
471                        text => 'windows-1252',
472                        level => $self->{level}->{info},
473                        line => 1, column => 1,
474                        layer => 'encode');
475        $self->{confident} = 0;
476      } # SNIFFING
477    
478      $self->{input_encoding} = $charset->get_iana_name;
479      if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
480        !!!parse-error (type => 'chardecode:fallback',
481                        text => $self->{input_encoding},
482                        level => $self->{level}->{uncertain},
483                        line => 1, column => 1,
484                        layer => 'encode');
485      } elsif (not ($e_status &
486                    Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
487        !!!parse-error (type => 'chardecode:no error',
488                        text => $self->{input_encoding},
489                        level => $self->{level}->{uncertain},
490                        line => 1, column => 1,
491                        layer => 'encode');
492      }
493    
494      $self->{change_encoding} = sub {
495        my $self = shift;
496        $charset_name = shift;
497        my $token = shift;
498    
499        $charset = Message::Charset::Info->get_by_iana_name ($charset_name);
500        ($char_stream, $e_status) = $charset->get_decode_handle
501            ($byte_stream, allow_error_reporting => 1, allow_fallback => 1,
502             byte_buffer => \ $buffer->{buffer});
503        
504        if ($char_stream) { # if supported
505          ## "Change the encoding" algorithm:
506    
507          ## Step 1    
508          if ($charset->{category} &
509              Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) {
510            $charset = Message::Charset::Info->get_by_iana_name ('utf-8');
511            ($char_stream, $e_status) = $charset->get_decode_handle
512                ($byte_stream,
513                 byte_buffer => \ $buffer->{buffer});
514          }
515          $charset_name = $charset->get_iana_name;
516          
517          ## Step 2
518          if (defined $self->{input_encoding} and
519              $self->{input_encoding} eq $charset_name) {
520            !!!parse-error (type => 'charset label:matching',
521                            text => $charset_name,
522                            level => $self->{level}->{info});
523            $self->{confident} = 1;
524            return;
525          }
526    
527          !!!parse-error (type => 'charset label detected',
528                          text => $self->{input_encoding},
529                          value => $charset_name,
530                          level => $self->{level}->{warn},
531                          token => $token);
532          
533          ## Step 3
534          # if (can) {
535            ## change the encoding on the fly.
536            #$self->{confident} = 1;
537            #return;
538          # }
539          
540          ## Step 4
541          throw Whatpm::HTML::RestartParser ();
542        }
543    }; # $self->{change_encoding}    }; # $self->{change_encoding}
544    
545      my $char_onerror = sub {
546        my (undef, $type, %opt) = @_;
547        !!!parse-error (layer => 'encode',
548                        %opt, type => $type,
549                        line => $self->{line}, column => $self->{column} + 1);
550        if ($opt{octets}) {
551          ${$opt{octets}} = "\x{FFFD}"; # relacement character
552        }
553      };
554      $char_stream->onerror ($char_onerror);
555    
556    my @args = @_; shift @args; # $s    my @args = @_; shift @args; # $s
557    my $return;    my $return;
558    try {    try {
559      $return = $self->parse_char_string ($s, @args);        $return = $self->parse_char_stream ($char_stream, @args);  
560    } catch Whatpm::HTML::RestartParser with {    } catch Whatpm::HTML::RestartParser with {
561      my $charset = shift->{charset};      ## NOTE: Invoked after {change_encoding}.
562      $s = \ (Encode::decode ($charset, $$bytes_s));      
563      $self->{input_encoding} = $charset; ## TODO: normalize      $self->{input_encoding} = $charset->get_iana_name;
564        if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) {
565          !!!parse-error (type => 'chardecode:fallback',
566                          text => $self->{input_encoding},
567                          level => $self->{level}->{uncertain},
568                          line => 1, column => 1,
569                          layer => 'encode');
570        } elsif (not ($e_status &
571                      Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) {
572          !!!parse-error (type => 'chardecode:no error',
573                          text => $self->{input_encoding},
574                          level => $self->{level}->{uncertain},
575                          line => 1, column => 1,
576                          layer => 'encode');
577        }
578      $self->{confident} = 1;      $self->{confident} = 1;
579      $return = $self->parse_char_string ($s, @args);      $char_stream->onerror ($char_onerror);
580        $return = $self->parse_char_stream ($char_stream, @args);
581    };    };
582    return $return;    return $return;
583  } # parse_byte_string  } # parse_byte_stream
584    
585  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM  ## NOTE: HTML5 spec says that the encoding layer MUST NOT strip BOM
586  ## and the HTML layer MUST ignore it.  However, we does strip BOM in  ## and the HTML layer MUST ignore it.  However, we does strip BOM in
# Line 411  sub parse_byte_string ($$$$;$) { Line 591  sub parse_byte_string ($$$$;$) {
591  ## such as |parse_byte_string| in this module, must ensure that it does  ## such as |parse_byte_string| in this module, must ensure that it does
592  ## strip the BOM and never strip any ZWNBSP.  ## strip the BOM and never strip any ZWNBSP.
593    
594  *parse_char_string = \&parse_string;  sub parse_char_string ($$$;$) {
595      my $self = shift;
596      require utf8;
597      my $s = ref $_[0] ? $_[0] : \($_[0]);
598      open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s;
599      return $self->parse_char_stream ($input, @_[1..$#_]);
600    } # parse_char_string
601    *parse_string = \&parse_char_string;
602    
603  sub parse_string ($$$;$) {  sub parse_char_stream ($$$;$) {
604    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
605    my $s = ref $_[0] ? $_[0] : \($_[0]);    my $input = $_[0];
606    $self->{document} = $_[1];    $self->{document} = $_[1];
607    @{$self->{document}->child_nodes} = ();    @{$self->{document}->child_nodes} = ();
608    
# Line 434  sub parse_string ($$$;$) { Line 621  sub parse_string ($$$;$) {
621      pop @{$self->{prev_char}};      pop @{$self->{prev_char}};
622      unshift @{$self->{prev_char}}, $self->{next_char};      unshift @{$self->{prev_char}}, $self->{next_char};
623    
624      $self->{next_char} = -1 and return if $i >= length $$s;      my $char;
625      $self->{next_char} = ord substr $$s, $i++, 1;      if (defined $self->{next_next_char}) {
626          $char = $self->{next_next_char};
627          delete $self->{next_next_char};
628        } else {
629          $char = $input->getc;
630        }
631        $self->{next_char} = -1 and return unless defined $char;
632        $self->{next_char} = ord $char;
633    
634      ($self->{line_prev}, $self->{column_prev})      ($self->{line_prev}, $self->{column_prev})
635          = ($self->{line}, $self->{column});          = ($self->{line}, $self->{column});
# Line 447  sub parse_string ($$$;$) { Line 641  sub parse_string ($$$;$) {
641        $self->{column} = 0;        $self->{column} = 0;
642      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
643        !!!cp ('j2');        !!!cp ('j2');
644        $i++ if substr ($$s, $i, 1) eq "\x0A";        my $next = $input->getc;
645          if (defined $next and $next ne "\x0A") {
646            $self->{next_next_char} = $next;
647          }
648        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
649        $self->{line}++;        $self->{line}++;
650        $self->{column} = 0;        $self->{column} = 0;
# Line 475  sub parse_string ($$$;$) { Line 672  sub parse_string ($$$;$) {
672                0x10FFFE => 1, 0x10FFFF => 1,                0x10FFFE => 1, 0x10FFFF => 1,
673               }->{$self->{next_char}}) {               }->{$self->{next_char}}) {
674        !!!cp ('j5');        !!!cp ('j5');
675        !!!parse-error (type => 'control char', level => $self->{must_level});        if ($self->{next_char} < 0x10000) {
676  ## TODO: error type documentation          !!!parse-error (type => 'control char',
677                            text => (sprintf 'U+%04X', $self->{next_char}));
678          } else {
679            !!!parse-error (type => 'control char',
680                            text => (sprintf 'U-%08X', $self->{next_char}));
681          }
682      }      }
683    };    };
684    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 500  sub parse_string ($$$;$) { Line 702  sub parse_string ($$$;$) {
702    delete $self->{parse_error}; # remove loop    delete $self->{parse_error}; # remove loop
703    
704    return $self->{document};    return $self->{document};
705  } # parse_string  } # parse_char_stream
706    
707  sub new ($) {  sub new ($) {
708    my $class = shift;    my $class = shift;
709    my $self = bless {}, $class;    my $self = bless {
710        level => {must => 'm',
711                  warn => 'w',
712                  info => 'i',
713                  uncertain => 'u'},
714      }, $class;
715    $self->{set_next_char} = sub {    $self->{set_next_char} = sub {
716      $self->{next_char} = -1;      $self->{next_char} = -1;
717    };    };
# Line 650  sub _initialize_tokenizer ($) { Line 857  sub _initialize_tokenizer ($) {
857  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|  ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
858  ##     while the token is pushed back to the stack.  ##     while the token is pushed back to the stack.
859    
 ## ISSUE: "When a DOCTYPE token is created, its  
 ## <i>self-closing flag</i> must be unset (its other state is that it  
 ## be set), and its attributes list must be empty.": Wrong subject?  
   
860  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
861    
862  ## Before each step, UA MAY check to see if either one of the scripts in  ## Before each step, UA MAY check to see if either one of the scripts in
# Line 869  sub _get_next_token ($) { Line 1072  sub _get_next_token ($) {
1072            redo A;            redo A;
1073          } else {          } else {
1074            !!!cp (23);            !!!cp (23);
1075            !!!parse-error (type => 'bare stago');            !!!parse-error (type => 'bare stago',
1076                              line => $self->{line_prev},
1077                              column => $self->{column_prev});
1078            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
1079            ## reconsume            ## reconsume
1080    
# Line 1164  sub _get_next_token ($) { Line 1369  sub _get_next_token ($) {
1369          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1370              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1371            !!!cp (57);            !!!cp (57);
1372            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});            !!!parse-error (type => 'duplicate attribute', text => $self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});
1373            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1374          } else {          } else {
1375            !!!cp (58);            !!!cp (58);
# Line 1335  sub _get_next_token ($) { Line 1540  sub _get_next_token ($) {
1540    
1541          redo A;          redo A;
1542        } else {        } else {
1543          !!!cp (82);          if ($self->{next_char} == 0x0022 or # "
1544                $self->{next_char} == 0x0027) { # '
1545              !!!cp (78);
1546              !!!parse-error (type => 'bad attribute name');
1547            } else {
1548              !!!cp (82);
1549            }
1550          $self->{current_attribute}          $self->{current_attribute}
1551              = {name => chr ($self->{next_char}),              = {name => chr ($self->{next_char}),
1552                 value => '',                 value => '',
# Line 1370  sub _get_next_token ($) { Line 1581  sub _get_next_token ($) {
1581          !!!next-input-character;          !!!next-input-character;
1582          redo A;          redo A;
1583        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1584            !!!parse-error (type => 'empty unquoted attribute value');
1585          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1586            !!!cp (87);            !!!cp (87);
1587            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1646  sub _get_next_token ($) { Line 1858  sub _get_next_token ($) {
1858          $self->{state} = SELF_CLOSING_START_TAG_STATE;          $self->{state} = SELF_CLOSING_START_TAG_STATE;
1859          !!!next-input-character;          !!!next-input-character;
1860          redo A;          redo A;
1861          } elsif ($self->{next_char} == -1) {
1862            !!!parse-error (type => 'unclosed tag');
1863            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1864              !!!cp (122.3);
1865              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1866            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1867              if ($self->{current_token}->{attributes}) {
1868                !!!cp (122.1);
1869                !!!parse-error (type => 'end tag attribute');
1870              } else {
1871                ## NOTE: This state should never be reached.
1872                !!!cp (122.2);
1873              }
1874            } else {
1875              die "$0: $self->{current_token}->{type}: Unknown token type";
1876            }
1877            $self->{state} = DATA_STATE;
1878            ## Reconsume.
1879            !!!emit ($self->{current_token}); # start tag or end tag
1880            redo A;
1881        } else {        } else {
1882          !!!cp ('124.1');          !!!cp ('124.1');
1883          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
# Line 1678  sub _get_next_token ($) { Line 1910  sub _get_next_token ($) {
1910          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
1911    
1912          redo A;          redo A;
1913          } elsif ($self->{next_char} == -1) {
1914            !!!parse-error (type => 'unclosed tag');
1915            if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1916              !!!cp (124.7);
1917              $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1918            } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1919              if ($self->{current_token}->{attributes}) {
1920                !!!cp (124.5);
1921                !!!parse-error (type => 'end tag attribute');
1922              } else {
1923                ## NOTE: This state should never be reached.
1924                !!!cp (124.6);
1925              }
1926            } else {
1927              die "$0: $self->{current_token}->{type}: Unknown token type";
1928            }
1929            $self->{state} = DATA_STATE;
1930            ## Reconsume.
1931            !!!emit ($self->{current_token}); # start tag or end tag
1932            redo A;
1933        } else {        } else {
1934          !!!cp ('124.4');          !!!cp ('124.4');
1935          !!!parse-error (type => 'nestc');          !!!parse-error (type => 'nestc');
# Line 2435  sub _get_next_token ($) { Line 2687  sub _get_next_token ($) {
2687          redo A;          redo A;
2688        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2689          !!!cp (208);          !!!cp (208);
2690          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2691    
2692          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2693          !!!next-input-character;          !!!next-input-character;
# Line 2471  sub _get_next_token ($) { Line 2723  sub _get_next_token ($) {
2723          redo A;          redo A;
2724        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
2725          !!!cp (212);          !!!cp (212);
2726          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2727    
2728          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2729          !!!next-input-character;          !!!next-input-character;
# Line 2519  sub _get_next_token ($) { Line 2771  sub _get_next_token ($) {
2771        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
2772          !!!cp (217);          !!!cp (217);
2773          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
   
2774          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2775          ## reconsume          ## reconsume
2776    
# Line 2681  sub _tokenize_attempt_to_consume_an_enti Line 2932  sub _tokenize_attempt_to_consume_an_enti
2932    
2933          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2934            !!!cp (1008);            !!!cp (1008);
2935            !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2936                              text => (sprintf 'U+%04X', $code),
2937                              line => $l, column => $c);
2938            $code = 0xFFFD;            $code = 0xFFFD;
2939          } elsif ($code > 0x10FFFF) {          } elsif ($code > 0x10FFFF) {
2940            !!!cp (1009);            !!!cp (1009);
2941            !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);            !!!parse-error (type => 'invalid character reference',
2942                              text => (sprintf 'U-%08X', $code),
2943                              line => $l, column => $c);
2944            $code = 0xFFFD;            $code = 0xFFFD;
2945          } elsif ($code == 0x000D) {          } elsif ($code == 0x000D) {
2946            !!!cp (1010);            !!!cp (1010);
# Line 2693  sub _tokenize_attempt_to_consume_an_enti Line 2948  sub _tokenize_attempt_to_consume_an_enti
2948            $code = 0x000A;            $code = 0x000A;
2949          } elsif (0x80 <= $code and $code <= 0x9F) {          } elsif (0x80 <= $code and $code <= 0x9F) {
2950            !!!cp (1011);            !!!cp (1011);
2951            !!!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);
2952            $code = $c1_entity_char->{$code};            $code = $c1_entity_char->{$code};
2953          }          }
2954    
# Line 2726  sub _tokenize_attempt_to_consume_an_enti Line 2981  sub _tokenize_attempt_to_consume_an_enti
2981    
2982        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
2983          !!!cp (1015);          !!!cp (1015);
2984          !!!parse-error (type => (sprintf 'invalid character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
2985                            text => (sprintf 'U+%04X', $code),
2986                            line => $l, column => $c);
2987          $code = 0xFFFD;          $code = 0xFFFD;
2988        } elsif ($code > 0x10FFFF) {        } elsif ($code > 0x10FFFF) {
2989          !!!cp (1016);          !!!cp (1016);
2990          !!!parse-error (type => (sprintf 'invalid character reference:U-%08X', $code), line => $l, column => $c);          !!!parse-error (type => 'invalid character reference',
2991                            text => (sprintf 'U-%08X', $code),
2992                            line => $l, column => $c);
2993          $code = 0xFFFD;          $code = 0xFFFD;
2994        } elsif ($code == 0x000D) {        } elsif ($code == 0x000D) {
2995          !!!cp (1017);          !!!cp (1017);
2996          !!!parse-error (type => 'CR character reference', line => $l, column => $c);          !!!parse-error (type => 'CR character reference',
2997                            line => $l, column => $c);
2998          $code = 0x000A;          $code = 0x000A;
2999        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
3000          !!!cp (1018);          !!!cp (1018);
3001          !!!parse-error (type => (sprintf 'C1 character reference:U+%04X', $code), line => $l, column => $c);          !!!parse-error (type => 'C1 character reference',
3002                            text => (sprintf 'U+%04X', $code),
3003                            line => $l, column => $c);
3004          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
3005        }        }
3006                
# Line 2836  sub _initialize_tree_constructor ($) { Line 3098  sub _initialize_tree_constructor ($) {
3098    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
3099    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
3100    $self->{document}->manakai_is_html (1); # MUST    $self->{document}->manakai_is_html (1); # MUST
3101      $self->{document}->set_user_data (manakai_source_line => 1);
3102      $self->{document}->set_user_data (manakai_source_column => 1);
3103  } # _initialize_tree_constructor  } # _initialize_tree_constructor
3104    
3105  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 2922  sub _tree_construction_initial ($) { Line 3186  sub _tree_construction_initial ($) {
3186        } elsif (defined $token->{public_identifier}) {        } elsif (defined $token->{public_identifier}) {
3187          my $pubid = $token->{public_identifier};          my $pubid = $token->{public_identifier};
3188          $pubid =~ tr/a-z/A-z/;          $pubid =~ tr/a-z/A-z/;
3189          if ({          my $prefix = [
3190            "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,            "+//SILMARIL//DTD HTML PRO V0R11 19970101//",
3191            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3192            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,            "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//",
3193            "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 1//",
3194            "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 LEVEL 2//",
3195            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//",
3196            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//",
3197            "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,            "-//IETF//DTD HTML 2.0 STRICT//",
3198            "-//IETF//DTD HTML 2.0//EN" => 1,            "-//IETF//DTD HTML 2.0//",
3199            "-//IETF//DTD HTML 2.1E//EN" => 1,            "-//IETF//DTD HTML 2.1E//",
3200            "-//IETF//DTD HTML 3.0//EN" => 1,            "-//IETF//DTD HTML 3.0//",
3201            "-//IETF//DTD HTML 3.0//EN//" => 1,            "-//IETF//DTD HTML 3.2 FINAL//",
3202            "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,            "-//IETF//DTD HTML 3.2//",
3203            "-//IETF//DTD HTML 3.2//EN" => 1,            "-//IETF//DTD HTML 3//",
3204            "-//IETF//DTD HTML 3//EN" => 1,            "-//IETF//DTD HTML LEVEL 0//",
3205            "-//IETF//DTD HTML LEVEL 0//EN" => 1,            "-//IETF//DTD HTML LEVEL 1//",
3206            "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,            "-//IETF//DTD HTML LEVEL 2//",
3207            "-//IETF//DTD HTML LEVEL 1//EN" => 1,            "-//IETF//DTD HTML LEVEL 3//",
3208            "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 0//",
3209            "-//IETF//DTD HTML LEVEL 2//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 1//",
3210            "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,            "-//IETF//DTD HTML STRICT LEVEL 2//",
3211            "-//IETF//DTD HTML LEVEL 3//EN" => 1,            "-//IETF//DTD HTML STRICT LEVEL 3//",
3212            "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,            "-//IETF//DTD HTML STRICT//",
3213            "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,            "-//IETF//DTD HTML//",
3214            "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,            "-//METRIUS//DTD METRIUS PRESENTATIONAL//",
3215            "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//",
3216            "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//",
3217            "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//",
3218            "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//",
3219            "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//",
3220            "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//",
3221            "-//IETF//DTD HTML STRICT//EN" => 1,            "-//NETSCAPE COMM. CORP.//DTD HTML//",
3222            "-//IETF//DTD HTML STRICT//EN//2.0" => 1,            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//",
3223            "-//IETF//DTD HTML STRICT//EN//3.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//",
3224            "-//IETF//DTD HTML//EN" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//",
3225            "-//IETF//DTD HTML//EN//2.0" => 1,            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//",
3226            "-//IETF//DTD HTML//EN//3.0" => 1,            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//",
3227            "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//",
3228            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//",
3229            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//",
3230            "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//",
3231            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//",
3232            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,            "-//W3C//DTD HTML 3 1995-03-24//",
3233            "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,            "-//W3C//DTD HTML 3.2 DRAFT//",
3234            "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,            "-//W3C//DTD HTML 3.2 FINAL//",
3235            "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,            "-//W3C//DTD HTML 3.2//",
3236            "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,            "-//W3C//DTD HTML 3.2S DRAFT//",
3237            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 FRAMESET//",
3238            "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED RELAXED 1.0//EN" => 1,            "-//W3C//DTD HTML 4.0 TRANSITIONAL//",
3239            "-//SOFTQUAD SOFTWARE//DTD HOTMETAL PRO 6.0::19990601::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMETNAL 19960712//",
3240            "-//SOFTQUAD//DTD HOTMETAL PRO 4.0::19971010::EXTENSIONS TO HTML 4.0//EN" => 1,            "-//W3C//DTD HTML EXPERIMENTAL 970421//",
3241            "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,            "-//W3C//DTD W3 HTML//",
3242            "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,            "-//W3O//DTD W3 HTML 3.0//",
3243            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML 2.0//",
3244            "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,            "-//WEBTECHS//DTD MOZILLA HTML//",
3245            "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,          ]; # $prefix
3246            "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,          my $match;
3247            "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,          for (@$prefix) {
3248            "-//W3C//DTD HTML 3.2//EN" => 1,            if (substr ($prefix, 0, length $_) eq $_) {
3249            "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,              $match = 1;
3250            "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,              last;
3251            "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,            }
3252            "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,          }
3253            "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,          if ($match or
3254            "-//W3C//DTD W3 HTML//EN" => 1,              $pubid eq "-//W3O//DTD W3 HTML STRICT 3.0//EN//" or
3255            "-//W3O//DTD W3 HTML 3.0//EN" => 1,              $pubid eq "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" or
3256            "-//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}) {  
3257            !!!cp ('t5');            !!!cp ('t5');
3258            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3259          } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD HTML 4.01 FRAMESET//] or
3260                   $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD HTML 4.01 TRANSITIONAL//]) {
3261            if (defined $token->{system_identifier}) {            if (defined $token->{system_identifier}) {
3262              !!!cp ('t6');              !!!cp ('t6');
3263              $self->{document}->manakai_compat_mode ('quirks');              $self->{document}->manakai_compat_mode ('quirks');
# Line 3007  sub _tree_construction_initial ($) { Line 3265  sub _tree_construction_initial ($) {
3265              !!!cp ('t7');              !!!cp ('t7');
3266              $self->{document}->manakai_compat_mode ('limited quirks');              $self->{document}->manakai_compat_mode ('limited quirks');
3267            }            }
3268          } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 FRAMESET//EN" or          } elsif ($pubid =~ m[^-//W3C//DTD XHTML 1.0 FRAMESET//] or
3269                   $pubid eq "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN") {                   $pubid =~ m[^-//W3C//DTD XHTML 1.0 TRANSITIONAL//]) {
3270            !!!cp ('t8');            !!!cp ('t8');
3271            $self->{document}->manakai_compat_mode ('limited quirks');            $self->{document}->manakai_compat_mode ('limited quirks');
3272          } else {          } else {
# Line 3021  sub _tree_construction_initial ($) { Line 3279  sub _tree_construction_initial ($) {
3279          my $sysid = $token->{system_identifier};          my $sysid = $token->{system_identifier};
3280          $sysid =~ tr/A-Z/a-z/;          $sysid =~ tr/A-Z/a-z/;
3281          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") {
3282            ## TODO: Check the spec: PUBLIC "(limited quirks)" "(quirks)"            ## NOTE: Ensure that |PUBLIC "(limited quirks)" "(quirks)"| is
3283              ## marked as quirks.
3284            $self->{document}->manakai_compat_mode ('quirks');            $self->{document}->manakai_compat_mode ('quirks');
3285            !!!cp ('t11');            !!!cp ('t11');
3286          } else {          } else {
# Line 3193  sub _reset_insertion_mode ($) { Line 3452  sub _reset_insertion_mode ($) {
3452        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3453          $last = 1;          $last = 1;
3454          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3455            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {            !!!cp ('t28');
3456              !!!cp ('t27');            $node = $self->{inner_html_node};
3457              #          } else {
3458            } else {            die "_reset_insertion_mode: t27";
             !!!cp ('t28');  
             $node = $self->{inner_html_node};  
           }  
3459          }          }
3460        }        }
3461              
3462      ## Step 4..14        ## Step 4..14
3463      my $new_mode;        my $new_mode;
3464      if ($node->[1] & FOREIGN_EL) {        if ($node->[1] & FOREIGN_EL) {
3465        ## NOTE: Strictly spaking, the line below only applies to MathML and          !!!cp ('t28.1');
3466        ## SVG elements.  Currently the HTML syntax supports only MathML and          ## NOTE: Strictly spaking, the line below only applies to MathML and
3467        ## SVG elements as foreigners.          ## SVG elements.  Currently the HTML syntax supports only MathML and
3468        $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;          ## SVG elements as foreigners.
3469        ## ISSUE: What is set as the secondary insertion mode?          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3470      } else {        } elsif ($node->[1] & TABLE_CELL_EL) {
3471        $new_mode = {          if ($last) {
3472              !!!cp ('t28.2');
3473              #
3474            } else {
3475              !!!cp ('t28.3');
3476              $new_mode = IN_CELL_IM;
3477            }
3478          } else {
3479            !!!cp ('t28.4');
3480            $new_mode = {
3481                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3482                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3483                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
                       td => IN_CELL_IM,  
                       th => IN_CELL_IM,  
3484                        tr => IN_ROW_IM,                        tr => IN_ROW_IM,
3485                        tbody => IN_TABLE_BODY_IM,                        tbody => IN_TABLE_BODY_IM,
3486                        thead => IN_TABLE_BODY_IM,                        thead => IN_TABLE_BODY_IM,
# Line 3229  sub _reset_insertion_mode ($) { Line 3492  sub _reset_insertion_mode ($) {
3492                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3493                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3494                       }->{$node->[0]->manakai_local_name};                       }->{$node->[0]->manakai_local_name};
3495      }        }
3496      $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3497                
3498        ## Step 15        ## Step 15
3499        if ($node->[1] & HTML_EL) {        if ($node->[1] & HTML_EL) {
# Line 3404  sub _tree_construction_main ($) { Line 3667  sub _tree_construction_main ($) {
3667        ## NOTE: An end-of-file token.        ## NOTE: An end-of-file token.
3668        if ($content_model_flag == CDATA_CONTENT_MODEL) {        if ($content_model_flag == CDATA_CONTENT_MODEL) {
3669          !!!cp ('t43');          !!!cp ('t43');
3670          !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in CDATA:#eof', token => $token);
3671        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {        } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {
3672          !!!cp ('t44');          !!!cp ('t44');
3673          !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);          !!!parse-error (type => 'in RCDATA:#eof', token => $token);
3674        } else {        } else {
3675          die "$0: $content_model_flag in parse_rcdata";          die "$0: $content_model_flag in parse_rcdata";
3676        }        }
# Line 3444  sub _tree_construction_main ($) { Line 3707  sub _tree_construction_main ($) {
3707        ## Ignore the token        ## Ignore the token
3708      } else {      } else {
3709        !!!cp ('t48');        !!!cp ('t48');
3710        !!!parse-error (type => 'in CDATA:#'.$token->{type}, token => $token);        !!!parse-error (type => 'in CDATA:#eof', token => $token);
3711        ## ISSUE: And ignore?        ## ISSUE: And ignore?
3712        ## TODO: mark as "already executed"        ## TODO: mark as "already executed"
3713      }      }
# Line 3495  sub _tree_construction_main ($) { Line 3758  sub _tree_construction_main ($) {
3758        } # AFE        } # AFE
3759        unless (defined $formatting_element) {        unless (defined $formatting_element) {
3760          !!!cp ('t53');          !!!cp ('t53');
3761          !!!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);
3762          ## Ignore the token          ## Ignore the token
3763          !!!next-token;          !!!next-token;
3764          return;          return;
# Line 3512  sub _tree_construction_main ($) { Line 3775  sub _tree_construction_main ($) {
3775              last INSCOPE;              last INSCOPE;
3776            } else { # in open elements but not in scope            } else { # in open elements but not in scope
3777              !!!cp ('t55');              !!!cp ('t55');
3778              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},              !!!parse-error (type => 'unmatched end tag',
3779                                text => $token->{tag_name},
3780                              token => $end_tag_token);                              token => $end_tag_token);
3781              ## Ignore the token              ## Ignore the token
3782              !!!next-token;              !!!next-token;
# Line 3525  sub _tree_construction_main ($) { Line 3789  sub _tree_construction_main ($) {
3789        } # INSCOPE        } # INSCOPE
3790        unless (defined $formatting_element_i_in_open) {        unless (defined $formatting_element_i_in_open) {
3791          !!!cp ('t57');          !!!cp ('t57');
3792          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name},          !!!parse-error (type => 'unmatched end tag',
3793                            text => $token->{tag_name},
3794                          token => $end_tag_token);                          token => $end_tag_token);
3795          pop @$active_formatting_elements; # $formatting_element          pop @$active_formatting_elements; # $formatting_element
3796          !!!next-token; ## TODO: ok?          !!!next-token; ## TODO: ok?
# Line 3534  sub _tree_construction_main ($) { Line 3799  sub _tree_construction_main ($) {
3799        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3800          !!!cp ('t58');          !!!cp ('t58');
3801          !!!parse-error (type => 'not closed',          !!!parse-error (type => 'not closed',
3802                          value => $self->{open_elements}->[-1]->[0]                          text => $self->{open_elements}->[-1]->[0]
3803                              ->manakai_local_name,                              ->manakai_local_name,
3804                          token => $end_tag_token);                          token => $end_tag_token);
3805        }        }
# Line 3743  sub _tree_construction_main ($) { Line 4008  sub _tree_construction_main ($) {
4008    B: while (1) {    B: while (1) {
4009      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4010        !!!cp ('t73');        !!!cp ('t73');
4011        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'in html:#DOCTYPE', token => $token);
4012        ## Ignore the token        ## Ignore the token
4013        ## Stay in the phase        ## Stay in the phase
4014        !!!next-token;        !!!next-token;
# Line 3752  sub _tree_construction_main ($) { Line 4017  sub _tree_construction_main ($) {
4017               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
4018        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
4019          !!!cp ('t79');          !!!cp ('t79');
4020          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4021          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
4022        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {        } elsif ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
4023          !!!cp ('t80');          !!!cp ('t80');
4024          !!!parse-error (type => 'after html:html', token => $token);          !!!parse-error (type => 'after html', text => 'html', token => $token);
4025          $self->{insertion_mode} = AFTER_FRAMESET_IM;          $self->{insertion_mode} = AFTER_FRAMESET_IM;
4026        } else {        } else {
4027          !!!cp ('t81');          !!!cp ('t81');
# Line 3807  sub _tree_construction_main ($) { Line 4072  sub _tree_construction_main ($) {
4072            #            #
4073          } elsif ({          } elsif ({
4074                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,                    b => 1, big => 1, blockquote => 1, body => 1, br => 1,
4075                    center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,                    center => 1, code => 1, dd => 1, div => 1, dl => 1, dt => 1,
4076                    embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!                    em => 1, embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1,
4077                    h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,                    h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, i => 1,
4078                    li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,                    img => 1, li => 1, listing => 1, menu => 1, meta => 1,
4079                    ruby => 1, s => 1, small => 1, span => 1, strong => 1,                    nobr => 1, ol => 1, p => 1, pre => 1, ruby => 1, s => 1,
4080                    sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,                    small => 1, span => 1, strong => 1, strike => 1, sub => 1,
4081                    var => 1,                    sup => 1, table => 1, tt => 1, u => 1, ul => 1, var => 1,
4082                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
4083            !!!cp ('t87.2');            !!!cp ('t87.2');
4084            !!!parse-error (type => 'not closed',            !!!parse-error (type => 'not closed',
4085                            value => $self->{open_elements}->[-1]->[0]                            text => $self->{open_elements}->[-1]->[0]
4086                                ->manakai_local_name,                                ->manakai_local_name,
4087                            token => $token);                            token => $token);
4088    
# Line 3893  sub _tree_construction_main ($) { Line 4158  sub _tree_construction_main ($) {
4158          !!!cp ('t87.5');          !!!cp ('t87.5');
4159          #          #
4160        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
         ## NOTE: "using the rules for secondary insertion mode" then "continue"  
4161          !!!cp ('t87.6');          !!!cp ('t87.6');
4162          #          !!!parse-error (type => 'not closed',
4163          ## TODO: ...                          text => $self->{open_elements}->[-1]->[0]
4164                                ->manakai_local_name,
4165                            token => $token);
4166    
4167            pop @{$self->{open_elements}}
4168                while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4169    
4170            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4171            ## Reprocess.
4172            next B;
4173        } else {        } else {
4174          die "$0: $token->{type}: Unknown token type";                  die "$0: $token->{type}: Unknown token type";        
4175        }        }
# Line 3937  sub _tree_construction_main ($) { Line 4210  sub _tree_construction_main ($) {
4210            !!!cp ('t90');            !!!cp ('t90');
4211            ## As if </noscript>            ## As if </noscript>
4212            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
4213            !!!parse-error (type => 'in noscript:#character', token => $token);            !!!parse-error (type => 'in noscript:#text', token => $token);
4214                        
4215            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
4216            ## As if </head>            ## As if </head>
# Line 3973  sub _tree_construction_main ($) { Line 4246  sub _tree_construction_main ($) {
4246              !!!next-token;              !!!next-token;
4247              next B;              next B;
4248            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4249              !!!cp ('t94');              !!!cp ('t93.2');
4250              #              !!!parse-error (type => 'after head', text => 'head',
4251                                token => $token);
4252                ## Ignore the token
4253                !!!nack ('t93.3');
4254                !!!next-token;
4255                next B;
4256            } else {            } else {
4257              !!!cp ('t95');              !!!cp ('t95');
4258              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              !!!parse-error (type => 'in head:head',
4259                                token => $token); # or in head noscript
4260              ## Ignore the token              ## Ignore the token
4261              !!!nack ('t95.1');              !!!nack ('t95.1');
4262              !!!next-token;              !!!next-token;
# Line 4002  sub _tree_construction_main ($) { Line 4281  sub _tree_construction_main ($) {
4281                  !!!cp ('t98');                  !!!cp ('t98');
4282                  ## As if </noscript>                  ## As if </noscript>
4283                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4284                  !!!parse-error (type => 'in noscript:base', token => $token);                  !!!parse-error (type => 'in noscript', text => 'base',
4285                                    token => $token);
4286                                
4287                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4288                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 4013  sub _tree_construction_main ($) { Line 4293  sub _tree_construction_main ($) {
4293                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4294                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4295                  !!!cp ('t100');                  !!!cp ('t100');
4296                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4297                                    text => $token->{tag_name}, token => $token);
4298                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4299                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4300                } else {                } else {
# Line 4030  sub _tree_construction_main ($) { Line 4311  sub _tree_construction_main ($) {
4311                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4312                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4313                  !!!cp ('t102');                  !!!cp ('t102');
4314                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4315                                    text => $token->{tag_name}, token => $token);
4316                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4317                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4318                } else {                } else {
# Line 4047  sub _tree_construction_main ($) { Line 4329  sub _tree_construction_main ($) {
4329                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4330                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4331                  !!!cp ('t104');                  !!!cp ('t104');
4332                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4333                                    text => $token->{tag_name}, token => $token);
4334                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4335                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4336                } else {                } else {
# Line 4057  sub _tree_construction_main ($) { Line 4340  sub _tree_construction_main ($) {
4340                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4341    
4342                unless ($self->{confident}) {                unless ($self->{confident}) {
4343                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) {
4344                    !!!cp ('t106');                    !!!cp ('t106');
4345                      ## NOTE: Whether the encoding is supported or not is handled
4346                      ## in the {change_encoding} callback.
4347                    $self->{change_encoding}                    $self->{change_encoding}
4348                        ->($self, $token->{attributes}->{charset}->{value},                        ->($self, $token->{attributes}->{charset}->{value},
4349                           $token);                           $token);
# Line 4068  sub _tree_construction_main ($) { Line 4353  sub _tree_construction_main ($) {
4353                                             $token->{attributes}->{charset}                                             $token->{attributes}->{charset}
4354                                                 ->{has_reference});                                                 ->{has_reference});
4355                  } elsif ($token->{attributes}->{content}) {                  } elsif ($token->{attributes}->{content}) {
                   ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
4356                    if ($token->{attributes}->{content}->{value}                    if ($token->{attributes}->{content}->{value}
4357                        =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                        =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
4358                            [\x09-\x0D\x20]*=                            [\x09-\x0D\x20]*=
4359                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                            [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
4360                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
4361                      !!!cp ('t107');                      !!!cp ('t107');
4362                        ## NOTE: Whether the encoding is supported or not is handled
4363                        ## in the {change_encoding} callback.
4364                      $self->{change_encoding}                      $self->{change_encoding}
4365                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,
4366                             $token);                             $token);
# Line 4113  sub _tree_construction_main ($) { Line 4399  sub _tree_construction_main ($) {
4399                  !!!cp ('t111');                  !!!cp ('t111');
4400                  ## As if </noscript>                  ## As if </noscript>
4401                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4402                  !!!parse-error (type => 'in noscript:title', token => $token);                  !!!parse-error (type => 'in noscript', text => 'title',
4403                                    token => $token);
4404                                
4405                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4406                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4407                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4408                  !!!cp ('t112');                  !!!cp ('t112');
4409                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4410                                    text => $token->{tag_name}, token => $token);
4411                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4412                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4413                } else {                } else {
# Line 4133  sub _tree_construction_main ($) { Line 4421  sub _tree_construction_main ($) {
4421                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4422                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4423                next B;                next B;
4424              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style' or
4425                         $token->{tag_name} eq 'noframes') {
4426                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4427                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
4428                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4429                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4430                  !!!cp ('t114');                  !!!cp ('t114');
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 4160  sub _tree_construction_main ($) { Line 4450  sub _tree_construction_main ($) {
4450                  next B;                  next B;
4451                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4452                  !!!cp ('t117');                  !!!cp ('t117');
4453                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript', text => 'noscript',
4454                                    token => $token);
4455                  ## Ignore the token                  ## Ignore the token
4456                  !!!nack ('t117.1');                  !!!nack ('t117.1');
4457                  !!!next-token;                  !!!next-token;
# Line 4174  sub _tree_construction_main ($) { Line 4465  sub _tree_construction_main ($) {
4465                  !!!cp ('t119');                  !!!cp ('t119');
4466                  ## As if </noscript>                  ## As if </noscript>
4467                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4468                  !!!parse-error (type => 'in noscript:script', token => $token);                  !!!parse-error (type => 'in noscript', text => 'script',
4469                                    token => $token);
4470                                
4471                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4472                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4473                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4474                  !!!cp ('t120');                  !!!cp ('t120');
4475                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head',
4476                                    text => $token->{tag_name}, token => $token);
4477                  push @{$self->{open_elements}},                  push @{$self->{open_elements}},
4478                      [$self->{head_element}, $el_category->{head}];                      [$self->{head_element}, $el_category->{head}];
4479                } else {                } else {
# Line 4198  sub _tree_construction_main ($) { Line 4491  sub _tree_construction_main ($) {
4491                  !!!cp ('t122');                  !!!cp ('t122');
4492                  ## As if </noscript>                  ## As if </noscript>
4493                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4494                  !!!parse-error (type => 'in noscript:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in noscript',
4495                                    text => $token->{tag_name}, token => $token);
4496                                    
4497                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4498                  ## As if </head>                  ## As if </head>
# Line 4237  sub _tree_construction_main ($) { Line 4531  sub _tree_construction_main ($) {
4531                !!!cp ('t129');                !!!cp ('t129');
4532                ## As if </noscript>                ## As if </noscript>
4533                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4534                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4535                                  text => $token->{tag_name}, token => $token);
4536                                
4537                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4538                ## As if </head>                ## As if </head>
# Line 4280  sub _tree_construction_main ($) { Line 4575  sub _tree_construction_main ($) {
4575                  !!!cp ('t133');                  !!!cp ('t133');
4576                  ## As if </noscript>                  ## As if </noscript>
4577                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4578                  !!!parse-error (type => 'in noscript:/head', token => $token);                  !!!parse-error (type => 'in noscript:/',
4579                                    text => 'head', token => $token);
4580                                    
4581                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4582                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4293  sub _tree_construction_main ($) { Line 4589  sub _tree_construction_main ($) {
4589                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4590                  !!!next-token;                  !!!next-token;
4591                  next B;                  next B;
4592                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4593                    !!!cp ('t134.1');
4594                    !!!parse-error (type => 'unmatched end tag', text => 'head',
4595                                    token => $token);
4596                    ## Ignore the token
4597                    !!!next-token;
4598                    next B;
4599                } else {                } else {
4600                  !!!cp ('t135');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
                 #  
4601                }                }
4602              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4603                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 4304  sub _tree_construction_main ($) { Line 4606  sub _tree_construction_main ($) {
4606                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4607                  !!!next-token;                  !!!next-token;
4608                  next B;                  next B;
4609                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM or
4610                           $self->{insertion_mode} == AFTER_HEAD_IM) {
4611                  !!!cp ('t137');                  !!!cp ('t137');
4612                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag',
4613                                    text => 'noscript', token => $token);
4614                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4615                  !!!next-token;                  !!!next-token;
4616                  next B;                  next B;
# Line 4317  sub _tree_construction_main ($) { Line 4621  sub _tree_construction_main ($) {
4621              } elsif ({              } elsif ({
4622                        body => 1, html => 1,                        body => 1, html => 1,
4623                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
4624                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM or
4625                  !!!cp ('t139');                    $self->{insertion_mode} == IN_HEAD_IM or
4626                  ## 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) {  
4627                  !!!cp ('t140');                  !!!cp ('t140');
4628                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4629                                    text => $token->{tag_name}, token => $token);
4630                    ## Ignore the token
4631                    !!!next-token;
4632                    next B;
4633                  } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4634                    !!!cp ('t140.1');
4635                    !!!parse-error (type => 'unmatched end tag',
4636                                    text => $token->{tag_name}, token => $token);
4637                  ## Ignore the token                  ## Ignore the token
4638                  !!!next-token;                  !!!next-token;
4639                  next B;                  next B;
4640                } else {                } else {
4641                  !!!cp ('t141');                  die "$0: $self->{insertion_mode}: Unknown insertion mode";
4642                }                }
4643                              } elsif ($token->{tag_name} eq 'p') {
4644                #                !!!cp ('t142');
4645              } elsif ({                !!!parse-error (type => 'unmatched end tag',
4646                        p => 1, br => 1,                                text => $token->{tag_name}, token => $token);
4647                       }->{$token->{tag_name}}) {                ## Ignore the token
4648                  !!!next-token;
4649                  next B;
4650                } elsif ($token->{tag_name} eq 'br') {
4651                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4652                  !!!cp ('t142');                  !!!cp ('t142.2');
4653                  ## As if <head>                  ## (before head) as if <head>, (in head) as if </head>
4654                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4655                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4656                  push @{$self->{open_elements}},                  $self->{insertion_mode} = AFTER_HEAD_IM;
4657                      [$self->{head_element}, $el_category->{head}];    
4658                    ## Reprocess in the "after head" insertion mode...
4659                  } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4660                    !!!cp ('t143.2');
4661                    ## As if </head>
4662                    pop @{$self->{open_elements}};
4663                    $self->{insertion_mode} = AFTER_HEAD_IM;
4664      
4665                    ## Reprocess in the "after head" insertion mode...
4666                  } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4667                    !!!cp ('t143.3');
4668                    ## ISSUE: Two parse errors for <head><noscript></br>
4669                    !!!parse-error (type => 'unmatched end tag',
4670                                    text => 'br', token => $token);
4671                    ## As if </noscript>
4672                    pop @{$self->{open_elements}};
4673                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4674    
4675                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4676                } else {                  ## As if </head>
4677                  !!!cp ('t143');                  pop @{$self->{open_elements}};
4678                }                  $self->{insertion_mode} = AFTER_HEAD_IM;
4679    
4680                #                  ## Reprocess in the "after head" insertion mode...
4681              } else {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4682                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                  !!!cp ('t143.4');
                 !!!cp ('t144');  
4683                  #                  #
4684                } else {                } else {
4685                  !!!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;  
4686                }                }
4687    
4688                  ## ISSUE: does not agree with IE7 - it doesn't ignore </br>.
4689                  !!!parse-error (type => 'unmatched end tag',
4690                                  text => 'br', token => $token);
4691                  ## Ignore the token
4692                  !!!next-token;
4693                  next B;
4694                } else {
4695                  !!!cp ('t145');
4696                  !!!parse-error (type => 'unmatched end tag',
4697                                  text => $token->{tag_name}, token => $token);
4698                  ## Ignore the token
4699                  !!!next-token;
4700                  next B;
4701              }              }
4702    
4703              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {              if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4704                !!!cp ('t146');                !!!cp ('t146');
4705                ## As if </noscript>                ## As if </noscript>
4706                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
4707                !!!parse-error (type => 'in noscript:/'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'in noscript:/',
4708                                  text => $token->{tag_name}, token => $token);
4709                                
4710                ## Reprocess in the "in head" insertion mode...                ## Reprocess in the "in head" insertion mode...
4711                ## As if </head>                ## As if </head>
# Line 4389  sub _tree_construction_main ($) { Line 4721  sub _tree_construction_main ($) {
4721              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4722  ## ISSUE: This case cannot be reached?  ## ISSUE: This case cannot be reached?
4723                !!!cp ('t148');                !!!cp ('t148');
4724                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
4725                                  text => $token->{tag_name}, token => $token);
4726                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4727                !!!next-token;                !!!next-token;
4728                next B;                next B;
# Line 4500  sub _tree_construction_main ($) { Line 4833  sub _tree_construction_main ($) {
4833    
4834                  !!!cp ('t153');                  !!!cp ('t153');
4835                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4836                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
4837                  ## Ignore the token                  ## Ignore the token
4838                  !!!nack ('t153.1');                  !!!nack ('t153.1');
4839                  !!!next-token;                  !!!next-token;
4840                  next B;                  next B;
4841                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4842                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed', text => 'caption',
4843                                    token => $token);
4844                                    
4845                  ## NOTE: As if </caption>.                  ## NOTE: As if </caption>.
4846                  ## have a table element in table scope                  ## have a table element in table scope
# Line 4526  sub _tree_construction_main ($) { Line 4860  sub _tree_construction_main ($) {
4860    
4861                    !!!cp ('t157');                    !!!cp ('t157');
4862                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4863                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4864                    ## Ignore the token                    ## Ignore the token
4865                    !!!nack ('t157.1');                    !!!nack ('t157.1');
4866                    !!!next-token;                    !!!next-token;
# Line 4543  sub _tree_construction_main ($) { Line 4877  sub _tree_construction_main ($) {
4877                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4878                    !!!cp ('t159');                    !!!cp ('t159');
4879                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4880                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4881                                        ->manakai_local_name,                                        ->manakai_local_name,
4882                                    token => $token);                                    token => $token);
4883                  } else {                  } else {
# Line 4585  sub _tree_construction_main ($) { Line 4919  sub _tree_construction_main ($) {
4919                  } # INSCOPE                  } # INSCOPE
4920                    unless (defined $i) {                    unless (defined $i) {
4921                      !!!cp ('t165');                      !!!cp ('t165');
4922                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
4923                                        text => $token->{tag_name},
4924                                        token => $token);
4925                      ## Ignore the token                      ## Ignore the token
4926                      !!!next-token;                      !!!next-token;
4927                      next B;                      next B;
# Line 4602  sub _tree_construction_main ($) { Line 4938  sub _tree_construction_main ($) {
4938                          ne $token->{tag_name}) {                          ne $token->{tag_name}) {
4939                    !!!cp ('t167');                    !!!cp ('t167');
4940                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
4941                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
4942                                        ->manakai_local_name,                                        ->manakai_local_name,
4943                                    token => $token);                                    token => $token);
4944                  } else {                  } else {
# Line 4619  sub _tree_construction_main ($) { Line 4955  sub _tree_construction_main ($) {
4955                  next B;                  next B;
4956                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4957                  !!!cp ('t169');                  !!!cp ('t169');
4958                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
4959                                    text => $token->{tag_name}, token => $token);
4960                  ## Ignore the token                  ## Ignore the token
4961                  !!!next-token;                  !!!next-token;
4962                  next B;                  next B;
# Line 4646  sub _tree_construction_main ($) { Line 4983  sub _tree_construction_main ($) {
4983    
4984                    !!!cp ('t173');                    !!!cp ('t173');
4985                    !!!parse-error (type => 'unmatched end tag',                    !!!parse-error (type => 'unmatched end tag',
4986                                    value => $token->{tag_name}, token => $token);                                    text => $token->{tag_name}, token => $token);
4987                    ## Ignore the token                    ## Ignore the token
4988                    !!!next-token;                    !!!next-token;
4989                    next B;                    next B;
# Line 4662  sub _tree_construction_main ($) { Line 4999  sub _tree_construction_main ($) {
4999                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5000                    !!!cp ('t175');                    !!!cp ('t175');
5001                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5002                                    value => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
5003                                        ->manakai_local_name,                                        ->manakai_local_name,
5004                                    token => $token);                                    token => $token);
5005                  } else {                  } else {
# Line 4679  sub _tree_construction_main ($) { Line 5016  sub _tree_construction_main ($) {
5016                  next B;                  next B;
5017                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
5018                  !!!cp ('t177');                  !!!cp ('t177');
5019                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5020                                    text => $token->{tag_name}, token => $token);
5021                  ## Ignore the token                  ## Ignore the token
5022                  !!!next-token;                  !!!next-token;
5023                  next B;                  next B;
# Line 4722  sub _tree_construction_main ($) { Line 5060  sub _tree_construction_main ($) {
5060    
5061                  !!!cp ('t182');                  !!!cp ('t182');
5062                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
5063                      value => $token->{tag_name}, token => $token);                      text => $token->{tag_name}, token => $token);
5064                  ## Ignore the token                  ## Ignore the token
5065                  !!!next-token;                  !!!next-token;
5066                  next B;                  next B;
5067                } # INSCOPE                } # INSCOPE
5068              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
5069                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5070                !!!parse-error (type => 'not closed:caption', token => $token);                !!!parse-error (type => 'not closed', text => 'caption',
5071                                  token => $token);
5072    
5073                ## As if </caption>                ## As if </caption>
5074                ## have a table element in table scope                ## have a table element in table scope
# Line 4747  sub _tree_construction_main ($) { Line 5086  sub _tree_construction_main ($) {
5086                } # INSCOPE                } # INSCOPE
5087                unless (defined $i) {                unless (defined $i) {
5088                  !!!cp ('t186');                  !!!cp ('t186');
5089                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5090                                    text => 'caption', token => $token);
5091                  ## Ignore the token                  ## Ignore the token
5092                  !!!next-token;                  !!!next-token;
5093                  next B;                  next B;
# Line 4762  sub _tree_construction_main ($) { Line 5102  sub _tree_construction_main ($) {
5102                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
5103                  !!!cp ('t188');                  !!!cp ('t188');
5104                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5105                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5106                                      ->manakai_local_name,                                      ->manakai_local_name,
5107                                  token => $token);                                  token => $token);
5108                } else {                } else {
# Line 4782  sub _tree_construction_main ($) { Line 5122  sub _tree_construction_main ($) {
5122                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5123                if ($self->{insertion_mode} & BODY_TABLE_IMS) {                if ($self->{insertion_mode} & BODY_TABLE_IMS) {
5124                  !!!cp ('t190');                  !!!cp ('t190');
5125                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5126                                    text => $token->{tag_name}, token => $token);
5127                  ## Ignore the token                  ## Ignore the token
5128                  !!!next-token;                  !!!next-token;
5129                  next B;                  next B;
# Line 4796  sub _tree_construction_main ($) { Line 5137  sub _tree_construction_main ($) {
5137                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
5138                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
5139                !!!cp ('t192');                !!!cp ('t192');
5140                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
5141                                  text => $token->{tag_name}, token => $token);
5142                ## Ignore the token                ## Ignore the token
5143                !!!next-token;                !!!next-token;
5144                next B;                next B;
# Line 4836  sub _tree_construction_main ($) { Line 5178  sub _tree_construction_main ($) {
5178            }            }
5179          }          }
5180    
5181              !!!parse-error (type => 'in table:#character', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5182    
5183              ## As if in body, but insert into foster parent element              ## As if in body, but insert into foster parent element
5184              ## ISSUE: Spec says that "whenever a node would be inserted              ## ISSUE: Spec says that "whenever a node would be inserted
# Line 4887  sub _tree_construction_main ($) { Line 5229  sub _tree_construction_main ($) {
5229          !!!next-token;          !!!next-token;
5230          next B;          next B;
5231        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5232              if ({          if ({
5233                   tr => ($self->{insertion_mode} != IN_ROW_IM),               tr => ($self->{insertion_mode} != IN_ROW_IM),
5234                   th => 1, td => 1,               th => 1, td => 1,
5235                  }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
5236                if ($self->{insertion_mode} == IN_TABLE_IM) {            if ($self->{insertion_mode} == IN_TABLE_IM) {
5237                  ## Clear back to table context              ## Clear back to table context
5238                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5239                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5240                    !!!cp ('t201');                !!!cp ('t201');
5241                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5242                  }              }
5243                                
5244                  !!!insert-element ('tbody',, $token);              !!!insert-element ('tbody',, $token);
5245                  $self->{insertion_mode} = IN_TABLE_BODY_IM;              $self->{insertion_mode} = IN_TABLE_BODY_IM;
5246                  ## reprocess in the "in table body" insertion mode...              ## reprocess in the "in table body" insertion mode...
5247                }            }
5248              
5249                if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {            if ($self->{insertion_mode} == IN_TABLE_BODY_IM) {
5250                  unless ($token->{tag_name} eq 'tr') {              unless ($token->{tag_name} eq 'tr') {
5251                    !!!cp ('t202');                !!!cp ('t202');
5252                    !!!parse-error (type => 'missing start tag:tr', token => $token);                !!!parse-error (type => 'missing start tag:tr', token => $token);
5253                  }              }
5254                                    
5255                  ## Clear back to table body context              ## Clear back to table body context
5256                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5257                                  & TABLE_ROWS_SCOPING_EL)) {                              & TABLE_ROWS_SCOPING_EL)) {
5258                    !!!cp ('t203');                !!!cp ('t203');
5259                    ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
5260                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5261                  }              }
5262                                    
5263                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
5264                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
# Line 4972  sub _tree_construction_main ($) { Line 5314  sub _tree_construction_main ($) {
5314                  unless (defined $i) {                  unless (defined $i) {
5315                    !!!cp ('t210');                    !!!cp ('t210');
5316  ## TODO: This type is wrong.  ## TODO: This type is wrong.
5317                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag',
5318                                      text => $token->{tag_name}, token => $token);
5319                    ## Ignore the token                    ## Ignore the token
5320                    !!!nack ('t210.1');                    !!!nack ('t210.1');
5321                    !!!next-token;                    !!!next-token;
# Line 5016  sub _tree_construction_main ($) { Line 5359  sub _tree_construction_main ($) {
5359                  } # INSCOPE                  } # INSCOPE
5360                  unless (defined $i) {                  unless (defined $i) {
5361                    !!!cp ('t216');                    !!!cp ('t216');
5362  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type is wrong.
5363                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5364                                      text => $token->{tag_name}, token => $token);
5365                    ## Ignore the token                    ## Ignore the token
5366                    !!!nack ('t216.1');                    !!!nack ('t216.1');
5367                    !!!next-token;                    !!!next-token;
# Line 5092  sub _tree_construction_main ($) { Line 5436  sub _tree_construction_main ($) {
5436                }                }
5437              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5438                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5439                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
5440                                    ->manakai_local_name,                                    ->manakai_local_name,
5441                                token => $token);                                token => $token);
5442    
# Line 5113  sub _tree_construction_main ($) { Line 5457  sub _tree_construction_main ($) {
5457                unless (defined $i) {                unless (defined $i) {
5458                  !!!cp ('t223');                  !!!cp ('t223');
5459  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5460                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag', text => 'table',
5461                                    token => $token);
5462                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5463                  !!!nack ('t223.1');                  !!!nack ('t223.1');
5464                  !!!next-token;                  !!!next-token;
5465                  next B;                  next B;
5466                }                }
5467                                
5468  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5469                ## generate implied end tags                ## generate implied end tags
5470                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
5471                  !!!cp ('t224');                  !!!cp ('t224');
# Line 5131  sub _tree_construction_main ($) { Line 5476  sub _tree_construction_main ($) {
5476                  !!!cp ('t225');                  !!!cp ('t225');
5477                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5478                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5479                                  value => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
5480                                      ->manakai_local_name,                                      ->manakai_local_name,
5481                                  token => $token);                                  token => $token);
5482                } else {                } else {
# Line 5172  sub _tree_construction_main ($) { Line 5517  sub _tree_construction_main ($) {
5517                my $type = lc $token->{attributes}->{type}->{value};                my $type = lc $token->{attributes}->{type}->{value};
5518                if ($type eq 'hidden') {                if ($type eq 'hidden') {
5519                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5520                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table',
5521                                    text => $token->{tag_name}, token => $token);
5522    
5523                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5524    
# Line 5200  sub _tree_construction_main ($) { Line 5546  sub _tree_construction_main ($) {
5546            #            #
5547          }          }
5548    
5549          !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in table', text => $token->{tag_name},
5550                            token => $token);
5551    
5552          $insert = $insert_to_foster;          $insert = $insert_to_foster;
5553          #          #
# Line 5222  sub _tree_construction_main ($) { Line 5569  sub _tree_construction_main ($) {
5569                } # INSCOPE                } # INSCOPE
5570                unless (defined $i) {                unless (defined $i) {
5571                  !!!cp ('t230');                  !!!cp ('t230');
5572                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5573                                    text => $token->{tag_name}, token => $token);
5574                  ## Ignore the token                  ## Ignore the token
5575                  !!!nack ('t230.1');                  !!!nack ('t230.1');
5576                  !!!next-token;                  !!!next-token;
# Line 5263  sub _tree_construction_main ($) { Line 5611  sub _tree_construction_main ($) {
5611                  unless (defined $i) {                  unless (defined $i) {
5612                    !!!cp ('t235');                    !!!cp ('t235');
5613  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5614                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5615                                      text => $token->{type}, token => $token);
5616                    ## Ignore the token                    ## Ignore the token
5617                    !!!nack ('t236.1');                    !!!nack ('t236.1');
5618                    !!!next-token;                    !!!next-token;
# Line 5299  sub _tree_construction_main ($) { Line 5648  sub _tree_construction_main ($) {
5648                  } # INSCOPE                  } # INSCOPE
5649                  unless (defined $i) {                  unless (defined $i) {
5650                    !!!cp ('t239');                    !!!cp ('t239');
5651                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag',
5652                                      text => $token->{tag_name}, token => $token);
5653                    ## Ignore the token                    ## Ignore the token
5654                    !!!nack ('t239.1');                    !!!nack ('t239.1');
5655                    !!!next-token;                    !!!next-token;
# Line 5345  sub _tree_construction_main ($) { Line 5695  sub _tree_construction_main ($) {
5695                } # INSCOPE                } # INSCOPE
5696                unless (defined $i) {                unless (defined $i) {
5697                  !!!cp ('t243');                  !!!cp ('t243');
5698                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5699                                    text => $token->{tag_name}, token => $token);
5700                  ## Ignore the token                  ## Ignore the token
5701                  !!!nack ('t243.1');                  !!!nack ('t243.1');
5702                  !!!next-token;                  !!!next-token;
# Line 5379  sub _tree_construction_main ($) { Line 5730  sub _tree_construction_main ($) {
5730                  } # INSCOPE                  } # INSCOPE
5731                    unless (defined $i) {                    unless (defined $i) {
5732                      !!!cp ('t249');                      !!!cp ('t249');
5733                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag',
5734                                        text => $token->{tag_name}, token => $token);
5735                      ## Ignore the token                      ## Ignore the token
5736                      !!!nack ('t249.1');                      !!!nack ('t249.1');
5737                      !!!next-token;                      !!!next-token;
# Line 5402  sub _tree_construction_main ($) { Line 5754  sub _tree_construction_main ($) {
5754                  } # INSCOPE                  } # INSCOPE
5755                    unless (defined $i) {                    unless (defined $i) {
5756                      !!!cp ('t252');                      !!!cp ('t252');
5757                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag',
5758                                        text => 'tr', token => $token);
5759                      ## Ignore the token                      ## Ignore the token
5760                      !!!nack ('t252.1');                      !!!nack ('t252.1');
5761                      !!!next-token;                      !!!next-token;
# Line 5437  sub _tree_construction_main ($) { Line 5790  sub _tree_construction_main ($) {
5790                } # INSCOPE                } # INSCOPE
5791                unless (defined $i) {                unless (defined $i) {
5792                  !!!cp ('t256');                  !!!cp ('t256');
5793                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag',
5794                                    text => $token->{tag_name}, token => $token);
5795                  ## Ignore the token                  ## Ignore the token
5796                  !!!nack ('t256.1');                  !!!nack ('t256.1');
5797                  !!!next-token;                  !!!next-token;
# Line 5464  sub _tree_construction_main ($) { Line 5818  sub _tree_construction_main ($) {
5818                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5819                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5820            !!!cp ('t258');            !!!cp ('t258');
5821            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
5822                              text => $token->{tag_name}, token => $token);
5823            ## Ignore the token            ## Ignore the token
5824            !!!nack ('t258.1');            !!!nack ('t258.1');
5825             !!!next-token;             !!!next-token;
5826            next B;            next B;
5827          } else {          } else {
5828            !!!cp ('t259');            !!!cp ('t259');
5829            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/',
5830                              text => $token->{tag_name}, token => $token);
5831    
5832            $insert = $insert_to_foster;            $insert = $insert_to_foster;
5833            #            #
# Line 5521  sub _tree_construction_main ($) { Line 5877  sub _tree_construction_main ($) {
5877              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5878                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5879                  !!!cp ('t264');                  !!!cp ('t264');
5880                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag',
5881                                    text => 'colgroup', token => $token);
5882                  ## Ignore the token                  ## Ignore the token
5883                  !!!next-token;                  !!!next-token;
5884                  next B;                  next B;
# Line 5534  sub _tree_construction_main ($) { Line 5891  sub _tree_construction_main ($) {
5891                }                }
5892              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5893                !!!cp ('t266');                !!!cp ('t266');
5894                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag',
5895                                  text => 'col', token => $token);
5896                ## Ignore the token                ## Ignore the token
5897                !!!next-token;                !!!next-token;
5898                next B;                next B;
# Line 5564  sub _tree_construction_main ($) { Line 5922  sub _tree_construction_main ($) {
5922            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5923              !!!cp ('t269');              !!!cp ('t269');
5924  ## TODO: Wrong error type?  ## TODO: Wrong error type?
5925              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag',
5926                                text => 'colgroup', token => $token);
5927              ## Ignore the token              ## Ignore the token
5928              !!!nack ('t269.1');              !!!nack ('t269.1');
5929              !!!next-token;              !!!next-token;
# Line 5618  sub _tree_construction_main ($) { Line 5977  sub _tree_construction_main ($) {
5977            !!!nack ('t277.1');            !!!nack ('t277.1');
5978            !!!next-token;            !!!next-token;
5979            next B;            next B;
5980          } elsif ($token->{tag_name} eq 'select' or          } elsif ({
5981                   $token->{tag_name} eq 'input' or                     select => 1, input => 1, textarea => 1,
5982                     }->{$token->{tag_name}} or
5983                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5984                    {                    {
5985                     caption => 1, table => 1,                     caption => 1, table => 1,
# Line 5627  sub _tree_construction_main ($) { Line 5987  sub _tree_construction_main ($) {
5987                     tr => 1, td => 1, th => 1,                     tr => 1, td => 1, th => 1,
5988                    }->{$token->{tag_name}})) {                    }->{$token->{tag_name}})) {
5989            ## TODO: The type below is not good - <select> is replaced by </select>            ## TODO: The type below is not good - <select> is replaced by </select>
5990            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed', text => 'select',
5991                              token => $token);
5992            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
5993            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
5994            ## have an element in table scope            ## have an element in table scope
# Line 5645  sub _tree_construction_main ($) { Line 6006  sub _tree_construction_main ($) {
6006            } # INSCOPE            } # INSCOPE
6007            unless (defined $i) {            unless (defined $i) {
6008              !!!cp ('t280');              !!!cp ('t280');
6009              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6010                                text => 'select', token => $token);
6011              ## Ignore the token              ## Ignore the token
6012              !!!nack ('t280.1');              !!!nack ('t280.1');
6013              !!!next-token;              !!!next-token;
# Line 5669  sub _tree_construction_main ($) { Line 6031  sub _tree_construction_main ($) {
6031            }            }
6032          } else {          } else {
6033            !!!cp ('t282');            !!!cp ('t282');
6034            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select',
6035                              text => $token->{tag_name}, token => $token);
6036            ## Ignore the token            ## Ignore the token
6037            !!!nack ('t282.1');            !!!nack ('t282.1');
6038            !!!next-token;            !!!next-token;
# Line 5687  sub _tree_construction_main ($) { Line 6050  sub _tree_construction_main ($) {
6050              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6051            } else {            } else {
6052              !!!cp ('t285');              !!!cp ('t285');
6053              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6054                                text => $token->{tag_name}, token => $token);
6055              ## Ignore the token              ## Ignore the token
6056            }            }
6057            !!!nack ('t285.1');            !!!nack ('t285.1');
# Line 5699  sub _tree_construction_main ($) { Line 6063  sub _tree_construction_main ($) {
6063              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6064            } else {            } else {
6065              !!!cp ('t287');              !!!cp ('t287');
6066              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6067                                text => $token->{tag_name}, token => $token);
6068              ## Ignore the token              ## Ignore the token
6069            }            }
6070            !!!nack ('t287.1');            !!!nack ('t287.1');
# Line 5721  sub _tree_construction_main ($) { Line 6086  sub _tree_construction_main ($) {
6086            } # INSCOPE            } # INSCOPE
6087            unless (defined $i) {            unless (defined $i) {
6088              !!!cp ('t290');              !!!cp ('t290');
6089              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6090                                text => $token->{tag_name}, token => $token);
6091              ## Ignore the token              ## Ignore the token
6092              !!!nack ('t290.1');              !!!nack ('t290.1');
6093              !!!next-token;              !!!next-token;
# Line 5742  sub _tree_construction_main ($) { Line 6108  sub _tree_construction_main ($) {
6108                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
6109                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6110  ## TODO: The following is wrong?  ## TODO: The following is wrong?
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                                
6114            ## have an element in table scope            ## have an element in table scope
6115            my $i;            my $i;
# Line 5783  sub _tree_construction_main ($) { Line 6150  sub _tree_construction_main ($) {
6150            unless (defined $i) {            unless (defined $i) {
6151              !!!cp ('t297');              !!!cp ('t297');
6152  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
6153              !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag',
6154                                text => 'select', token => $token);
6155              ## Ignore the </select> token              ## Ignore the </select> token
6156              !!!nack ('t297.1');              !!!nack ('t297.1');
6157              !!!next-token; ## TODO: ok?              !!!next-token; ## TODO: ok?
# Line 5800  sub _tree_construction_main ($) { Line 6168  sub _tree_construction_main ($) {
6168            next B;            next B;
6169          } else {          } else {
6170            !!!cp ('t299');            !!!cp ('t299');
6171            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/',
6172                              text => $token->{tag_name}, token => $token);
6173            ## Ignore the token            ## Ignore the token
6174            !!!nack ('t299.3');            !!!nack ('t299.3');
6175            !!!next-token;            !!!next-token;
# Line 5838  sub _tree_construction_main ($) { Line 6207  sub _tree_construction_main ($) {
6207                    
6208          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6209            !!!cp ('t301');            !!!cp ('t301');
6210            !!!parse-error (type => 'after html:#character', token => $token);            !!!parse-error (type => 'after html:#text', token => $token);
6211    
6212            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6213          } else {          } else {
# Line 5846  sub _tree_construction_main ($) { Line 6215  sub _tree_construction_main ($) {
6215          }          }
6216                    
6217          ## "after body" insertion mode          ## "after body" insertion mode
6218          !!!parse-error (type => 'after body:#character', token => $token);          !!!parse-error (type => 'after body:#text', token => $token);
6219    
6220          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6221          ## reprocess          ## reprocess
# Line 5854  sub _tree_construction_main ($) { Line 6223  sub _tree_construction_main ($) {
6223        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6224          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6225            !!!cp ('t303');            !!!cp ('t303');
6226            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6227                              text => $token->{tag_name}, token => $token);
6228                        
6229            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
6230          } else {          } else {
# Line 5862  sub _tree_construction_main ($) { Line 6232  sub _tree_construction_main ($) {
6232          }          }
6233    
6234          ## "after body" insertion mode          ## "after body" insertion mode
6235          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body',
6236                            text => $token->{tag_name}, token => $token);
6237    
6238          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
6239          !!!ack-later;          !!!ack-later;
# Line 5871  sub _tree_construction_main ($) { Line 6242  sub _tree_construction_main ($) {
6242        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6243          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
6244            !!!cp ('t305');            !!!cp ('t305');
6245            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6246                              text => $token->{tag_name}, token => $token);
6247                        
6248            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6249            ## Reprocess in the "after body" insertion mode.            ## Reprocess in the "after body" insertion mode.
# Line 5883  sub _tree_construction_main ($) { Line 6255  sub _tree_construction_main ($) {
6255          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
6256            if (defined $self->{inner_html_node}) {            if (defined $self->{inner_html_node}) {
6257              !!!cp ('t307');              !!!cp ('t307');
6258              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag',
6259                                text => 'html', token => $token);
6260              ## Ignore the token              ## Ignore the token
6261              !!!next-token;              !!!next-token;
6262              next B;              next B;
# Line 5895  sub _tree_construction_main ($) { Line 6268  sub _tree_construction_main ($) {
6268            }            }
6269          } else {          } else {
6270            !!!cp ('t309');            !!!cp ('t309');
6271            !!!parse-error (type => 'after body:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after body:/',
6272                              text => $token->{tag_name}, token => $token);
6273    
6274            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
6275            ## reprocess            ## reprocess
# Line 5923  sub _tree_construction_main ($) { Line 6297  sub _tree_construction_main ($) {
6297          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {          if ($token->{data} =~ s/^[^\x09\x0A\x0B\x0C\x20]+//) {
6298            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6299              !!!cp ('t311');              !!!cp ('t311');
6300              !!!parse-error (type => 'in frameset:#character', token => $token);              !!!parse-error (type => 'in frameset:#text', token => $token);
6301            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {            } elsif ($self->{insertion_mode} == AFTER_FRAMESET_IM) {
6302              !!!cp ('t312');              !!!cp ('t312');
6303              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6304            } else { # "after html frameset"            } else { # "after html frameset"
6305              !!!cp ('t313');              !!!cp ('t313');
6306              !!!parse-error (type => 'after html:#character', token => $token);              !!!parse-error (type => 'after html:#text', token => $token);
6307    
6308              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
6309              ## Reprocess in the "after frameset" insertion mode.              ## Reprocess in the "after frameset" insertion mode.
6310              !!!parse-error (type => 'after frameset:#character', token => $token);              !!!parse-error (type => 'after frameset:#text', token => $token);
6311            }            }
6312                        
6313            ## Ignore the token.            ## Ignore the token.
# Line 5951  sub _tree_construction_main ($) { Line 6325  sub _tree_construction_main ($) {
6325        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6326          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
6327            !!!cp ('t316');            !!!cp ('t316');
6328            !!!parse-error (type => 'after html:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html',
6329                              text => $token->{tag_name}, token => $token);
6330    
6331            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
6332            ## Process in the "after frameset" insertion mode.            ## Process in the "after frameset" insertion mode.
# Line 5976  sub _tree_construction_main ($) { Line 6351  sub _tree_construction_main ($) {
6351            next B;            next B;
6352          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
6353            !!!cp ('t320');            !!!cp ('t320');
6354            ## NOTE: As if in body.            ## NOTE: As if in head.
6355            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
6356            next B;            next B;
6357          } else {          } else {
6358            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6359              !!!cp ('t321');              !!!cp ('t321');
6360              !!!parse-error (type => 'in frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset',
6361                                text => $token->{tag_name}, token => $token);
6362            } else {            } else {
6363              !!!cp ('t322');              !!!cp ('t322');
6364              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset',
6365                                text => $token->{tag_name}, token => $token);
6366            }            }
6367            ## Ignore the token            ## Ignore the token
6368            !!!nack ('t322.1');            !!!nack ('t322.1');
# Line 5995  sub _tree_construction_main ($) { Line 6372  sub _tree_construction_main ($) {
6372        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6373          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
6374            !!!cp ('t323');            !!!cp ('t323');
6375            !!!parse-error (type => 'after html:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'after html:/',
6376                              text => $token->{tag_name}, token => $token);
6377    
6378            $self->{insertion_mode} = AFTER_FRAMESET_IM;            $self->{insertion_mode} = AFTER_FRAMESET_IM;
6379            ## Process in the "after frameset" insertion mode.            ## Process in the "after frameset" insertion mode.
# Line 6008  sub _tree_construction_main ($) { Line 6386  sub _tree_construction_main ($) {
6386            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6387                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6388              !!!cp ('t325');              !!!cp ('t325');
6389              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
6390                                text => $token->{tag_name}, token => $token);
6391              ## Ignore the token              ## Ignore the token
6392              !!!next-token;              !!!next-token;
6393            } else {            } else {
# Line 6034  sub _tree_construction_main ($) { Line 6413  sub _tree_construction_main ($) {
6413          } else {          } else {
6414            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6415              !!!cp ('t330');              !!!cp ('t330');
6416              !!!parse-error (type => 'in frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'in frameset:/',
6417                                text => $token->{tag_name}, token => $token);
6418            } else {            } else {
6419              !!!cp ('t331');              !!!cp ('t331');
6420              !!!parse-error (type => 'after frameset:/'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset:/',
6421                                text => $token->{tag_name}, token => $token);
6422            }            }
6423            ## Ignore the token            ## Ignore the token
6424            !!!next-token;            !!!next-token;
# Line 6091  sub _tree_construction_main ($) { Line 6472  sub _tree_construction_main ($) {
6472          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
6473    
6474          unless ($self->{confident}) {          unless ($self->{confident}) {
6475            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) {
6476              !!!cp ('t335');              !!!cp ('t335');
6477                ## NOTE: Whether the encoding is supported or not is handled
6478                ## in the {change_encoding} callback.
6479              $self->{change_encoding}              $self->{change_encoding}
6480                  ->($self, $token->{attributes}->{charset}->{value}, $token);                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6481                            
# Line 6101  sub _tree_construction_main ($) { Line 6484  sub _tree_construction_main ($) {
6484                                       $token->{attributes}->{charset}                                       $token->{attributes}->{charset}
6485                                           ->{has_reference});                                           ->{has_reference});
6486            } elsif ($token->{attributes}->{content}) {            } elsif ($token->{attributes}->{content}) {
             ## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition.  
6487              if ($token->{attributes}->{content}->{value}              if ($token->{attributes}->{content}->{value}
6488                  =~ /\A[^;]*;[\x09-\x0D\x20]*[Cc][Hh][Aa][Rr][Ss][Ee][Tt]                  =~ /[Cc][Hh][Aa][Rr][Ss][Ee][Tt]
6489                      [\x09-\x0D\x20]*=                      [\x09-\x0D\x20]*=
6490                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|                      [\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'|
6491                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20\x3B]*))/x) {
6492                !!!cp ('t336');                !!!cp ('t336');
6493                  ## NOTE: Whether the encoding is supported or not is handled
6494                  ## in the {change_encoding} callback.
6495                $self->{change_encoding}                $self->{change_encoding}
6496                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6497                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
# Line 6142  sub _tree_construction_main ($) { Line 6526  sub _tree_construction_main ($) {
6526          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6527          next B;          next B;
6528        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6529          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6530                                
6531          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6532              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
# Line 6262  sub _tree_construction_main ($) { Line 6646  sub _tree_construction_main ($) {
6646              if ($i != -1) {              if ($i != -1) {
6647                !!!cp ('t355');                !!!cp ('t355');
6648                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
6649                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
6650                                    ->manakai_local_name,                                    ->manakai_local_name,
6651                                token => $token);                                token => $token);
6652              } else {              } else {
# Line 6416  sub _tree_construction_main ($) { Line 6800  sub _tree_construction_main ($) {
6800                  xmp => 1,                  xmp => 1,
6801                  iframe => 1,                  iframe => 1,
6802                  noembed => 1,                  noembed => 1,
6803                  noframes => 1,                  noframes => 1, ## NOTE: This is an "as if in head" code clone.
6804                  noscript => 0, ## TODO: 1 if scripting is enabled                  noscript => 0, ## TODO: 1 if scripting is enabled
6805                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6806          if ($token->{tag_name} eq 'xmp') {          if ($token->{tag_name} eq 'xmp') {
# Line 6438  sub _tree_construction_main ($) { Line 6822  sub _tree_construction_main ($) {
6822            !!!next-token;            !!!next-token;
6823            next B;            next B;
6824          } else {          } else {
6825              !!!ack ('t391.1');
6826    
6827            my $at = $token->{attributes};            my $at = $token->{attributes};
6828            my $form_attrs;            my $form_attrs;
6829            $form_attrs->{action} = $at->{action} if $at->{action};            $form_attrs->{action} = $at->{action} if $at->{action};
# Line 6481  sub _tree_construction_main ($) { Line 6867  sub _tree_construction_main ($) {
6867                           line => $token->{line}, column => $token->{column}},                           line => $token->{line}, column => $token->{column}},
6868                          {type => END_TAG_TOKEN, tag_name => 'form',                          {type => END_TAG_TOKEN, tag_name => 'form',
6869                           line => $token->{line}, column => $token->{column}};                           line => $token->{line}, column => $token->{column}};
           !!!nack ('t391.1'); ## NOTE: Not acknowledged.  
6870            !!!back-token (@tokens);            !!!back-token (@tokens);
6871            !!!next-token;            !!!next-token;
6872            next B;            next B;
# Line 6529  sub _tree_construction_main ($) { Line 6914  sub _tree_construction_main ($) {
6914            ## Ignore the token            ## Ignore the token
6915          } else {          } else {
6916            !!!cp ('t398');            !!!cp ('t398');
6917            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#eof', token => $token);
6918          }          }
6919          !!!next-token;          !!!next-token;
6920          next B;          next B;
6921          } elsif ($token->{tag_name} eq 'rt' or
6922                   $token->{tag_name} eq 'rp') {
6923            ## has a |ruby| element in scope
6924            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6925              my $node = $self->{open_elements}->[$_];
6926              if ($node->[1] & RUBY_EL) {
6927                !!!cp ('t398.1');
6928                ## generate implied end tags
6929                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
6930                  !!!cp ('t398.2');
6931                  pop @{$self->{open_elements}};
6932                }
6933                unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {
6934                  !!!cp ('t398.3');
6935                  !!!parse-error (type => 'not closed',
6936                                  text => $self->{open_elements}->[-1]->[0]
6937                                      ->manakai_local_name,
6938                                  token => $token);
6939                  pop @{$self->{open_elements}}
6940                      while not $self->{open_elements}->[-1]->[1] & RUBY_EL;
6941                }
6942                last INSCOPE;
6943              } elsif ($node->[1] & SCOPING_EL) {
6944                !!!cp ('t398.4');
6945                last INSCOPE;
6946              }
6947            } # INSCOPE
6948    
6949            !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6950    
6951            !!!nack ('t398.5');
6952            !!!next-token;
6953            redo B;
6954        } elsif ($token->{tag_name} eq 'math' or        } elsif ($token->{tag_name} eq 'math' or
6955                 $token->{tag_name} eq 'svg') {                 $token->{tag_name} eq 'svg') {
6956          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6957    
6958            ## "Adjust MathML attributes" ('math' only) - done in insert-element-f
6959    
6960          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f          ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6961    
6962          ## "adjust foreign attributes" - done in insert-element-f          ## "adjust foreign attributes" - done in insert-element-f
# Line 6563  sub _tree_construction_main ($) { Line 6983  sub _tree_construction_main ($) {
6983                  thead => 1, tr => 1,                  thead => 1, tr => 1,
6984                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6985          !!!cp ('t401');          !!!cp ('t401');
6986          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body',
6987                            text => $token->{tag_name}, token => $token);
6988          ## Ignore the token          ## Ignore the token
6989          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.          !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
6990          !!!next-token;          !!!next-token;
# Line 6648  sub _tree_construction_main ($) { Line 7069  sub _tree_construction_main ($) {
7069            }            }
7070    
7071            !!!parse-error (type => 'start tag not allowed',            !!!parse-error (type => 'start tag not allowed',
7072                            value => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7073            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7074            !!!next-token;            !!!next-token;
7075            next B;            next B;
# Line 6658  sub _tree_construction_main ($) { Line 7079  sub _tree_construction_main ($) {
7079            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
7080              !!!cp ('t403');              !!!cp ('t403');
7081              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7082                              value => $_->[0]->manakai_local_name,                              text => $_->[0]->manakai_local_name,
7083                              token => $token);                              token => $token);
7084              last;              last;
7085            } else {            } else {
# Line 6678  sub _tree_construction_main ($) { Line 7099  sub _tree_construction_main ($) {
7099            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
7100              !!!cp ('t406');              !!!cp ('t406');
7101              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7102                              value => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
7103                                  ->manakai_local_name,                                  ->manakai_local_name,
7104                              token => $token);                              token => $token);
7105            } else {            } else {
# Line 6689  sub _tree_construction_main ($) { Line 7110  sub _tree_construction_main ($) {
7110            next B;            next B;
7111          } else {          } else {
7112            !!!cp ('t408');            !!!cp ('t408');
7113            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7114                              text => $token->{tag_name}, token => $token);
7115            ## Ignore the token            ## Ignore the token
7116            !!!next-token;            !!!next-token;
7117            next B;            next B;
# Line 6717  sub _tree_construction_main ($) { Line 7139  sub _tree_construction_main ($) {
7139    
7140          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7141            !!!cp ('t413');            !!!cp ('t413');
7142            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7143                              text => $token->{tag_name}, token => $token);
7144              ## NOTE: Ignore the token.
7145          } else {          } else {
7146            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7147            while ({            while ({
7148                      ## END_TAG_OPTIONAL_EL
7149                    dd => ($token->{tag_name} ne 'dd'),                    dd => ($token->{tag_name} ne 'dd'),
7150                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
7151                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
7152                    p => 1,                    p => 1,
7153                      rt => 1,
7154                      rp => 1,
7155                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
7156              !!!cp ('t409');              !!!cp ('t409');
7157              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6735  sub _tree_construction_main ($) { Line 7162  sub _tree_construction_main ($) {
7162                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7163              !!!cp ('t412');              !!!cp ('t412');
7164              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7165                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7166                                  ->manakai_local_name,                                  ->manakai_local_name,
7167                              token => $token);                              token => $token);
7168            } else {            } else {
# Line 6772  sub _tree_construction_main ($) { Line 7199  sub _tree_construction_main ($) {
7199    
7200          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7201            !!!cp ('t421');            !!!cp ('t421');
7202            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7203                              text => $token->{tag_name}, token => $token);
7204              ## NOTE: Ignore the token.
7205          } else {          } else {
7206            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7207            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6785  sub _tree_construction_main ($) { Line 7214  sub _tree_construction_main ($) {
7214                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7215              !!!cp ('t417.1');              !!!cp ('t417.1');
7216              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7217                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7218                                  ->manakai_local_name,                                  ->manakai_local_name,
7219                              token => $token);                              token => $token);
7220            } else {            } else {
# Line 6817  sub _tree_construction_main ($) { Line 7246  sub _tree_construction_main ($) {
7246    
7247          unless (defined $i) { # has an element in scope          unless (defined $i) { # has an element in scope
7248            !!!cp ('t425.1');            !!!cp ('t425.1');
7249            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7250                              text => $token->{tag_name}, token => $token);
7251              ## NOTE: Ignore the token.
7252          } else {          } else {
7253            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
7254            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 6829  sub _tree_construction_main ($) { Line 7260  sub _tree_construction_main ($) {
7260            if ($self->{open_elements}->[-1]->[0]->manakai_local_name            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
7261                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7262              !!!cp ('t425');              !!!cp ('t425');
7263              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag',
7264                                text => $token->{tag_name}, token => $token);
7265            } else {            } else {
7266              !!!cp ('t426');              !!!cp ('t426');
7267            }            }
# Line 6860  sub _tree_construction_main ($) { Line 7292  sub _tree_construction_main ($) {
7292                    ne $token->{tag_name}) {                    ne $token->{tag_name}) {
7293              !!!cp ('t412.1');              !!!cp ('t412.1');
7294              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7295                              value => $self->{open_elements}->[-1]->[0]                              text => $self->{open_elements}->[-1]->[0]
7296                                  ->manakai_local_name,                                  ->manakai_local_name,
7297                              token => $token);                              token => $token);
7298            } else {            } else {
# Line 6870  sub _tree_construction_main ($) { Line 7302  sub _tree_construction_main ($) {
7302            splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
7303          } else {          } else {
7304            !!!cp ('t413.1');            !!!cp ('t413.1');
7305            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag',
7306                              text => $token->{tag_name}, token => $token);
7307    
7308            !!!cp ('t415.1');            !!!cp ('t415.1');
7309            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
# Line 6893  sub _tree_construction_main ($) { Line 7326  sub _tree_construction_main ($) {
7326          next B;          next B;
7327        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
7328          !!!cp ('t428');          !!!cp ('t428');
7329          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag',
7330                            text => 'br', token => $token);
7331    
7332          ## As if <br>          ## As if <br>
7333          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 6918  sub _tree_construction_main ($) { Line 7352  sub _tree_construction_main ($) {
7352                  noscript => 0, ## TODO: if scripting is enabled                  noscript => 0, ## TODO: if scripting is enabled
7353                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
7354          !!!cp ('t429');          !!!cp ('t429');
7355          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag',
7356                            text => $token->{tag_name}, token => $token);
7357          ## Ignore the token          ## Ignore the token
7358          !!!next-token;          !!!next-token;
7359          next B;          next B;
# Line 6937  sub _tree_construction_main ($) { Line 7372  sub _tree_construction_main ($) {
7372              ## generate implied end tags              ## generate implied end tags
7373              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7374                !!!cp ('t430');                !!!cp ('t430');
7375                ## ISSUE: Can this case be reached?                ## NOTE: |<ruby><rt></ruby>|.
7376                  ## ISSUE: <ruby><rt></rt> will also take this code path,
7377                  ## which seems wrong.
7378                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7379                  $node_i++;
7380              }              }
7381                    
7382              ## Step 2              ## Step 2
# Line 6947  sub _tree_construction_main ($) { Line 7385  sub _tree_construction_main ($) {
7385                !!!cp ('t431');                !!!cp ('t431');
7386                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7387                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7388                                value => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7389                                    ->manakai_local_name,                                    ->manakai_local_name,
7390                                token => $token);                                token => $token);
7391              } else {              } else {
# Line 6955  sub _tree_construction_main ($) { Line 7393  sub _tree_construction_main ($) {
7393              }              }
7394                            
7395              ## Step 3              ## Step 3
7396              splice @{$self->{open_elements}}, $node_i;              splice @{$self->{open_elements}}, $node_i if $node_i < 0;
7397    
7398              !!!next-token;              !!!next-token;
7399              last S2;              last S2;
# Line 6966  sub _tree_construction_main ($) { Line 7404  sub _tree_construction_main ($) {
7404                  ($node->[1] & SPECIAL_EL or                  ($node->[1] & SPECIAL_EL or
7405                   $node->[1] & SCOPING_EL)) {                   $node->[1] & SCOPING_EL)) {
7406                !!!cp ('t433');                !!!cp ('t433');
7407                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag',
7408                                  text => $token->{tag_name}, token => $token);
7409                ## Ignore the token                ## Ignore the token
7410                !!!next-token;                !!!next-token;
7411                last S2;                last S2;
# Line 7102  sub set_inner_html ($$$) { Line 7541  sub set_inner_html ($$$) {
7541                  0x10FFFE => 1, 0x10FFFF => 1,                  0x10FFFE => 1, 0x10FFFF => 1,
7542                 }->{$self->{next_char}}) {                 }->{$self->{next_char}}) {
7543          !!!cp ('i4.1');          !!!cp ('i4.1');
7544          !!!parse-error (type => 'control char', level => $self->{must_level});          if ($self->{next_char} < 0x10000) {
7545  ## TODO: error type documentation            !!!parse-error (type => 'control char',
7546                              text => (sprintf 'U+%04X', $self->{next_char}));
7547            } else {
7548              !!!parse-error (type => 'control char',
7549                              text => (sprintf 'U-%08X', $self->{next_char}));
7550            }
7551        }        }
7552      };      };
7553      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];

Legend:
Removed from v.1.132  
changed lines
  Added in v.1.157

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24