/[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.6 by wakaba, Sat May 26 08:12:34 2007 UTC revision 1.26 by wakaba, Sun Jun 24 06:20:37 2007 UTC
# Line 2  package Whatpm::HTML; Line 2  package Whatpm::HTML;
2  use strict;  use strict;
3  our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};  our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4    
5  ## This is an early version of an HTML parser.  ## ISSUE:
6    ## var doc = implementation.createDocument (null, null, null);
7    ## doc.write ('');
8    ## alert (doc.compatMode);
9    
10  my $permitted_slash_tag_name = {  my $permitted_slash_tag_name = {
11    base => 1,    base => 1,
# Line 18  my $permitted_slash_tag_name = { Line 21  my $permitted_slash_tag_name = {
21    input => 1,    input => 1,
22  };  };
23    
 my $entity_char = {  
   AElig => "\x{00C6}",  
   Aacute => "\x{00C1}",  
   Acirc => "\x{00C2}",  
   Agrave => "\x{00C0}",  
   Alpha => "\x{0391}",  
   Aring => "\x{00C5}",  
   Atilde => "\x{00C3}",  
   Auml => "\x{00C4}",  
   Beta => "\x{0392}",  
   Ccedil => "\x{00C7}",  
   Chi => "\x{03A7}",  
   Dagger => "\x{2021}",  
   Delta => "\x{0394}",  
   ETH => "\x{00D0}",  
   Eacute => "\x{00C9}",  
   Ecirc => "\x{00CA}",  
   Egrave => "\x{00C8}",  
   Epsilon => "\x{0395}",  
   Eta => "\x{0397}",  
   Euml => "\x{00CB}",  
   Gamma => "\x{0393}",  
   Iacute => "\x{00CD}",  
   Icirc => "\x{00CE}",  
   Igrave => "\x{00CC}",  
   Iota => "\x{0399}",  
   Iuml => "\x{00CF}",  
   Kappa => "\x{039A}",  
   Lambda => "\x{039B}",  
   Mu => "\x{039C}",  
   Ntilde => "\x{00D1}",  
   Nu => "\x{039D}",  
   OElig => "\x{0152}",  
   Oacute => "\x{00D3}",  
   Ocirc => "\x{00D4}",  
   Ograve => "\x{00D2}",  
   Omega => "\x{03A9}",  
   Omicron => "\x{039F}",  
   Oslash => "\x{00D8}",  
   Otilde => "\x{00D5}",  
   Ouml => "\x{00D6}",  
   Phi => "\x{03A6}",  
   Pi => "\x{03A0}",  
   Prime => "\x{2033}",  
   Psi => "\x{03A8}",  
   Rho => "\x{03A1}",  
   Scaron => "\x{0160}",  
   Sigma => "\x{03A3}",  
   THORN => "\x{00DE}",  
   Tau => "\x{03A4}",  
   Theta => "\x{0398}",  
   Uacute => "\x{00DA}",  
   Ucirc => "\x{00DB}",  
   Ugrave => "\x{00D9}",  
   Upsilon => "\x{03A5}",  
   Uuml => "\x{00DC}",  
   Xi => "\x{039E}",  
   Yacute => "\x{00DD}",  
   Yuml => "\x{0178}",  
   Zeta => "\x{0396}",  
   aacute => "\x{00E1}",  
   acirc => "\x{00E2}",  
   acute => "\x{00B4}",  
   aelig => "\x{00E6}",  
   agrave => "\x{00E0}",  
   alefsym => "\x{2135}",  
   alpha => "\x{03B1}",  
   amp => "\x{0026}",  
   AMP => "\x{0026}",  
   and => "\x{2227}",  
   ang => "\x{2220}",  
   apos => "\x{0027}",  
   aring => "\x{00E5}",  
   asymp => "\x{2248}",  
   atilde => "\x{00E3}",  
   auml => "\x{00E4}",  
   bdquo => "\x{201E}",  
   beta => "\x{03B2}",  
   brvbar => "\x{00A6}",  
   bull => "\x{2022}",  
   cap => "\x{2229}",  
   ccedil => "\x{00E7}",  
   cedil => "\x{00B8}",  
   cent => "\x{00A2}",  
   chi => "\x{03C7}",  
   circ => "\x{02C6}",  
   clubs => "\x{2663}",  
   cong => "\x{2245}",  
   copy => "\x{00A9}",  
   COPY => "\x{00A9}",  
   crarr => "\x{21B5}",  
   cup => "\x{222A}",  
   curren => "\x{00A4}",  
   dArr => "\x{21D3}",  
   dagger => "\x{2020}",  
   darr => "\x{2193}",  
   deg => "\x{00B0}",  
   delta => "\x{03B4}",  
   diams => "\x{2666}",  
   divide => "\x{00F7}",  
   eacute => "\x{00E9}",  
   ecirc => "\x{00EA}",  
   egrave => "\x{00E8}",  
   empty => "\x{2205}",  
   emsp => "\x{2003}",  
   ensp => "\x{2002}",  
   epsilon => "\x{03B5}",  
   equiv => "\x{2261}",  
   eta => "\x{03B7}",  
   eth => "\x{00F0}",  
   euml => "\x{00EB}",  
   euro => "\x{20AC}",  
   exist => "\x{2203}",  
   fnof => "\x{0192}",  
   forall => "\x{2200}",  
   frac12 => "\x{00BD}",  
   frac14 => "\x{00BC}",  
   frac34 => "\x{00BE}",  
   frasl => "\x{2044}",  
   gamma => "\x{03B3}",  
   ge => "\x{2265}",  
   gt => "\x{003E}",  
   GT => "\x{003E}",  
   hArr => "\x{21D4}",  
   harr => "\x{2194}",  
   hearts => "\x{2665}",  
   hellip => "\x{2026}",  
   iacute => "\x{00ED}",  
   icirc => "\x{00EE}",  
   iexcl => "\x{00A1}",  
   igrave => "\x{00EC}",  
   image => "\x{2111}",  
   infin => "\x{221E}",  
   int => "\x{222B}",  
   iota => "\x{03B9}",  
   iquest => "\x{00BF}",  
   isin => "\x{2208}",  
   iuml => "\x{00EF}",  
   kappa => "\x{03BA}",  
   lArr => "\x{21D0}",  
   lambda => "\x{03BB}",  
   lang => "\x{2329}",  
   laquo => "\x{00AB}",  
   larr => "\x{2190}",  
   lceil => "\x{2308}",  
   ldquo => "\x{201C}",  
   le => "\x{2264}",  
   lfloor => "\x{230A}",  
   lowast => "\x{2217}",  
   loz => "\x{25CA}",  
   lrm => "\x{200E}",  
   lsaquo => "\x{2039}",  
   lsquo => "\x{2018}",  
   lt => "\x{003C}",  
   LT => "\x{003C}",  
   macr => "\x{00AF}",  
   mdash => "\x{2014}",  
   micro => "\x{00B5}",  
   middot => "\x{00B7}",  
   minus => "\x{2212}",  
   mu => "\x{03BC}",  
   nabla => "\x{2207}",  
   nbsp => "\x{00A0}",  
   ndash => "\x{2013}",  
   ne => "\x{2260}",  
   ni => "\x{220B}",  
   not => "\x{00AC}",  
   notin => "\x{2209}",  
   nsub => "\x{2284}",  
   ntilde => "\x{00F1}",  
   nu => "\x{03BD}",  
   oacute => "\x{00F3}",  
   ocirc => "\x{00F4}",  
   oelig => "\x{0153}",  
   ograve => "\x{00F2}",  
   oline => "\x{203E}",  
   omega => "\x{03C9}",  
   omicron => "\x{03BF}",  
   oplus => "\x{2295}",  
   or => "\x{2228}",  
   ordf => "\x{00AA}",  
   ordm => "\x{00BA}",  
   oslash => "\x{00F8}",  
   otilde => "\x{00F5}",  
   otimes => "\x{2297}",  
   ouml => "\x{00F6}",  
   para => "\x{00B6}",  
   part => "\x{2202}",  
   permil => "\x{2030}",  
   perp => "\x{22A5}",  
   phi => "\x{03C6}",  
   pi => "\x{03C0}",  
   piv => "\x{03D6}",  
   plusmn => "\x{00B1}",  
   pound => "\x{00A3}",  
   prime => "\x{2032}",  
   prod => "\x{220F}",  
   prop => "\x{221D}",  
   psi => "\x{03C8}",  
   quot => "\x{0022}",  
   QUOT => "\x{0022}",  
   rArr => "\x{21D2}",  
   radic => "\x{221A}",  
   rang => "\x{232A}",  
   raquo => "\x{00BB}",  
   rarr => "\x{2192}",  
   rceil => "\x{2309}",  
   rdquo => "\x{201D}",  
   real => "\x{211C}",  
   reg => "\x{00AE}",  
   REG => "\x{00AE}",  
   rfloor => "\x{230B}",  
   rho => "\x{03C1}",  
   rlm => "\x{200F}",  
   rsaquo => "\x{203A}",  
   rsquo => "\x{2019}",  
   sbquo => "\x{201A}",  
   scaron => "\x{0161}",  
   sdot => "\x{22C5}",  
   sect => "\x{00A7}",  
   shy => "\x{00AD}",  
   sigma => "\x{03C3}",  
   sigmaf => "\x{03C2}",  
   sim => "\x{223C}",  
   spades => "\x{2660}",  
   sub => "\x{2282}",  
   sube => "\x{2286}",  
   sum => "\x{2211}",  
   sup => "\x{2283}",  
   sup1 => "\x{00B9}",  
   sup2 => "\x{00B2}",  
   sup3 => "\x{00B3}",  
   supe => "\x{2287}",  
   szlig => "\x{00DF}",  
   tau => "\x{03C4}",  
   there4 => "\x{2234}",  
   theta => "\x{03B8}",  
   thetasym => "\x{03D1}",  
   thinsp => "\x{2009}",  
   thorn => "\x{00FE}",  
   tilde => "\x{02DC}",  
   times => "\x{00D7}",  
   trade => "\x{2122}",  
   uArr => "\x{21D1}",  
   uacute => "\x{00FA}",  
   uarr => "\x{2191}",  
   ucirc => "\x{00FB}",  
   ugrave => "\x{00F9}",  
   uml => "\x{00A8}",  
   upsih => "\x{03D2}",  
   upsilon => "\x{03C5}",  
   uuml => "\x{00FC}",  
   weierp => "\x{2118}",  
   xi => "\x{03BE}",  
   yacute => "\x{00FD}",  
   yen => "\x{00A5}",  
   yuml => "\x{00FF}",  
   zeta => "\x{03B6}",  
   zwj => "\x{200D}",  
   zwnj => "\x{200C}",  
 }; # $entity_char  
   
 ## <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-December/thread.html#8562>  
24  my $c1_entity_char = {  my $c1_entity_char = {
25       128, 8364,    0x80 => 0x20AC,
26       129, 65533,    0x81 => 0xFFFD,
27       130, 8218,    0x82 => 0x201A,
28       131, 402,    0x83 => 0x0192,
29       132, 8222,    0x84 => 0x201E,
30       133, 8230,    0x85 => 0x2026,
31       134, 8224,    0x86 => 0x2020,
32       135, 8225,    0x87 => 0x2021,
33       136, 710,    0x88 => 0x02C6,
34       137, 8240,    0x89 => 0x2030,
35       138, 352,    0x8A => 0x0160,
36       139, 8249,    0x8B => 0x2039,
37       140, 338,    0x8C => 0x0152,
38       141, 65533,    0x8D => 0xFFFD,
39       142, 381,    0x8E => 0x017D,
40       143, 65533,    0x8F => 0xFFFD,
41       144, 65533,    0x90 => 0xFFFD,
42       145, 8216,    0x91 => 0x2018,
43       146, 8217,    0x92 => 0x2019,
44       147, 8220,    0x93 => 0x201C,
45       148, 8221,    0x94 => 0x201D,
46       149, 8226,    0x95 => 0x2022,
47       150, 8211,    0x96 => 0x2013,
48       151, 8212,    0x97 => 0x2014,
49       152, 732,    0x98 => 0x02DC,
50       153, 8482,    0x99 => 0x2122,
51       154, 353,    0x9A => 0x0161,
52       155, 8250,    0x9B => 0x203A,
53       156, 339,    0x9C => 0x0153,
54       157, 65533,    0x9D => 0xFFFD,
55       158, 382,    0x9E => 0x017E,
56       159, 376,    0x9F => 0x0178,
57  }; # $c1_entity_char  }; # $c1_entity_char
58    
59  my $special_category = {  my $special_category = {
# Line 350  sub parse_string ($$$;$) { Line 90  sub parse_string ($$$;$) {
90    my $column = 0;    my $column = 0;
91    $self->{set_next_input_character} = sub {    $self->{set_next_input_character} = sub {
92      my $self = shift;      my $self = shift;
93    
94        pop @{$self->{prev_input_character}};
95        unshift @{$self->{prev_input_character}}, $self->{next_input_character};
96    
97      $self->{next_input_character} = -1 and return if $i >= length $$s;      $self->{next_input_character} = -1 and return if $i >= length $$s;
98      $self->{next_input_character} = ord substr $$s, $i++, 1;      $self->{next_input_character} = ord substr $$s, $i++, 1;
99      $column++;      $column++;
# Line 358  sub parse_string ($$$;$) { Line 102  sub parse_string ($$$;$) {
102        $line++;        $line++;
103        $column = 0;        $column = 0;
104      } elsif ($self->{next_input_character} == 0x000D) { # CR      } elsif ($self->{next_input_character} == 0x000D) { # CR
105        if ($i >= length $$s) {        $i++ if substr ($$s, $i, 1) eq "\x0A";
         #  
       } else {  
         my $next_char = ord substr $$s, $i++, 1;  
         if ($next_char == 0x000A) { # LF  
           #  
         } else {  
           push @{$self->{char}}, $next_char;  
         }  
       }  
106        $self->{next_input_character} = 0x000A; # LF # MUST        $self->{next_input_character} = 0x000A; # LF # MUST
107        $line++;        $line++;
108        $column = 0;        $column = 0;
109      } elsif ($self->{next_input_character} > 0x10FFFF) {      } elsif ($self->{next_input_character} > 0x10FFFF) {
110        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
111      } elsif ($self->{next_input_character} == 0x0000) { # NULL      } elsif ($self->{next_input_character} == 0x0000) { # NULL
112          !!!parse-error (type => 'NULL');
113        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
114      }      }
115    };    };
116      $self->{prev_input_character} = [-1, -1, -1];
117      $self->{next_input_character} = -1;
118    
119    my $onerror = $_[2] || sub {    my $onerror = $_[2] || sub {
120      my (%opt) = @_;      my (%opt) = @_;
# Line 420  sub _initialize_tokenizer ($) { Line 158  sub _initialize_tokenizer ($) {
158    # $self->{next_input_character}    # $self->{next_input_character}
159    !!!next-input-character;    !!!next-input-character;
160    $self->{token} = [];    $self->{token} = [];
161      # $self->{escape}
162  } # _initialize_tokenizer  } # _initialize_tokenizer
163    
164  ## A token has:  ## A token has:
165  ##   ->{type} eq 'DOCTYPE', 'start tag', 'end tag', 'comment',  ##   ->{type} eq 'DOCTYPE', 'start tag', 'end tag', 'comment',
166  ##       'character', or 'end-of-file'  ##       'character', or 'end-of-file'
167  ##   ->{name} (DOCTYPE, start tag (tagname), end tag (tagname))  ##   ->{name} (DOCTYPE, start tag (tag name), end tag (tag name))
168      ## ISSUE: the spec need s/tagname/tag name/  ##   ->{public_identifier} (DOCTYPE)
169  ##   ->{error} == 1 or 0 (DOCTYPE)  ##   ->{system_identifier} (DOCTYPE)
170    ##   ->{correct} == 1 or 0 (DOCTYPE)
171  ##   ->{attributes} isa HASH (start tag, end tag)  ##   ->{attributes} isa HASH (start tag, end tag)
172  ##   ->{data} (comment, character)  ##   ->{data} (comment, character)
173    
 ## Macros  
 ##   Macros MUST be preceded by three EXCLAMATION MARKs.  
 ##   emit ($token)  
 ##     Emits the specified token.  
   
174  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
175    
176  ## 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 461  sub _get_next_token ($) { Line 196  sub _get_next_token ($) {
196          } else {          } else {
197            #            #
198          }          }
199          } elsif ($self->{next_input_character} == 0x002D) { # -
200            if ($self->{content_model_flag} eq 'RCDATA' or
201                $self->{content_model_flag} eq 'CDATA') {
202              unless ($self->{escape}) {
203                if ($self->{prev_input_character}->[0] == 0x002D and # -
204                    $self->{prev_input_character}->[1] == 0x0021 and # !
205                    $self->{prev_input_character}->[2] == 0x003C) { # <
206                  $self->{escape} = 1;
207                }
208              }
209            }
210            
211            #
212        } elsif ($self->{next_input_character} == 0x003C) { # <        } elsif ($self->{next_input_character} == 0x003C) { # <
213          if ($self->{content_model_flag} ne 'PLAINTEXT') {          if ($self->{content_model_flag} eq 'PCDATA' or
214                (($self->{content_model_flag} eq 'CDATA' or
215                  $self->{content_model_flag} eq 'RCDATA') and
216                 not $self->{escape})) {
217            $self->{state} = 'tag open';            $self->{state} = 'tag open';
218            !!!next-input-character;            !!!next-input-character;
219            redo A;            redo A;
220          } else {          } else {
221            #            #
222          }          }
223          } elsif ($self->{next_input_character} == 0x003E) { # >
224            if ($self->{escape} and
225                ($self->{content_model_flag} eq 'RCDATA' or
226                 $self->{content_model_flag} eq 'CDATA')) {
227              if ($self->{prev_input_character}->[0] == 0x002D and # -
228                  $self->{prev_input_character}->[1] == 0x002D) { # -
229                delete $self->{escape};
230              }
231            }
232            
233            #
234        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
235          !!!emit ({type => 'end-of-file'});          !!!emit ({type => 'end-of-file'});
236          last A; ## TODO: ok?          last A; ## TODO: ok?
# Line 485  sub _get_next_token ($) { Line 247  sub _get_next_token ($) {
247      } elsif ($self->{state} eq 'entity data') {      } elsif ($self->{state} eq 'entity data') {
248        ## (cannot happen in CDATA state)        ## (cannot happen in CDATA state)
249                
250        my $token = $self->_tokenize_attempt_to_consume_an_entity;        my $token = $self->_tokenize_attempt_to_consume_an_entity (0);
251    
252        $self->{state} = 'data';        $self->{state} = 'data';
253        # next-input-character is already done        # next-input-character is already done
# Line 564  sub _get_next_token ($) { Line 326  sub _get_next_token ($) {
326      } elsif ($self->{state} eq 'close tag open') {      } elsif ($self->{state} eq 'close tag open') {
327        if ($self->{content_model_flag} eq 'RCDATA' or        if ($self->{content_model_flag} eq 'RCDATA' or
328            $self->{content_model_flag} eq 'CDATA') {            $self->{content_model_flag} eq 'CDATA') {
329          my @next_char;          if (defined $self->{last_emitted_start_tag_name}) {
330          TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {            my @next_char;
331              TAGNAME: for (my $i = 0; $i < length $self->{last_emitted_start_tag_name}; $i++) {
332                push @next_char, $self->{next_input_character};
333                my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);
334                my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;
335                if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) {
336                  !!!next-input-character;
337                  next TAGNAME;
338                } else {
339                  $self->{next_input_character} = shift @next_char; # reconsume
340                  !!!back-next-input-character (@next_char);
341                  $self->{state} = 'data';
342    
343                  !!!emit ({type => 'character', data => '</'});
344      
345                  redo A;
346                }
347              }
348            push @next_char, $self->{next_input_character};            push @next_char, $self->{next_input_character};
349            my $c = ord substr ($self->{last_emitted_start_tag_name}, $i, 1);        
350            my $C = 0x0061 <= $c && $c <= 0x007A ? $c - 0x0020 : $c;            unless ($self->{next_input_character} == 0x0009 or # HT
351            if ($self->{next_input_character} == $c or $self->{next_input_character} == $C) {                    $self->{next_input_character} == 0x000A or # LF
352              !!!next-input-character;                    $self->{next_input_character} == 0x000B or # VT
353              next TAGNAME;                    $self->{next_input_character} == 0x000C or # FF
354            } else {                    $self->{next_input_character} == 0x0020 or # SP
355              !!!parse-error (type => 'unmatched end tag');                    $self->{next_input_character} == 0x003E or # >
356                      $self->{next_input_character} == 0x002F or # /
357                      $self->{next_input_character} == -1) {
358              $self->{next_input_character} = shift @next_char; # reconsume              $self->{next_input_character} = shift @next_char; # reconsume
359              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
360              $self->{state} = 'data';              $self->{state} = 'data';
   
361              !!!emit ({type => 'character', data => '</'});              !!!emit ({type => 'character', data => '</'});
   
362              redo A;              redo A;
363              } else {
364                $self->{next_input_character} = shift @next_char;
365                !!!back-next-input-character (@next_char);
366                # and consume...
367            }            }
368          }          } else {
369          push @next_char, $self->{next_input_character};            ## No start tag token has ever been emitted
370                  # next-input-character is already done
         unless ($self->{next_input_character} == 0x0009 or # HT  
                 $self->{next_input_character} == 0x000A or # LF  
                 $self->{next_input_character} == 0x000B or # VT  
                 $self->{next_input_character} == 0x000C or # FF  
                 $self->{next_input_character} == 0x0020 or # SP  
                 $self->{next_input_character} == 0x003E or # >  
                 $self->{next_input_character} == 0x002F or # /  
                 $self->{next_input_character} == 0x003C or # <  
                 $self->{next_input_character} == -1) {  
           !!!parse-error (type => 'unmatched end tag');  
           $self->{next_input_character} = shift @next_char; # reconsume  
           !!!back-next-input-character (@next_char);  
371            $self->{state} = 'data';            $self->{state} = 'data';
   
372            !!!emit ({type => 'character', data => '</'});            !!!emit ({type => 'character', data => '</'});
   
373            redo A;            redo A;
         } else {  
           $self->{next_input_character} = shift @next_char;  
           !!!back-next-input-character (@next_char);  
           # and consume...  
374          }          }
375        }        }
376                
# Line 666  sub _get_next_token ($) { Line 431  sub _get_next_token ($) {
431          !!!next-input-character;          !!!next-input-character;
432    
433          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
434    
435          redo A;          redo A;
436        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 676  sub _get_next_token ($) { Line 440  sub _get_next_token ($) {
440          ## Stay in this state          ## Stay in this state
441          !!!next-input-character;          !!!next-input-character;
442          redo A;          redo A;
443        } elsif ($self->{next_input_character} == 0x003C or # <        } elsif ($self->{next_input_character} == -1) {
                $self->{next_input_character} == -1) {  
444          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
445          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
446            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 693  sub _get_next_token ($) { Line 456  sub _get_next_token ($) {
456          # reconsume          # reconsume
457    
458          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
459    
460          redo A;          redo A;
461        } elsif ($self->{next_input_character} == 0x002F) { # /        } elsif ($self->{next_input_character} == 0x002F) { # /
# Line 740  sub _get_next_token ($) { Line 502  sub _get_next_token ($) {
502          !!!next-input-character;          !!!next-input-character;
503    
504          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
505    
506          redo A;          redo A;
507        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 763  sub _get_next_token ($) { Line 524  sub _get_next_token ($) {
524          ## Stay in the state          ## Stay in the state
525          # next-input-character is already done          # next-input-character is already done
526          redo A;          redo A;
527        } elsif ($self->{next_input_character} == 0x003C or # <        } elsif ($self->{next_input_character} == -1) {
                $self->{next_input_character} == -1) {  
528          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
529          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
530            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 780  sub _get_next_token ($) { Line 540  sub _get_next_token ($) {
540          # reconsume          # reconsume
541    
542          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
543    
544          redo A;          redo A;
545        } else {        } else {
# Line 832  sub _get_next_token ($) { Line 591  sub _get_next_token ($) {
591          !!!next-input-character;          !!!next-input-character;
592    
593          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
594    
595          redo A;          redo A;
596        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 855  sub _get_next_token ($) { Line 613  sub _get_next_token ($) {
613          $self->{state} = 'before attribute name';          $self->{state} = 'before attribute name';
614          # next-input-character is already done          # next-input-character is already done
615          redo A;          redo A;
616        } elsif ($self->{next_input_character} == 0x003C or # <        } elsif ($self->{next_input_character} == -1) {
                $self->{next_input_character} == -1) {  
617          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
618          $before_leave->();          $before_leave->();
619          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
# Line 873  sub _get_next_token ($) { Line 630  sub _get_next_token ($) {
630          # reconsume          # reconsume
631    
632          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
633    
634          redo A;          redo A;
635        } else {        } else {
# Line 910  sub _get_next_token ($) { Line 666  sub _get_next_token ($) {
666          !!!next-input-character;          !!!next-input-character;
667    
668          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
669    
670          redo A;          redo A;
671        } elsif (0x0041 <= $self->{next_input_character} and        } elsif (0x0041 <= $self->{next_input_character} and
# Line 933  sub _get_next_token ($) { Line 688  sub _get_next_token ($) {
688          $self->{state} = 'before attribute name';          $self->{state} = 'before attribute name';
689          # next-input-character is already done          # next-input-character is already done
690          redo A;          redo A;
691        } elsif ($self->{next_input_character} == 0x003C or # <        } elsif ($self->{next_input_character} == -1) {
                $self->{next_input_character} == -1) {  
692          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
693          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
694            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 950  sub _get_next_token ($) { Line 704  sub _get_next_token ($) {
704          # reconsume          # reconsume
705    
706          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
707    
708          redo A;          redo A;
709        } else {        } else {
# Line 996  sub _get_next_token ($) { Line 749  sub _get_next_token ($) {
749          !!!next-input-character;          !!!next-input-character;
750    
751          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
752    
753          redo A;          redo A;
754        } elsif ($self->{next_input_character} == 0x003C or # <        } elsif ($self->{next_input_character} == -1) {
                $self->{next_input_character} == -1) {  
755          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
756          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
757            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1016  sub _get_next_token ($) { Line 767  sub _get_next_token ($) {
767          ## reconsume          ## reconsume
768    
769          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
770    
771          redo A;          redo A;
772        } else {        } else {
# Line 1051  sub _get_next_token ($) { Line 801  sub _get_next_token ($) {
801          ## reconsume          ## reconsume
802    
803          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
804    
805          redo A;          redo A;
806        } else {        } else {
# Line 1086  sub _get_next_token ($) { Line 835  sub _get_next_token ($) {
835          ## reconsume          ## reconsume
836    
837          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
838    
839          redo A;          redo A;
840        } else {        } else {
# Line 1124  sub _get_next_token ($) { Line 872  sub _get_next_token ($) {
872          !!!next-input-character;          !!!next-input-character;
873    
874          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
875    
876          redo A;          redo A;
877        } elsif ($self->{next_input_character} == 0x003C or # <        } elsif ($self->{next_input_character} == -1) {
                $self->{next_input_character} == -1) {  
878          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
879          if ($self->{current_token}->{type} eq 'start tag') {          if ($self->{current_token}->{type} eq 'start tag') {
880            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
# Line 1144  sub _get_next_token ($) { Line 890  sub _get_next_token ($) {
890          ## reconsume          ## reconsume
891    
892          !!!emit ($self->{current_token}); # start tag or end tag          !!!emit ($self->{current_token}); # start tag or end tag
         undef $self->{current_token};  
893    
894          redo A;          redo A;
895        } else {        } else {
# Line 1154  sub _get_next_token ($) { Line 899  sub _get_next_token ($) {
899          redo A;          redo A;
900        }        }
901      } elsif ($self->{state} eq 'entity in attribute value') {      } elsif ($self->{state} eq 'entity in attribute value') {
902        my $token = $self->_tokenize_attempt_to_consume_an_entity;        my $token = $self->_tokenize_attempt_to_consume_an_entity (1);
903    
904        unless (defined $token) {        unless (defined $token) {
905          $self->{current_attribute}->{value} .= '&';          $self->{current_attribute}->{value} .= '&';
# Line 1203  sub _get_next_token ($) { Line 948  sub _get_next_token ($) {
948          push @next_char, $self->{next_input_character};          push @next_char, $self->{next_input_character};
949          if ($self->{next_input_character} == 0x002D) { # -          if ($self->{next_input_character} == 0x002D) { # -
950            $self->{current_token} = {type => 'comment', data => ''};            $self->{current_token} = {type => 'comment', data => ''};
951            $self->{state} = 'comment';            $self->{state} = 'comment start';
952            !!!next-input-character;            !!!next-input-character;
953            redo A;            redo A;
954          }          }
# Line 1253  sub _get_next_token ($) { Line 998  sub _get_next_token ($) {
998                
999        ## ISSUE: typos in spec: chacacters, is is a parse error        ## ISSUE: typos in spec: chacacters, is is a parse error
1000        ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it?        ## ISSUE: spec is somewhat unclear on "is the first character that will be in the comment"; what is "that will be in the comment" is what the algorithm defines, isn't it?
1001        } elsif ($self->{state} eq 'comment start') {
1002          if ($self->{next_input_character} == 0x002D) { # -
1003            $self->{state} = 'comment start dash';
1004            !!!next-input-character;
1005            redo A;
1006          } elsif ($self->{next_input_character} == 0x003E) { # >
1007            !!!parse-error (type => 'bogus comment');
1008            $self->{state} = 'data';
1009            !!!next-input-character;
1010    
1011            !!!emit ($self->{current_token}); # comment
1012    
1013            redo A;
1014          } elsif ($self->{next_input_character} == -1) {
1015            !!!parse-error (type => 'unclosed comment');
1016            $self->{state} = 'data';
1017            ## reconsume
1018    
1019            !!!emit ($self->{current_token}); # comment
1020    
1021            redo A;
1022          } else {
1023            $self->{current_token}->{data} # comment
1024                .= chr ($self->{next_input_character});
1025            $self->{state} = 'comment';
1026            !!!next-input-character;
1027            redo A;
1028          }
1029        } elsif ($self->{state} eq 'comment start dash') {
1030          if ($self->{next_input_character} == 0x002D) { # -
1031            $self->{state} = 'comment end';
1032            !!!next-input-character;
1033            redo A;
1034          } elsif ($self->{next_input_character} == 0x003E) { # >
1035            !!!parse-error (type => 'bogus comment');
1036            $self->{state} = 'data';
1037            !!!next-input-character;
1038    
1039            !!!emit ($self->{current_token}); # comment
1040    
1041            redo A;
1042          } elsif ($self->{next_input_character} == -1) {
1043            !!!parse-error (type => 'unclosed comment');
1044            $self->{state} = 'data';
1045            ## reconsume
1046    
1047            !!!emit ($self->{current_token}); # comment
1048    
1049            redo A;
1050          } else {
1051            $self->{current_token}->{data} # comment
1052                .= chr ($self->{next_input_character});
1053            $self->{state} = 'comment';
1054            !!!next-input-character;
1055            redo A;
1056          }
1057      } elsif ($self->{state} eq 'comment') {      } elsif ($self->{state} eq 'comment') {
1058        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1059          $self->{state} = 'comment dash';          $self->{state} = 'comment end dash';
1060          !!!next-input-character;          !!!next-input-character;
1061          redo A;          redo A;
1062        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1264  sub _get_next_token ($) { Line 1065  sub _get_next_token ($) {
1065          ## reconsume          ## reconsume
1066    
1067          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1068    
1069          redo A;          redo A;
1070        } else {        } else {
# Line 1273  sub _get_next_token ($) { Line 1073  sub _get_next_token ($) {
1073          !!!next-input-character;          !!!next-input-character;
1074          redo A;          redo A;
1075        }        }
1076      } elsif ($self->{state} eq 'comment dash') {      } elsif ($self->{state} eq 'comment end dash') {
1077        if ($self->{next_input_character} == 0x002D) { # -        if ($self->{next_input_character} == 0x002D) { # -
1078          $self->{state} = 'comment end';          $self->{state} = 'comment end';
1079          !!!next-input-character;          !!!next-input-character;
# Line 1284  sub _get_next_token ($) { Line 1084  sub _get_next_token ($) {
1084          ## reconsume          ## reconsume
1085    
1086          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1087    
1088          redo A;          redo A;
1089        } else {        } else {
# Line 1299  sub _get_next_token ($) { Line 1098  sub _get_next_token ($) {
1098          !!!next-input-character;          !!!next-input-character;
1099    
1100          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1101    
1102          redo A;          redo A;
1103        } elsif ($self->{next_input_character} == 0x002D) { # -        } elsif ($self->{next_input_character} == 0x002D) { # -
# Line 1314  sub _get_next_token ($) { Line 1112  sub _get_next_token ($) {
1112          ## reconsume          ## reconsume
1113    
1114          !!!emit ($self->{current_token}); # comment          !!!emit ($self->{current_token}); # comment
         undef $self->{current_token};  
1115    
1116          redo A;          redo A;
1117        } else {        } else {
# Line 1348  sub _get_next_token ($) { Line 1145  sub _get_next_token ($) {
1145          ## Stay in the state          ## Stay in the state
1146          !!!next-input-character;          !!!next-input-character;
1147          redo A;          redo A;
       } elsif (0x0061 <= $self->{next_input_character} and  
                $self->{next_input_character} <= 0x007A) { # a..z  
 ## ISSUE: "Set the token's name name to the" in the spec  
         $self->{current_token} = {type => 'DOCTYPE',  
                           name => chr ($self->{next_input_character} - 0x0020),  
                           error => 1};  
         $self->{state} = 'DOCTYPE name';  
         !!!next-input-character;  
         redo A;  
1148        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
1149          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
1150          $self->{state} = 'data';          $self->{state} = 'data';
1151          !!!next-input-character;          !!!next-input-character;
1152    
1153          !!!emit ({type => 'DOCTYPE', name => '', error => 1});          !!!emit ({type => 'DOCTYPE'}); # incorrect
1154    
1155          redo A;          redo A;
1156        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1370  sub _get_next_token ($) { Line 1158  sub _get_next_token ($) {
1158          $self->{state} = 'data';          $self->{state} = 'data';
1159          ## reconsume          ## reconsume
1160    
1161          !!!emit ({type => 'DOCTYPE', name => '', error => 1});          !!!emit ({type => 'DOCTYPE'}); # incorrect
1162    
1163          redo A;          redo A;
1164        } else {        } else {
1165          $self->{current_token} = {type => 'DOCTYPE',          $self->{current_token}
1166                            name => chr ($self->{next_input_character}),              = {type => 'DOCTYPE',
1167                            error => 1};                 name => chr ($self->{next_input_character}),
1168                   correct => 1};
1169  ## ISSUE: "Set the token's name name to the" in the spec  ## ISSUE: "Set the token's name name to the" in the spec
1170          $self->{state} = 'DOCTYPE name';          $self->{state} = 'DOCTYPE name';
1171          !!!next-input-character;          !!!next-input-character;
1172          redo A;          redo A;
1173        }        }
1174      } elsif ($self->{state} eq 'DOCTYPE name') {      } elsif ($self->{state} eq 'DOCTYPE name') {
1175    ## ISSUE: Redundant "First," in the spec.
1176        if ($self->{next_input_character} == 0x0009 or # HT        if ($self->{next_input_character} == 0x0009 or # HT
1177            $self->{next_input_character} == 0x000A or # LF            $self->{next_input_character} == 0x000A or # LF
1178            $self->{next_input_character} == 0x000B or # VT            $self->{next_input_character} == 0x000B or # VT
1179            $self->{next_input_character} == 0x000C or # FF            $self->{next_input_character} == 0x000C or # FF
1180            $self->{next_input_character} == 0x0020) { # SP            $self->{next_input_character} == 0x0020) { # SP
         $self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML'); # DOCTYPE  
1181          $self->{state} = 'after DOCTYPE name';          $self->{state} = 'after DOCTYPE name';
1182          !!!next-input-character;          !!!next-input-character;
1183          redo A;          redo A;
1184        } elsif ($self->{next_input_character} == 0x003E) { # >        } elsif ($self->{next_input_character} == 0x003E) { # >
         $self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML'); # DOCTYPE  
1185          $self->{state} = 'data';          $self->{state} = 'data';
1186          !!!next-input-character;          !!!next-input-character;
1187    
1188          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1189    
1190          redo A;          redo A;
       } elsif (0x0061 <= $self->{next_input_character} and  
                $self->{next_input_character} <= 0x007A) { # a..z  
         $self->{current_token}->{name} .= chr ($self->{next_input_character} - 0x0020); # DOCTYPE  
         #$self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML');  
         ## Stay in the state  
         !!!next-input-character;  
         redo A;  
1191        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
1192          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
         $self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML'); # DOCTYPE  
1193          $self->{state} = 'data';          $self->{state} = 'data';
1194          ## reconsume          ## reconsume
1195    
1196          !!!emit ($self->{current_token});          delete $self->{current_token}->{correct};
1197          undef $self->{current_token};          !!!emit ($self->{current_token}); # DOCTYPE
1198    
1199          redo A;          redo A;
1200        } else {        } else {
1201          $self->{current_token}->{name}          $self->{current_token}->{name}
1202            .= chr ($self->{next_input_character}); # DOCTYPE            .= chr ($self->{next_input_character}); # DOCTYPE
         #$self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML');  
1203          ## Stay in the state          ## Stay in the state
1204          !!!next-input-character;          !!!next-input-character;
1205          redo A;          redo A;
# Line 1440  sub _get_next_token ($) { Line 1218  sub _get_next_token ($) {
1218          !!!next-input-character;          !!!next-input-character;
1219    
1220          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1221    
1222          redo A;          redo A;
1223        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1448  sub _get_next_token ($) { Line 1225  sub _get_next_token ($) {
1225          $self->{state} = 'data';          $self->{state} = 'data';
1226          ## reconsume          ## reconsume
1227    
1228            delete $self->{current_token}->{correct};
1229          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1230    
1231          redo A;          redo A;
1232          } elsif ($self->{next_input_character} == 0x0050 or # P
1233                   $self->{next_input_character} == 0x0070) { # p
1234            !!!next-input-character;
1235            if ($self->{next_input_character} == 0x0055 or # U
1236                $self->{next_input_character} == 0x0075) { # u
1237              !!!next-input-character;
1238              if ($self->{next_input_character} == 0x0042 or # B
1239                  $self->{next_input_character} == 0x0062) { # b
1240                !!!next-input-character;
1241                if ($self->{next_input_character} == 0x004C or # L
1242                    $self->{next_input_character} == 0x006C) { # l
1243                  !!!next-input-character;
1244                  if ($self->{next_input_character} == 0x0049 or # I
1245                      $self->{next_input_character} == 0x0069) { # i
1246                    !!!next-input-character;
1247                    if ($self->{next_input_character} == 0x0043 or # C
1248                        $self->{next_input_character} == 0x0063) { # c
1249                      $self->{state} = 'before DOCTYPE public identifier';
1250                      !!!next-input-character;
1251                      redo A;
1252                    }
1253                  }
1254                }
1255              }
1256            }
1257    
1258            #
1259          } elsif ($self->{next_input_character} == 0x0053 or # S
1260                   $self->{next_input_character} == 0x0073) { # s
1261            !!!next-input-character;
1262            if ($self->{next_input_character} == 0x0059 or # Y
1263                $self->{next_input_character} == 0x0079) { # y
1264              !!!next-input-character;
1265              if ($self->{next_input_character} == 0x0053 or # S
1266                  $self->{next_input_character} == 0x0073) { # s
1267                !!!next-input-character;
1268                if ($self->{next_input_character} == 0x0054 or # T
1269                    $self->{next_input_character} == 0x0074) { # t
1270                  !!!next-input-character;
1271                  if ($self->{next_input_character} == 0x0045 or # E
1272                      $self->{next_input_character} == 0x0065) { # e
1273                    !!!next-input-character;
1274                    if ($self->{next_input_character} == 0x004D or # M
1275                        $self->{next_input_character} == 0x006D) { # m
1276                      $self->{state} = 'before DOCTYPE system identifier';
1277                      !!!next-input-character;
1278                      redo A;
1279                    }
1280                  }
1281                }
1282              }
1283            }
1284    
1285            #
1286        } else {        } else {
1287          !!!parse-error (type => 'string after DOCTYPE name');          !!!next-input-character;
1288          $self->{current_token}->{error} = 1; # DOCTYPE          #
1289          }
1290    
1291          !!!parse-error (type => 'string after DOCTYPE name');
1292          $self->{state} = 'bogus DOCTYPE';
1293          # next-input-character is already done
1294          redo A;
1295        } elsif ($self->{state} eq 'before DOCTYPE public identifier') {
1296          if ({
1297                0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1298                #0x000D => 1, # HT, LF, VT, FF, SP, CR
1299              }->{$self->{next_input_character}}) {
1300            ## Stay in the state
1301            !!!next-input-character;
1302            redo A;
1303          } elsif ($self->{next_input_character} eq 0x0022) { # "
1304            $self->{current_token}->{public_identifier} = ''; # DOCTYPE
1305            $self->{state} = 'DOCTYPE public identifier (double-quoted)';
1306            !!!next-input-character;
1307            redo A;
1308          } elsif ($self->{next_input_character} eq 0x0027) { # '
1309            $self->{current_token}->{public_identifier} = ''; # DOCTYPE
1310            $self->{state} = 'DOCTYPE public identifier (single-quoted)';
1311            !!!next-input-character;
1312            redo A;
1313          } elsif ($self->{next_input_character} eq 0x003E) { # >
1314            !!!parse-error (type => 'no PUBLIC literal');
1315    
1316            $self->{state} = 'data';
1317            !!!next-input-character;
1318    
1319            delete $self->{current_token}->{correct};
1320            !!!emit ($self->{current_token}); # DOCTYPE
1321    
1322            redo A;
1323          } elsif ($self->{next_input_character} == -1) {
1324            !!!parse-error (type => 'unclosed DOCTYPE');
1325    
1326            $self->{state} = 'data';
1327            ## reconsume
1328    
1329            delete $self->{current_token}->{correct};
1330            !!!emit ($self->{current_token}); # DOCTYPE
1331    
1332            redo A;
1333          } else {
1334            !!!parse-error (type => 'string after PUBLIC');
1335            $self->{state} = 'bogus DOCTYPE';
1336            !!!next-input-character;
1337            redo A;
1338          }
1339        } elsif ($self->{state} eq 'DOCTYPE public identifier (double-quoted)') {
1340          if ($self->{next_input_character} == 0x0022) { # "
1341            $self->{state} = 'after DOCTYPE public identifier';
1342            !!!next-input-character;
1343            redo A;
1344          } elsif ($self->{next_input_character} == -1) {
1345            !!!parse-error (type => 'unclosed PUBLIC literal');
1346    
1347            $self->{state} = 'data';
1348            ## reconsume
1349    
1350            delete $self->{current_token}->{correct};
1351            !!!emit ($self->{current_token}); # DOCTYPE
1352    
1353            redo A;
1354          } else {
1355            $self->{current_token}->{public_identifier} # DOCTYPE
1356                .= chr $self->{next_input_character};
1357            ## Stay in the state
1358            !!!next-input-character;
1359            redo A;
1360          }
1361        } elsif ($self->{state} eq 'DOCTYPE public identifier (single-quoted)') {
1362          if ($self->{next_input_character} == 0x0027) { # '
1363            $self->{state} = 'after DOCTYPE public identifier';
1364            !!!next-input-character;
1365            redo A;
1366          } elsif ($self->{next_input_character} == -1) {
1367            !!!parse-error (type => 'unclosed PUBLIC literal');
1368    
1369            $self->{state} = 'data';
1370            ## reconsume
1371    
1372            delete $self->{current_token}->{correct};
1373            !!!emit ($self->{current_token}); # DOCTYPE
1374    
1375            redo A;
1376          } else {
1377            $self->{current_token}->{public_identifier} # DOCTYPE
1378                .= chr $self->{next_input_character};
1379            ## Stay in the state
1380            !!!next-input-character;
1381            redo A;
1382          }
1383        } elsif ($self->{state} eq 'after DOCTYPE public identifier') {
1384          if ({
1385                0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1386                #0x000D => 1, # HT, LF, VT, FF, SP, CR
1387              }->{$self->{next_input_character}}) {
1388            ## Stay in the state
1389            !!!next-input-character;
1390            redo A;
1391          } elsif ($self->{next_input_character} == 0x0022) { # "
1392            $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1393            $self->{state} = 'DOCTYPE system identifier (double-quoted)';
1394            !!!next-input-character;
1395            redo A;
1396          } elsif ($self->{next_input_character} == 0x0027) { # '
1397            $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1398            $self->{state} = 'DOCTYPE system identifier (single-quoted)';
1399            !!!next-input-character;
1400            redo A;
1401          } elsif ($self->{next_input_character} == 0x003E) { # >
1402            $self->{state} = 'data';
1403            !!!next-input-character;
1404    
1405            !!!emit ($self->{current_token}); # DOCTYPE
1406    
1407            redo A;
1408          } elsif ($self->{next_input_character} == -1) {
1409            !!!parse-error (type => 'unclosed DOCTYPE');
1410    
1411            $self->{state} = 'data';
1412            ## reconsume
1413    
1414            delete $self->{current_token}->{correct};
1415            !!!emit ($self->{current_token}); # DOCTYPE
1416    
1417            redo A;
1418          } else {
1419            !!!parse-error (type => 'string after PUBLIC literal');
1420            $self->{state} = 'bogus DOCTYPE';
1421            !!!next-input-character;
1422            redo A;
1423          }
1424        } elsif ($self->{state} eq 'before DOCTYPE system identifier') {
1425          if ({
1426                0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1427                #0x000D => 1, # HT, LF, VT, FF, SP, CR
1428              }->{$self->{next_input_character}}) {
1429            ## Stay in the state
1430            !!!next-input-character;
1431            redo A;
1432          } elsif ($self->{next_input_character} == 0x0022) { # "
1433            $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1434            $self->{state} = 'DOCTYPE system identifier (double-quoted)';
1435            !!!next-input-character;
1436            redo A;
1437          } elsif ($self->{next_input_character} == 0x0027) { # '
1438            $self->{current_token}->{system_identifier} = ''; # DOCTYPE
1439            $self->{state} = 'DOCTYPE system identifier (single-quoted)';
1440            !!!next-input-character;
1441            redo A;
1442          } elsif ($self->{next_input_character} == 0x003E) { # >
1443            !!!parse-error (type => 'no SYSTEM literal');
1444            $self->{state} = 'data';
1445            !!!next-input-character;
1446    
1447            delete $self->{current_token}->{correct};
1448            !!!emit ($self->{current_token}); # DOCTYPE
1449    
1450            redo A;
1451          } elsif ($self->{next_input_character} == -1) {
1452            !!!parse-error (type => 'unclosed DOCTYPE');
1453    
1454            $self->{state} = 'data';
1455            ## reconsume
1456    
1457            delete $self->{current_token}->{correct};
1458            !!!emit ($self->{current_token}); # DOCTYPE
1459    
1460            redo A;
1461          } else {
1462            !!!parse-error (type => 'string after PUBLIC literal');
1463            $self->{state} = 'bogus DOCTYPE';
1464            !!!next-input-character;
1465            redo A;
1466          }
1467        } elsif ($self->{state} eq 'DOCTYPE system identifier (double-quoted)') {
1468          if ($self->{next_input_character} == 0x0022) { # "
1469            $self->{state} = 'after DOCTYPE system identifier';
1470            !!!next-input-character;
1471            redo A;
1472          } elsif ($self->{next_input_character} == -1) {
1473            !!!parse-error (type => 'unclosed SYSTEM literal');
1474    
1475            $self->{state} = 'data';
1476            ## reconsume
1477    
1478            delete $self->{current_token}->{correct};
1479            !!!emit ($self->{current_token}); # DOCTYPE
1480    
1481            redo A;
1482          } else {
1483            $self->{current_token}->{system_identifier} # DOCTYPE
1484                .= chr $self->{next_input_character};
1485            ## Stay in the state
1486            !!!next-input-character;
1487            redo A;
1488          }
1489        } elsif ($self->{state} eq 'DOCTYPE system identifier (single-quoted)') {
1490          if ($self->{next_input_character} == 0x0027) { # '
1491            $self->{state} = 'after DOCTYPE system identifier';
1492            !!!next-input-character;
1493            redo A;
1494          } elsif ($self->{next_input_character} == -1) {
1495            !!!parse-error (type => 'unclosed SYSTEM literal');
1496    
1497            $self->{state} = 'data';
1498            ## reconsume
1499    
1500            delete $self->{current_token}->{correct};
1501            !!!emit ($self->{current_token}); # DOCTYPE
1502    
1503            redo A;
1504          } else {
1505            $self->{current_token}->{system_identifier} # DOCTYPE
1506                .= chr $self->{next_input_character};
1507            ## Stay in the state
1508            !!!next-input-character;
1509            redo A;
1510          }
1511        } elsif ($self->{state} eq 'after DOCTYPE system identifier') {
1512          if ({
1513                0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1,
1514                #0x000D => 1, # HT, LF, VT, FF, SP, CR
1515              }->{$self->{next_input_character}}) {
1516            ## Stay in the state
1517            !!!next-input-character;
1518            redo A;
1519          } elsif ($self->{next_input_character} == 0x003E) { # >
1520            $self->{state} = 'data';
1521            !!!next-input-character;
1522    
1523            !!!emit ($self->{current_token}); # DOCTYPE
1524    
1525            redo A;
1526          } elsif ($self->{next_input_character} == -1) {
1527            !!!parse-error (type => 'unclosed DOCTYPE');
1528    
1529            $self->{state} = 'data';
1530            ## reconsume
1531    
1532            delete $self->{current_token}->{correct};
1533            !!!emit ($self->{current_token}); # DOCTYPE
1534    
1535            redo A;
1536          } else {
1537            !!!parse-error (type => 'string after SYSTEM literal');
1538          $self->{state} = 'bogus DOCTYPE';          $self->{state} = 'bogus DOCTYPE';
1539          !!!next-input-character;          !!!next-input-character;
1540          redo A;          redo A;
# Line 1464  sub _get_next_token ($) { Line 1544  sub _get_next_token ($) {
1544          $self->{state} = 'data';          $self->{state} = 'data';
1545          !!!next-input-character;          !!!next-input-character;
1546    
1547            delete $self->{current_token}->{correct};
1548          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1549    
1550          redo A;          redo A;
1551        } elsif ($self->{next_input_character} == -1) {        } elsif ($self->{next_input_character} == -1) {
# Line 1473  sub _get_next_token ($) { Line 1553  sub _get_next_token ($) {
1553          $self->{state} = 'data';          $self->{state} = 'data';
1554          ## reconsume          ## reconsume
1555    
1556            delete $self->{current_token}->{correct};
1557          !!!emit ($self->{current_token}); # DOCTYPE          !!!emit ($self->{current_token}); # DOCTYPE
         undef $self->{current_token};  
1558    
1559          redo A;          redo A;
1560        } else {        } else {
# Line 1490  sub _get_next_token ($) { Line 1570  sub _get_next_token ($) {
1570    die "$0: _get_next_token: unexpected case";    die "$0: _get_next_token: unexpected case";
1571  } # _get_next_token  } # _get_next_token
1572    
1573  sub _tokenize_attempt_to_consume_an_entity ($) {  sub _tokenize_attempt_to_consume_an_entity ($$) {
1574    my $self = shift;    my ($self, $in_attr) = @_;
1575      
1576    if ($self->{next_input_character} == 0x0023) { # #    if ({
1577           0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF,
1578           0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR
1579          }->{$self->{next_input_character}}) {
1580        ## Don't consume
1581        ## No error
1582        return undef;
1583      } elsif ($self->{next_input_character} == 0x0023) { # #
1584      !!!next-input-character;      !!!next-input-character;
1585      if ($self->{next_input_character} == 0x0078 or # x      if ($self->{next_input_character} == 0x0078 or # x
1586          $self->{next_input_character} == 0x0058) { # X          $self->{next_input_character} == 0x0058) { # X
1587        my $num;        my $code;
1588        X: {        X: {
1589          my $x_char = $self->{next_input_character};          my $x_char = $self->{next_input_character};
1590          !!!next-input-character;          !!!next-input-character;
1591          if (0x0030 <= $self->{next_input_character} and          if (0x0030 <= $self->{next_input_character} and
1592              $self->{next_input_character} <= 0x0039) { # 0..9              $self->{next_input_character} <= 0x0039) { # 0..9
1593            $num ||= 0;            $code ||= 0;
1594            $num *= 0x10;            $code *= 0x10;
1595            $num += $self->{next_input_character} - 0x0030;            $code += $self->{next_input_character} - 0x0030;
1596            redo X;            redo X;
1597          } elsif (0x0061 <= $self->{next_input_character} and          } elsif (0x0061 <= $self->{next_input_character} and
1598                   $self->{next_input_character} <= 0x0066) { # a..f                   $self->{next_input_character} <= 0x0066) { # a..f
1599            ## ISSUE: the spec says U+0078, which is apparently incorrect            $code ||= 0;
1600            $num ||= 0;            $code *= 0x10;
1601            $num *= 0x10;            $code += $self->{next_input_character} - 0x0060 + 9;
           $num += $self->{next_input_character} - 0x0060 + 9;  
1602            redo X;            redo X;
1603          } elsif (0x0041 <= $self->{next_input_character} and          } elsif (0x0041 <= $self->{next_input_character} and
1604                   $self->{next_input_character} <= 0x0046) { # A..F                   $self->{next_input_character} <= 0x0046) { # A..F
1605            ## ISSUE: the spec says U+0058, which is apparently incorrect            $code ||= 0;
1606            $num ||= 0;            $code *= 0x10;
1607            $num *= 0x10;            $code += $self->{next_input_character} - 0x0040 + 9;
           $num += $self->{next_input_character} - 0x0040 + 9;  
1608            redo X;            redo X;
1609          } elsif (not defined $num) { # no hexadecimal digit          } elsif (not defined $code) { # no hexadecimal digit
1610            !!!parse-error (type => 'bare hcro');            !!!parse-error (type => 'bare hcro');
1611            $self->{next_input_character} = 0x0023; # #            $self->{next_input_character} = 0x0023; # #
1612            !!!back-next-input-character ($x_char);            !!!back-next-input-character ($x_char);
# Line 1532  sub _tokenize_attempt_to_consume_an_enti Line 1617  sub _tokenize_attempt_to_consume_an_enti
1617            !!!parse-error (type => 'no refc');            !!!parse-error (type => 'no refc');
1618          }          }
1619    
1620          ## TODO: check the definition for |a valid Unicode character|.          if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
1621          ## <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-December/thread.html#8189>            !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
1622          if ($num > 1114111 or $num == 0) {            $code = 0xFFFD;
1623            $num = 0xFFFD; # REPLACEMENT CHARACTER          } elsif ($code > 0x10FFFF) {
1624            ## ISSUE: Why this is not an error?            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
1625          } elsif (0x80 <= $num and $num <= 0x9F) {            $code = 0xFFFD;
1626            ## NOTE: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-December/thread.html#8562>          } elsif ($code == 0x000D) {
1627            ## ISSUE: Not in the spec yet; parse error?            !!!parse-error (type => 'CR character reference');
1628            $num = $c1_entity_char->{$num};            $code = 0x000A;
1629            } elsif (0x80 <= $code and $code <= 0x9F) {
1630              !!!parse-error (type => sprintf 'c1 entity:U+%04X', $code);
1631              $code = $c1_entity_char->{$code};
1632          }          }
1633    
1634          return {type => 'character', data => chr $num};          return {type => 'character', data => chr $code};
1635        } # X        } # X
1636      } elsif (0x0030 <= $self->{next_input_character} and      } elsif (0x0030 <= $self->{next_input_character} and
1637               $self->{next_input_character} <= 0x0039) { # 0..9               $self->{next_input_character} <= 0x0039) { # 0..9
# Line 1564  sub _tokenize_attempt_to_consume_an_enti Line 1652  sub _tokenize_attempt_to_consume_an_enti
1652          !!!parse-error (type => 'no refc');          !!!parse-error (type => 'no refc');
1653        }        }
1654    
1655        ## TODO: check the definition for |a valid Unicode character|.        if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) {
1656        if ($code > 1114111 or $code == 0) {          !!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code);
1657          $code = 0xFFFD; # REPLACEMENT CHARACTER          $code = 0xFFFD;
1658          ## ISSUE: Why this is not an error?        } elsif ($code > 0x10FFFF) {
1659            !!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code);
1660            $code = 0xFFFD;
1661          } elsif ($code == 0x000D) {
1662            !!!parse-error (type => 'CR character reference');
1663            $code = 0x000A;
1664        } elsif (0x80 <= $code and $code <= 0x9F) {        } elsif (0x80 <= $code and $code <= 0x9F) {
1665          ## NOTE: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-December/thread.html#8562>          !!!parse-error (type => sprintf 'c1 entity:U+%04X', $code);
         ## ISSUE: Not in the spec yet; parse error?  
1666          $code = $c1_entity_char->{$code};          $code = $c1_entity_char->{$code};
1667        }        }
1668                
# Line 1590  sub _tokenize_attempt_to_consume_an_enti Line 1682  sub _tokenize_attempt_to_consume_an_enti
1682    
1683      my $value = $entity_name;      my $value = $entity_name;
1684      my $match;      my $match;
1685        require Whatpm::_NamedEntityList;
1686        our $EntityChar;
1687    
1688      while (length $entity_name < 10 and      while (length $entity_name < 10 and
1689             ## NOTE: Some number greater than the maximum length of entity name             ## NOTE: Some number greater than the maximum length of entity name
1690             ((0x0041 <= $self->{next_input_character} and             ((0x0041 <= $self->{next_input_character} and # a
1691               $self->{next_input_character} <= 0x005A) or               $self->{next_input_character} <= 0x005A) or # x
1692              (0x0061 <= $self->{next_input_character} and              (0x0061 <= $self->{next_input_character} and # a
1693               $self->{next_input_character} <= 0x007A) or               $self->{next_input_character} <= 0x007A) or # z
1694              (0x0030 <= $self->{next_input_character} and              (0x0030 <= $self->{next_input_character} and # 0
1695               $self->{next_input_character} <= 0x0039))) {               $self->{next_input_character} <= 0x0039) or # 9
1696                $self->{next_input_character} == 0x003B)) { # ;
1697        $entity_name .= chr $self->{next_input_character};        $entity_name .= chr $self->{next_input_character};
1698        if (defined $entity_char->{$entity_name}) {        if (defined $EntityChar->{$entity_name}) {
1699          $value = $entity_char->{$entity_name};          if ($self->{next_input_character} == 0x003B) { # ;
1700          $match = 1;            $value = $EntityChar->{$entity_name};
1701              $match = 1;
1702              !!!next-input-character;
1703              last;
1704            } elsif (not $in_attr) {
1705              $value = $EntityChar->{$entity_name};
1706              $match = -1;
1707            } else {
1708              $value .= chr $self->{next_input_character};
1709            }
1710        } else {        } else {
1711          $value .= chr $self->{next_input_character};          $value .= chr $self->{next_input_character};
1712        }        }
1713        !!!next-input-character;        !!!next-input-character;
1714      }      }
1715            
1716      if ($match) {      if ($match > 0) {
1717        if ($self->{next_input_character} == 0x003B) { # ;        return {type => 'character', data => $value};
1718          !!!next-input-character;      } elsif ($match < 0) {
1719        } else {        !!!parse-error (type => 'refc');
         !!!parse-error (type => 'refc');  
       }  
   
1720        return {type => 'character', data => $value};        return {type => 'character', data => $value};
1721      } else {      } else {
1722        !!!parse-error (type => 'bare ero');        !!!parse-error (type => 'bare ero');
1723        ## NOTE: No characters are consumed in the spec.        ## NOTE: No characters are consumed in the spec.
1724        !!!back-token ({type => 'character', data => $value});        return {type => 'character', data => '&'.$value};
       return undef;  
1725      }      }
1726    } else {    } else {
1727      ## no characters are consumed      ## no characters are consumed
# Line 1636  sub _initialize_tree_constructor ($) { Line 1736  sub _initialize_tree_constructor ($) {
1736    $self->{document}->strict_error_checking (0);    $self->{document}->strict_error_checking (0);
1737    ## TODO: Turn mutation events off # MUST    ## TODO: Turn mutation events off # MUST
1738    ## TODO: Turn loose Document option (manakai extension) on    ## TODO: Turn loose Document option (manakai extension) on
1739    ## TODO: Mark the Document as an HTML document # MUST    $self->{document}->manakai_is_html (1); # MUST
1740  } # _initialize_tree_constructor  } # _initialize_tree_constructor
1741    
1742  sub _terminate_tree_constructor ($) {  sub _terminate_tree_constructor ($) {
# Line 1676  sub _construct_tree ($) { Line 1776  sub _construct_tree ($) {
1776    
1777  sub _tree_construction_initial ($) {  sub _tree_construction_initial ($) {
1778    my $self = shift;    my $self = shift;
1779    B: {    INITIAL: {
1780        if ($token->{type} eq 'DOCTYPE') {      if ($token->{type} eq 'DOCTYPE') {
1781          if ($token->{error}) {        ## NOTE: Conformance checkers MAY, instead of reporting "not HTML5"
1782            ## ISSUE: Spec currently left this case undefined.        ## error, switch to a conformance checking mode for another
1783            !!!parse-error (type => 'bogus DOCTYPE');        ## language.
1784          }        my $doctype_name = $token->{name};
1785          my $doctype = $self->{document}->create_document_type_definition        $doctype_name = '' unless defined $doctype_name;
1786            ($token->{name});        $doctype_name =~ tr/a-z/A-Z/;
1787          $self->{document}->append_child ($doctype);        if (not defined $token->{name} or # <!DOCTYPE>
1788          #$phase = 'root element';            defined $token->{public_identifier} or
1789          !!!next-token;            defined $token->{system_identifier}) {
1790          #redo B;          !!!parse-error (type => 'not HTML5');
1791          return;        } elsif ($doctype_name ne 'HTML') {
1792        } elsif ({          ## ISSUE: ASCII case-insensitive? (in fact it does not matter)
1793                  comment => 1,          !!!parse-error (type => 'not HTML5');
1794                  'start tag' => 1,        }
1795                  'end tag' => 1,        
1796                  'end-of-file' => 1,        my $doctype = $self->{document}->create_document_type_definition
1797                 }->{$token->{type}}) {          ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?
1798          ## ISSUE: Spec currently left this case undefined.        $doctype->public_id ($token->{public_identifier})
1799          !!!parse-error (type => 'missing DOCTYPE');            if defined $token->{public_identifier};
1800          #$phase = 'root element';        $doctype->system_id ($token->{system_identifier})
1801          ## reprocess            if defined $token->{system_identifier};
1802          #redo B;        ## NOTE: Other DocumentType attributes are null or empty lists.
1803          return;        ## ISSUE: internalSubset = null??
1804        } elsif ($token->{type} eq 'character') {        $self->{document}->append_child ($doctype);
1805          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {        
1806            $self->{document}->manakai_append_text ($1);        if (not $token->{correct} or $doctype_name ne 'HTML') {
1807            ## ISSUE: DOM3 Core does not allow Document > Text          $self->{document}->manakai_compat_mode ('quirks');
1808            unless (length $token->{data}) {        } elsif (defined $token->{public_identifier}) {
1809              ## Stay in the phase          my $pubid = $token->{public_identifier};
1810              !!!next-token;          $pubid =~ tr/a-z/A-z/;
1811              redo B;          if ({
1812              "+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1,
1813              "-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,
1814              "-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1,
1815              "-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1,
1816              "-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1,
1817              "-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1,
1818              "-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1,
1819              "-//IETF//DTD HTML 2.0 STRICT//EN" => 1,
1820              "-//IETF//DTD HTML 2.0//EN" => 1,
1821              "-//IETF//DTD HTML 2.1E//EN" => 1,
1822              "-//IETF//DTD HTML 3.0//EN" => 1,
1823              "-//IETF//DTD HTML 3.0//EN//" => 1,
1824              "-//IETF//DTD HTML 3.2 FINAL//EN" => 1,
1825              "-//IETF//DTD HTML 3.2//EN" => 1,
1826              "-//IETF//DTD HTML 3//EN" => 1,
1827              "-//IETF//DTD HTML LEVEL 0//EN" => 1,
1828              "-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1,
1829              "-//IETF//DTD HTML LEVEL 1//EN" => 1,
1830              "-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1,
1831              "-//IETF//DTD HTML LEVEL 2//EN" => 1,
1832              "-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1,
1833              "-//IETF//DTD HTML LEVEL 3//EN" => 1,
1834              "-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1,
1835              "-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1,
1836              "-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1,
1837              "-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1,
1838              "-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1,
1839              "-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1,
1840              "-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1,
1841              "-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1,
1842              "-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1,
1843              "-//IETF//DTD HTML STRICT//EN" => 1,
1844              "-//IETF//DTD HTML STRICT//EN//2.0" => 1,
1845              "-//IETF//DTD HTML STRICT//EN//3.0" => 1,
1846              "-//IETF//DTD HTML//EN" => 1,
1847              "-//IETF//DTD HTML//EN//2.0" => 1,
1848              "-//IETF//DTD HTML//EN//3.0" => 1,
1849              "-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1,
1850              "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1,
1851              "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1,
1852              "-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1,
1853              "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1,
1854              "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1,
1855              "-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1,
1856              "-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1,
1857              "-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1,
1858              "-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1,
1859              "-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1,
1860              "-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1,
1861              "-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1,
1862              "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1,
1863              "-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1,
1864              "-//W3C//DTD HTML 3 1995-03-24//EN" => 1,
1865              "-//W3C//DTD HTML 3.2 DRAFT//EN" => 1,
1866              "-//W3C//DTD HTML 3.2 FINAL//EN" => 1,
1867              "-//W3C//DTD HTML 3.2//EN" => 1,
1868              "-//W3C//DTD HTML 3.2S DRAFT//EN" => 1,
1869              "-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1,
1870              "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1,
1871              "-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1,
1872              "-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1,
1873              "-//W3C//DTD W3 HTML//EN" => 1,
1874              "-//W3O//DTD W3 HTML 3.0//EN" => 1,
1875              "-//W3O//DTD W3 HTML 3.0//EN//" => 1,
1876              "-//W3O//DTD W3 HTML STRICT 3.0//EN//" => 1,
1877              "-//WEBTECHS//DTD MOZILLA HTML 2.0//EN" => 1,
1878              "-//WEBTECHS//DTD MOZILLA HTML//EN" => 1,
1879              "-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1,
1880              "HTML" => 1,
1881            }->{$pubid}) {
1882              $self->{document}->manakai_compat_mode ('quirks');
1883            } elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or
1884                     $pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") {
1885              if (defined $token->{system_identifier}) {
1886                $self->{document}->manakai_compat_mode ('quirks');
1887              } else {
1888                $self->{document}->manakai_compat_mode ('limited quirks');
1889            }            }
1890            } elsif ($pubid eq "-//W3C//DTD XHTML 1.0 Frameset//EN" or
1891                     $pubid eq "-//W3C//DTD XHTML 1.0 Transitional//EN") {
1892              $self->{document}->manakai_compat_mode ('limited quirks');
1893            }
1894          }
1895          if (defined $token->{system_identifier}) {
1896            my $sysid = $token->{system_identifier};
1897            $sysid =~ tr/A-Z/a-z/;
1898            if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {
1899              $self->{document}->manakai_compat_mode ('quirks');
1900            }
1901          }
1902          
1903          ## Go to the root element phase.
1904          !!!next-token;
1905          return;
1906        } elsif ({
1907                  'start tag' => 1,
1908                  'end tag' => 1,
1909                  'end-of-file' => 1,
1910                 }->{$token->{type}}) {
1911          !!!parse-error (type => 'no DOCTYPE');
1912          $self->{document}->manakai_compat_mode ('quirks');
1913          ## Go to the root element phase
1914          ## reprocess
1915          return;
1916        } elsif ($token->{type} eq 'character') {
1917          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
1918            ## Ignore the token
1919    
1920            unless (length $token->{data}) {
1921              ## Stay in the phase
1922              !!!next-token;
1923              redo INITIAL;
1924          }          }
         ## ISSUE: Spec currently left this case undefined.  
         !!!parse-error (type => 'missing DOCTYPE');  
         #$phase = 'root element';  
         ## reprocess  
         #redo B;  
         return;  
       } else {  
         die "$0: $token->{type}: Unknown token";  
1925        }        }
1926      } # B  
1927          !!!parse-error (type => 'no DOCTYPE');
1928          $self->{document}->manakai_compat_mode ('quirks');
1929          ## Go to the root element phase
1930          ## reprocess
1931          return;
1932        } elsif ($token->{type} eq 'comment') {
1933          my $comment = $self->{document}->create_comment ($token->{data});
1934          $self->{document}->append_child ($comment);
1935          
1936          ## Stay in the phase.
1937          !!!next-token;
1938          redo INITIAL;
1939        } else {
1940          die "$0: $token->{type}: Unknown token";
1941        }
1942      } # INITIAL
1943  } # _tree_construction_initial  } # _tree_construction_initial
1944    
1945  sub _tree_construction_root_element ($) {  sub _tree_construction_root_element ($) {
# Line 1740  sub _tree_construction_root_element ($) Line 1959  sub _tree_construction_root_element ($)
1959          !!!next-token;          !!!next-token;
1960          redo B;          redo B;
1961        } elsif ($token->{type} eq 'character') {        } elsif ($token->{type} eq 'character') {
1962          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
1963            $self->{document}->manakai_append_text ($1);            ## Ignore the token.
1964            ## ISSUE: DOM3 Core does not allow Document > Text  
1965            unless (length $token->{data}) {            unless (length $token->{data}) {
1966              ## Stay in the phase              ## Stay in the phase
1967              !!!next-token;              !!!next-token;
# Line 1919  sub _tree_construction_main ($) { Line 2138  sub _tree_construction_main ($) {
2138      }      }
2139    }; # $clear_up_to_marker    }; # $clear_up_to_marker
2140    
2141    my $style_start_tag = sub {    my $parse_rcdata = sub ($$) {
2142      my $style_el; !!!create-element ($style_el, 'style', $token->{attributes});      my ($content_model_flag, $insert) = @_;
2143      ## $self->{insertion_mode} eq 'in head' and ... (always true)  
2144      (($self->{insertion_mode} eq 'in head' and defined $self->{head_element})      ## Step 1
2145       ? $self->{head_element} : $self->{open_elements}->[-1]->[0])      my $start_tag_name = $token->{tag_name};
2146        ->append_child ($style_el);      my $el;
2147      $self->{content_model_flag} = 'CDATA';      !!!create-element ($el, $start_tag_name, $token->{attributes});
2148                  
2149        ## Step 2
2150        $insert->($el); # /context node/->append_child ($el)
2151    
2152        ## Step 3
2153        $self->{content_model_flag} = $content_model_flag; # CDATA or RCDATA
2154        delete $self->{escape}; # MUST
2155    
2156        ## Step 4
2157      my $text = '';      my $text = '';
2158      !!!next-token;      !!!next-token;
2159      while ($token->{type} eq 'character') {      while ($token->{type} eq 'character') { # or until stop tokenizing
2160        $text .= $token->{data};        $text .= $token->{data};
2161        !!!next-token;        !!!next-token;
2162      } # stop if non-character token or tokenizer stops tokenising      }
2163    
2164        ## Step 5
2165      if (length $text) {      if (length $text) {
2166        $style_el->manakai_append_text ($text);        my $text = $self->{document}->create_text_node ($text);
2167          $el->append_child ($text);
2168      }      }
2169        
2170        ## Step 6
2171      $self->{content_model_flag} = 'PCDATA';      $self->{content_model_flag} = 'PCDATA';
2172                  
2173      if ($token->{type} eq 'end tag' and $token->{tag_name} eq 'style') {      ## Step 7
2174        if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) {
2175        ## Ignore the token        ## Ignore the token
2176      } else {      } else {
2177        !!!parse-error (type => 'in CDATA:#'.$token->{type});        !!!parse-error (type => 'in '.$content_model_flag.':#'.$token->{type});
       ## ISSUE: And ignore?  
2178      }      }
2179      !!!next-token;      !!!next-token;
2180    }; # $style_start_tag    }; # $parse_rcdata
2181    
2182    my $script_start_tag = sub {    my $script_start_tag = sub ($) {
2183        my $insert = $_[0];
2184      my $script_el;      my $script_el;
2185      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, 'script', $token->{attributes});
2186      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
2187    
2188      $self->{content_model_flag} = 'CDATA';      $self->{content_model_flag} = 'CDATA';
2189        delete $self->{escape}; # MUST
2190            
2191      my $text = '';      my $text = '';
2192      !!!next-token;      !!!next-token;
# Line 1981  sub _tree_construction_main ($) { Line 2214  sub _tree_construction_main ($) {
2214      } else {      } else {
2215        ## TODO: $old_insertion_point = current insertion point        ## TODO: $old_insertion_point = current insertion point
2216        ## TODO: insertion point = just before the next input character        ## TODO: insertion point = just before the next input character
2217          
2218        (($self->{insertion_mode} eq 'in head' and defined $self->{head_element})        $insert->($script_el);
        ? $self->{head_element} : $self->{open_elements}->[-1]->[0])->append_child ($script_el);  
2219                
2220        ## TODO: insertion point = $old_insertion_point (might be "undefined")        ## TODO: insertion point = $old_insertion_point (might be "undefined")
2221                
# Line 2177  sub _tree_construction_main ($) { Line 2409  sub _tree_construction_main ($) {
2409    }; # $formatting_end_tag    }; # $formatting_end_tag
2410    
2411    my $insert_to_current = sub {    my $insert_to_current = sub {
2412      $self->{open_elements}->[-1]->[0]->append_child (shift);      $self->{open_elements}->[-1]->[0]->append_child ($_[0]);
2413    }; # $insert_to_current    }; # $insert_to_current
2414    
2415    my $insert_to_foster = sub {    my $insert_to_foster = sub {
# Line 2215  sub _tree_construction_main ($) { Line 2447  sub _tree_construction_main ($) {
2447      my $insert = shift;      my $insert = shift;
2448      if ($token->{type} eq 'start tag') {      if ($token->{type} eq 'start tag') {
2449        if ($token->{tag_name} eq 'script') {        if ($token->{tag_name} eq 'script') {
2450          $script_start_tag->();          ## NOTE: This is an "as if in head" code clone
2451            $script_start_tag->($insert);
2452          return;          return;
2453        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
2454          $style_start_tag->();          ## NOTE: This is an "as if in head" code clone
2455            $parse_rcdata->('CDATA', $insert);
2456          return;          return;
2457        } elsif ({        } elsif ({
2458                  base => 1, link => 1, meta => 1,                  base => 1, link => 1, meta => 1,
2459                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
2460          !!!parse-error (type => 'in body:'.$token->{tag_name});          ## NOTE: This is an "as if in head" code clone, only "-t" differs
2461          ## NOTE: This is an "as if in head" code clone          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2462          my $el;          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
         !!!create-element ($el, $token->{tag_name}, $token->{attributes});  
         if (defined $self->{head_element}) {  
           $self->{head_element}->append_child ($el);  
         } else {  
           $insert->($el);  
         }  
           
2463          !!!next-token;          !!!next-token;
2464            ## TODO: Extracting |charset| from |meta|.
2465          return;          return;
2466        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
2467          !!!parse-error (type => 'in body:title');          !!!parse-error (type => 'in body:title');
2468          ## NOTE: There is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
2469          my $title_el;          $parse_rcdata->('RCDATA', $insert);
         !!!create-element ($title_el, 'title', $token->{attributes});  
         (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])  
           ->append_child ($title_el);  
         $self->{content_model_flag} = 'RCDATA';  
           
         my $text = '';  
         !!!next-token;  
         while ($token->{type} eq 'character') {  
           $text .= $token->{data};  
           !!!next-token;  
         }  
         if (length $text) {  
           $title_el->manakai_append_text ($text);  
         }  
           
         $self->{content_model_flag} = 'PCDATA';  
           
         if ($token->{type} eq 'end tag' and  
             $token->{tag_name} eq 'title') {  
           ## Ignore the token  
         } else {  
           !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
           ## ISSUE: And ignore?  
         }  
         !!!next-token;  
2470          return;          return;
2471        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
2472          !!!parse-error (type => 'in body:body');          !!!parse-error (type => 'in body:body');
# Line 2320  sub _tree_construction_main ($) { Line 2523  sub _tree_construction_main ($) {
2523          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
2524            !!!parse-error (type => 'in form:form');            !!!parse-error (type => 'in form:form');
2525            ## Ignore the token            ## Ignore the token
2526              !!!next-token;
2527              return;
2528          } else {          } else {
2529            ## has a p element in scope            ## has a p element in scope
2530            INSCOPE: for (reverse @{$self->{open_elements}}) {            INSCOPE: for (reverse @{$self->{open_elements}}) {
# Line 2361  sub _tree_construction_main ($) { Line 2566  sub _tree_construction_main ($) {
2566          LI: {          LI: {
2567            ## Step 2            ## Step 2
2568            if ($node->[1] eq 'li') {            if ($node->[1] eq 'li') {
2569                if ($i != -1) {
2570                  !!!parse-error (type => 'end tag missing:'.
2571                                  $self->{open_elements}->[-1]->[1]);
2572                  ## TODO: test
2573                }
2574              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2575              last LI;              last LI;
2576            }            }
# Line 2404  sub _tree_construction_main ($) { Line 2614  sub _tree_construction_main ($) {
2614          LI: {          LI: {
2615            ## Step 2            ## Step 2
2616            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {            if ($node->[1] eq 'dt' or $node->[1] eq 'dd') {
2617                if ($i != -1) {
2618                  !!!parse-error (type => 'end tag missing:'.
2619                                  $self->{open_elements}->[-1]->[1]);
2620                  ## TODO: test
2621                }
2622              splice @{$self->{open_elements}}, $i;              splice @{$self->{open_elements}}, $i;
2623              last LI;              last LI;
2624            }            }
# Line 2465  sub _tree_construction_main ($) { Line 2680  sub _tree_construction_main ($) {
2680            }            }
2681          } # INSCOPE          } # INSCOPE
2682                        
2683            ## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926>
2684          ## has an element in scope          ## has an element in scope
2685          my $i;          #my $i;
2686          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          #INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2687            my $node = $self->{open_elements}->[$_];          #  my $node = $self->{open_elements}->[$_];
2688            if ({          #  if ({
2689                 h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,          #       h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
2690                }->{$node->[1]}) {          #      }->{$node->[1]}) {
2691              $i = $_;          #    $i = $_;
2692              last INSCOPE;          #    last INSCOPE;
2693            } elsif ({          #  } elsif ({
2694                      table => 1, caption => 1, td => 1, th => 1,          #            table => 1, caption => 1, td => 1, th => 1,
2695                      button => 1, marquee => 1, object => 1, html => 1,          #            button => 1, marquee => 1, object => 1, html => 1,
2696                     }->{$node->[1]}) {          #           }->{$node->[1]}) {
2697              last INSCOPE;          #    last INSCOPE;
2698            }          #  }
2699          } # INSCOPE          #} # INSCOPE
2700                      #  
2701          if (defined $i) {          #if (defined $i) {
2702            !!!parse-error (type => 'in hn:hn');          #  !!! parse-error (type => 'in hn:hn');
2703            splice @{$self->{open_elements}}, $i;          #  splice @{$self->{open_elements}}, $i;
2704          }          #}
2705                        
2706          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2707                        
# Line 2528  sub _tree_construction_main ($) { Line 2744  sub _tree_construction_main ($) {
2744          return;          return;
2745        } elsif ({        } elsif ({
2746                  b => 1, big => 1, em => 1, font => 1, i => 1,                  b => 1, big => 1, em => 1, font => 1, i => 1,
2747                  nobr => 1, s => 1, small => 1, strile => 1,                  s => 1, small => 1, strile => 1,
2748                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
2749                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
2750          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
# Line 2538  sub _tree_construction_main ($) { Line 2754  sub _tree_construction_main ($) {
2754                    
2755          !!!next-token;          !!!next-token;
2756          return;          return;
2757          } elsif ($token->{tag_name} eq 'nobr') {
2758            $reconstruct_active_formatting_elements->($insert_to_current);
2759    
2760            ## has a |nobr| element in scope
2761            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
2762              my $node = $self->{open_elements}->[$_];
2763              if ($node->[1] eq 'nobr') {
2764                !!!back-token;
2765                $token = {type => 'end tag', tag_name => 'nobr'};
2766                return;
2767              } elsif ({
2768                        table => 1, caption => 1, td => 1, th => 1,
2769                        button => 1, marquee => 1, object => 1, html => 1,
2770                       }->{$node->[1]}) {
2771                last INSCOPE;
2772              }
2773            } # INSCOPE
2774            
2775            !!!insert-element-t ($token->{tag_name}, $token->{attributes});
2776            push @$active_formatting_elements, $self->{open_elements}->[-1];
2777            
2778            !!!next-token;
2779            return;
2780        } elsif ($token->{tag_name} eq 'button') {        } elsif ($token->{tag_name} eq 'button') {
2781          ## has a button element in scope          ## has a button element in scope
2782          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
# Line 2573  sub _tree_construction_main ($) { Line 2812  sub _tree_construction_main ($) {
2812          return;          return;
2813        } elsif ($token->{tag_name} eq 'xmp') {        } elsif ($token->{tag_name} eq 'xmp') {
2814          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2815                    $parse_rcdata->('CDATA', $insert);
         !!!insert-element-t ($token->{tag_name}, $token->{attributes});  
           
         $self->{content_model_flag} = 'CDATA';  
           
         !!!next-token;  
2816          return;          return;
2817        } elsif ($token->{tag_name} eq 'table') {        } elsif ($token->{tag_name} eq 'table') {
2818          ## has a p element in scope          ## has a p element in scope
# Line 2656  sub _tree_construction_main ($) { Line 2890  sub _tree_construction_main ($) {
2890            return;            return;
2891          } else {          } else {
2892            my $at = $token->{attributes};            my $at = $token->{attributes};
2893              my $form_attrs;
2894              $form_attrs->{action} = $at->{action} if $at->{action};
2895              my $prompt_attr = $at->{prompt};
2896            $at->{name} = {name => 'name', value => 'isindex'};            $at->{name} = {name => 'name', value => 'isindex'};
2897              delete $at->{action};
2898              delete $at->{prompt};
2899            my @tokens = (            my @tokens = (
2900                          {type => 'start tag', tag_name => 'form'},                          {type => 'start tag', tag_name => 'form',
2901                             attributes => $form_attrs},
2902                          {type => 'start tag', tag_name => 'hr'},                          {type => 'start tag', tag_name => 'hr'},
2903                          {type => 'start tag', tag_name => 'p'},                          {type => 'start tag', tag_name => 'p'},
2904                          {type => 'start tag', tag_name => 'label'},                          {type => 'start tag', tag_name => 'label'},
2905                          {type => 'character',                         );
2906                           data => 'This is a searchable index. Insert your search keywords here: '}, # SHOULD            if ($prompt_attr) {
2907                          ## TODO: make this configurable              push @tokens, {type => 'character', data => $prompt_attr->{value}};
2908              } else {
2909                push @tokens, {type => 'character',
2910                               data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD
2911                ## TODO: make this configurable
2912              }
2913              push @tokens,
2914                          {type => 'start tag', tag_name => 'input', attributes => $at},                          {type => 'start tag', tag_name => 'input', attributes => $at},
2915                          #{type => 'character', data => ''}, # SHOULD                          #{type => 'character', data => ''}, # SHOULD
2916                          {type => 'end tag', tag_name => 'label'},                          {type => 'end tag', tag_name => 'label'},
2917                          {type => 'end tag', tag_name => 'p'},                          {type => 'end tag', tag_name => 'p'},
2918                          {type => 'start tag', tag_name => 'hr'},                          {type => 'start tag', tag_name => 'hr'},
2919                          {type => 'end tag', tag_name => 'form'},                          {type => 'end tag', tag_name => 'form'};
                        );  
2920            $token = shift @tokens;            $token = shift @tokens;
2921            !!!back-token (@tokens);            !!!back-token (@tokens);
2922            return;            return;
2923          }          }
2924        } elsif ({        } elsif ($token->{tag_name} eq 'textarea') {
                 textarea => 1,  
                 iframe => 1,  
                 noembed => 1,  
                 noframes => 1,  
                 noscript => 0, ## TODO: 1 if scripting is enabled  
                }->{$token->{tag_name}}) {  
2925          my $tag_name = $token->{tag_name};          my $tag_name = $token->{tag_name};
2926          my $el;          my $el;
2927          !!!create-element ($el, $token->{tag_name}, $token->{attributes});          !!!create-element ($el, $token->{tag_name}, $token->{attributes});
2928                    
2929          if ($token->{tag_name} eq 'textarea') {          ## TODO: $self->{form_element} if defined
2930            ## TODO: $self->{form_element} if defined          $self->{content_model_flag} = 'RCDATA';
2931            $self->{content_model_flag} = 'RCDATA';          delete $self->{escape}; # MUST
         } else {  
           $self->{content_model_flag} = 'CDATA';  
         }  
2932                    
2933          $insert->($el);          $insert->($el);
2934                    
2935          my $text = '';          my $text = '';
2936          !!!next-token;          !!!next-token;
2937            if ($token->{type} eq 'character') {
2938              $token->{data} =~ s/^\x0A//;
2939              unless (length $token->{data}) {
2940                !!!next-token;
2941              }
2942            }
2943          while ($token->{type} eq 'character') {          while ($token->{type} eq 'character') {
2944            $text .= $token->{data};            $text .= $token->{data};
2945            !!!next-token;            !!!next-token;
# Line 2712  sub _tree_construction_main ($) { Line 2954  sub _tree_construction_main ($) {
2954              $token->{tag_name} eq $tag_name) {              $token->{tag_name} eq $tag_name) {
2955            ## Ignore the token            ## Ignore the token
2956          } else {          } else {
2957            if ($token->{tag_name} eq 'textarea') {            !!!parse-error (type => 'in RCDATA:#'.$token->{type});
             !!!parse-error (type => 'in CDATA:#'.$token->{type});  
           } else {  
             !!!parse-error (type => 'in RCDATA:#'.$token->{type});  
           }  
           ## ISSUE: And ignore?  
2958          }          }
2959          !!!next-token;          !!!next-token;
2960          return;          return;
2961          } elsif ({
2962                    iframe => 1,
2963                    noembed => 1,
2964                    noframes => 1,
2965                    noscript => 0, ## TODO: 1 if scripting is enabled
2966                   }->{$token->{tag_name}}) {
2967            $parse_rcdata->('CDATA', $insert);
2968            return;
2969        } elsif ($token->{tag_name} eq 'select') {        } elsif ($token->{tag_name} eq 'select') {
2970          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
2971                    
# Line 2751  sub _tree_construction_main ($) { Line 2996  sub _tree_construction_main ($) {
2996        }        }
2997      } elsif ($token->{type} eq 'end tag') {      } elsif ($token->{type} eq 'end tag') {
2998        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
2999          if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {          if (@{$self->{open_elements}} > 1 and
3000            ## ISSUE: There is an issue in the spec.              $self->{open_elements}->[1]->[1] eq 'body') {
3001            if ($self->{open_elements}->[-1]->[1] ne 'body') {            for (@{$self->{open_elements}}) {
3002              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);              unless ({
3003                           dd => 1, dt => 1, li => 1, p => 1, td => 1,
3004                           th => 1, tr => 1, body => 1, html => 1,
3005                        }->{$_->[1]}) {
3006                  !!!parse-error (type => 'not closed:'.$_->[1]);
3007                }
3008            }            }
3009    
3010            $self->{insertion_mode} = 'after body';            $self->{insertion_mode} = 'after body';
3011            !!!next-token;            !!!next-token;
3012            return;            return;
# Line 2784  sub _tree_construction_main ($) { Line 3035  sub _tree_construction_main ($) {
3035                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
3036                  div => 1, dl => 1, fieldset => 1, listing => 1,                  div => 1, dl => 1, fieldset => 1, listing => 1,
3037                  menu => 1, ol => 1, pre => 1, ul => 1,                  menu => 1, ol => 1, pre => 1, ul => 1,
                 form => 1,  
3038                  p => 1,                  p => 1,
3039                  dd => 1, dt => 1, li => 1,                  dd => 1, dt => 1, li => 1,
3040                  button => 1, marquee => 1, object => 1,                  button => 1, marquee => 1, object => 1,
# Line 2822  sub _tree_construction_main ($) { Line 3072  sub _tree_construction_main ($) {
3072          }          }
3073                    
3074          splice @{$self->{open_elements}}, $i if defined $i;          splice @{$self->{open_elements}}, $i if defined $i;
         undef $self->{form_element} if $token->{tag_name} eq 'form';  
3075          $clear_up_to_marker->()          $clear_up_to_marker->()
3076            if {            if {
3077              button => 1, marquee => 1, object => 1,              button => 1, marquee => 1, object => 1,
3078            }->{$token->{tag_name}};            }->{$token->{tag_name}};
3079          !!!next-token;          !!!next-token;
3080          return;          return;
3081          } elsif ($token->{tag_name} eq 'form') {
3082            ## has an element in scope
3083            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
3084              my $node = $self->{open_elements}->[$_];
3085              if ($node->[1] eq $token->{tag_name}) {
3086                ## generate implied end tags
3087                if ({
3088                     dd => 1, dt => 1, li => 1, p => 1,
3089                     td => 1, th => 1, tr => 1,
3090                    }->{$self->{open_elements}->[-1]->[1]}) {
3091                  !!!back-token;
3092                  $token = {type => 'end tag',
3093                            tag_name => $self->{open_elements}->[-1]->[1]}; # MUST
3094                  return;
3095                }
3096                last INSCOPE;
3097              } elsif ({
3098                        table => 1, caption => 1, td => 1, th => 1,
3099                        button => 1, marquee => 1, object => 1, html => 1,
3100                       }->{$node->[1]}) {
3101                last INSCOPE;
3102              }
3103            } # INSCOPE
3104            
3105            if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) {
3106              pop @{$self->{open_elements}};
3107            } else {
3108              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]);
3109            }
3110    
3111            undef $self->{form_element};
3112            !!!next-token;
3113            return;
3114        } elsif ({        } elsif ({
3115                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
3116                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 2873  sub _tree_construction_main ($) { Line 3155  sub _tree_construction_main ($) {
3155                  strong => 1, tt => 1, u => 1,                  strong => 1, tt => 1, u => 1,
3156                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
3157          $formatting_end_tag->($token->{tag_name});          $formatting_end_tag->($token->{tag_name});
3158    ## TODO: <http://html5.org/tools/web-apps-tracker?from=883&to=884>
3159          return;          return;
3160        } elsif ({        } elsif ({
3161                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
# Line 2929  sub _tree_construction_main ($) { Line 3212  sub _tree_construction_main ($) {
3212                  #not $phrasing_category->{$node->[1]} and                  #not $phrasing_category->{$node->[1]} and
3213                  ($special_category->{$node->[1]} or                  ($special_category->{$node->[1]} or
3214                   $scoping_category->{$node->[1]})) {                   $scoping_category->{$node->[1]})) {
3215                !!!parse-error (type => 'not closed:'.$node->[1]);                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3216                ## Ignore the token                ## Ignore the token
3217                !!!next-token;                !!!next-token;
3218                last S2;                last S2;
# Line 3032  sub _tree_construction_main ($) { Line 3315  sub _tree_construction_main ($) {
3315              }              }
3316              redo B;              redo B;
3317            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3318              if ($token->{tag_name} eq 'html') {              if ({head => 1, body => 1, html => 1}->{$token->{tag_name}}) {
3319                ## As if <head>                ## As if <head>
3320                !!!create-element ($self->{head_element}, 'head');                !!!create-element ($self->{head_element}, 'head');
3321                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
# Line 3042  sub _tree_construction_main ($) { Line 3325  sub _tree_construction_main ($) {
3325                redo B;                redo B;
3326              } else {              } else {
3327                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3328                ## Ignore the token                ## Ignore the token ## ISSUE: An issue in the spec.
3329                !!!next-token;                !!!next-token;
3330                redo B;                redo B;
3331              }              }
3332            } else {            } else {
3333              die "$0: $token->{type}: Unknown type";              die "$0: $token->{type}: Unknown type";
3334            }            }
3335          } elsif ($self->{insertion_mode} eq 'in head') {          } elsif ($self->{insertion_mode} eq 'in head' or
3336                     $self->{insertion_mode} eq 'in head noscript' or
3337                     $self->{insertion_mode} eq 'after head') {
3338            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3339              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {              if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3340                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
# Line 3066  sub _tree_construction_main ($) { Line 3351  sub _tree_construction_main ($) {
3351              !!!next-token;              !!!next-token;
3352              redo B;              redo B;
3353            } elsif ($token->{type} eq 'start tag') {            } elsif ($token->{type} eq 'start tag') {
3354              if ($token->{tag_name} eq 'title') {              if ({base => ($self->{insertion_mode} eq 'in head' or
3355                ## NOTE: There is an "as if in head" code clone                            $self->{insertion_mode} eq 'after head'),
3356                my $title_el;                   link => 1, meta => 1}->{$token->{tag_name}}) {
3357                !!!create-element ($title_el, 'title', $token->{attributes});                ## NOTE: There is a "as if in head" code clone.
3358                (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])                if ($self->{insertion_mode} eq 'after head') {
3359                  ->append_child ($title_el);                  !!!parse-error (type => 'after head:'.$token->{tag_name});
3360                $self->{content_model_flag} = 'RCDATA';                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3361                  }
3362                my $text = '';                !!!insert-element ($token->{tag_name}, $token->{attributes});
3363                  pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
3364                  ## TODO: Extracting |charset| from |meta|.
3365                  pop @{$self->{open_elements}}
3366                      if $self->{insertion_mode} eq 'after head';
3367                !!!next-token;                !!!next-token;
3368                while ($token->{type} eq 'character') {                redo B;
3369                  $text .= $token->{data};              } elsif ($token->{tag_name} eq 'title' and
3370                         $self->{insertion_mode} eq 'in head') {
3371                  ## NOTE: There is a "as if in head" code clone.
3372                  if ($self->{insertion_mode} eq 'after head') {
3373                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3374                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3375                  }
3376                  $parse_rcdata->('RCDATA', $insert_to_current);
3377                  pop @{$self->{open_elements}}
3378                      if $self->{insertion_mode} eq 'after head';
3379                  redo B;
3380                } elsif ($token->{tag_name} eq 'style') {
3381                  ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
3382                  ## insertion mode 'in head')
3383                  ## NOTE: There is a "as if in head" code clone.
3384                  if ($self->{insertion_mode} eq 'after head') {
3385                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3386                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3387                  }
3388                  $parse_rcdata->('CDATA', $insert_to_current);
3389                  pop @{$self->{open_elements}}
3390                      if $self->{insertion_mode} eq 'after head';
3391                  redo B;
3392                } elsif ($token->{tag_name} eq 'noscript') {
3393                  if ($self->{insertion_mode} eq 'in head') {
3394                    ## NOTE: and scripting is disalbed
3395                    !!!insert-element ($token->{tag_name}, $token->{attributes});
3396                    $self->{insertion_mode} = 'in head noscript';
3397                  !!!next-token;                  !!!next-token;
3398                }                  redo B;
3399                if (length $text) {                } elsif ($self->{insertion_mode} eq 'in head noscript') {
3400                  $title_el->manakai_append_text ($text);                  !!!parse-error (type => 'noscript in noscript');
               }  
                 
               $self->{content_model_flag} = 'PCDATA';  
                 
               if ($token->{type} eq 'end tag' and  
                   $token->{tag_name} eq 'title') {  
3401                  ## Ignore the token                  ## Ignore the token
3402                    redo B;
3403                } else {                } else {
3404                  !!!parse-error (type => 'in RCDATA:#'.$token->{type});                  #
                 ## ISSUE: And ignore?  
3405                }                }
3406                } elsif ($token->{tag_name} eq 'head' and
3407                         $self->{insertion_mode} ne 'after head') {
3408                  !!!parse-error (type => 'in head:head'); # or in head noscript
3409                  ## Ignore the token
3410                !!!next-token;                !!!next-token;
3411                redo B;                redo B;
3412              } elsif ($token->{tag_name} eq 'style') {              } elsif ($self->{insertion_mode} ne 'in head noscript' and
3413                $style_start_tag->();                       $token->{tag_name} eq 'script') {
3414                  if ($self->{insertion_mode} eq 'after head') {
3415                    !!!parse-error (type => 'after head:'.$token->{tag_name});
3416                    push @{$self->{open_elements}}, [$self->{head_element}, 'head'];
3417                  }
3418                  ## NOTE: There is a "as if in head" code clone.
3419                  $script_start_tag->($insert_to_current);
3420                  pop @{$self->{open_elements}}
3421                      if $self->{insertion_mode} eq 'after head';
3422                redo B;                redo B;
3423              } elsif ($token->{tag_name} eq 'script') {              } elsif ($self->{insertion_mode} eq 'after head' and
3424                $script_start_tag->();                       $token->{tag_name} eq 'body') {
3425                redo B;                !!!insert-element ('body', $token->{attributes});
3426              } elsif ({base => 1, link => 1, meta => 1}->{$token->{tag_name}}) {                $self->{insertion_mode} = 'in body';
               ## NOTE: There are "as if in head" code clones  
               my $el;  
               !!!create-element ($el, $token->{tag_name}, $token->{attributes});  
               (defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0])  
                 ->append_child ($el);  
   
3427                !!!next-token;                !!!next-token;
3428                redo B;                redo B;
3429              } elsif ($token->{tag_name} eq 'head') {              } elsif ($self->{insertion_mode} eq 'after head' and
3430                !!!parse-error (type => 'in head:head');                       $token->{tag_name} eq 'frameset') {
3431                ## Ignore the token                !!!insert-element ('frameset', $token->{attributes});
3432                  $self->{insertion_mode} = 'in frameset';
3433                !!!next-token;                !!!next-token;
3434                redo B;                redo B;
3435              } else {              } else {
3436                #                #
3437              }              }
3438            } elsif ($token->{type} eq 'end tag') {            } elsif ($token->{type} eq 'end tag') {
3439              if ($token->{tag_name} eq 'head') {              if ($self->{insertion_mode} eq 'in head' and
3440                if ($self->{open_elements}->[-1]->[1] eq 'head') {                  $token->{tag_name} eq 'head') {
3441                  pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
               } else {  
                 !!!parse-error (type => 'unmatched end tag:head');  
               }  
3442                $self->{insertion_mode} = 'after head';                $self->{insertion_mode} = 'after head';
3443                !!!next-token;                !!!next-token;
3444                redo B;                redo B;
3445              } elsif ($token->{tag_name} eq 'html') {              } elsif ($self->{insertion_mode} eq 'in head noscript' and
3446                    $token->{tag_name} eq 'noscript') {
3447                  pop @{$self->{open_elements}};
3448                  $self->{insertion_mode} = 'in head';
3449                  !!!next-token;
3450                  redo B;
3451                } elsif ($self->{insertion_mode} eq 'in head' and
3452                         ($token->{tag_name} eq 'body' or
3453                          $token->{tag_name} eq 'html')) {
3454                #                #
3455              } else {              } elsif ($self->{insertion_mode} ne 'after head') {
3456                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name});
3457                ## Ignore the token                ## Ignore the token
3458                !!!next-token;                !!!next-token;
3459                redo B;                redo B;
3460                } else {
3461                  #
3462              }              }
3463            } else {            } else {
3464              #              #
3465            }            }
3466    
3467            if ($self->{open_elements}->[-1]->[1] eq 'head') {            ## As if </head> or </noscript> or <body>
3468              ## As if </head>            if ($self->{insertion_mode} eq 'in head') {
3469                pop @{$self->{open_elements}};
3470                $self->{insertion_mode} = 'after head';
3471              } elsif ($self->{insertion_mode} eq 'in head noscript') {
3472              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
3473                !!!parse-error (type => 'in noscript:'.(defined $token->{tag_name} ? ($token->{type} eq 'end tag' ? '/' : '') . $token->{tag_name} : '#' . $token->{type}));
3474                $self->{insertion_mode} = 'in head';
3475              } else { # 'after head'
3476                !!!insert-element ('body');
3477                $self->{insertion_mode} = 'in body';
3478            }            }
           $self->{insertion_mode} = 'after head';  
3479            ## reprocess            ## reprocess
3480            redo B;            redo B;
3481    
3482            ## ISSUE: An issue in the spec.            ## ISSUE: An issue in the spec.
         } elsif ($self->{insertion_mode} eq 'after head') {  
           if ($token->{type} eq 'character') {  
             if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {  
               $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);  
               unless (length $token->{data}) {  
                 !!!next-token;  
                 redo B;  
               }  
             }  
               
             #  
           } elsif ($token->{type} eq 'comment') {  
             my $comment = $self->{document}->create_comment ($token->{data});  
             $self->{open_elements}->[-1]->[0]->append_child ($comment);  
             !!!next-token;  
             redo B;  
           } elsif ($token->{type} eq 'start tag') {  
             if ($token->{tag_name} eq 'body') {  
               !!!insert-element ('body', $token->{attributes});  
               $self->{insertion_mode} = 'in body';  
               !!!next-token;  
               redo B;  
             } elsif ($token->{tag_name} eq 'frameset') {  
               !!!insert-element ('frameset', $token->{attributes});  
               $self->{insertion_mode} = 'in frameset';  
               !!!next-token;  
               redo B;  
             } elsif ({  
                       base => 1, link => 1, meta => 1,  
                       script => 1, style => 1, title => 1,  
                      }->{$token->{tag_name}}) {  
               !!!parse-error (type => 'after head:'.$token->{tag_name});  
               $self->{insertion_mode} = 'in head';  
               ## reprocess  
               redo B;  
             } else {  
               #  
             }  
           } else {  
             #  
           }  
             
           ## As if <body>  
           !!!insert-element ('body');  
           $self->{insertion_mode} = 'in body';  
           ## reprocess  
           redo B;  
3483          } elsif ($self->{insertion_mode} eq 'in body') {          } elsif ($self->{insertion_mode} eq 'in body') {
3484            if ($token->{type} eq 'character') {            if ($token->{type} eq 'character') {
3485              ## NOTE: There is a code clone of "character in body".              ## NOTE: There is a code clone of "character in body".
# Line 4844  sub set_inner_html ($$$) { Line 5128  sub set_inner_html ($$$) {
5128      ## NOTE: Most of this code is copied from |parse_string|      ## NOTE: Most of this code is copied from |parse_string|
5129    
5130      ## Step 1 # MUST      ## Step 1 # MUST
5131      my $doc = $node->owner_document->implementation->create_document;      my $this_doc = $node->owner_document;
5132      ## TODO: Mark as HTML document      my $doc = $this_doc->implementation->create_document;
5133        $doc->manakai_is_html (1);
5134      my $p = $class->new;      my $p = $class->new;
5135      $p->{document} = $doc;      $p->{document} = $doc;
5136    
# Line 4855  sub set_inner_html ($$$) { Line 5140  sub set_inner_html ($$$) {
5140      my $column = 0;      my $column = 0;
5141      $p->{set_next_input_character} = sub {      $p->{set_next_input_character} = sub {
5142        my $self = shift;        my $self = shift;
5143    
5144          pop @{$self->{prev_input_character}};
5145          unshift @{$self->{prev_input_character}}, $self->{next_input_character};
5146    
5147        $self->{next_input_character} = -1 and return if $i >= length $$s;        $self->{next_input_character} = -1 and return if $i >= length $$s;
5148        $self->{next_input_character} = ord substr $$s, $i++, 1;        $self->{next_input_character} = ord substr $$s, $i++, 1;
5149        $column++;        $column++;
# Line 4863  sub set_inner_html ($$$) { Line 5152  sub set_inner_html ($$$) {
5152          $line++;          $line++;
5153          $column = 0;          $column = 0;
5154        } elsif ($self->{next_input_character} == 0x000D) { # CR        } elsif ($self->{next_input_character} == 0x000D) { # CR
5155          if ($i >= length $$s) {          $i++ if substr ($$s, $i, 1) eq "\x0A";
           #  
         } else {  
           my $next_char = ord substr $$s, $i++, 1;  
           if ($next_char == 0x000A) { # LF  
             #  
           } else {  
             push @{$self->{char}}, $next_char;  
           }  
         }  
5156          $self->{next_input_character} = 0x000A; # LF # MUST          $self->{next_input_character} = 0x000A; # LF # MUST
5157          $line++;          $line++;
5158          $column = 0;          $column = 0;
5159        } elsif ($self->{next_input_character} > 0x10FFFF) {        } elsif ($self->{next_input_character} > 0x10FFFF) {
5160          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
5161        } elsif ($self->{next_input_character} == 0x0000) { # NULL        } elsif ($self->{next_input_character} == 0x0000) { # NULL
5162            !!!parse-error (type => 'NULL');
5163          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
5164        }        }
5165      };      };
5166        $p->{prev_input_character} = [-1, -1, -1];
5167        $p->{next_input_character} = -1;
5168            
5169      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
5170        my (%opt) = @_;        my (%opt) = @_;
# Line 4960  sub set_inner_html ($$$) { Line 5243  sub set_inner_html ($$$) {
5243      ## Step 12 # MUST      ## Step 12 # MUST
5244      @cn = @{$root->child_nodes};      @cn = @{$root->child_nodes};
5245      for (@cn) {      for (@cn) {
5246          $this_doc->adopt_node ($_);
5247        $node->append_child ($_);        $node->append_child ($_);
5248      }      }
5249      ## ISSUE: adopt_node? mutation events?      ## ISSUE: mutation events?
5250    
5251      $p->_terminate_tree_constructor;      $p->_terminate_tree_constructor;
5252    } else {    } else {
# Line 5033  sub get_inner_html ($$$) { Line 5317  sub get_inner_html ($$$) {
5317          spacer => 1, wbr => 1,          spacer => 1, wbr => 1,
5318        }->{$tag_name};        }->{$tag_name};
5319    
5320          $s .= "\x0A" if $tag_name eq 'pre' or $tag_name eq 'textarea';
5321    
5322        if (not $in_cdata and {        if (not $in_cdata and {
5323          style => 1, script => 1, xmp => 1, iframe => 1,          style => 1, script => 1, xmp => 1, iframe => 1,
5324          noembed => 1, noframes => 1, noscript => 1,          noembed => 1, noframes => 1, noscript => 1,
5325            plaintext => 1,
5326        }->{$tag_name}) {        }->{$tag_name}) {
5327          unshift @node, 'cdata-out';          unshift @node, 'cdata-out';
5328          $in_cdata = 1;          $in_cdata = 1;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.26

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24