/[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.113 by wakaba, Sun Mar 16 07:07:59 2008 UTC revision 1.132 by wakaba, Sun Apr 13 10:36:40 2008 UTC
# Line 8  use Error qw(:try); Line 8  use Error qw(:try);
8  ## doc.write ('');  ## doc.write ('');
9  ## alert (doc.compatMode);  ## alert (doc.compatMode);
10    
 ## TODO: Control charcters and noncharacters are not allowed (HTML5 revision 1263)  
11  ## TODO: 1252 parse error (revision 1264)  ## TODO: 1252 parse error (revision 1264)
12  ## TODO: 8859-11 = 874 (revision 1271)  ## TODO: 8859-11 = 874 (revision 1271)
13    
14  my $permitted_slash_tag_name = {  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
15    base => 1,  my $MML_NS = q<http://www.w3.org/1998/Math/MathML>;
16    link => 1,  my $SVG_NS = q<http://www.w3.org/2000/svg>;
17    meta => 1,  my $XLINK_NS = q<http://www.w3.org/1999/xlink>;
18    hr => 1,  my $XML_NS = q<http://www.w3.org/XML/1998/namespace>;
19    br => 1,  my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>;
20    img => 1,  
21    embed => 1,  sub A_EL () { 0b1 }
22    param => 1,  sub ADDRESS_EL () { 0b10 }
23    area => 1,  sub BODY_EL () { 0b100 }
24    col => 1,  sub BUTTON_EL () { 0b1000 }
25    input => 1,  sub CAPTION_EL () { 0b10000 }
26    sub DD_EL () { 0b100000 }
27    sub DIV_EL () { 0b1000000 }
28    sub DT_EL () { 0b10000000 }
29    sub FORM_EL () { 0b100000000 }
30    sub FORMATTING_EL () { 0b1000000000 }
31    sub FRAMESET_EL () { 0b10000000000 }
32    sub HEADING_EL () { 0b100000000000 }
33    sub HTML_EL () { 0b1000000000000 }
34    sub LI_EL () { 0b10000000000000 }
35    sub NOBR_EL () { 0b100000000000000 }
36    sub OPTION_EL () { 0b1000000000000000 }
37    sub OPTGROUP_EL () { 0b10000000000000000 }
38    sub P_EL () { 0b100000000000000000 }
39    sub SELECT_EL () { 0b1000000000000000000 }
40    sub TABLE_EL () { 0b10000000000000000000 }
41    sub TABLE_CELL_EL () { 0b100000000000000000000 }
42    sub TABLE_ROW_EL () { 0b1000000000000000000000 }
43    sub TABLE_ROW_GROUP_EL () { 0b10000000000000000000000 }
44    sub MISC_SCOPING_EL () { 0b100000000000000000000000 }
45    sub MISC_SPECIAL_EL () { 0b1000000000000000000000000 }
46    sub FOREIGN_EL () { 0b10000000000000000000000000 }
47    sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }
48    sub MML_AXML_EL () { 0b1000000000000000000000000000 }
49    
50    sub TABLE_ROWS_EL () {
51      TABLE_EL |
52      TABLE_ROW_EL |
53      TABLE_ROW_GROUP_EL
54    }
55    
56    sub END_TAG_OPTIONAL_EL () {
57      DD_EL |
58      DT_EL |
59      LI_EL |
60      P_EL
61    }
62    
63    sub ALL_END_TAG_OPTIONAL_EL () {
64      END_TAG_OPTIONAL_EL |
65      BODY_EL |
66      HTML_EL |
67      TABLE_CELL_EL |
68      TABLE_ROW_EL |
69      TABLE_ROW_GROUP_EL
70    }
71    
72    sub SCOPING_EL () {
73      BUTTON_EL |
74      CAPTION_EL |
75      HTML_EL |
76      TABLE_EL |
77      TABLE_CELL_EL |
78      MISC_SCOPING_EL
79    }
80    
81    sub TABLE_SCOPING_EL () {
82      HTML_EL |
83      TABLE_EL
84    }
85    
86    sub TABLE_ROWS_SCOPING_EL () {
87      HTML_EL |
88      TABLE_ROW_GROUP_EL
89    }
90    
91    sub TABLE_ROW_SCOPING_EL () {
92      HTML_EL |
93      TABLE_ROW_EL
94    }
95    
96    sub SPECIAL_EL () {
97      ADDRESS_EL |
98      BODY_EL |
99      DIV_EL |
100      END_TAG_OPTIONAL_EL |
101      FORM_EL |
102      FRAMESET_EL |
103      HEADING_EL |
104      OPTION_EL |
105      OPTGROUP_EL |
106      SELECT_EL |
107      TABLE_ROW_EL |
108      TABLE_ROW_GROUP_EL |
109      MISC_SPECIAL_EL
110    }
111    
112    my $el_category = {
113      a => A_EL | FORMATTING_EL,
114      address => ADDRESS_EL,
115      applet => MISC_SCOPING_EL,
116      area => MISC_SPECIAL_EL,
117      b => FORMATTING_EL,
118      base => MISC_SPECIAL_EL,
119      basefont => MISC_SPECIAL_EL,
120      bgsound => MISC_SPECIAL_EL,
121      big => FORMATTING_EL,
122      blockquote => MISC_SPECIAL_EL,
123      body => BODY_EL,
124      br => MISC_SPECIAL_EL,
125      button => BUTTON_EL,
126      caption => CAPTION_EL,
127      center => MISC_SPECIAL_EL,
128      col => MISC_SPECIAL_EL,
129      colgroup => MISC_SPECIAL_EL,
130      dd => DD_EL,
131      dir => MISC_SPECIAL_EL,
132      div => DIV_EL,
133      dl => MISC_SPECIAL_EL,
134      dt => DT_EL,
135      em => FORMATTING_EL,
136      embed => MISC_SPECIAL_EL,
137      fieldset => MISC_SPECIAL_EL,
138      font => FORMATTING_EL,
139      form => FORM_EL,
140      frame => MISC_SPECIAL_EL,
141      frameset => FRAMESET_EL,
142      h1 => HEADING_EL,
143      h2 => HEADING_EL,
144      h3 => HEADING_EL,
145      h4 => HEADING_EL,
146      h5 => HEADING_EL,
147      h6 => HEADING_EL,
148      head => MISC_SPECIAL_EL,
149      hr => MISC_SPECIAL_EL,
150      html => HTML_EL,
151      i => FORMATTING_EL,
152      iframe => MISC_SPECIAL_EL,
153      img => MISC_SPECIAL_EL,
154      input => MISC_SPECIAL_EL,
155      isindex => MISC_SPECIAL_EL,
156      li => LI_EL,
157      link => MISC_SPECIAL_EL,
158      listing => MISC_SPECIAL_EL,
159      marquee => MISC_SCOPING_EL,
160      menu => MISC_SPECIAL_EL,
161      meta => MISC_SPECIAL_EL,
162      nobr => NOBR_EL | FORMATTING_EL,
163      noembed => MISC_SPECIAL_EL,
164      noframes => MISC_SPECIAL_EL,
165      noscript => MISC_SPECIAL_EL,
166      object => MISC_SCOPING_EL,
167      ol => MISC_SPECIAL_EL,
168      optgroup => OPTGROUP_EL,
169      option => OPTION_EL,
170      p => P_EL,
171      param => MISC_SPECIAL_EL,
172      plaintext => MISC_SPECIAL_EL,
173      pre => MISC_SPECIAL_EL,
174      s => FORMATTING_EL,
175      script => MISC_SPECIAL_EL,
176      select => SELECT_EL,
177      small => FORMATTING_EL,
178      spacer => MISC_SPECIAL_EL,
179      strike => FORMATTING_EL,
180      strong => FORMATTING_EL,
181      style => MISC_SPECIAL_EL,
182      table => TABLE_EL,
183      tbody => TABLE_ROW_GROUP_EL,
184      td => TABLE_CELL_EL,
185      textarea => MISC_SPECIAL_EL,
186      tfoot => TABLE_ROW_GROUP_EL,
187      th => TABLE_CELL_EL,
188      thead => TABLE_ROW_GROUP_EL,
189      title => MISC_SPECIAL_EL,
190      tr => TABLE_ROW_EL,
191      tt => FORMATTING_EL,
192      u => FORMATTING_EL,
193      ul => MISC_SPECIAL_EL,
194      wbr => MISC_SPECIAL_EL,
195  };  };
196    
197    my $el_category_f = {
198      $MML_NS => {
199        'annotation-xml' => MML_AXML_EL,
200        mi => FOREIGN_FLOW_CONTENT_EL,
201        mo => FOREIGN_FLOW_CONTENT_EL,
202        mn => FOREIGN_FLOW_CONTENT_EL,
203        ms => FOREIGN_FLOW_CONTENT_EL,
204        mtext => FOREIGN_FLOW_CONTENT_EL,
205      },
206      $SVG_NS => {
207        foreignObject => FOREIGN_FLOW_CONTENT_EL,
208        desc => FOREIGN_FLOW_CONTENT_EL,
209        title => FOREIGN_FLOW_CONTENT_EL,
210      },
211      ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.
212    };
213    
214    my $svg_attr_name = {
215      attributetype => 'attributeType',
216      basefrequency => 'baseFrequency',
217      baseprofile => 'baseProfile',
218      calcmode => 'calcMode',
219      clippathunits => 'clipPathUnits',
220      contentscripttype => 'contentScriptType',
221      contentstyletype => 'contentStyleType',
222      diffuseconstant => 'diffuseConstant',
223      edgemode => 'edgeMode',
224      externalresourcesrequired => 'externalResourcesRequired',
225      fecolormatrix => 'feColorMatrix',
226      fecomposite => 'feComposite',
227      fegaussianblur => 'feGaussianBlur',
228      femorphology => 'feMorphology',
229      fetile => 'feTile',
230      filterres => 'filterRes',
231      filterunits => 'filterUnits',
232      glyphref => 'glyphRef',
233      gradienttransform => 'gradientTransform',
234      gradientunits => 'gradientUnits',
235      kernelmatrix => 'kernelMatrix',
236      kernelunitlength => 'kernelUnitLength',
237      keypoints => 'keyPoints',
238      keysplines => 'keySplines',
239      keytimes => 'keyTimes',
240      lengthadjust => 'lengthAdjust',
241      limitingconeangle => 'limitingConeAngle',
242      markerheight => 'markerHeight',
243      markerunits => 'markerUnits',
244      markerwidth => 'markerWidth',
245      maskcontentunits => 'maskContentUnits',
246      maskunits => 'maskUnits',
247      numoctaves => 'numOctaves',
248      pathlength => 'pathLength',
249      patterncontentunits => 'patternContentUnits',
250      patterntransform => 'patternTransform',
251      patternunits => 'patternUnits',
252      pointsatx => 'pointsAtX',
253      pointsaty => 'pointsAtY',
254      pointsatz => 'pointsAtZ',
255      preservealpha => 'preserveAlpha',
256      preserveaspectratio => 'preserveAspectRatio',
257      primitiveunits => 'primitiveUnits',
258      refx => 'refX',
259      refy => 'refY',
260      repeatcount => 'repeatCount',
261      repeatdur => 'repeatDur',
262      requiredextensions => 'requiredExtensions',
263      specularconstant => 'specularConstant',
264      specularexponent => 'specularExponent',
265      spreadmethod => 'spreadMethod',
266      startoffset => 'startOffset',
267      stddeviation => 'stdDeviation',
268      stitchtiles => 'stitchTiles',
269      surfacescale => 'surfaceScale',
270      systemlanguage => 'systemLanguage',
271      tablevalues => 'tableValues',
272      targetx => 'targetX',
273      targety => 'targetY',
274      textlength => 'textLength',
275      viewbox => 'viewBox',
276      viewtarget => 'viewTarget',
277      xchannelselector => 'xChannelSelector',
278      ychannelselector => 'yChannelSelector',
279      zoomandpan => 'zoomAndPan',
280    };
281    
282    my $foreign_attr_xname = {
283      'xlink:actuate' => [$XLINK_NS, ['xlink', 'actuate']],
284      'xlink:arcrole' => [$XLINK_NS, ['xlink', 'arcrole']],
285      'xlink:href' => [$XLINK_NS, ['xlink', 'href']],
286      'xlink:role' => [$XLINK_NS, ['xlink', 'role']],
287      'xlink:show' => [$XLINK_NS, ['xlink', 'show']],
288      'xlink:title' => [$XLINK_NS, ['xlink', 'title']],
289      'xlink:type' => [$XLINK_NS, ['xlink', 'type']],
290      'xml:base' => [$XML_NS, ['xml', 'base']],
291      'xml:lang' => [$XML_NS, ['xml', 'lang']],
292      'xml:space' => [$XML_NS, ['xml', 'space']],
293      'xmlns' => [$XMLNS_NS, [undef, 'xmlns']],
294      'xmlns:xlink' => [$XMLNS_NS, ['xmlns', 'xlink']],
295    };
296    
297    ## ISSUE: xmlns:xlink="non-xlink-ns" is not an error.
298    
299  my $c1_entity_char = {  my $c1_entity_char = {
300    0x80 => 0x20AC,    0x80 => 0x20AC,
301    0x81 => 0xFFFD,    0x81 => 0xFFFD,
# Line 61  my $c1_entity_char = { Line 331  my $c1_entity_char = {
331    0x9F => 0x0178,    0x9F => 0x0178,
332  }; # $c1_entity_char  }; # $c1_entity_char
333    
 my $special_category = {  
   address => 1, area => 1, base => 1, basefont => 1, bgsound => 1,  
   blockquote => 1, body => 1, br => 1, center => 1, col => 1, colgroup => 1,  
   dd => 1, dir => 1, div => 1, dl => 1, dt => 1, embed => 1, fieldset => 1,  
   form => 1, frame => 1, frameset => 1, h1 => 1, h2 => 1, h3 => 1,  
   h4 => 1, h5 => 1, h6 => 1, head => 1, hr => 1, iframe => 1, image => 1,  
   img => 1, input => 1, isindex => 1, li => 1, link => 1, listing => 1,  
   menu => 1, meta => 1, noembed => 1, noframes => 1, noscript => 1,  
   ol => 1, optgroup => 1, option => 1, p => 1, param => 1, plaintext => 1,  
   pre => 1, script => 1, select => 1, spacer => 1, style => 1, tbody => 1,  
   textarea => 1, tfoot => 1, thead => 1, title => 1, tr => 1, ul => 1, wbr => 1,  
 };  
 my $scoping_category = {  
   applet => 1, button => 1, caption => 1, html => 1, marquee => 1, object => 1,  
   table => 1, td => 1, th => 1,  
 };  
 my $formatting_category = {  
   a => 1, b => 1, big => 1, em => 1, font => 1, i => 1, nobr => 1,  
   s => 1, small => 1, strile => 1, strong => 1, tt => 1, u => 1,  
 };  
 # $phrasing_category: all other elements  
   
334  sub parse_byte_string ($$$$;$) {  sub parse_byte_string ($$$$;$) {
335    my $self = ref $_[0] ? shift : shift->new;    my $self = ref $_[0] ? shift : shift->new;
336    my $charset = shift;    my $charset = shift;
# Line 108  sub parse_byte_string ($$$$;$) { Line 356  sub parse_byte_string ($$$$;$) {
356    $self->{change_encoding} = sub {    $self->{change_encoding} = sub {
357      my $self = shift;      my $self = shift;
358      my $charset = lc shift;      my $charset = lc shift;
359        my $token = shift;
360      ## TODO: if $charset is supported      ## TODO: if $charset is supported
361      ## TODO: normalize charset name      ## TODO: normalize charset name
362    
# Line 126  sub parse_byte_string ($$$$;$) { Line 375  sub parse_byte_string ($$$$;$) {
375      }      }
376    
377      !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.      !!!parse-error (type => 'charset label detected:'.$self->{input_encoding}.
378          ':'.$charset, level => 'w');          ':'.$charset, level => 'w', token => $token);
379    
380      ## Step 3      ## Step 3
381      # if (can) {      # if (can) {
# Line 193  sub parse_string ($$$;$) { Line 442  sub parse_string ($$$;$) {
442      $self->{column}++;      $self->{column}++;
443            
444      if ($self->{next_char} == 0x000A) { # LF      if ($self->{next_char} == 0x000A) { # LF
445          !!!cp ('j1');
446        $self->{line}++;        $self->{line}++;
447        $self->{column} = 0;        $self->{column} = 0;
448      } elsif ($self->{next_char} == 0x000D) { # CR      } elsif ($self->{next_char} == 0x000D) { # CR
449          !!!cp ('j2');
450        $i++ if substr ($$s, $i, 1) eq "\x0A";        $i++ if substr ($$s, $i, 1) eq "\x0A";
451        $self->{next_char} = 0x000A; # LF # MUST        $self->{next_char} = 0x000A; # LF # MUST
452        $self->{line}++;        $self->{line}++;
453        $self->{column} = 0;        $self->{column} = 0;
454      } elsif ($self->{next_char} > 0x10FFFF) {      } elsif ($self->{next_char} > 0x10FFFF) {
455          !!!cp ('j3');
456        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
457      } elsif ($self->{next_char} == 0x0000) { # NULL      } elsif ($self->{next_char} == 0x0000) { # NULL
458          !!!cp ('j4');
459        !!!parse-error (type => 'NULL');        !!!parse-error (type => 'NULL');
460        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST        $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
461        } elsif ($self->{next_char} <= 0x0008 or
462                 (0x000E <= $self->{next_char} and $self->{next_char} <= 0x001F) or
463                 (0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or
464                 (0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or
465                 (0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or
466                 {
467                  0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
468                  0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
469                  0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
470                  0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
471                  0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
472                  0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
473                  0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
474                  0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
475                  0x10FFFE => 1, 0x10FFFF => 1,
476                 }->{$self->{next_char}}) {
477          !!!cp ('j5');
478          !!!parse-error (type => 'control char', level => $self->{must_level});
479    ## TODO: error type documentation
480      }      }
481    };    };
482    $self->{prev_char} = [-1, -1, -1];    $self->{prev_char} = [-1, -1, -1];
# Line 294  sub DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUO Line 566  sub DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUO
566  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 31 }  sub AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE () { 31 }
567  sub BOGUS_DOCTYPE_STATE () { 32 }  sub BOGUS_DOCTYPE_STATE () { 32 }
568  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }  sub AFTER_ATTRIBUTE_VALUE_QUOTED_STATE () { 33 }
569    sub SELF_CLOSING_START_TAG_STATE () { 34 }
570    sub CDATA_BLOCK_STATE () { 35 }
571    
572  sub DOCTYPE_TOKEN () { 1 }  sub DOCTYPE_TOKEN () { 1 }
573  sub COMMENT_TOKEN () { 2 }  sub COMMENT_TOKEN () { 2 }
# Line 311  sub ROW_IMS ()        { 0b10000000 } Line 585  sub ROW_IMS ()        { 0b10000000 }
585  sub BODY_AFTER_IMS () { 0b100000000 }  sub BODY_AFTER_IMS () { 0b100000000 }
586  sub FRAME_IMS ()      { 0b1000000000 }  sub FRAME_IMS ()      { 0b1000000000 }
587  sub SELECT_IMS ()     { 0b10000000000 }  sub SELECT_IMS ()     { 0b10000000000 }
588    sub IN_FOREIGN_CONTENT_IM () { 0b100000000000 }
589        ## NOTE: "in foreign content" insertion mode is special; it is combined
590        ## with the secondary insertion mode.  In this parser, they are stored
591        ## together in the bit-or'ed form.
592    
593  ## NOTE: "initial" and "before html" insertion modes have no constants.  ## NOTE: "initial" and "before html" insertion modes have no constants.
594    
# Line 347  sub _initialize_tokenizer ($) { Line 625  sub _initialize_tokenizer ($) {
625    undef $self->{current_attribute};    undef $self->{current_attribute};
626    undef $self->{last_emitted_start_tag_name};    undef $self->{last_emitted_start_tag_name};
627    undef $self->{last_attribute_value_state};    undef $self->{last_attribute_value_state};
628      delete $self->{self_closing};
629    $self->{char} = [];    $self->{char} = [];
630    # $self->{next_char}    # $self->{next_char}
631    !!!next-input-character;    !!!next-input-character;
# Line 367  sub _initialize_tokenizer ($) { Line 646  sub _initialize_tokenizer ($) {
646  ##        ->{value}  ##        ->{value}
647  ##        ->{has_reference} == 1 or 0  ##        ->{has_reference} == 1 or 0
648  ##   ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN)  ##   ->{data} (COMMENT_TOKEN, CHARACTER_TOKEN)
649    ## NOTE: The "self-closing flag" is hold as |$self->{self_closing}|.
650    ##     |->{self_closing}| is used to save the value of |$self->{self_closing}|
651    ##     while the token is pushed back to the stack.
652    
653    ## ISSUE: "When a DOCTYPE token is created, its
654    ## <i>self-closing flag</i> must be unset (its other state is that it
655    ## be set), and its attributes list must be empty.": Wrong subject?
656    
657  ## Emitted token MUST immediately be handled by the tree construction state.  ## Emitted token MUST immediately be handled by the tree construction state.
658    
# Line 393  sub _initialize_tokenizer ($) { Line 679  sub _initialize_tokenizer ($) {
679    
680  sub _get_next_token ($) {  sub _get_next_token ($) {
681    my $self = shift;    my $self = shift;
682    
683      if ($self->{self_closing}) {
684        !!!parse-error (type => 'nestc', token => $self->{current_token});
685        ## NOTE: The |self_closing| flag is only set by start tag token.
686        ## In addition, when a start tag token is emitted, it is always set to
687        ## |current_token|.
688        delete $self->{self_closing};
689      }
690    
691    if (@{$self->{token}}) {    if (@{$self->{token}}) {
692        $self->{self_closing} = $self->{token}->[0]->{self_closing};
693      return shift @{$self->{token}};      return shift @{$self->{token}};
694    }    }
695    
# Line 465  sub _get_next_token ($) { Line 761  sub _get_next_token ($) {
761        # Anything else        # Anything else
762        my $token = {type => CHARACTER_TOKEN,        my $token = {type => CHARACTER_TOKEN,
763                     data => chr $self->{next_char},                     data => chr $self->{next_char},
764                     line => $self->{line}, column => $self->{column}};                     line => $self->{line}, column => $self->{column},
765                      };
766        ## Stay in the data state        ## Stay in the data state
767        !!!next-input-character;        !!!next-input-character;
768    
# Line 485  sub _get_next_token ($) { Line 782  sub _get_next_token ($) {
782        unless (defined $token) {        unless (defined $token) {
783          !!!cp (13);          !!!cp (13);
784          !!!emit ({type => CHARACTER_TOKEN, data => '&',          !!!emit ({type => CHARACTER_TOKEN, data => '&',
785                    line => $l, column => $c});                    line => $l, column => $c,
786                     });
787        } else {        } else {
788          !!!cp (14);          !!!cp (14);
789          !!!emit ($token);          !!!emit ($token);
# Line 506  sub _get_next_token ($) { Line 804  sub _get_next_token ($) {
804    
805            !!!emit ({type => CHARACTER_TOKEN, data => '<',            !!!emit ({type => CHARACTER_TOKEN, data => '<',
806                      line => $self->{line_prev},                      line => $self->{line_prev},
807                      column => $self->{column_prev}});                      column => $self->{column_prev},
808                       });
809    
810            redo A;            redo A;
811          }          }
# Line 544  sub _get_next_token ($) { Line 843  sub _get_next_token ($) {
843            redo A;            redo A;
844          } elsif ($self->{next_char} == 0x003E) { # >          } elsif ($self->{next_char} == 0x003E) { # >
845            !!!cp (21);            !!!cp (21);
846            !!!parse-error (type => 'empty start tag');            !!!parse-error (type => 'empty start tag',
847                              line => $self->{line_prev},
848                              column => $self->{column_prev});
849            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
850            !!!next-input-character;            !!!next-input-character;
851    
852            !!!emit ({type => CHARACTER_TOKEN, data => '<>',            !!!emit ({type => CHARACTER_TOKEN, data => '<>',
853                      line => $self->{line_prev},                      line => $self->{line_prev},
854                      column => $self->{column_prev}});                      column => $self->{column_prev},
855                       });
856    
857            redo A;            redo A;
858          } elsif ($self->{next_char} == 0x003F) { # ?          } elsif ($self->{next_char} == 0x003F) { # ?
859            !!!cp (22);            !!!cp (22);
860            !!!parse-error (type => 'pio');            !!!parse-error (type => 'pio',
861                              line => $self->{line_prev},
862                              column => $self->{column_prev});
863            $self->{state} = BOGUS_COMMENT_STATE;            $self->{state} = BOGUS_COMMENT_STATE;
864            $self->{current_token} = {type => COMMENT_TOKEN, data => '',            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
865                                      line => $self->{line_prev},                                      line => $self->{line_prev},
866                                      column => $self->{column_prev}};                                      column => $self->{column_prev},
867                                       };
868            ## $self->{next_char} is intentionally left as is            ## $self->{next_char} is intentionally left as is
869            redo A;            redo A;
870          } else {          } else {
# Line 570  sub _get_next_token ($) { Line 875  sub _get_next_token ($) {
875    
876            !!!emit ({type => CHARACTER_TOKEN, data => '<',            !!!emit ({type => CHARACTER_TOKEN, data => '<',
877                      line => $self->{line_prev},                      line => $self->{line_prev},
878                      column => $self->{column_prev}});                      column => $self->{column_prev},
879                       });
880    
881            redo A;            redo A;
882          }          }
# Line 599  sub _get_next_token ($) { Line 905  sub _get_next_token ($) {
905                $self->{state} = DATA_STATE;                $self->{state} = DATA_STATE;
906    
907                !!!emit ({type => CHARACTER_TOKEN, data => '</',                !!!emit ({type => CHARACTER_TOKEN, data => '</',
908                          line => $l, column => $c});                          line => $l, column => $c,
909                           });
910        
911                redo A;                redo A;
912              }              }
# Line 619  sub _get_next_token ($) { Line 926  sub _get_next_token ($) {
926              !!!back-next-input-character (@next_char);              !!!back-next-input-character (@next_char);
927              $self->{state} = DATA_STATE;              $self->{state} = DATA_STATE;
928              !!!emit ({type => CHARACTER_TOKEN, data => '</',              !!!emit ({type => CHARACTER_TOKEN, data => '</',
929                        line => $l, column => $c});                        line => $l, column => $c,
930                         });
931              redo A;              redo A;
932            } else {            } else {
933              !!!cp (27);              !!!cp (27);
# Line 633  sub _get_next_token ($) { Line 941  sub _get_next_token ($) {
941            # next-input-character is already done            # next-input-character is already done
942            $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
943            !!!emit ({type => CHARACTER_TOKEN, data => '</',            !!!emit ({type => CHARACTER_TOKEN, data => '</',
944                      line => $l, column => $c});                      line => $l, column => $c,
945                       });
946            redo A;            redo A;
947          }          }
948        }        }
# Line 659  sub _get_next_token ($) { Line 968  sub _get_next_token ($) {
968          redo A;          redo A;
969        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
970          !!!cp (31);          !!!cp (31);
971          !!!parse-error (type => 'empty end tag');          !!!parse-error (type => 'empty end tag',
972                            line => $self->{line_prev}, ## "<" in "</>"
973                            column => $self->{column_prev} - 1);
974          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
975          !!!next-input-character;          !!!next-input-character;
976          redo A;          redo A;
# Line 670  sub _get_next_token ($) { Line 981  sub _get_next_token ($) {
981          # reconsume          # reconsume
982    
983          !!!emit ({type => CHARACTER_TOKEN, data => '</',          !!!emit ({type => CHARACTER_TOKEN, data => '</',
984                    line => $l, column => $c});                    line => $l, column => $c,
985                     });
986    
987          redo A;          redo A;
988        } else {        } else {
# Line 679  sub _get_next_token ($) { Line 991  sub _get_next_token ($) {
991          $self->{state} = BOGUS_COMMENT_STATE;          $self->{state} = BOGUS_COMMENT_STATE;
992          $self->{current_token} = {type => COMMENT_TOKEN, data => '',          $self->{current_token} = {type => COMMENT_TOKEN, data => '',
993                                    line => $self->{line_prev}, # "<" of "</"                                    line => $self->{line_prev}, # "<" of "</"
994                                    column => $self->{column_prev} - 1};                                    column => $self->{column_prev} - 1,
995                                     };
996          ## $self->{next_char} is intentionally left as is          ## $self->{next_char} is intentionally left as is
997          redo A;          redo A;
998        }        }
# Line 696  sub _get_next_token ($) { Line 1009  sub _get_next_token ($) {
1009        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1010          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1011            !!!cp (35);            !!!cp (35);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1012            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1013          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1014            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 729  sub _get_next_token ($) { Line 1040  sub _get_next_token ($) {
1040          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1041          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1042            !!!cp (39);            !!!cp (39);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1043            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1044          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1045            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 751  sub _get_next_token ($) { Line 1060  sub _get_next_token ($) {
1060    
1061          redo A;          redo A;
1062        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
1063            !!!cp (42);
1064            $self->{state} = SELF_CLOSING_START_TAG_STATE;
1065          !!!next-input-character;          !!!next-input-character;
         if ($self->{next_char} == 0x003E and # >  
             $self->{current_token}->{type} == START_TAG_TOKEN and  
             $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {  
           # permitted slash  
           !!!cp (42);  
           #  
         } else {  
           !!!cp (43);  
           !!!parse-error (type => 'nestc');  
         }  
         $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;  
         # next-input-character is already done  
1066          redo A;          redo A;
1067        } else {        } else {
1068          !!!cp (44);          !!!cp (44);
# Line 786  sub _get_next_token ($) { Line 1085  sub _get_next_token ($) {
1085        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1086          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1087            !!!cp (46);            !!!cp (46);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1088            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1089          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1090            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 809  sub _get_next_token ($) { Line 1106  sub _get_next_token ($) {
1106        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{next_char} and
1107                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
1108          !!!cp (49);          !!!cp (49);
1109          $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),          $self->{current_attribute}
1110                                value => ''};              = {name => chr ($self->{next_char} + 0x0020),
1111                   value => '',
1112                   line => $self->{line}, column => $self->{column}};
1113          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1114          !!!next-input-character;          !!!next-input-character;
1115          redo A;          redo A;
1116        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
1117            !!!cp (50);
1118            $self->{state} = SELF_CLOSING_START_TAG_STATE;
1119          !!!next-input-character;          !!!next-input-character;
         if ($self->{next_char} == 0x003E and # >  
             $self->{current_token}->{type} == START_TAG_TOKEN and  
             $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {  
           # permitted slash  
           !!!cp (50);  
           #  
         } else {  
           !!!cp (51);  
           !!!parse-error (type => 'nestc');  
         }  
         ## Stay in the state  
         # next-input-character is already done  
1120          redo A;          redo A;
1121        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1122          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1123          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1124            !!!cp (52);            !!!cp (52);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1125            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1126          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1127            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 864  sub _get_next_token ($) { Line 1151  sub _get_next_token ($) {
1151          } else {          } else {
1152            !!!cp (56);            !!!cp (56);
1153          }          }
1154          $self->{current_attribute} = {name => chr ($self->{next_char}),          $self->{current_attribute}
1155                                value => ''};              = {name => chr ($self->{next_char}),
1156                   value => '',
1157                   line => $self->{line}, column => $self->{column}};
1158          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1159          !!!next-input-character;          !!!next-input-character;
1160          redo A;          redo A;
# Line 875  sub _get_next_token ($) { Line 1164  sub _get_next_token ($) {
1164          if (exists $self->{current_token}->{attributes} # start tag or end tag          if (exists $self->{current_token}->{attributes} # start tag or end tag
1165              ->{$self->{current_attribute}->{name}}) { # MUST              ->{$self->{current_attribute}->{name}}) { # MUST
1166            !!!cp (57);            !!!cp (57);
1167            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name});            !!!parse-error (type => 'duplicate attribute:'.$self->{current_attribute}->{name}, line => $self->{current_attribute}->{line}, column => $self->{current_attribute}->{column});
1168            ## Discard $self->{current_attribute} # MUST            ## Discard $self->{current_attribute} # MUST
1169          } else {          } else {
1170            !!!cp (58);            !!!cp (58);
# Line 904  sub _get_next_token ($) { Line 1193  sub _get_next_token ($) {
1193          $before_leave->();          $before_leave->();
1194          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1195            !!!cp (61);            !!!cp (61);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1196            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1197          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1198            !!!cp (62);            !!!cp (62);
# Line 930  sub _get_next_token ($) { Line 1217  sub _get_next_token ($) {
1217          !!!next-input-character;          !!!next-input-character;
1218          redo A;          redo A;
1219        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
1220            !!!cp (64);
1221          $before_leave->();          $before_leave->();
1222            $self->{state} = SELF_CLOSING_START_TAG_STATE;
1223          !!!next-input-character;          !!!next-input-character;
         if ($self->{next_char} == 0x003E and # >  
             $self->{current_token}->{type} == START_TAG_TOKEN and  
             $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {  
           # permitted slash  
           !!!cp (64);  
           #  
         } else {  
           !!!cp (65);  
           !!!parse-error (type => 'nestc');  
         }  
         $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;  
         # next-input-character is already done  
1224          redo A;          redo A;
1225        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1226          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1227          $before_leave->();          $before_leave->();
1228          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1229            !!!cp (66);            !!!cp (66);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1230            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1231          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1232            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1002  sub _get_next_token ($) { Line 1277  sub _get_next_token ($) {
1277        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1278          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1279            !!!cp (73);            !!!cp (73);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1280            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1281          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1282            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1026  sub _get_next_token ($) { Line 1299  sub _get_next_token ($) {
1299        } elsif (0x0041 <= $self->{next_char} and        } elsif (0x0041 <= $self->{next_char} and
1300                 $self->{next_char} <= 0x005A) { # A..Z                 $self->{next_char} <= 0x005A) { # A..Z
1301          !!!cp (76);          !!!cp (76);
1302          $self->{current_attribute} = {name => chr ($self->{next_char} + 0x0020),          $self->{current_attribute}
1303                                value => ''};              = {name => chr ($self->{next_char} + 0x0020),
1304                   value => '',
1305                   line => $self->{line}, column => $self->{column}};
1306          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1307          !!!next-input-character;          !!!next-input-character;
1308          redo A;          redo A;
1309        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
1310            !!!cp (77);
1311            $self->{state} = SELF_CLOSING_START_TAG_STATE;
1312          !!!next-input-character;          !!!next-input-character;
         if ($self->{next_char} == 0x003E and # >  
             $self->{current_token}->{type} == START_TAG_TOKEN and  
             $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {  
           # permitted slash  
           !!!cp (77);  
           #  
         } else {  
           !!!cp (78);  
           !!!parse-error (type => 'nestc');  
           ## TODO: Different error type for <aa / bb> than <aa/>  
         }  
         $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;  
         # next-input-character is already done  
1313          redo A;          redo A;
1314        } elsif ($self->{next_char} == -1) {        } elsif ($self->{next_char} == -1) {
1315          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1316          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1317            !!!cp (79);            !!!cp (79);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1318            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1319          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1320            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1074  sub _get_next_token ($) { Line 1336  sub _get_next_token ($) {
1336          redo A;          redo A;
1337        } else {        } else {
1338          !!!cp (82);          !!!cp (82);
1339          $self->{current_attribute} = {name => chr ($self->{next_char}),          $self->{current_attribute}
1340                                value => ''};              = {name => chr ($self->{next_char}),
1341                   value => '',
1342                   line => $self->{line}, column => $self->{column}};
1343          $self->{state} = ATTRIBUTE_NAME_STATE;          $self->{state} = ATTRIBUTE_NAME_STATE;
1344          !!!next-input-character;          !!!next-input-character;
1345          redo A;                  redo A;        
# Line 1108  sub _get_next_token ($) { Line 1372  sub _get_next_token ($) {
1372        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1373          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1374            !!!cp (87);            !!!cp (87);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1375            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1376          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1377            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1133  sub _get_next_token ($) { Line 1395  sub _get_next_token ($) {
1395          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1396          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1397            !!!cp (90);            !!!cp (90);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1398            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1399          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1400            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1182  sub _get_next_token ($) { Line 1442  sub _get_next_token ($) {
1442          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1443          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1444            !!!cp (97);            !!!cp (97);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1445            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1446          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1447            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1226  sub _get_next_token ($) { Line 1484  sub _get_next_token ($) {
1484          !!!parse-error (type => 'unclosed attribute value');          !!!parse-error (type => 'unclosed attribute value');
1485          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1486            !!!cp (103);            !!!cp (103);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1487            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1488          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1489            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1273  sub _get_next_token ($) { Line 1529  sub _get_next_token ($) {
1529        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1530          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1531            !!!cp (109);            !!!cp (109);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1532            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1533          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1534            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1298  sub _get_next_token ($) { Line 1552  sub _get_next_token ($) {
1552          !!!parse-error (type => 'unclosed tag');          !!!parse-error (type => 'unclosed tag');
1553          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1554            !!!cp (112);            !!!cp (112);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1555            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1556          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1557            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1370  sub _get_next_token ($) { Line 1622  sub _get_next_token ($) {
1622        } elsif ($self->{next_char} == 0x003E) { # >        } elsif ($self->{next_char} == 0x003E) { # >
1623          if ($self->{current_token}->{type} == START_TAG_TOKEN) {          if ($self->{current_token}->{type} == START_TAG_TOKEN) {
1624            !!!cp (119);            !!!cp (119);
           $self->{current_token}->{first_start_tag}  
               = not defined $self->{last_emitted_start_tag_name};  
1625            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};            $self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name};
1626          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {          } elsif ($self->{current_token}->{type} == END_TAG_TOKEN) {
1627            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
# Line 1392  sub _get_next_token ($) { Line 1642  sub _get_next_token ($) {
1642    
1643          redo A;          redo A;
1644        } elsif ($self->{next_char} == 0x002F) { # /        } elsif ($self->{next_char} == 0x002F) { # /
1645            !!!cp (122);
1646            $self->{state} = SELF_CLOSING_START_TAG_STATE;
1647          !!!next-input-character;          !!!next-input-character;
         if ($self->{next_char} == 0x003E and # >  
             $self->{current_token}->{type} == START_TAG_TOKEN and  
             $permitted_slash_tag_name->{$self->{current_token}->{tag_name}}) {  
           # permitted slash  
           !!!cp (122);  
           #  
         } else {  
           !!!cp (123);  
           !!!parse-error (type => 'nestc');  
         }  
         $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;  
         # next-input-character is already done  
1648          redo A;          redo A;
1649        } else {        } else {
1650          !!!cp (124);          !!!cp ('124.1');
1651          !!!parse-error (type => 'no space between attributes');          !!!parse-error (type => 'no space between attributes');
1652          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1653          ## reconsume          ## reconsume
1654          redo A;          redo A;
1655        }        }
1656        } elsif ($self->{state} == SELF_CLOSING_START_TAG_STATE) {
1657          if ($self->{next_char} == 0x003E) { # >
1658            if ($self->{current_token}->{type} == END_TAG_TOKEN) {
1659              !!!cp ('124.2');
1660              !!!parse-error (type => 'nestc', token => $self->{current_token});
1661              ## TODO: Different type than slash in start tag
1662              $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1663              if ($self->{current_token}->{attributes}) {
1664                !!!cp ('124.4');
1665                !!!parse-error (type => 'end tag attribute');
1666              } else {
1667                !!!cp ('124.5');
1668              }
1669              ## TODO: Test |<title></title/>|
1670            } else {
1671              !!!cp ('124.3');
1672              $self->{self_closing} = 1;
1673            }
1674    
1675            $self->{state} = DATA_STATE;
1676            !!!next-input-character;
1677    
1678            !!!emit ($self->{current_token}); # start tag or end tag
1679    
1680            redo A;
1681          } else {
1682            !!!cp ('124.4');
1683            !!!parse-error (type => 'nestc');
1684            ## TODO: This error type is wrong.
1685            $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1686            ## Reconsume.
1687            redo A;
1688          }
1689      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
1690        ## (only happen if PCDATA state)        ## (only happen if PCDATA state)
1691                
# Line 1459  sub _get_next_token ($) { Line 1732  sub _get_next_token ($) {
1732          if ($self->{next_char} == 0x002D) { # -          if ($self->{next_char} == 0x002D) { # -
1733            !!!cp (127);            !!!cp (127);
1734            $self->{current_token} = {type => COMMENT_TOKEN, data => '',            $self->{current_token} = {type => COMMENT_TOKEN, data => '',
1735                                      line => $l, column => $c};                                      line => $l, column => $c,
1736                                       };
1737            $self->{state} = COMMENT_START_STATE;            $self->{state} = COMMENT_START_STATE;
1738            !!!next-input-character;            !!!next-input-character;
1739            redo A;            redo A;
# Line 1497  sub _get_next_token ($) { Line 1771  sub _get_next_token ($) {
1771                      $self->{state} = DOCTYPE_STATE;                      $self->{state} = DOCTYPE_STATE;
1772                      $self->{current_token} = {type => DOCTYPE_TOKEN,                      $self->{current_token} = {type => DOCTYPE_TOKEN,
1773                                                quirks => 1,                                                quirks => 1,
1774                                                line => $l, column => $c};                                                line => $l, column => $c,
1775                                                 };
1776                      !!!next-input-character;                      !!!next-input-character;
1777                      redo A;                      redo A;
1778                    } else {                    } else {
# Line 1518  sub _get_next_token ($) { Line 1793  sub _get_next_token ($) {
1793          } else {          } else {
1794            !!!cp (135);            !!!cp (135);
1795          }          }
1796          } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM and
1797                   $self->{open_elements}->[-1]->[1] & FOREIGN_EL and
1798                   $self->{next_char} == 0x005B) { # [
1799            !!!next-input-character;
1800            push @next_char, $self->{next_char};
1801            if ($self->{next_char} == 0x0043) { # C
1802              !!!next-input-character;
1803              push @next_char, $self->{next_char};
1804              if ($self->{next_char} == 0x0044) { # D
1805                !!!next-input-character;
1806                push @next_char, $self->{next_char};
1807                if ($self->{next_char} == 0x0041) { # A
1808                  !!!next-input-character;
1809                  push @next_char, $self->{next_char};
1810                  if ($self->{next_char} == 0x0054) { # T
1811                    !!!next-input-character;
1812                    push @next_char, $self->{next_char};
1813                    if ($self->{next_char} == 0x0041) { # A
1814                      !!!next-input-character;
1815                      push @next_char, $self->{next_char};
1816                      if ($self->{next_char} == 0x005B) { # [
1817                        !!!cp (135.1);
1818                        $self->{state} = CDATA_BLOCK_STATE;
1819                        !!!next-input-character;
1820                        redo A;
1821                      } else {
1822                        !!!cp (135.2);
1823                      }
1824                    } else {
1825                      !!!cp (135.3);
1826                    }
1827                  } else {
1828                    !!!cp (135.4);                
1829                  }
1830                } else {
1831                  !!!cp (135.5);
1832                }
1833              } else {
1834                !!!cp (135.6);
1835              }
1836            } else {
1837              !!!cp (135.7);
1838            }
1839        } else {        } else {
1840          !!!cp (136);          !!!cp (136);
1841        }        }
# Line 1527  sub _get_next_token ($) { Line 1845  sub _get_next_token ($) {
1845        !!!back-next-input-character (@next_char);        !!!back-next-input-character (@next_char);
1846        $self->{state} = BOGUS_COMMENT_STATE;        $self->{state} = BOGUS_COMMENT_STATE;
1847        $self->{current_token} = {type => COMMENT_TOKEN, data => '',        $self->{current_token} = {type => COMMENT_TOKEN, data => '',
1848                                  line => $l, column => $c};                                  line => $l, column => $c,
1849                                   };
1850        redo A;        redo A;
1851                
1852        ## ISSUE: typos in spec: chacacters, is is a parse error        ## ISSUE: typos in spec: chacacters, is is a parse error
# Line 1651  sub _get_next_token ($) { Line 1970  sub _get_next_token ($) {
1970          redo A;          redo A;
1971        } elsif ($self->{next_char} == 0x002D) { # -        } elsif ($self->{next_char} == 0x002D) { # -
1972          !!!cp (152);          !!!cp (152);
1973          !!!parse-error (type => 'dash in comment');          !!!parse-error (type => 'dash in comment',
1974                            line => $self->{line_prev},
1975                            column => $self->{column_prev});
1976          $self->{current_token}->{data} .= '-'; # comment          $self->{current_token}->{data} .= '-'; # comment
1977          ## Stay in the state          ## Stay in the state
1978          !!!next-input-character;          !!!next-input-character;
# Line 1667  sub _get_next_token ($) { Line 1988  sub _get_next_token ($) {
1988          redo A;          redo A;
1989        } else {        } else {
1990          !!!cp (154);          !!!cp (154);
1991          !!!parse-error (type => 'dash in comment');          !!!parse-error (type => 'dash in comment',
1992                            line => $self->{line_prev},
1993                            column => $self->{column_prev});
1994          $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment          $self->{current_token}->{data} .= '--' . chr ($self->{next_char}); # comment
1995          $self->{state} = COMMENT_STATE;          $self->{state} = COMMENT_STATE;
1996          !!!next-input-character;          !!!next-input-character;
# Line 2237  sub _get_next_token ($) { Line 2560  sub _get_next_token ($) {
2560          !!!next-input-character;          !!!next-input-character;
2561          redo A;          redo A;
2562        }        }
2563        } elsif ($self->{state} == CDATA_BLOCK_STATE) {
2564          my $s = '';
2565          
2566          my ($l, $c) = ($self->{line}, $self->{column});
2567    
2568          CS: while ($self->{next_char} != -1) {
2569            if ($self->{next_char} == 0x005D) { # ]
2570              !!!next-input-character;
2571              if ($self->{next_char} == 0x005D) { # ]
2572                !!!next-input-character;
2573                MDC: {
2574                  if ($self->{next_char} == 0x003E) { # >
2575                    !!!cp (221.1);
2576                    !!!next-input-character;
2577                    last CS;
2578                  } elsif ($self->{next_char} == 0x005D) { # ]
2579                    !!!cp (221.2);
2580                    $s .= ']';
2581                    !!!next-input-character;
2582                    redo MDC;
2583                  } else {
2584                    !!!cp (221.3);
2585                    $s .= ']]';
2586                    #
2587                  }
2588                } # MDC
2589              } else {
2590                !!!cp (221.4);
2591                $s .= ']';
2592                #
2593              }
2594            } else {
2595              !!!cp (221.5);
2596              #
2597            }
2598            $s .= chr $self->{next_char};
2599            !!!next-input-character;
2600          } # CS
2601    
2602          $self->{state} = DATA_STATE;
2603          ## next-input-character done or EOF, which is reconsumed.
2604    
2605          if (length $s) {
2606            !!!cp (221.6);
2607            !!!emit ({type => CHARACTER_TOKEN, data => $s,
2608                      line => $l, column => $c});
2609          } else {
2610            !!!cp (221.7);
2611          }
2612    
2613          redo A;
2614    
2615          ## ISSUE: "text tokens" in spec.
2616          ## TODO: Streaming support
2617      } else {      } else {
2618        die "$0: $self->{state}: Unknown state";        die "$0: $self->{state}: Unknown state";
2619      }      }
# Line 2321  sub _tokenize_attempt_to_consume_an_enti Line 2698  sub _tokenize_attempt_to_consume_an_enti
2698          }          }
2699    
2700          return {type => CHARACTER_TOKEN, data => chr $code,          return {type => CHARACTER_TOKEN, data => chr $code,
2701                  has_reference => 1, line => $l, column => $c};                  has_reference => 1,
2702                    line => $l, column => $c,
2703                   };
2704        } # X        } # X
2705      } elsif (0x0030 <= $self->{next_char} and      } elsif (0x0030 <= $self->{next_char} and
2706               $self->{next_char} <= 0x0039) { # 0..9               $self->{next_char} <= 0x0039) { # 0..9
# Line 2364  sub _tokenize_attempt_to_consume_an_enti Line 2743  sub _tokenize_attempt_to_consume_an_enti
2743        }        }
2744                
2745        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,        return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1,
2746                line => $l, column => $c};                line => $l, column => $c,
2747                 };
2748      } else {      } else {
2749        !!!cp (1019);        !!!cp (1019);
2750        !!!parse-error (type => 'bare nero', line => $l, column => $c);        !!!parse-error (type => 'bare nero', line => $l, column => $c);
# Line 2384  sub _tokenize_attempt_to_consume_an_enti Line 2764  sub _tokenize_attempt_to_consume_an_enti
2764      require Whatpm::_NamedEntityList;      require Whatpm::_NamedEntityList;
2765      our $EntityChar;      our $EntityChar;
2766    
2767      while (length $entity_name < 10 and      while (length $entity_name < 30 and
2768             ## NOTE: Some number greater than the maximum length of entity name             ## NOTE: Some number greater than the maximum length of entity name
2769             ((0x0041 <= $self->{next_char} and # a             ((0x0041 <= $self->{next_char} and # a
2770               $self->{next_char} <= 0x005A) or # x               $self->{next_char} <= 0x005A) or # x
# Line 2418  sub _tokenize_attempt_to_consume_an_enti Line 2798  sub _tokenize_attempt_to_consume_an_enti
2798      if ($match > 0) {      if ($match > 0) {
2799        !!!cp (1023);        !!!cp (1023);
2800        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,        return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,
2801                line => $l, column => $c};                line => $l, column => $c,
2802                 };
2803      } elsif ($match < 0) {      } elsif ($match < 0) {
2804        !!!parse-error (type => 'no refc', line => $l, column => $c);        !!!parse-error (type => 'no refc', line => $l, column => $c);
2805        if ($in_attr and $match < -1) {        if ($in_attr and $match < -1) {
2806          !!!cp (1024);          !!!cp (1024);
2807          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,          return {type => CHARACTER_TOKEN, data => '&'.$entity_name,
2808                  line => $l, column => $c};                  line => $l, column => $c,
2809                   };
2810        } else {        } else {
2811          !!!cp (1025);          !!!cp (1025);
2812          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,          return {type => CHARACTER_TOKEN, data => $value, has_reference => 1,
2813                  line => $l, column => $c};                  line => $l, column => $c,
2814                   };
2815        }        }
2816      } else {      } else {
2817        !!!cp (1026);        !!!cp (1026);
2818        !!!parse-error (type => 'bare ero', line => $l, column => $c);        !!!parse-error (type => 'bare ero', line => $l, column => $c);
2819        ## NOTE: "No characters are consumed" in the spec.        ## NOTE: "No characters are consumed" in the spec.
2820        return {type => CHARACTER_TOKEN, data => '&'.$value,        return {type => CHARACTER_TOKEN, data => '&'.$value,
2821                line => $l, column => $c};                line => $l, column => $c,
2822                 };
2823      }      }
2824    } else {    } else {
2825      !!!cp (1027);      !!!cp (1027);
# Line 2522  sub _tree_construction_initial ($) { Line 2906  sub _tree_construction_initial ($) {
2906                
2907        my $doctype = $self->{document}->create_document_type_definition        my $doctype = $self->{document}->create_document_type_definition
2908          ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?          ($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)?
2909          ## NOTE: Default value for both |public_id| and |system_id| attributes
2910          ## are empty strings, so that we don't set any value in missing cases.
2911        $doctype->public_id ($token->{public_identifier})        $doctype->public_id ($token->{public_identifier})
2912            if defined $token->{public_identifier};            if defined $token->{public_identifier};
2913        $doctype->system_id ($token->{system_identifier})        $doctype->system_id ($token->{system_identifier})
# Line 2658  sub _tree_construction_initial ($) { Line 3044  sub _tree_construction_initial ($) {
3044        $self->{document}->manakai_compat_mode ('quirks');        $self->{document}->manakai_compat_mode ('quirks');
3045        ## Go to the "before html" insertion mode.        ## Go to the "before html" insertion mode.
3046        ## reprocess        ## reprocess
3047          !!!ack-later;
3048        return;        return;
3049      } elsif ($token->{type} == CHARACTER_TOKEN) {      } elsif ($token->{type} == CHARACTER_TOKEN) {
3050        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D        if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D
# Line 2738  sub _tree_construction_root_element ($) Line 3125  sub _tree_construction_root_element ($)
3125        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
3126          if ($token->{tag_name} eq 'html') {          if ($token->{tag_name} eq 'html') {
3127            my $root_element;            my $root_element;
3128            !!!create-element ($root_element, $token->{tag_name}, $token->{attributes});            !!!create-element ($root_element, $HTML_NS, $token->{tag_name}, $token->{attributes}, $token);
3129            $self->{document}->append_child ($root_element);            $self->{document}->append_child ($root_element);
3130            push @{$self->{open_elements}}, [$root_element, 'html'];            push @{$self->{open_elements}},
3131                  [$root_element, $el_category->{html}];
3132    
3133            if ($token->{attributes}->{manifest}) {            if ($token->{attributes}->{manifest}) {
3134              !!!cp ('t24');              !!!cp ('t24');
3135              $self->{application_cache_selection}              $self->{application_cache_selection}
3136                  ->($token->{attributes}->{manifest}->{value});                  ->($token->{attributes}->{manifest}->{value});
3137              ## ISSUE: No relative reference resolution?              ## ISSUE: Spec is unclear on relative references.
3138                ## According to Hixie (#whatwg 2008-03-19), it should be
3139                ## resolved against the base URI of the document in HTML
3140                ## or xml:base of the element in XHTML.
3141            } else {            } else {
3142              !!!cp ('t25');              !!!cp ('t25');
3143              $self->{application_cache_selection}->(undef);              $self->{application_cache_selection}->(undef);
3144            }            }
3145    
3146              !!!nack ('t25c');
3147    
3148            !!!next-token;            !!!next-token;
3149            return; ## Go to the "before head" insertion mode.            return; ## Go to the "before head" insertion mode.
3150          } else {          } else {
# Line 2768  sub _tree_construction_root_element ($) Line 3161  sub _tree_construction_root_element ($)
3161          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
3162        }        }
3163    
3164      my $root_element; !!!create-element ($root_element, 'html');      my $root_element;
3165        !!!create-element ($root_element, $HTML_NS, 'html',, $token);
3166      $self->{document}->append_child ($root_element);      $self->{document}->append_child ($root_element);
3167      push @{$self->{open_elements}}, [$root_element, 'html'];      push @{$self->{open_elements}}, [$root_element, $el_category->{html}];
3168    
3169      $self->{application_cache_selection}->(undef);      $self->{application_cache_selection}->(undef);
3170    
3171      ## NOTE: Reprocess the token.      ## NOTE: Reprocess the token.
3172        !!!ack-later;
3173      return; ## Go to the "before head" insertion mode.      return; ## Go to the "before head" insertion mode.
3174    
3175      ## ISSUE: There is an issue in the spec      ## ISSUE: There is an issue in the spec
# Line 2798  sub _reset_insertion_mode ($) { Line 3193  sub _reset_insertion_mode ($) {
3193        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {        if ($self->{open_elements}->[0]->[0] eq $node->[0]) {
3194          $last = 1;          $last = 1;
3195          if (defined $self->{inner_html_node}) {          if (defined $self->{inner_html_node}) {
3196            if ($self->{inner_html_node}->[1] eq 'td' or            if ($self->{inner_html_node}->[1] & TABLE_CELL_EL) {
               $self->{inner_html_node}->[1] eq 'th') {  
3197              !!!cp ('t27');              !!!cp ('t27');
3198              #              #
3199            } else {            } else {
# Line 2809  sub _reset_insertion_mode ($) { Line 3203  sub _reset_insertion_mode ($) {
3203          }          }
3204        }        }
3205            
3206        ## Step 4..13      ## Step 4..14
3207        my $new_mode = {      my $new_mode;
3208        if ($node->[1] & FOREIGN_EL) {
3209          ## NOTE: Strictly spaking, the line below only applies to MathML and
3210          ## SVG elements.  Currently the HTML syntax supports only MathML and
3211          ## SVG elements as foreigners.
3212          $new_mode = $self->{insertion_mode} | IN_FOREIGN_CONTENT_IM;
3213          ## ISSUE: What is set as the secondary insertion mode?
3214        } else {
3215          $new_mode = {
3216                        select => IN_SELECT_IM,                        select => IN_SELECT_IM,
3217                        ## NOTE: |option| and |optgroup| do not set                        ## NOTE: |option| and |optgroup| do not set
3218                        ## insertion mode to "in select" by themselves.                        ## insertion mode to "in select" by themselves.
# Line 2826  sub _reset_insertion_mode ($) { Line 3228  sub _reset_insertion_mode ($) {
3228                        head => IN_BODY_IM, # not in head!                        head => IN_BODY_IM, # not in head!
3229                        body => IN_BODY_IM,                        body => IN_BODY_IM,
3230                        frameset => IN_FRAMESET_IM,                        frameset => IN_FRAMESET_IM,
3231                       }->{$node->[1]};                       }->{$node->[0]->manakai_local_name};
3232        $self->{insertion_mode} = $new_mode and return if defined $new_mode;      }
3233        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3234                
3235        ## Step 14        ## Step 15
3236        if ($node->[1] eq 'html') {        if ($node->[1] & HTML_EL) {
3237          unless (defined $self->{head_element}) {          unless (defined $self->{head_element}) {
3238            !!!cp ('t29');            !!!cp ('t29');
3239            $self->{insertion_mode} = BEFORE_HEAD_IM;            $self->{insertion_mode} = BEFORE_HEAD_IM;
# Line 2844  sub _reset_insertion_mode ($) { Line 3247  sub _reset_insertion_mode ($) {
3247          !!!cp ('t31');          !!!cp ('t31');
3248        }        }
3249                
3250        ## Step 15        ## Step 16
3251        $self->{insertion_mode} = IN_BODY_IM and return if $last;        $self->{insertion_mode} = IN_BODY_IM and return if $last;
3252                
3253        ## Step 16        ## Step 17
3254        $i--;        $i--;
3255        $node = $self->{open_elements}->[$i];        $node = $self->{open_elements}->[$i];
3256                
3257        ## Step 17        ## Step 18
3258        redo S3;        redo S3;
3259      } # S3      } # S3
3260    
# Line 2963  sub _tree_construction_main ($) { Line 3366  sub _tree_construction_main ($) {
3366      ## Step 1      ## Step 1
3367      my $start_tag_name = $token->{tag_name};      my $start_tag_name = $token->{tag_name};
3368      my $el;      my $el;
3369      !!!create-element ($el, $start_tag_name, $token->{attributes});      !!!create-element ($el, $HTML_NS, $start_tag_name, $token->{attributes}, $token);
3370    
3371      ## Step 2      ## Step 2
3372      $insert->($el);      $insert->($el);
# Line 2974  sub _tree_construction_main ($) { Line 3377  sub _tree_construction_main ($) {
3377    
3378      ## Step 4      ## Step 4
3379      my $text = '';      my $text = '';
3380        !!!nack ('t40.1');
3381      !!!next-token;      !!!next-token;
3382      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing      while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing
3383        !!!cp ('t40');        !!!cp ('t40');
# Line 3013  sub _tree_construction_main ($) { Line 3417  sub _tree_construction_main ($) {
3417    
3418    my $script_start_tag = sub () {    my $script_start_tag = sub () {
3419      my $script_el;      my $script_el;
3420      !!!create-element ($script_el, 'script', $token->{attributes});      !!!create-element ($script_el, $HTML_NS, 'script', $token->{attributes}, $token);
3421      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
3422    
3423      $self->{content_model} = CDATA_CONTENT_MODEL;      $self->{content_model} = CDATA_CONTENT_MODEL;
3424      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
3425            
3426      my $text = '';      my $text = '';
3427        !!!nack ('t45.1');
3428      !!!next-token;      !!!next-token;
3429      while ($token->{type} == CHARACTER_TOKEN) {      while ($token->{type} == CHARACTER_TOKEN) {
3430        !!!cp ('t45');        !!!cp ('t45');
# Line 3077  sub _tree_construction_main ($) { Line 3482  sub _tree_construction_main ($) {
3482        my $formatting_element;        my $formatting_element;
3483        my $formatting_element_i_in_active;        my $formatting_element_i_in_active;
3484        AFE: for (reverse 0..$#$active_formatting_elements) {        AFE: for (reverse 0..$#$active_formatting_elements) {
3485          if ($active_formatting_elements->[$_]->[1] eq $tag_name) {          if ($active_formatting_elements->[$_]->[0] eq '#marker') {
3486              !!!cp ('t52');
3487              last AFE;
3488            } elsif ($active_formatting_elements->[$_]->[0]->manakai_local_name
3489                         eq $tag_name) {
3490            !!!cp ('t51');            !!!cp ('t51');
3491            $formatting_element = $active_formatting_elements->[$_];            $formatting_element = $active_formatting_elements->[$_];
3492            $formatting_element_i_in_active = $_;            $formatting_element_i_in_active = $_;
3493            last AFE;            last AFE;
         } elsif ($active_formatting_elements->[$_]->[0] eq '#marker') {  
           !!!cp ('t52');  
           last AFE;  
3494          }          }
3495        } # AFE        } # AFE
3496        unless (defined $formatting_element) {        unless (defined $formatting_element) {
# Line 3112  sub _tree_construction_main ($) { Line 3518  sub _tree_construction_main ($) {
3518              !!!next-token;              !!!next-token;
3519              return;              return;
3520            }            }
3521          } elsif ({          } elsif ($node->[1] & SCOPING_EL) {
                   applet => 1, table => 1, caption => 1, td => 1, th => 1,  
                   button => 1, marquee => 1, object => 1, html => 1,  
                  }->{$node->[1]}) {  
3522            !!!cp ('t56');            !!!cp ('t56');
3523            $in_scope = 0;            $in_scope = 0;
3524          }          }
# Line 3130  sub _tree_construction_main ($) { Line 3533  sub _tree_construction_main ($) {
3533        }        }
3534        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {        if (not $self->{open_elements}->[-1]->[0] eq $formatting_element->[0]) {
3535          !!!cp ('t58');          !!!cp ('t58');
3536          !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1],          !!!parse-error (type => 'not closed',
3537                            value => $self->{open_elements}->[-1]->[0]
3538                                ->manakai_local_name,
3539                          token => $end_tag_token);                          token => $end_tag_token);
3540        }        }
3541                
# Line 3139  sub _tree_construction_main ($) { Line 3544  sub _tree_construction_main ($) {
3544        my $furthest_block_i_in_open;        my $furthest_block_i_in_open;
3545        OE: for (reverse 0..$#{$self->{open_elements}}) {        OE: for (reverse 0..$#{$self->{open_elements}}) {
3546          my $node = $self->{open_elements}->[$_];          my $node = $self->{open_elements}->[$_];
3547          if (not $formatting_category->{$node->[1]} and          if (not ($node->[1] & FORMATTING_EL) and
3548              #not $phrasing_category->{$node->[1]} and              #not $phrasing_category->{$node->[1]} and
3549              ($special_category->{$node->[1]} or              ($node->[1] & SPECIAL_EL or
3550               $scoping_category->{$node->[1]})) { ## Scoping is redundant, maybe               $node->[1] & SCOPING_EL)) { ## Scoping is redundant, maybe
3551            !!!cp ('t59');            !!!cp ('t59');
3552            $furthest_block = $node;            $furthest_block = $node;
3553            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
# Line 3228  sub _tree_construction_main ($) { Line 3633  sub _tree_construction_main ($) {
3633        } # S7          } # S7  
3634                
3635        ## Step 8        ## Step 8
3636        if ({        if ($common_ancestor_node->[1] & TABLE_ROWS_EL) {
            table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,  
           }->{$common_ancestor_node->[1]}) {  
3637          my $foster_parent_element;          my $foster_parent_element;
3638          my $next_sibling;          my $next_sibling;
3639                           OE: for (reverse 0..$#{$self->{open_elements}}) {          OE: for (reverse 0..$#{$self->{open_elements}}) {
3640                             if ($self->{open_elements}->[$_]->[1] eq 'table') {            if ($self->{open_elements}->[$_]->[1] & TABLE_EL) {
3641                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3642                               if (defined $parent and $parent->node_type == 1) {                               if (defined $parent and $parent->node_type == 1) {
3643                                 !!!cp ('t65.1');                                 !!!cp ('t65.1');
# Line 3307  sub _tree_construction_main ($) { Line 3710  sub _tree_construction_main ($) {
3710    
3711    my $insert_to_foster = sub {    my $insert_to_foster = sub {
3712      my $child = shift;      my $child = shift;
3713      if ({      if ($self->{open_elements}->[-1]->[1] & TABLE_ROWS_EL) {
          table => 1, tbody => 1, tfoot => 1, thead => 1, tr => 1,  
         }->{$self->{open_elements}->[-1]->[1]}) {  
3714        # MUST        # MUST
3715        my $foster_parent_element;        my $foster_parent_element;
3716        my $next_sibling;        my $next_sibling;
3717                           OE: for (reverse 0..$#{$self->{open_elements}}) {        OE: for (reverse 0..$#{$self->{open_elements}}) {
3718                             if ($self->{open_elements}->[$_]->[1] eq 'table') {          if ($self->{open_elements}->[$_]->[1] & TABLE_EL) {
3719                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
3720                               if (defined $parent and $parent->node_type == 1) {                               if (defined $parent and $parent->node_type == 1) {
3721                                 !!!cp ('t70');                                 !!!cp ('t70');
# Line 3339  sub _tree_construction_main ($) { Line 3740  sub _tree_construction_main ($) {
3740      }      }
3741    }; # $insert_to_foster    }; # $insert_to_foster
3742    
3743    B: {    B: while (1) {
3744      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
3745        !!!cp ('t73');        !!!cp ('t73');
3746        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);        !!!parse-error (type => 'DOCTYPE in the middle', token => $token);
3747        ## Ignore the token        ## Ignore the token
3748        ## Stay in the phase        ## Stay in the phase
3749        !!!next-token;        !!!next-token;
3750        redo B;        next B;
3751      } elsif ($token->{type} == START_TAG_TOKEN and      } elsif ($token->{type} == START_TAG_TOKEN and
3752               $token->{tag_name} eq 'html') {               $token->{tag_name} eq 'html') {
3753        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {        if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
# Line 3372  sub _tree_construction_main ($) { Line 3773  sub _tree_construction_main ($) {
3773               $token->{attributes}->{$attr_name}->{value});               $token->{attributes}->{$attr_name}->{value});
3774          }          }
3775        }        }
3776          !!!nack ('t84.1');
3777        !!!next-token;        !!!next-token;
3778        redo B;        next B;
3779      } elsif ($token->{type} == COMMENT_TOKEN) {      } elsif ($token->{type} == COMMENT_TOKEN) {
3780        my $comment = $self->{document}->create_comment ($token->{data});        my $comment = $self->{document}->create_comment ($token->{data});
3781        if ($self->{insertion_mode} & AFTER_HTML_IMS) {        if ($self->{insertion_mode} & AFTER_HTML_IMS) {
# Line 3387  sub _tree_construction_main ($) { Line 3789  sub _tree_construction_main ($) {
3789          $self->{open_elements}->[-1]->[0]->append_child ($comment);          $self->{open_elements}->[-1]->[0]->append_child ($comment);
3790        }        }
3791        !!!next-token;        !!!next-token;
3792        redo B;        next B;
3793      } elsif ($self->{insertion_mode} & HEAD_IMS) {      } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM) {
3794          if ($token->{type} == CHARACTER_TOKEN) {
3795            !!!cp ('t87.1');
3796            $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
3797            !!!next-token;
3798            next B;
3799          } elsif ($token->{type} == START_TAG_TOKEN) {
3800            if ((not {mglyph => 1, malignmark => 1}->{$token->{tag_name}} and
3801                 $self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL) or
3802                not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or
3803                ($token->{tag_name} eq 'svg' and
3804                 $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {
3805              ## NOTE: "using the rules for secondary insertion mode"then"continue"
3806              !!!cp ('t87.2');
3807              #
3808            } elsif ({
3809                      b => 1, big => 1, blockquote => 1, body => 1, br => 1,
3810                      center => 1, code => 1, dd => 1, div => 1, dl => 1, em => 1,
3811                      embed => 1, font => 1, h1 => 1, h2 => 1, h3 => 1, ## No h4!
3812                      h5 => 1, h6 => 1, head => 1, hr => 1, i => 1, img => 1,
3813                      li => 1, menu => 1, meta => 1, nobr => 1, p => 1, pre => 1,
3814                      ruby => 1, s => 1, small => 1, span => 1, strong => 1,
3815                      sub => 1, sup => 1, table => 1, tt => 1, u => 1, ul => 1,
3816                      var => 1,
3817                     }->{$token->{tag_name}}) {
3818              !!!cp ('t87.2');
3819              !!!parse-error (type => 'not closed',
3820                              value => $self->{open_elements}->[-1]->[0]
3821                                  ->manakai_local_name,
3822                              token => $token);
3823    
3824              pop @{$self->{open_elements}}
3825                  while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
3826    
3827              $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
3828              ## Reprocess.
3829              next B;
3830            } else {
3831              my $nsuri = $self->{open_elements}->[-1]->[0]->namespace_uri;
3832              my $tag_name = $token->{tag_name};
3833              if ($nsuri eq $SVG_NS) {
3834                $tag_name = {
3835                   altglyph => 'altGlyph',
3836                   altglyphdef => 'altGlyphDef',
3837                   altglyphitem => 'altGlyphItem',
3838                   animatecolor => 'animateColor',
3839                   animatemotion => 'animateMotion',
3840                   animatetransform => 'animateTransform',
3841                   clippath => 'clipPath',
3842                   feblend => 'feBlend',
3843                   fecolormatrix => 'feColorMatrix',
3844                   fecomponenttransfer => 'feComponentTransfer',
3845                   fecomposite => 'feComposite',
3846                   feconvolvematrix => 'feConvolveMatrix',
3847                   fediffuselighting => 'feDiffuseLighting',
3848                   fedisplacementmap => 'feDisplacementMap',
3849                   fedistantlight => 'feDistantLight',
3850                   feflood => 'feFlood',
3851                   fefunca => 'feFuncA',
3852                   fefuncb => 'feFuncB',
3853                   fefuncg => 'feFuncG',
3854                   fefuncr => 'feFuncR',
3855                   fegaussianblur => 'feGaussianBlur',
3856                   feimage => 'feImage',
3857                   femerge => 'feMerge',
3858                   femergenode => 'feMergeNode',
3859                   femorphology => 'feMorphology',
3860                   feoffset => 'feOffset',
3861                   fepointlight => 'fePointLight',
3862                   fespecularlighting => 'feSpecularLighting',
3863                   fespotlight => 'feSpotLight',
3864                   fetile => 'feTile',
3865                   feturbulence => 'feTurbulence',
3866                   foreignobject => 'foreignObject',
3867                   glyphref => 'glyphRef',
3868                   lineargradient => 'linearGradient',
3869                   radialgradient => 'radialGradient',
3870                   #solidcolor => 'solidColor', ## NOTE: Commented in spec (SVG1.2)
3871                   textpath => 'textPath',  
3872                }->{$tag_name} || $tag_name;
3873              }
3874    
3875              ## "adjust SVG attributes" (SVG only) - done in insert-element-f
3876    
3877              ## "adjust foreign attributes" - done in insert-element-f
3878    
3879              !!!insert-element-f ($nsuri, $tag_name, $token->{attributes}, $token);
3880    
3881              if ($self->{self_closing}) {
3882                pop @{$self->{open_elements}};
3883                !!!ack ('t87.3');
3884              } else {
3885                !!!cp ('t87.4');
3886              }
3887    
3888              !!!next-token;
3889              next B;
3890            }
3891          } elsif ($token->{type} == END_TAG_TOKEN) {
3892            ## NOTE: "using the rules for secondary insertion mode" then "continue"
3893            !!!cp ('t87.5');
3894            #
3895          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
3896            ## NOTE: "using the rules for secondary insertion mode" then "continue"
3897            !!!cp ('t87.6');
3898            #
3899            ## TODO: ...
3900          } else {
3901            die "$0: $token->{type}: Unknown token type";        
3902          }
3903        }
3904    
3905        if ($self->{insertion_mode} & HEAD_IMS) {
3906        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
3907          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) {
3908            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
# Line 3398  sub _tree_construction_main ($) { Line 3912  sub _tree_construction_main ($) {
3912              !!!cp ('t88.1');              !!!cp ('t88.1');
3913              ## Ignore the token.              ## Ignore the token.
3914              !!!next-token;              !!!next-token;
3915              redo B;              next B;
3916            }            }
3917            unless (length $token->{data}) {            unless (length $token->{data}) {
3918              !!!cp ('t88');              !!!cp ('t88');
3919              !!!next-token;              !!!next-token;
3920              redo B;              next B;
3921            }            }
3922          }          }
3923    
3924          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3925            !!!cp ('t89');            !!!cp ('t89');
3926            ## As if <head>            ## As if <head>
3927            !!!create-element ($self->{head_element}, 'head');            !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
3928            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});            $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
3929            push @{$self->{open_elements}}, [$self->{head_element}, 'head'];            push @{$self->{open_elements}},
3930                  [$self->{head_element}, $el_category->{head}];
3931    
3932            ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
3933            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
# Line 3438  sub _tree_construction_main ($) { Line 3953  sub _tree_construction_main ($) {
3953            !!!cp ('t92');            !!!cp ('t92');
3954          }          }
3955    
3956              ## "after head" insertion mode          ## "after head" insertion mode
3957              ## As if <body>          ## As if <body>
3958              !!!insert-element ('body');          !!!insert-element ('body',, $token);
3959              $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
3960              ## reprocess          ## reprocess
3961              redo B;          next B;
3962            } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
3963              if ($token->{tag_name} eq 'head') {          if ($token->{tag_name} eq 'head') {
3964                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {            if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3965                  !!!cp ('t93');              !!!cp ('t93');
3966                  !!!create-element ($self->{head_element}, $token->{tag_name}, $token->{attributes});              !!!create-element ($self->{head_element}, $HTML_NS, $token->{tag_name}, $token->{attributes}, $token);
3967                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});              $self->{open_elements}->[-1]->[0]->append_child
3968                  push @{$self->{open_elements}}, [$self->{head_element}, $token->{tag_name}];                  ($self->{head_element});
3969                  $self->{insertion_mode} = IN_HEAD_IM;              push @{$self->{open_elements}},
3970                  !!!next-token;                  [$self->{head_element}, $el_category->{head}];
3971                  redo B;              $self->{insertion_mode} = IN_HEAD_IM;
3972                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {              !!!nack ('t93.1');
3973                  !!!cp ('t94');              !!!next-token;
3974                  #              next B;
3975                } else {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
3976                  !!!cp ('t95');              !!!cp ('t94');
3977                  !!!parse-error (type => 'in head:head', token => $token); # or in head noscript              #
3978                  ## Ignore the token            } else {
3979                  !!!next-token;              !!!cp ('t95');
3980                  redo B;              !!!parse-error (type => 'in head:head', token => $token); # or in head noscript
3981                }              ## Ignore the token
3982              } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {              !!!nack ('t95.1');
3983                !!!cp ('t96');              !!!next-token;
3984                ## As if <head>              next B;
3985                !!!create-element ($self->{head_element}, 'head');            }
3986                $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});          } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
3987                push @{$self->{open_elements}}, [$self->{head_element}, 'head'];            !!!cp ('t96');
3988              ## As if <head>
3989              !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
3990              $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
3991              push @{$self->{open_elements}},
3992                  [$self->{head_element}, $el_category->{head}];
3993    
3994                $self->{insertion_mode} = IN_HEAD_IM;            $self->{insertion_mode} = IN_HEAD_IM;
3995                ## Reprocess in the "in head" insertion mode...            ## Reprocess in the "in head" insertion mode...
3996              } else {          } else {
3997                !!!cp ('t97');            !!!cp ('t97');
3998              }          }
3999    
4000              if ($token->{tag_name} eq 'base') {              if ($token->{tag_name} eq 'base') {
4001                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 3494  sub _tree_construction_main ($) { Line 4014  sub _tree_construction_main ($) {
4014                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4015                  !!!cp ('t100');                  !!!cp ('t100');
4016                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
4017                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}},
4018                        [$self->{head_element}, $el_category->{head}];
4019                } else {                } else {
4020                  !!!cp ('t101');                  !!!cp ('t101');
4021                }                }
4022                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
4023                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4024                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4025                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4026                  !!!nack ('t101.1');
4027                !!!next-token;                !!!next-token;
4028                redo B;                next B;
4029              } elsif ($token->{tag_name} eq 'link') {              } elsif ($token->{tag_name} eq 'link') {
4030                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4031                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4032                  !!!cp ('t102');                  !!!cp ('t102');
4033                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
4034                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}},
4035                        [$self->{head_element}, $el_category->{head}];
4036                } else {                } else {
4037                  !!!cp ('t103');                  !!!cp ('t103');
4038                }                }
4039                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
4040                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4041                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4042                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4043                  !!!ack ('t103.1');
4044                !!!next-token;                !!!next-token;
4045                redo B;                next B;
4046              } elsif ($token->{tag_name} eq 'meta') {              } elsif ($token->{tag_name} eq 'meta') {
4047                ## NOTE: There is a "as if in head" code clone.                ## NOTE: There is a "as if in head" code clone.
4048                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4049                  !!!cp ('t104');                  !!!cp ('t104');
4050                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
4051                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}},
4052                        [$self->{head_element}, $el_category->{head}];
4053                } else {                } else {
4054                  !!!cp ('t105');                  !!!cp ('t105');
4055                }                }
4056                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
4057                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.                my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
4058    
4059                unless ($self->{confident}) {                unless ($self->{confident}) {
4060                  if ($token->{attributes}->{charset}) { ## TODO: And if supported                  if ($token->{attributes}->{charset}) { ## TODO: And if supported
4061                    !!!cp ('t106');                    !!!cp ('t106');
4062                    $self->{change_encoding}                    $self->{change_encoding}
4063                        ->($self, $token->{attributes}->{charset}->{value});                        ->($self, $token->{attributes}->{charset}->{value},
4064                             $token);
4065                                        
4066                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')                    $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
4067                        ->set_user_data (manakai_has_reference =>                        ->set_user_data (manakai_has_reference =>
# Line 3550  sub _tree_construction_main ($) { Line 4076  sub _tree_construction_main ($) {
4076                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                            ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
4077                      !!!cp ('t107');                      !!!cp ('t107');
4078                      $self->{change_encoding}                      $self->{change_encoding}
4079                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                          ->($self, defined $1 ? $1 : defined $2 ? $2 : $3,
4080                               $token);
4081                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')                      $meta_el->[0]->get_attribute_node_ns (undef, 'content')
4082                          ->set_user_data (manakai_has_reference =>                          ->set_user_data (manakai_has_reference =>
4083                                               $token->{attributes}->{content}                                               $token->{attributes}->{content}
# Line 3578  sub _tree_construction_main ($) { Line 4105  sub _tree_construction_main ($) {
4105    
4106                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4107                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4108                  !!!ack ('t110.1');
4109                !!!next-token;                !!!next-token;
4110                redo B;                next B;
4111              } elsif ($token->{tag_name} eq 'title') {              } elsif ($token->{tag_name} eq 'title') {
4112                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4113                  !!!cp ('t111');                  !!!cp ('t111');
# Line 3592  sub _tree_construction_main ($) { Line 4120  sub _tree_construction_main ($) {
4120                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4121                  !!!cp ('t112');                  !!!cp ('t112');
4122                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
4123                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}},
4124                        [$self->{head_element}, $el_category->{head}];
4125                } else {                } else {
4126                  !!!cp ('t113');                  !!!cp ('t113');
4127                }                }
# Line 3603  sub _tree_construction_main ($) { Line 4132  sub _tree_construction_main ($) {
4132                $parse_rcdata->(RCDATA_CONTENT_MODEL);                $parse_rcdata->(RCDATA_CONTENT_MODEL);
4133                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4134                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4135                redo B;                next B;
4136              } elsif ($token->{tag_name} eq 'style') {              } elsif ($token->{tag_name} eq 'style') {
4137                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4138                ## insertion mode IN_HEAD_IM)                ## insertion mode IN_HEAD_IM)
# Line 3611  sub _tree_construction_main ($) { Line 4140  sub _tree_construction_main ($) {
4140                if ($self->{insertion_mode} == AFTER_HEAD_IM) {                if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4141                  !!!cp ('t114');                  !!!cp ('t114');
4142                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
4143                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}},
4144                        [$self->{head_element}, $el_category->{head}];
4145                } else {                } else {
4146                  !!!cp ('t115');                  !!!cp ('t115');
4147                }                }
4148                $parse_rcdata->(CDATA_CONTENT_MODEL);                $parse_rcdata->(CDATA_CONTENT_MODEL);
4149                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4150                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4151                redo B;                next B;
4152              } elsif ($token->{tag_name} eq 'noscript') {              } elsif ($token->{tag_name} eq 'noscript') {
4153                if ($self->{insertion_mode} == IN_HEAD_IM) {                if ($self->{insertion_mode} == IN_HEAD_IM) {
4154                  !!!cp ('t116');                  !!!cp ('t116');
4155                  ## NOTE: and scripting is disalbed                  ## NOTE: and scripting is disalbed
4156                  !!!insert-element ($token->{tag_name}, $token->{attributes});                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
4157                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;                  $self->{insertion_mode} = IN_HEAD_NOSCRIPT_IM;
4158                    !!!nack ('t116.1');
4159                  !!!next-token;                  !!!next-token;
4160                  redo B;                  next B;
4161                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4162                  !!!cp ('t117');                  !!!cp ('t117');
4163                  !!!parse-error (type => 'in noscript:noscript', token => $token);                  !!!parse-error (type => 'in noscript:noscript', token => $token);
4164                  ## Ignore the token                  ## Ignore the token
4165                    !!!nack ('t117.1');
4166                  !!!next-token;                  !!!next-token;
4167                  redo B;                  next B;
4168                } else {                } else {
4169                  !!!cp ('t118');                  !!!cp ('t118');
4170                  #                  #
# Line 3649  sub _tree_construction_main ($) { Line 4181  sub _tree_construction_main ($) {
4181                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4182                  !!!cp ('t120');                  !!!cp ('t120');
4183                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'after head:'.$token->{tag_name}, token => $token);
4184                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}},
4185                        [$self->{head_element}, $el_category->{head}];
4186                } else {                } else {
4187                  !!!cp ('t121');                  !!!cp ('t121');
4188                }                }
# Line 3658  sub _tree_construction_main ($) { Line 4191  sub _tree_construction_main ($) {
4191                $script_start_tag->();                $script_start_tag->();
4192                pop @{$self->{open_elements}} # <head>                pop @{$self->{open_elements}} # <head>
4193                    if $self->{insertion_mode} == AFTER_HEAD_IM;                    if $self->{insertion_mode} == AFTER_HEAD_IM;
4194                redo B;                next B;
4195              } elsif ($token->{tag_name} eq 'body' or              } elsif ($token->{tag_name} eq 'body' or
4196                       $token->{tag_name} eq 'frameset') {                       $token->{tag_name} eq 'frameset') {
4197                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
# Line 3682  sub _tree_construction_main ($) { Line 4215  sub _tree_construction_main ($) {
4215                }                }
4216    
4217                ## "after head" insertion mode                ## "after head" insertion mode
4218                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
4219                if ($token->{tag_name} eq 'body') {                if ($token->{tag_name} eq 'body') {
4220                  !!!cp ('t126');                  !!!cp ('t126');
4221                  $self->{insertion_mode} = IN_BODY_IM;                  $self->{insertion_mode} = IN_BODY_IM;
# Line 3692  sub _tree_construction_main ($) { Line 4225  sub _tree_construction_main ($) {
4225                } else {                } else {
4226                  die "$0: tag name: $self->{tag_name}";                  die "$0: tag name: $self->{tag_name}";
4227                }                }
4228                  !!!nack ('t127.1');
4229                !!!next-token;                !!!next-token;
4230                redo B;                next B;
4231              } else {              } else {
4232                !!!cp ('t128');                !!!cp ('t128');
4233                #                #
# Line 3722  sub _tree_construction_main ($) { Line 4256  sub _tree_construction_main ($) {
4256    
4257              ## "after head" insertion mode              ## "after head" insertion mode
4258              ## As if <body>              ## As if <body>
4259              !!!insert-element ('body');              !!!insert-element ('body',, $token);
4260              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
4261              ## reprocess              ## reprocess
4262              redo B;              !!!ack-later;
4263                next B;
4264            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
4265              if ($token->{tag_name} eq 'head') {              if ($token->{tag_name} eq 'head') {
4266                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4267                  !!!cp ('t132');                  !!!cp ('t132');
4268                  ## As if <head>                  ## As if <head>
4269                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4270                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4271                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}},
4272                        [$self->{head_element}, $el_category->{head}];
4273    
4274                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
4275                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4276                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4277                  !!!next-token;                  !!!next-token;
4278                  redo B;                  next B;
4279                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4280                  !!!cp ('t133');                  !!!cp ('t133');
4281                  ## As if </noscript>                  ## As if </noscript>
# Line 3750  sub _tree_construction_main ($) { Line 4286  sub _tree_construction_main ($) {
4286                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4287                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4288                  !!!next-token;                  !!!next-token;
4289                  redo B;                  next B;
4290                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {                } elsif ($self->{insertion_mode} == IN_HEAD_IM) {
4291                  !!!cp ('t134');                  !!!cp ('t134');
4292                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4293                  $self->{insertion_mode} = AFTER_HEAD_IM;                  $self->{insertion_mode} = AFTER_HEAD_IM;
4294                  !!!next-token;                  !!!next-token;
4295                  redo B;                  next B;
4296                } else {                } else {
4297                  !!!cp ('t135');                  !!!cp ('t135');
4298                  #                  #
# Line 3767  sub _tree_construction_main ($) { Line 4303  sub _tree_construction_main ($) {
4303                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4304                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4305                  !!!next-token;                  !!!next-token;
4306                  redo B;                  next B;
4307                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {                } elsif ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4308                  !!!cp ('t137');                  !!!cp ('t137');
4309                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);                  !!!parse-error (type => 'unmatched end tag:noscript', token => $token);
4310                  ## Ignore the token ## ISSUE: An issue in the spec.                  ## Ignore the token ## ISSUE: An issue in the spec.
4311                  !!!next-token;                  !!!next-token;
4312                  redo B;                  next B;
4313                } else {                } else {
4314                  !!!cp ('t138');                  !!!cp ('t138');
4315                  #                  #
# Line 3784  sub _tree_construction_main ($) { Line 4320  sub _tree_construction_main ($) {
4320                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4321                  !!!cp ('t139');                  !!!cp ('t139');
4322                  ## As if <head>                  ## As if <head>
4323                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4324                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4325                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}},
4326                        [$self->{head_element}, $el_category->{head}];
4327    
4328                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4329                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 3795  sub _tree_construction_main ($) { Line 4332  sub _tree_construction_main ($) {
4332                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4333                  ## Ignore the token                  ## Ignore the token
4334                  !!!next-token;                  !!!next-token;
4335                  redo B;                  next B;
4336                } else {                } else {
4337                  !!!cp ('t141');                  !!!cp ('t141');
4338                }                }
# Line 3807  sub _tree_construction_main ($) { Line 4344  sub _tree_construction_main ($) {
4344                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {                if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4345                  !!!cp ('t142');                  !!!cp ('t142');
4346                  ## As if <head>                  ## As if <head>
4347                  !!!create-element ($self->{head_element}, 'head');                  !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4348                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});                  $self->{open_elements}->[-1]->[0]->append_child ($self->{head_element});
4349                  push @{$self->{open_elements}}, [$self->{head_element}, 'head'];                  push @{$self->{open_elements}},
4350                        [$self->{head_element}, $el_category->{head}];
4351    
4352                  $self->{insertion_mode} = IN_HEAD_IM;                  $self->{insertion_mode} = IN_HEAD_IM;
4353                  ## Reprocess in the "in head" insertion mode...                  ## Reprocess in the "in head" insertion mode...
# Line 3827  sub _tree_construction_main ($) { Line 4365  sub _tree_construction_main ($) {
4365                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4366                  ## Ignore the token                  ## Ignore the token
4367                  !!!next-token;                  !!!next-token;
4368                  redo B;                  next B;
4369                }                }
4370              }              }
4371    
# Line 3854  sub _tree_construction_main ($) { Line 4392  sub _tree_construction_main ($) {
4392                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4393                ## Ignore the token ## ISSUE: An issue in the spec.                ## Ignore the token ## ISSUE: An issue in the spec.
4394                !!!next-token;                !!!next-token;
4395                redo B;                next B;
4396              } else {              } else {
4397                !!!cp ('t149');                !!!cp ('t149');
4398              }              }
4399    
4400              ## "after head" insertion mode              ## "after head" insertion mode
4401              ## As if <body>              ## As if <body>
4402              !!!insert-element ('body');              !!!insert-element ('body',, $token);
4403              $self->{insertion_mode} = IN_BODY_IM;              $self->{insertion_mode} = IN_BODY_IM;
4404              ## reprocess              ## reprocess
4405              redo B;              next B;
4406        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4407          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {          if ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4408            !!!cp ('t149.1');            !!!cp ('t149.1');
4409    
4410            ## NOTE: As if <head>            ## NOTE: As if <head>
4411            !!!create-element ($self->{head_element}, 'head');            !!!create-element ($self->{head_element}, $HTML_NS, 'head',, $token);
4412            $self->{open_elements}->[-1]->[0]->append_child            $self->{open_elements}->[-1]->[0]->append_child
4413                ($self->{head_element});                ($self->{head_element});
4414            #push @{$self->{open_elements}}, [$self->{head_element}, 'head'];            #push @{$self->{open_elements}},
4415              #    [$self->{head_element}, $el_category->{head}];
4416            #$self->{insertion_mode} = IN_HEAD_IM;            #$self->{insertion_mode} = IN_HEAD_IM;
4417            ## NOTE: Reprocess.            ## NOTE: Reprocess.
4418    
# Line 3914  sub _tree_construction_main ($) { Line 4453  sub _tree_construction_main ($) {
4453          }          }
4454    
4455          ## NOTE: As if <body>          ## NOTE: As if <body>
4456          !!!insert-element ('body');          !!!insert-element ('body',, $token);
4457          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
4458          ## NOTE: Reprocess.          ## NOTE: Reprocess.
4459          redo B;          next B;
4460        } else {        } else {
4461          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
4462        }        }
# Line 3932  sub _tree_construction_main ($) { Line 4471  sub _tree_construction_main ($) {
4471              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});              $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
4472    
4473              !!!next-token;              !!!next-token;
4474              redo B;              next B;
4475            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
4476              if ({              if ({
4477                   caption => 1, col => 1, colgroup => 1, tbody => 1,                   caption => 1, col => 1, colgroup => 1, tbody => 1,
# Line 3942  sub _tree_construction_main ($) { Line 4481  sub _tree_construction_main ($) {
4481                  ## have an element in table scope                  ## have an element in table scope
4482                  for (reverse 0..$#{$self->{open_elements}}) {                  for (reverse 0..$#{$self->{open_elements}}) {
4483                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4484                    if ($node->[1] eq 'td' or $node->[1] eq 'th') {                    if ($node->[1] & TABLE_CELL_EL) {
4485                      !!!cp ('t151');                      !!!cp ('t151');
4486    
4487                      ## Close the cell                      ## Close the cell
4488                      !!!back-token; # <?>                      !!!back-token; # <x>
4489                      $token = {type => END_TAG_TOKEN, tag_name => $node->[1]};                      $token = {type => END_TAG_TOKEN,
4490                      redo B;                                tag_name => $node->[0]->manakai_local_name,
4491                    } elsif ({                                line => $token->{line},
4492                              table => 1, html => 1,                                column => $token->{column}};
4493                             }->{$node->[1]}) {                      next B;
4494                      } elsif ($node->[1] & TABLE_SCOPING_EL) {
4495                      !!!cp ('t152');                      !!!cp ('t152');
4496                      ## ISSUE: This case can never be reached, maybe.                      ## ISSUE: This case can never be reached, maybe.
4497                      last;                      last;
# Line 3962  sub _tree_construction_main ($) { Line 4502  sub _tree_construction_main ($) {
4502                  !!!parse-error (type => 'start tag not allowed',                  !!!parse-error (type => 'start tag not allowed',
4503                      value => $token->{tag_name}, token => $token);                      value => $token->{tag_name}, token => $token);
4504                  ## Ignore the token                  ## Ignore the token
4505                    !!!nack ('t153.1');
4506                  !!!next-token;                  !!!next-token;
4507                  redo B;                  next B;
4508                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4509                  !!!parse-error (type => 'not closed:caption', token => $token);                  !!!parse-error (type => 'not closed:caption', token => $token);
4510                                    
# Line 3973  sub _tree_construction_main ($) { Line 4514  sub _tree_construction_main ($) {
4514                  INSCOPE: {                  INSCOPE: {
4515                    for (reverse 0..$#{$self->{open_elements}}) {                    for (reverse 0..$#{$self->{open_elements}}) {
4516                      my $node = $self->{open_elements}->[$_];                      my $node = $self->{open_elements}->[$_];
4517                      if ($node->[1] eq 'caption') {                      if ($node->[1] & CAPTION_EL) {
4518                        !!!cp ('t155');                        !!!cp ('t155');
4519                        $i = $_;                        $i = $_;
4520                        last INSCOPE;                        last INSCOPE;
4521                      } elsif ({                      } elsif ($node->[1] & TABLE_SCOPING_EL) {
                               table => 1, html => 1,  
                              }->{$node->[1]}) {  
4522                        !!!cp ('t156');                        !!!cp ('t156');
4523                        last;                        last;
4524                      }                      }
# Line 3989  sub _tree_construction_main ($) { Line 4528  sub _tree_construction_main ($) {
4528                    !!!parse-error (type => 'start tag not allowed',                    !!!parse-error (type => 'start tag not allowed',
4529                                    value => $token->{tag_name}, token => $token);                                    value => $token->{tag_name}, token => $token);
4530                    ## Ignore the token                    ## Ignore the token
4531                      !!!nack ('t157.1');
4532                    !!!next-token;                    !!!next-token;
4533                    redo B;                    next B;
4534                  } # INSCOPE                  } # INSCOPE
4535                                    
4536                  ## generate implied end tags                  ## generate implied end tags
4537                  while ({                  while ($self->{open_elements}->[-1]->[1]
4538                          dd => 1, dt => 1, li => 1, p => 1,                             & END_TAG_OPTIONAL_EL) {
                        }->{$self->{open_elements}->[-1]->[1]}) {  
4539                    !!!cp ('t158');                    !!!cp ('t158');
4540                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4541                  }                  }
4542    
4543                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4544                    !!!cp ('t159');                    !!!cp ('t159');
4545                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);                    !!!parse-error (type => 'not closed',
4546                                      value => $self->{open_elements}->[-1]->[0]
4547                                          ->manakai_local_name,
4548                                      token => $token);
4549                  } else {                  } else {
4550                    !!!cp ('t160');                    !!!cp ('t160');
4551                  }                  }
# Line 4015  sub _tree_construction_main ($) { Line 4557  sub _tree_construction_main ($) {
4557                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4558                                    
4559                  ## reprocess                  ## reprocess
4560                  redo B;                  !!!ack-later;
4561                    next B;
4562                } else {                } else {
4563                  !!!cp ('t161');                  !!!cp ('t161');
4564                  #                  #
# Line 4031  sub _tree_construction_main ($) { Line 4574  sub _tree_construction_main ($) {
4574                  my $i;                  my $i;
4575                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4576                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4577                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[0]->manakai_local_name eq $token->{tag_name}) {
4578                      !!!cp ('t163');                      !!!cp ('t163');
4579                      $i = $_;                      $i = $_;
4580                      last INSCOPE;                      last INSCOPE;
4581                    } elsif ({                    } elsif ($node->[1] & TABLE_SCOPING_EL) {
                             table => 1, html => 1,  
                            }->{$node->[1]}) {  
4582                      !!!cp ('t164');                      !!!cp ('t164');
4583                      last INSCOPE;                      last INSCOPE;
4584                    }                    }
# Line 4047  sub _tree_construction_main ($) { Line 4588  sub _tree_construction_main ($) {
4588                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4589                      ## Ignore the token                      ## Ignore the token
4590                      !!!next-token;                      !!!next-token;
4591                      redo B;                      next B;
4592                    }                    }
4593                                    
4594                  ## generate implied end tags                  ## generate implied end tags
4595                  while ({                  while ($self->{open_elements}->[-1]->[1]
4596                          dd => 1, dt => 1, li => 1, p => 1,                             & END_TAG_OPTIONAL_EL) {
                        }->{$self->{open_elements}->[-1]->[1]}) {  
4597                    !!!cp ('t166');                    !!!cp ('t166');
4598                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4599                  }                  }
4600    
4601                  if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {                  if ($self->{open_elements}->[-1]->[0]->manakai_local_name
4602                            ne $token->{tag_name}) {
4603                    !!!cp ('t167');                    !!!cp ('t167');
4604                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);                    !!!parse-error (type => 'not closed',
4605                                      value => $self->{open_elements}->[-1]->[0]
4606                                          ->manakai_local_name,
4607                                      token => $token);
4608                  } else {                  } else {
4609                    !!!cp ('t168');                    !!!cp ('t168');
4610                  }                  }
# Line 4072  sub _tree_construction_main ($) { Line 4616  sub _tree_construction_main ($) {
4616                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
4617                                    
4618                  !!!next-token;                  !!!next-token;
4619                  redo B;                  next B;
4620                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {                } elsif ($self->{insertion_mode} == IN_CAPTION_IM) {
4621                  !!!cp ('t169');                  !!!cp ('t169');
4622                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4623                  ## Ignore the token                  ## Ignore the token
4624                  !!!next-token;                  !!!next-token;
4625                  redo B;                  next B;
4626                } else {                } else {
4627                  !!!cp ('t170');                  !!!cp ('t170');
4628                  #                  #
# Line 4090  sub _tree_construction_main ($) { Line 4634  sub _tree_construction_main ($) {
4634                  INSCOPE: {                  INSCOPE: {
4635                    for (reverse 0..$#{$self->{open_elements}}) {                    for (reverse 0..$#{$self->{open_elements}}) {
4636                      my $node = $self->{open_elements}->[$_];                      my $node = $self->{open_elements}->[$_];
4637                      if ($node->[1] eq $token->{tag_name}) {                      if ($node->[1] & CAPTION_EL) {
4638                        !!!cp ('t171');                        !!!cp ('t171');
4639                        $i = $_;                        $i = $_;
4640                        last INSCOPE;                        last INSCOPE;
4641                      } elsif ({                      } elsif ($node->[1] & TABLE_SCOPING_EL) {
                               table => 1, html => 1,  
                              }->{$node->[1]}) {  
4642                        !!!cp ('t172');                        !!!cp ('t172');
4643                        last;                        last;
4644                      }                      }
# Line 4107  sub _tree_construction_main ($) { Line 4649  sub _tree_construction_main ($) {
4649                                    value => $token->{tag_name}, token => $token);                                    value => $token->{tag_name}, token => $token);
4650                    ## Ignore the token                    ## Ignore the token
4651                    !!!next-token;                    !!!next-token;
4652                    redo B;                    next B;
4653                  } # INSCOPE                  } # INSCOPE
4654                                    
4655                  ## generate implied end tags                  ## generate implied end tags
4656                  while ({                  while ($self->{open_elements}->[-1]->[1]
4657                          dd => 1, dt => 1, li => 1, p => 1,                             & END_TAG_OPTIONAL_EL) {
                        }->{$self->{open_elements}->[-1]->[1]}) {  
4658                    !!!cp ('t174');                    !!!cp ('t174');
4659                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4660                  }                  }
4661                                    
4662                  if ($self->{open_elements}->[-1]->[1] ne 'caption') {                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4663                    !!!cp ('t175');                    !!!cp ('t175');
4664                    !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);                    !!!parse-error (type => 'not closed',
4665                                      value => $self->{open_elements}->[-1]->[0]
4666                                          ->manakai_local_name,
4667                                      token => $token);
4668                  } else {                  } else {
4669                    !!!cp ('t176');                    !!!cp ('t176');
4670                  }                  }
# Line 4132  sub _tree_construction_main ($) { Line 4676  sub _tree_construction_main ($) {
4676                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
4677                                    
4678                  !!!next-token;                  !!!next-token;
4679                  redo B;                  next B;
4680                } elsif ($self->{insertion_mode} == IN_CELL_IM) {                } elsif ($self->{insertion_mode} == IN_CELL_IM) {
4681                  !!!cp ('t177');                  !!!cp ('t177');
4682                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4683                  ## Ignore the token                  ## Ignore the token
4684                  !!!next-token;                  !!!next-token;
4685                  redo B;                  next B;
4686                } else {                } else {
4687                  !!!cp ('t178');                  !!!cp ('t178');
4688                  #                  #
# Line 4154  sub _tree_construction_main ($) { Line 4698  sub _tree_construction_main ($) {
4698                INSCOPE: {                INSCOPE: {
4699                  for (reverse 0..$#{$self->{open_elements}}) {                  for (reverse 0..$#{$self->{open_elements}}) {
4700                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4701                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[0]->manakai_local_name eq $token->{tag_name}) {
4702                      !!!cp ('t179');                      !!!cp ('t179');
4703                      $i = $_;                      $i = $_;
4704    
4705                      ## Close the cell                      ## Close the cell
4706                      !!!back-token; # </?>                      !!!back-token; # </x>
4707                      $token = {type => END_TAG_TOKEN, tag_name => $tn};                      $token = {type => END_TAG_TOKEN, tag_name => $tn,
4708                      redo B;                                line => $token->{line},
4709                    } elsif ($node->[1] eq 'td' or $node->[1] eq 'th') {                                column => $token->{column}};
4710                        next B;
4711                      } elsif ($node->[1] & TABLE_CELL_EL) {
4712                      !!!cp ('t180');                      !!!cp ('t180');
4713                      $tn = $node->[1];                      $tn = $node->[0]->manakai_local_name;
4714                      ## NOTE: There is exactly one |td| or |th| element                      ## NOTE: There is exactly one |td| or |th| element
4715                      ## in scope in the stack of open elements by definition.                      ## in scope in the stack of open elements by definition.
4716                    } elsif ({                    } elsif ($node->[1] & TABLE_SCOPING_EL) {
                             table => 1, html => 1,  
                            }->{$node->[1]}) {  
4717                      ## ISSUE: Can this be reached?                      ## ISSUE: Can this be reached?
4718                      !!!cp ('t181');                      !!!cp ('t181');
4719                      last;                      last;
# Line 4181  sub _tree_construction_main ($) { Line 4725  sub _tree_construction_main ($) {
4725                      value => $token->{tag_name}, token => $token);                      value => $token->{tag_name}, token => $token);
4726                  ## Ignore the token                  ## Ignore the token
4727                  !!!next-token;                  !!!next-token;
4728                  redo B;                  next B;
4729                } # INSCOPE                } # INSCOPE
4730              } elsif ($token->{tag_name} eq 'table' and              } elsif ($token->{tag_name} eq 'table' and
4731                       $self->{insertion_mode} == IN_CAPTION_IM) {                       $self->{insertion_mode} == IN_CAPTION_IM) {
# Line 4192  sub _tree_construction_main ($) { Line 4736  sub _tree_construction_main ($) {
4736                my $i;                my $i;
4737                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4738                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
4739                  if ($node->[1] eq 'caption') {                  if ($node->[1] & CAPTION_EL) {
4740                    !!!cp ('t184');                    !!!cp ('t184');
4741                    $i = $_;                    $i = $_;
4742                    last INSCOPE;                    last INSCOPE;
4743                  } elsif ({                  } elsif ($node->[1] & TABLE_SCOPING_EL) {
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
4744                    !!!cp ('t185');                    !!!cp ('t185');
4745                    last INSCOPE;                    last INSCOPE;
4746                  }                  }
# Line 4208  sub _tree_construction_main ($) { Line 4750  sub _tree_construction_main ($) {
4750                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);                  !!!parse-error (type => 'unmatched end tag:caption', token => $token);
4751                  ## Ignore the token                  ## Ignore the token
4752                  !!!next-token;                  !!!next-token;
4753                  redo B;                  next B;
4754                }                }
4755                                
4756                ## generate implied end tags                ## generate implied end tags
4757                while ({                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
                       dd => 1, dt => 1, li => 1, p => 1,  
                      }->{$self->{open_elements}->[-1]->[1]}) {  
4758                  !!!cp ('t187');                  !!!cp ('t187');
4759                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4760                }                }
4761    
4762                if ($self->{open_elements}->[-1]->[1] ne 'caption') {                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {
4763                  !!!cp ('t188');                  !!!cp ('t188');
4764                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);                  !!!parse-error (type => 'not closed',
4765                                    value => $self->{open_elements}->[-1]->[0]
4766                                        ->manakai_local_name,
4767                                    token => $token);
4768                } else {                } else {
4769                  !!!cp ('t189');                  !!!cp ('t189');
4770                }                }
# Line 4233  sub _tree_construction_main ($) { Line 4776  sub _tree_construction_main ($) {
4776                $self->{insertion_mode} = IN_TABLE_IM;                $self->{insertion_mode} = IN_TABLE_IM;
4777    
4778                ## reprocess                ## reprocess
4779                redo B;                next B;
4780              } elsif ({              } elsif ({
4781                        body => 1, col => 1, colgroup => 1, html => 1,                        body => 1, col => 1, colgroup => 1, html => 1,
4782                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
# Line 4242  sub _tree_construction_main ($) { Line 4785  sub _tree_construction_main ($) {
4785                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4786                  ## Ignore the token                  ## Ignore the token
4787                  !!!next-token;                  !!!next-token;
4788                  redo B;                  next B;
4789                } else {                } else {
4790                  !!!cp ('t191');                  !!!cp ('t191');
4791                  #                  #
# Line 4256  sub _tree_construction_main ($) { Line 4799  sub _tree_construction_main ($) {
4799                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
4800                ## Ignore the token                ## Ignore the token
4801                !!!next-token;                !!!next-token;
4802                redo B;                next B;
4803              } else {              } else {
4804                !!!cp ('t193');                !!!cp ('t193');
4805                #                #
4806              }              }
4807        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4808          for my $entry (@{$self->{open_elements}}) {          for my $entry (@{$self->{open_elements}}) {
4809            if (not {            unless ($entry->[1] & ALL_END_TAG_OPTIONAL_EL) {
             dd => 1, dt => 1, li => 1, p => 1, tbody => 1, td => 1, tfoot => 1,  
             th => 1, thead => 1, tr => 1, body => 1, html => 1,  
           }->{$entry->[1]}) {  
4810              !!!cp ('t75');              !!!cp ('t75');
4811              !!!parse-error (type => 'in body:#eof', token => $token);              !!!parse-error (type => 'in body:#eof', token => $token);
4812              last;              last;
# Line 4290  sub _tree_construction_main ($) { Line 4830  sub _tree_construction_main ($) {
4830            unless (length $token->{data}) {            unless (length $token->{data}) {
4831              !!!cp ('t194');              !!!cp ('t194');
4832              !!!next-token;              !!!next-token;
4833              redo B;              next B;
4834            } else {            } else {
4835              !!!cp ('t195');              !!!cp ('t195');
4836            }            }
# Line 4304  sub _tree_construction_main ($) { Line 4844  sub _tree_construction_main ($) {
4844              ## result in a new Text node.              ## result in a new Text node.
4845              $reconstruct_active_formatting_elements->($insert_to_foster);              $reconstruct_active_formatting_elements->($insert_to_foster);
4846                            
4847              if ({              if ($self->{open_elements}->[-1]->[1] & TABLE_ROWS_EL) {
                  table => 1, tbody => 1, tfoot => 1,  
                  thead => 1, tr => 1,  
                 }->{$self->{open_elements}->[-1]->[1]}) {  
4848                # MUST                # MUST
4849                my $foster_parent_element;                my $foster_parent_element;
4850                my $next_sibling;                my $next_sibling;
4851                my $prev_sibling;                my $prev_sibling;
4852                OE: for (reverse 0..$#{$self->{open_elements}}) {                OE: for (reverse 0..$#{$self->{open_elements}}) {
4853                  if ($self->{open_elements}->[$_]->[1] eq 'table') {                  if ($self->{open_elements}->[$_]->[1] & TABLE_EL) {
4854                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
4855                    if (defined $parent and $parent->node_type == 1) {                    if (defined $parent and $parent->node_type == 1) {
4856                      !!!cp ('t196');                      !!!cp ('t196');
# Line 4348  sub _tree_construction_main ($) { Line 4885  sub _tree_construction_main ($) {
4885          }          }
4886                            
4887          !!!next-token;          !!!next-token;
4888          redo B;          next B;
4889        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
4890              if ({              if ({
4891                   tr => ($self->{insertion_mode} != IN_ROW_IM),                   tr => ($self->{insertion_mode} != IN_ROW_IM),
# Line 4356  sub _tree_construction_main ($) { Line 4893  sub _tree_construction_main ($) {
4893                  }->{$token->{tag_name}}) {                  }->{$token->{tag_name}}) {
4894                if ($self->{insertion_mode} == IN_TABLE_IM) {                if ($self->{insertion_mode} == IN_TABLE_IM) {
4895                  ## Clear back to table context                  ## Clear back to table context
4896                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while (not ($self->{open_elements}->[-1]->[1]
4897                         $self->{open_elements}->[-1]->[1] ne 'html') {                                  & TABLE_SCOPING_EL)) {
4898                    !!!cp ('t201');                    !!!cp ('t201');
4899                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
4900                  }                  }
4901                                    
4902                  !!!insert-element ('tbody');                  !!!insert-element ('tbody',, $token);
4903                  $self->{insertion_mode} = IN_TABLE_BODY_IM;                  $self->{insertion_mode} = IN_TABLE_BODY_IM;
4904                  ## reprocess in the "in table body" insertion mode...                  ## reprocess in the "in table body" insertion mode...
4905                }                }
# Line 4374  sub _tree_construction_main ($) { Line 4911  sub _tree_construction_main ($) {
4911                  }                  }
4912                                    
4913                  ## Clear back to table body context                  ## Clear back to table body context
4914                  while (not {                  while (not ($self->{open_elements}->[-1]->[1]
4915                    tbody => 1, tfoot => 1, thead => 1, html => 1,                                  & TABLE_ROWS_SCOPING_EL)) {
                 }->{$self->{open_elements}->[-1]->[1]}) {  
4916                    !!!cp ('t203');                    !!!cp ('t203');
4917                    ## ISSUE: Can this case be reached?                    ## ISSUE: Can this case be reached?
4918                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
# Line 4385  sub _tree_construction_main ($) { Line 4921  sub _tree_construction_main ($) {
4921                  $self->{insertion_mode} = IN_ROW_IM;                  $self->{insertion_mode} = IN_ROW_IM;
4922                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4923                    !!!cp ('t204');                    !!!cp ('t204');
4924                    !!!insert-element ($token->{tag_name}, $token->{attributes});                    !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
4925                      !!!nack ('t204');
4926                    !!!next-token;                    !!!next-token;
4927                    redo B;                    next B;
4928                  } else {                  } else {
4929                    !!!cp ('t205');                    !!!cp ('t205');
4930                    !!!insert-element ('tr');                    !!!insert-element ('tr',, $token);
4931                    ## reprocess in the "in row" insertion mode                    ## reprocess in the "in row" insertion mode
4932                  }                  }
4933                } else {                } else {
# Line 4398  sub _tree_construction_main ($) { Line 4935  sub _tree_construction_main ($) {
4935                }                }
4936    
4937                ## Clear back to table row context                ## Clear back to table row context
4938                while (not {                while (not ($self->{open_elements}->[-1]->[1]
4939                  tr => 1, html => 1,                                & TABLE_ROW_SCOPING_EL)) {
               }->{$self->{open_elements}->[-1]->[1]}) {  
4940                  !!!cp ('t207');                  !!!cp ('t207');
4941                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
4942                }                }
4943                                
4944                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
4945                $self->{insertion_mode} = IN_CELL_IM;                $self->{insertion_mode} = IN_CELL_IM;
4946    
4947                push @$active_formatting_elements, ['#marker', ''];                push @$active_formatting_elements, ['#marker', ''];
4948                                
4949                  !!!nack ('t207.1');
4950                !!!next-token;                !!!next-token;
4951                redo B;                next B;
4952              } elsif ({              } elsif ({
4953                        caption => 1, col => 1, colgroup => 1,                        caption => 1, col => 1, colgroup => 1,
4954                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
# Line 4423  sub _tree_construction_main ($) { Line 4960  sub _tree_construction_main ($) {
4960                  my $i;                  my $i;
4961                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
4962                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
4963                    if ($node->[1] eq 'tr') {                    if ($node->[1] & TABLE_ROW_EL) {
4964                      !!!cp ('t208');                      !!!cp ('t208');
4965                      $i = $_;                      $i = $_;
4966                      last INSCOPE;                      last INSCOPE;
4967                    } elsif ({                    } elsif ($node->[1] & TABLE_SCOPING_EL) {
                             html => 1,  
   
                             ## NOTE: This element does not appear here, maybe.  
                             table => 1,  
                            }->{$node->[1]}) {  
4968                      !!!cp ('t209');                      !!!cp ('t209');
4969                      last INSCOPE;                      last INSCOPE;
4970                    }                    }
4971                  } # INSCOPE                  } # INSCOPE
4972                  unless (defined $i) {                  unless (defined $i) {
4973                   !!!cp ('t210');                    !!!cp ('t210');
4974  ## TODO: This type is wrong.  ## TODO: This type is wrong.
4975                   !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmacthed end tag:'.$token->{tag_name}, token => $token);
4976                    ## Ignore the token                    ## Ignore the token
4977                      !!!nack ('t210.1');
4978                    !!!next-token;                    !!!next-token;
4979                    redo B;                    next B;
4980                  }                  }
4981                                    
4982                  ## Clear back to table row context                  ## Clear back to table row context
4983                  while (not {                  while (not ($self->{open_elements}->[-1]->[1]
4984                    tr => 1, html => 1,                                  & TABLE_ROW_SCOPING_EL)) {
                 }->{$self->{open_elements}->[-1]->[1]}) {  
4985                    !!!cp ('t211');                    !!!cp ('t211');
4986                    ## ISSUE: Can this case be reached?                    ## ISSUE: Can this case be reached?
4987                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
# Line 4460  sub _tree_construction_main ($) { Line 4992  sub _tree_construction_main ($) {
4992                  if ($token->{tag_name} eq 'tr') {                  if ($token->{tag_name} eq 'tr') {
4993                    !!!cp ('t212');                    !!!cp ('t212');
4994                    ## reprocess                    ## reprocess
4995                    redo B;                    !!!ack-later;
4996                      next B;
4997                  } else {                  } else {
4998                    !!!cp ('t213');                    !!!cp ('t213');
4999                    ## reprocess in the "in table body" insertion mode...                    ## reprocess in the "in table body" insertion mode...
# Line 4472  sub _tree_construction_main ($) { Line 5005  sub _tree_construction_main ($) {
5005                  my $i;                  my $i;
5006                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5007                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
5008                    if ({                    if ($node->[1] & TABLE_ROW_GROUP_EL) {
                        tbody => 1, thead => 1, tfoot => 1,  
                       }->{$node->[1]}) {  
5009                      !!!cp ('t214');                      !!!cp ('t214');
5010                      $i = $_;                      $i = $_;
5011                      last INSCOPE;                      last INSCOPE;
5012                    } elsif ({                    } elsif ($node->[1] & TABLE_SCOPING_EL) {
                             table => 1, html => 1,  
                            }->{$node->[1]}) {  
5013                      !!!cp ('t215');                      !!!cp ('t215');
5014                      last INSCOPE;                      last INSCOPE;
5015                    }                    }
# Line 4490  sub _tree_construction_main ($) { Line 5019  sub _tree_construction_main ($) {
5019  ## TODO: This erorr type ios wrong.  ## TODO: This erorr type ios wrong.
5020                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5021                    ## Ignore the token                    ## Ignore the token
5022                      !!!nack ('t216.1');
5023                    !!!next-token;                    !!!next-token;
5024                    redo B;                    next B;
5025                  }                  }
5026    
5027                  ## Clear back to table body context                  ## Clear back to table body context
5028                  while (not {                  while (not ($self->{open_elements}->[-1]->[1]
5029                    tbody => 1, tfoot => 1, thead => 1, html => 1,                                  & TABLE_ROWS_SCOPING_EL)) {
                 }->{$self->{open_elements}->[-1]->[1]}) {  
5030                    !!!cp ('t217');                    !!!cp ('t217');
5031                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
5032                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
# Line 4519  sub _tree_construction_main ($) { Line 5048  sub _tree_construction_main ($) {
5048    
5049                if ($token->{tag_name} eq 'col') {                if ($token->{tag_name} eq 'col') {
5050                  ## Clear back to table context                  ## Clear back to table context
5051                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while (not ($self->{open_elements}->[-1]->[1]
5052                         $self->{open_elements}->[-1]->[1] ne 'html') {                                  & TABLE_SCOPING_EL)) {
5053                    !!!cp ('t219');                    !!!cp ('t219');
5054                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
5055                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
5056                  }                  }
5057                                    
5058                  !!!insert-element ('colgroup');                  !!!insert-element ('colgroup',, $token);
5059                  $self->{insertion_mode} = IN_COLUMN_GROUP_IM;                  $self->{insertion_mode} = IN_COLUMN_GROUP_IM;
5060                  ## reprocess                  ## reprocess
5061                  redo B;                  !!!ack-later;
5062                    next B;
5063                } elsif ({                } elsif ({
5064                          caption => 1,                          caption => 1,
5065                          colgroup => 1,                          colgroup => 1,
5066                          tbody => 1, tfoot => 1, thead => 1,                          tbody => 1, tfoot => 1, thead => 1,
5067                         }->{$token->{tag_name}}) {                         }->{$token->{tag_name}}) {
5068                  ## Clear back to table context                  ## Clear back to table context
5069                  while ($self->{open_elements}->[-1]->[1] ne 'table' and                  while (not ($self->{open_elements}->[-1]->[1]
5070                         $self->{open_elements}->[-1]->[1] ne 'html') {                                  & TABLE_SCOPING_EL)) {
5071                    !!!cp ('t220');                    !!!cp ('t220');
5072                    ## ISSUE: Can this state be reached?                    ## ISSUE: Can this state be reached?
5073                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
# Line 4546  sub _tree_construction_main ($) { Line 5076  sub _tree_construction_main ($) {
5076                  push @$active_formatting_elements, ['#marker', '']                  push @$active_formatting_elements, ['#marker', '']
5077                      if $token->{tag_name} eq 'caption';                      if $token->{tag_name} eq 'caption';
5078                                    
5079                  !!!insert-element ($token->{tag_name}, $token->{attributes});                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5080                  $self->{insertion_mode} = {                  $self->{insertion_mode} = {
5081                                             caption => IN_CAPTION_IM,                                             caption => IN_CAPTION_IM,
5082                                             colgroup => IN_COLUMN_GROUP_IM,                                             colgroup => IN_COLUMN_GROUP_IM,
# Line 4555  sub _tree_construction_main ($) { Line 5085  sub _tree_construction_main ($) {
5085                                             thead => IN_TABLE_BODY_IM,                                             thead => IN_TABLE_BODY_IM,
5086                                            }->{$token->{tag_name}};                                            }->{$token->{tag_name}};
5087                  !!!next-token;                  !!!next-token;
5088                  redo B;                  !!!nack ('t220.1');
5089                    next B;
5090                } else {                } else {
5091                  die "$0: in table: <>: $token->{tag_name}";                  die "$0: in table: <>: $token->{tag_name}";
5092                }                }
5093              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5094                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);                !!!parse-error (type => 'not closed',
5095                                  value => $self->{open_elements}->[-1]->[0]
5096                                      ->manakai_local_name,
5097                                  token => $token);
5098    
5099                ## As if </table>                ## As if </table>
5100                ## have a table element in table scope                ## have a table element in table scope
5101                my $i;                my $i;
5102                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5103                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5104                  if ($node->[1] eq 'table') {                  if ($node->[1] & TABLE_EL) {
5105                    !!!cp ('t221');                    !!!cp ('t221');
5106                    $i = $_;                    $i = $_;
5107                    last INSCOPE;                    last INSCOPE;
5108                  } elsif ({                  } elsif ($node->[1] & TABLE_SCOPING_EL) {
                           #table => 1,  
                           html => 1,  
                          }->{$node->[1]}) {  
5109                    !!!cp ('t222');                    !!!cp ('t222');
5110                    last INSCOPE;                    last INSCOPE;
5111                  }                  }
# Line 4584  sub _tree_construction_main ($) { Line 5115  sub _tree_construction_main ($) {
5115  ## TODO: The following is wrong, maybe.  ## TODO: The following is wrong, maybe.
5116                  !!!parse-error (type => 'unmatched end tag:table', token => $token);                  !!!parse-error (type => 'unmatched end tag:table', token => $token);
5117                  ## Ignore tokens </table><table>                  ## Ignore tokens </table><table>
5118                    !!!nack ('t223.1');
5119                  !!!next-token;                  !!!next-token;
5120                  redo B;                  next B;
5121                }                }
5122                                
5123  ## TODO: Followings are removed from the latest spec.  ## TODO: Followings are removed from the latest spec.
5124                ## generate implied end tags                ## generate implied end tags
5125                while ({                while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
                       dd => 1, dt => 1, li => 1, p => 1,  
                      }->{$self->{open_elements}->[-1]->[1]}) {  
5126                  !!!cp ('t224');                  !!!cp ('t224');
5127                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5128                }                }
5129    
5130                if ($self->{open_elements}->[-1]->[1] ne 'table') {                unless ($self->{open_elements}->[-1]->[1] & TABLE_EL) {
5131                  !!!cp ('t225');                  !!!cp ('t225');
5132  ## ISSUE: Can this case be reached?                  ## NOTE: |<table><tr><table>|
5133                  !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);                  !!!parse-error (type => 'not closed',
5134                                    value => $self->{open_elements}->[-1]->[0]
5135                                        ->manakai_local_name,
5136                                    token => $token);
5137                } else {                } else {
5138                  !!!cp ('t226');                  !!!cp ('t226');
5139                }                }
# Line 4610  sub _tree_construction_main ($) { Line 5143  sub _tree_construction_main ($) {
5143    
5144                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
5145    
5146                ## reprocess            ## reprocess
5147                redo B;            !!!ack-later;
5148              next B;
5149          } elsif ($token->{tag_name} eq 'style') {          } elsif ($token->{tag_name} eq 'style') {
5150            if (not $open_tables->[-1]->[1]) { # tainted            if (not $open_tables->[-1]->[1]) { # tainted
5151              !!!cp ('t227.8');              !!!cp ('t227.8');
5152              ## NOTE: This is a "as if in head" code clone.              ## NOTE: This is a "as if in head" code clone.
5153              $parse_rcdata->(CDATA_CONTENT_MODEL);              $parse_rcdata->(CDATA_CONTENT_MODEL);
5154              redo B;              next B;
5155            } else {            } else {
5156              !!!cp ('t227.7');              !!!cp ('t227.7');
5157              #              #
# Line 4627  sub _tree_construction_main ($) { Line 5161  sub _tree_construction_main ($) {
5161              !!!cp ('t227.6');              !!!cp ('t227.6');
5162              ## NOTE: This is a "as if in head" code clone.              ## NOTE: This is a "as if in head" code clone.
5163              $script_start_tag->();              $script_start_tag->();
5164              redo B;              next B;
5165            } else {            } else {
5166              !!!cp ('t227.5');              !!!cp ('t227.5');
5167              #              #
# Line 4640  sub _tree_construction_main ($) { Line 5174  sub _tree_construction_main ($) {
5174                  !!!cp ('t227.3');                  !!!cp ('t227.3');
5175                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'in table:'.$token->{tag_name}, token => $token);
5176    
5177                  !!!insert-element ($token->{tag_name}, $token->{attributes});                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5178    
5179                  ## TODO: form element pointer                  ## TODO: form element pointer
5180    
5181                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5182    
5183                  !!!next-token;                  !!!next-token;
5184                  redo B;                  !!!ack ('t227.2.1');
5185                    next B;
5186                } else {                } else {
5187                  !!!cp ('t227.2');                  !!!cp ('t227.2');
5188                  #                  #
# Line 4676  sub _tree_construction_main ($) { Line 5211  sub _tree_construction_main ($) {
5211                my $i;                my $i;
5212                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5213                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5214                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] & TABLE_ROW_EL) {
5215                    !!!cp ('t228');                    !!!cp ('t228');
5216                    $i = $_;                    $i = $_;
5217                    last INSCOPE;                    last INSCOPE;
5218                  } elsif ({                  } elsif ($node->[1] & TABLE_SCOPING_EL) {
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
5219                    !!!cp ('t229');                    !!!cp ('t229');
5220                    last INSCOPE;                    last INSCOPE;
5221                  }                  }
# Line 4691  sub _tree_construction_main ($) { Line 5224  sub _tree_construction_main ($) {
5224                  !!!cp ('t230');                  !!!cp ('t230');
5225                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5226                  ## Ignore the token                  ## Ignore the token
5227                    !!!nack ('t230.1');
5228                  !!!next-token;                  !!!next-token;
5229                  redo B;                  next B;
5230                } else {                } else {
5231                  !!!cp ('t232');                  !!!cp ('t232');
5232                }                }
5233    
5234                ## Clear back to table row context                ## Clear back to table row context
5235                while (not {                while (not ($self->{open_elements}->[-1]->[1]
5236                  tr => 1, html => 1,                                & TABLE_ROW_SCOPING_EL)) {
               }->{$self->{open_elements}->[-1]->[1]}) {  
5237                  !!!cp ('t231');                  !!!cp ('t231');
5238  ## ISSUE: Can this state be reached?  ## ISSUE: Can this state be reached?
5239                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4709  sub _tree_construction_main ($) { Line 5242  sub _tree_construction_main ($) {
5242                pop @{$self->{open_elements}}; # tr                pop @{$self->{open_elements}}; # tr
5243                $self->{insertion_mode} = IN_TABLE_BODY_IM;                $self->{insertion_mode} = IN_TABLE_BODY_IM;
5244                !!!next-token;                !!!next-token;
5245                redo B;                !!!nack ('t231.1');
5246                  next B;
5247              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5248                if ($self->{insertion_mode} == IN_ROW_IM) {                if ($self->{insertion_mode} == IN_ROW_IM) {
5249                  ## As if </tr>                  ## As if </tr>
# Line 4717  sub _tree_construction_main ($) { Line 5251  sub _tree_construction_main ($) {
5251                  my $i;                  my $i;
5252                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5253                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
5254                    if ($node->[1] eq 'tr') {                    if ($node->[1] & TABLE_ROW_EL) {
5255                      !!!cp ('t233');                      !!!cp ('t233');
5256                      $i = $_;                      $i = $_;
5257                      last INSCOPE;                      last INSCOPE;
5258                    } elsif ({                    } elsif ($node->[1] & TABLE_SCOPING_EL) {
                             table => 1, html => 1,  
                            }->{$node->[1]}) {  
5259                      !!!cp ('t234');                      !!!cp ('t234');
5260                      last INSCOPE;                      last INSCOPE;
5261                    }                    }
# Line 4733  sub _tree_construction_main ($) { Line 5265  sub _tree_construction_main ($) {
5265  ## TODO: The following is wrong.  ## TODO: The following is wrong.
5266                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);                    !!!parse-error (type => 'unmatched end tag:'.$token->{type}, token => $token);
5267                    ## Ignore the token                    ## Ignore the token
5268                      !!!nack ('t236.1');
5269                    !!!next-token;                    !!!next-token;
5270                    redo B;                    next B;
5271                  }                  }
5272                                    
5273                  ## Clear back to table row context                  ## Clear back to table row context
5274                  while (not {                  while (not ($self->{open_elements}->[-1]->[1]
5275                    tr => 1, html => 1,                                  & TABLE_ROW_SCOPING_EL)) {
                 }->{$self->{open_elements}->[-1]->[1]}) {  
5276                    !!!cp ('t236');                    !!!cp ('t236');
5277  ## ISSUE: Can this state be reached?  ## ISSUE: Can this state be reached?
5278                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
# Line 4756  sub _tree_construction_main ($) { Line 5288  sub _tree_construction_main ($) {
5288                  my $i;                  my $i;
5289                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5290                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
5291                    if ({                    if ($node->[1] & TABLE_ROW_GROUP_EL) {
                        tbody => 1, thead => 1, tfoot => 1,  
                       }->{$node->[1]}) {  
5292                      !!!cp ('t237');                      !!!cp ('t237');
5293                      $i = $_;                      $i = $_;
5294                      last INSCOPE;                      last INSCOPE;
5295                    } elsif ({                    } elsif ($node->[1] & TABLE_SCOPING_EL) {
                             table => 1, html => 1,  
                            }->{$node->[1]}) {  
5296                      !!!cp ('t238');                      !!!cp ('t238');
5297                      last INSCOPE;                      last INSCOPE;
5298                    }                    }
# Line 4773  sub _tree_construction_main ($) { Line 5301  sub _tree_construction_main ($) {
5301                    !!!cp ('t239');                    !!!cp ('t239');
5302                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                    !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5303                    ## Ignore the token                    ## Ignore the token
5304                      !!!nack ('t239.1');
5305                    !!!next-token;                    !!!next-token;
5306                    redo B;                    next B;
5307                  }                  }
5308                                    
5309                  ## Clear back to table body context                  ## Clear back to table body context
5310                  while (not {                  while (not ($self->{open_elements}->[-1]->[1]
5311                    tbody => 1, tfoot => 1, thead => 1, html => 1,                                  & TABLE_ROWS_SCOPING_EL)) {
                 }->{$self->{open_elements}->[-1]->[1]}) {  
5312                    !!!cp ('t240');                    !!!cp ('t240');
5313                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
5314                  }                  }
# Line 4806  sub _tree_construction_main ($) { Line 5334  sub _tree_construction_main ($) {
5334                my $i;                my $i;
5335                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5336                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5337                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[1] & TABLE_EL) {
5338                    !!!cp ('t241');                    !!!cp ('t241');
5339                    $i = $_;                    $i = $_;
5340                    last INSCOPE;                    last INSCOPE;
5341                  } elsif ({                  } elsif ($node->[1] & TABLE_SCOPING_EL) {
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
5342                    !!!cp ('t242');                    !!!cp ('t242');
5343                    last INSCOPE;                    last INSCOPE;
5344                  }                  }
# Line 4821  sub _tree_construction_main ($) { Line 5347  sub _tree_construction_main ($) {
5347                  !!!cp ('t243');                  !!!cp ('t243');
5348                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5349                  ## Ignore the token                  ## Ignore the token
5350                    !!!nack ('t243.1');
5351                  !!!next-token;                  !!!next-token;
5352                  redo B;                  next B;
5353                }                }
5354                                    
5355                splice @{$self->{open_elements}}, $i;                splice @{$self->{open_elements}}, $i;
# Line 4831  sub _tree_construction_main ($) { Line 5358  sub _tree_construction_main ($) {
5358                $self->_reset_insertion_mode;                $self->_reset_insertion_mode;
5359                                
5360                !!!next-token;                !!!next-token;
5361                redo B;                next B;
5362              } elsif ({              } elsif ({
5363                        tbody => 1, tfoot => 1, thead => 1,                        tbody => 1, tfoot => 1, thead => 1,
5364                       }->{$token->{tag_name}} and                       }->{$token->{tag_name}} and
# Line 4841  sub _tree_construction_main ($) { Line 5368  sub _tree_construction_main ($) {
5368                  my $i;                  my $i;
5369                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5370                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
5371                    if ($node->[1] eq $token->{tag_name}) {                    if ($node->[0]->manakai_local_name eq $token->{tag_name}) {
5372                      !!!cp ('t247');                      !!!cp ('t247');
5373                      $i = $_;                      $i = $_;
5374                      last INSCOPE;                      last INSCOPE;
5375                    } elsif ({                    } elsif ($node->[1] & TABLE_SCOPING_EL) {
                             table => 1, html => 1,  
                            }->{$node->[1]}) {  
5376                      !!!cp ('t248');                      !!!cp ('t248');
5377                      last INSCOPE;                      last INSCOPE;
5378                    }                    }
# Line 4856  sub _tree_construction_main ($) { Line 5381  sub _tree_construction_main ($) {
5381                      !!!cp ('t249');                      !!!cp ('t249');
5382                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                      !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5383                      ## Ignore the token                      ## Ignore the token
5384                        !!!nack ('t249.1');
5385                      !!!next-token;                      !!!next-token;
5386                      redo B;                      next B;
5387                    }                    }
5388                                    
5389                  ## As if </tr>                  ## As if </tr>
# Line 4865  sub _tree_construction_main ($) { Line 5391  sub _tree_construction_main ($) {
5391                  my $i;                  my $i;
5392                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5393                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
5394                    if ($node->[1] eq 'tr') {                    if ($node->[1] & TABLE_ROW_EL) {
5395                      !!!cp ('t250');                      !!!cp ('t250');
5396                      $i = $_;                      $i = $_;
5397                      last INSCOPE;                      last INSCOPE;
5398                    } elsif ({                    } elsif ($node->[1] & TABLE_SCOPING_EL) {
                             table => 1, html => 1,  
                            }->{$node->[1]}) {  
5399                      !!!cp ('t251');                      !!!cp ('t251');
5400                      last INSCOPE;                      last INSCOPE;
5401                    }                    }
# Line 4880  sub _tree_construction_main ($) { Line 5404  sub _tree_construction_main ($) {
5404                      !!!cp ('t252');                      !!!cp ('t252');
5405                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);                      !!!parse-error (type => 'unmatched end tag:tr', token => $token);
5406                      ## Ignore the token                      ## Ignore the token
5407                        !!!nack ('t252.1');
5408                      !!!next-token;                      !!!next-token;
5409                      redo B;                      next B;
5410                    }                    }
5411                                    
5412                  ## Clear back to table row context                  ## Clear back to table row context
5413                  while (not {                  while (not ($self->{open_elements}->[-1]->[1]
5414                    tr => 1, html => 1,                                  & TABLE_ROW_SCOPING_EL)) {
                 }->{$self->{open_elements}->[-1]->[1]}) {  
5415                    !!!cp ('t253');                    !!!cp ('t253');
5416  ## ISSUE: Can this case be reached?  ## ISSUE: Can this case be reached?
5417                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
# Line 4902  sub _tree_construction_main ($) { Line 5426  sub _tree_construction_main ($) {
5426                my $i;                my $i;
5427                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5428                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5429                  if ($node->[1] eq $token->{tag_name}) {                  if ($node->[0]->manakai_local_name eq $token->{tag_name}) {
5430                    !!!cp ('t254');                    !!!cp ('t254');
5431                    $i = $_;                    $i = $_;
5432                    last INSCOPE;                    last INSCOPE;
5433                  } elsif ({                  } elsif ($node->[1] & TABLE_SCOPING_EL) {
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
5434                    !!!cp ('t255');                    !!!cp ('t255');
5435                    last INSCOPE;                    last INSCOPE;
5436                  }                  }
# Line 4917  sub _tree_construction_main ($) { Line 5439  sub _tree_construction_main ($) {
5439                  !!!cp ('t256');                  !!!cp ('t256');
5440                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5441                  ## Ignore the token                  ## Ignore the token
5442                    !!!nack ('t256.1');
5443                  !!!next-token;                  !!!next-token;
5444                  redo B;                  next B;
5445                }                }
5446    
5447                ## Clear back to table body context                ## Clear back to table body context
5448                while (not {                while (not ($self->{open_elements}->[-1]->[1]
5449                  tbody => 1, tfoot => 1, thead => 1, html => 1,                                & TABLE_ROWS_SCOPING_EL)) {
               }->{$self->{open_elements}->[-1]->[1]}) {  
5450                  !!!cp ('t257');                  !!!cp ('t257');
5451  ## ISSUE: Can this case be reached?  ## ISSUE: Can this case be reached?
5452                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
# Line 4932  sub _tree_construction_main ($) { Line 5454  sub _tree_construction_main ($) {
5454    
5455                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5456                $self->{insertion_mode} = IN_TABLE_IM;                $self->{insertion_mode} = IN_TABLE_IM;
5457                  !!!nack ('t257.1');
5458                !!!next-token;                !!!next-token;
5459                redo B;                next B;
5460              } elsif ({              } elsif ({
5461                        body => 1, caption => 1, col => 1, colgroup => 1,                        body => 1, caption => 1, col => 1, colgroup => 1,
5462                        html => 1, td => 1, th => 1,                        html => 1, td => 1, th => 1,
5463                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM                        tr => 1, # $self->{insertion_mode} == IN_ROW_IM
5464                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM                        tbody => 1, tfoot => 1, thead => 1, # $self->{insertion_mode} == IN_TABLE_IM
5465                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5466                !!!cp ('t258');            !!!cp ('t258');
5467                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5468                ## Ignore the token            ## Ignore the token
5469                !!!next-token;            !!!nack ('t258.1');
5470                redo B;             !!!next-token;
5471              next B;
5472          } else {          } else {
5473            !!!cp ('t259');            !!!cp ('t259');
5474            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in table:/'.$token->{tag_name}, token => $token);
# Line 4953  sub _tree_construction_main ($) { Line 5477  sub _tree_construction_main ($) {
5477            #            #
5478          }          }
5479        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5480          unless ($self->{open_elements}->[-1]->[1] eq 'html' and          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and
5481                  @{$self->{open_elements}} == 1) { # redundant, maybe                  @{$self->{open_elements}} == 1) { # redundant, maybe
5482            !!!parse-error (type => 'in body:#eof', token => $token);            !!!parse-error (type => 'in body:#eof', token => $token);
5483            !!!cp ('t259.1');            !!!cp ('t259.1');
# Line 4975  sub _tree_construction_main ($) { Line 5499  sub _tree_construction_main ($) {
5499                unless (length $token->{data}) {                unless (length $token->{data}) {
5500                  !!!cp ('t260');                  !!!cp ('t260');
5501                  !!!next-token;                  !!!next-token;
5502                  redo B;                  next B;
5503                }                }
5504              }              }
5505                            
# Line 4984  sub _tree_construction_main ($) { Line 5508  sub _tree_construction_main ($) {
5508            } elsif ($token->{type} == START_TAG_TOKEN) {            } elsif ($token->{type} == START_TAG_TOKEN) {
5509              if ($token->{tag_name} eq 'col') {              if ($token->{tag_name} eq 'col') {
5510                !!!cp ('t262');                !!!cp ('t262');
5511                !!!insert-element ($token->{tag_name}, $token->{attributes});                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5512                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5513                  !!!ack ('t262.1');
5514                !!!next-token;                !!!next-token;
5515                redo B;                next B;
5516              } else {              } else {
5517                !!!cp ('t263');                !!!cp ('t263');
5518                #                #
5519              }              }
5520            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
5521              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
5522                if ($self->{open_elements}->[-1]->[1] eq 'html') {                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5523                  !!!cp ('t264');                  !!!cp ('t264');
5524                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);                  !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);
5525                  ## Ignore the token                  ## Ignore the token
5526                  !!!next-token;                  !!!next-token;
5527                  redo B;                  next B;
5528                } else {                } else {
5529                  !!!cp ('t265');                  !!!cp ('t265');
5530                  pop @{$self->{open_elements}}; # colgroup                  pop @{$self->{open_elements}}; # colgroup
5531                  $self->{insertion_mode} = IN_TABLE_IM;                  $self->{insertion_mode} = IN_TABLE_IM;
5532                  !!!next-token;                  !!!next-token;
5533                  redo B;                              next B;            
5534                }                }
5535              } elsif ($token->{tag_name} eq 'col') {              } elsif ($token->{tag_name} eq 'col') {
5536                !!!cp ('t266');                !!!cp ('t266');
5537                !!!parse-error (type => 'unmatched end tag:col', token => $token);                !!!parse-error (type => 'unmatched end tag:col', token => $token);
5538                ## Ignore the token                ## Ignore the token
5539                !!!next-token;                !!!next-token;
5540                redo B;                next B;
5541              } else {              } else {
5542                !!!cp ('t267');                !!!cp ('t267');
5543                #                #
5544              }              }
5545        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5546          if ($self->{open_elements}->[-1]->[1] eq 'html' or          if ($self->{open_elements}->[-1]->[1] & HTML_EL and
5547              @{$self->{open_elements}} == 1) { # redundant, maybe              @{$self->{open_elements}} == 1) { # redundant, maybe
5548            !!!cp ('t270.2');            !!!cp ('t270.2');
5549            ## Stop parsing.            ## Stop parsing.
# Line 5029  sub _tree_construction_main ($) { Line 5554  sub _tree_construction_main ($) {
5554            pop @{$self->{open_elements}}; # colgroup            pop @{$self->{open_elements}}; # colgroup
5555            $self->{insertion_mode} = IN_TABLE_IM;            $self->{insertion_mode} = IN_TABLE_IM;
5556            ## Reprocess.            ## Reprocess.
5557            redo B;            next B;
5558          }          }
5559        } else {        } else {
5560          die "$0: $token->{type}: Unknown token type";          die "$0: $token->{type}: Unknown token type";
5561        }        }
5562    
5563            ## As if </colgroup>            ## As if </colgroup>
5564            if ($self->{open_elements}->[-1]->[1] eq 'html') {            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {
5565              !!!cp ('t269');              !!!cp ('t269');
5566  ## TODO: Wrong error type?  ## TODO: Wrong error type?
5567              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);              !!!parse-error (type => 'unmatched end tag:colgroup', token => $token);
5568              ## Ignore the token              ## Ignore the token
5569                !!!nack ('t269.1');
5570              !!!next-token;              !!!next-token;
5571              redo B;              next B;
5572            } else {            } else {
5573              !!!cp ('t270');              !!!cp ('t270');
5574              pop @{$self->{open_elements}}; # colgroup              pop @{$self->{open_elements}}; # colgroup
5575              $self->{insertion_mode} = IN_TABLE_IM;              $self->{insertion_mode} = IN_TABLE_IM;
5576                !!!ack-later;
5577              ## reprocess              ## reprocess
5578              redo B;              next B;
5579            }            }
5580      } elsif ($self->{insertion_mode} & SELECT_IMS) {      } elsif ($self->{insertion_mode} & SELECT_IMS) {
5581        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
5582          !!!cp ('t271');          !!!cp ('t271');
5583          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});          $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});
5584          !!!next-token;          !!!next-token;
5585          redo B;          next B;
5586        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5587              if ($token->{tag_name} eq 'option') {          if ($token->{tag_name} eq 'option') {
5588                if ($self->{open_elements}->[-1]->[1] eq 'option') {            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {
5589                  !!!cp ('t272');              !!!cp ('t272');
5590                  ## As if </option>              ## As if </option>
5591                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
5592                } else {            } else {
5593                  !!!cp ('t273');              !!!cp ('t273');
5594                }            }
5595    
5596                !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5597                !!!next-token;            !!!nack ('t273.1');
5598                redo B;            !!!next-token;
5599              } elsif ($token->{tag_name} eq 'optgroup') {            next B;
5600                if ($self->{open_elements}->[-1]->[1] eq 'option') {          } elsif ($token->{tag_name} eq 'optgroup') {
5601                  !!!cp ('t274');            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {
5602                  ## As if </option>              !!!cp ('t274');
5603                  pop @{$self->{open_elements}};              ## As if </option>
5604                } else {              pop @{$self->{open_elements}};
5605                  !!!cp ('t275');            } else {
5606                }              !!!cp ('t275');
5607              }
5608    
5609                if ($self->{open_elements}->[-1]->[1] eq 'optgroup') {            if ($self->{open_elements}->[-1]->[1] & OPTGROUP_EL) {
5610                  !!!cp ('t276');              !!!cp ('t276');
5611                  ## As if </optgroup>              ## As if </optgroup>
5612                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
5613                } else {            } else {
5614                  !!!cp ('t277');              !!!cp ('t277');
5615                }            }
5616    
5617                !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5618                !!!next-token;            !!!nack ('t277.1');
5619                redo B;            !!!next-token;
5620              next B;
5621          } elsif ($token->{tag_name} eq 'select' or          } elsif ($token->{tag_name} eq 'select' or
5622                   $token->{tag_name} eq 'input' or                   $token->{tag_name} eq 'input' or
5623                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and                   ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
# Line 5101  sub _tree_construction_main ($) { Line 5630  sub _tree_construction_main ($) {
5630            !!!parse-error (type => 'not closed:select', token => $token);            !!!parse-error (type => 'not closed:select', token => $token);
5631            ## NOTE: As if the token were </select> (<select> case) or            ## NOTE: As if the token were </select> (<select> case) or
5632            ## as if there were </select> (otherwise).            ## as if there were </select> (otherwise).
5633                ## have an element in table scope            ## have an element in table scope
5634                my $i;            my $i;
5635                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5636                  my $node = $self->{open_elements}->[$_];              my $node = $self->{open_elements}->[$_];
5637                  if ($node->[1] eq 'select') {              if ($node->[1] & SELECT_EL) {
5638                    !!!cp ('t278');                !!!cp ('t278');
5639                    $i = $_;                $i = $_;
5640                    last INSCOPE;                last INSCOPE;
5641                  } elsif ({              } elsif ($node->[1] & TABLE_SCOPING_EL) {
5642                            table => 1, html => 1,                !!!cp ('t279');
5643                           }->{$node->[1]}) {                last INSCOPE;
5644                    !!!cp ('t279');              }
5645                    last INSCOPE;            } # INSCOPE
5646                  }            unless (defined $i) {
5647                } # INSCOPE              !!!cp ('t280');
5648                unless (defined $i) {              !!!parse-error (type => 'unmatched end tag:select', token => $token);
5649                  !!!cp ('t280');              ## Ignore the token
5650                  !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!nack ('t280.1');
5651                  ## Ignore the token              !!!next-token;
5652                  !!!next-token;              next B;
5653                  redo B;            }
               }  
5654                                
5655                !!!cp ('t281');            !!!cp ('t281');
5656                splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
5657    
5658                $self->_reset_insertion_mode;            $self->_reset_insertion_mode;
5659    
5660            if ($token->{tag_name} eq 'select') {            if ($token->{tag_name} eq 'select') {
5661              !!!cp ('t281.2');              !!!nack ('t281.2');
5662              !!!next-token;              !!!next-token;
5663              redo B;              next B;
5664            } else {            } else {
5665              !!!cp ('t281.1');              !!!cp ('t281.1');
5666                !!!ack-later;
5667              ## Reprocess the token.              ## Reprocess the token.
5668              redo B;              next B;
5669            }            }
5670          } else {          } else {
5671            !!!cp ('t282');            !!!cp ('t282');
5672            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:'.$token->{tag_name}, token => $token);
5673            ## Ignore the token            ## Ignore the token
5674              !!!nack ('t282.1');
5675            !!!next-token;            !!!next-token;
5676            redo B;            next B;
5677          }          }
5678        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5679              if ($token->{tag_name} eq 'optgroup') {          if ($token->{tag_name} eq 'optgroup') {
5680                if ($self->{open_elements}->[-1]->[1] eq 'option' and            if ($self->{open_elements}->[-1]->[1] & OPTION_EL and
5681                    $self->{open_elements}->[-2]->[1] eq 'optgroup') {                $self->{open_elements}->[-2]->[1] & OPTGROUP_EL) {
5682                  !!!cp ('t283');              !!!cp ('t283');
5683                  ## As if </option>              ## As if </option>
5684                  splice @{$self->{open_elements}}, -2;              splice @{$self->{open_elements}}, -2;
5685                } elsif ($self->{open_elements}->[-1]->[1] eq 'optgroup') {            } elsif ($self->{open_elements}->[-1]->[1] & OPTGROUP_EL) {
5686                  !!!cp ('t284');              !!!cp ('t284');
5687                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
5688                } else {            } else {
5689                  !!!cp ('t285');              !!!cp ('t285');
5690                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5691                  ## Ignore the token              ## Ignore the token
5692                }            }
5693                !!!next-token;            !!!nack ('t285.1');
5694                redo B;            !!!next-token;
5695              } elsif ($token->{tag_name} eq 'option') {            next B;
5696                if ($self->{open_elements}->[-1]->[1] eq 'option') {          } elsif ($token->{tag_name} eq 'option') {
5697                  !!!cp ('t286');            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {
5698                  pop @{$self->{open_elements}};              !!!cp ('t286');
5699                } else {              pop @{$self->{open_elements}};
5700                  !!!cp ('t287');            } else {
5701                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!cp ('t287');
5702                  ## Ignore the token              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5703                }              ## Ignore the token
5704                !!!next-token;            }
5705                redo B;            !!!nack ('t287.1');
5706              } elsif ($token->{tag_name} eq 'select') {            !!!next-token;
5707                ## have an element in table scope            next B;
5708                my $i;          } elsif ($token->{tag_name} eq 'select') {
5709                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            ## have an element in table scope
5710                  my $node = $self->{open_elements}->[$_];            my $i;
5711                  if ($node->[1] eq $token->{tag_name}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5712                    !!!cp ('t288');              my $node = $self->{open_elements}->[$_];
5713                    $i = $_;              if ($node->[1] & SELECT_EL) {
5714                    last INSCOPE;                !!!cp ('t288');
5715                  } elsif ({                $i = $_;
5716                            table => 1, html => 1,                last INSCOPE;
5717                           }->{$node->[1]}) {              } elsif ($node->[1] & TABLE_SCOPING_EL) {
5718                    !!!cp ('t289');                !!!cp ('t289');
5719                    last INSCOPE;                last INSCOPE;
5720                  }              }
5721                } # INSCOPE            } # INSCOPE
5722                unless (defined $i) {            unless (defined $i) {
5723                  !!!cp ('t290');              !!!cp ('t290');
5724                  !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5725                  ## Ignore the token              ## Ignore the token
5726                  !!!next-token;              !!!nack ('t290.1');
5727                  redo B;              !!!next-token;
5728                }              next B;
5729              }
5730                                
5731                !!!cp ('t291');            !!!cp ('t291');
5732                splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
5733    
5734                $self->_reset_insertion_mode;            $self->_reset_insertion_mode;
5735    
5736                !!!next-token;            !!!nack ('t291.1');
5737                redo B;            !!!next-token;
5738              next B;
5739          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and          } elsif ($self->{insertion_mode} == IN_SELECT_IN_TABLE_IM and
5740                   {                   {
5741                    caption => 1, table => 1, tbody => 1,                    caption => 1, table => 1, tbody => 1,
5742                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,                    tfoot => 1, thead => 1, tr => 1, td => 1, th => 1,
5743                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
5744  ## TODO: The following is wrong?  ## TODO: The following is wrong?
5745                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
5746                                
5747                ## have an element in table scope            ## have an element in table scope
5748                my $i;            my $i;
5749                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5750                  my $node = $self->{open_elements}->[$_];              my $node = $self->{open_elements}->[$_];
5751                  if ($node->[1] eq $token->{tag_name}) {              if ($node->[0]->manakai_local_name eq $token->{tag_name}) {
5752                    !!!cp ('t292');                !!!cp ('t292');
5753                    $i = $_;                $i = $_;
5754                    last INSCOPE;                last INSCOPE;
5755                  } elsif ({              } elsif ($node->[1] & TABLE_SCOPING_EL) {
5756                            table => 1, html => 1,                !!!cp ('t293');
5757                           }->{$node->[1]}) {                last INSCOPE;
5758                    !!!cp ('t293');              }
5759                    last INSCOPE;            } # INSCOPE
5760                  }            unless (defined $i) {
5761                } # INSCOPE              !!!cp ('t294');
5762                unless (defined $i) {              ## Ignore the token
5763                  !!!cp ('t294');              !!!nack ('t294.1');
5764                  ## Ignore the token              !!!next-token;
5765                  !!!next-token;              next B;
5766                  redo B;            }
               }  
5767                                
5768                ## As if </select>            ## As if </select>
5769                ## have an element in table scope            ## have an element in table scope
5770                undef $i;            undef $i;
5771                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5772                  my $node = $self->{open_elements}->[$_];              my $node = $self->{open_elements}->[$_];
5773                  if ($node->[1] eq 'select') {              if ($node->[1] & SELECT_EL) {
5774                    !!!cp ('t295');                !!!cp ('t295');
5775                    $i = $_;                $i = $_;
5776                    last INSCOPE;                last INSCOPE;
5777                  } elsif ({              } elsif ($node->[1] & TABLE_SCOPING_EL) {
                           table => 1, html => 1,  
                          }->{$node->[1]}) {  
5778  ## ISSUE: Can this state be reached?  ## ISSUE: Can this state be reached?
5779                    !!!cp ('t296');                !!!cp ('t296');
5780                    last INSCOPE;                last INSCOPE;
5781                  }              }
5782                } # INSCOPE            } # INSCOPE
5783                unless (defined $i) {            unless (defined $i) {
5784                  !!!cp ('t297');              !!!cp ('t297');
5785  ## TODO: The following error type is correct?  ## TODO: The following error type is correct?
5786                  !!!parse-error (type => 'unmatched end tag:select', token => $token);              !!!parse-error (type => 'unmatched end tag:select', token => $token);
5787                  ## Ignore the </select> token              ## Ignore the </select> token
5788                  !!!next-token; ## TODO: ok?              !!!nack ('t297.1');
5789                  redo B;              !!!next-token; ## TODO: ok?
5790                }              next B;
5791              }
5792                                
5793                !!!cp ('t298');            !!!cp ('t298');
5794                splice @{$self->{open_elements}}, $i;            splice @{$self->{open_elements}}, $i;
5795    
5796                $self->_reset_insertion_mode;            $self->_reset_insertion_mode;
5797    
5798                ## reprocess            !!!ack-later;
5799                redo B;            ## reprocess
5800              next B;
5801          } else {          } else {
5802            !!!cp ('t299');            !!!cp ('t299');
5803            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'in select:/'.$token->{tag_name}, token => $token);
5804            ## Ignore the token            ## Ignore the token
5805              !!!nack ('t299.3');
5806            !!!next-token;            !!!next-token;
5807            redo B;            next B;
5808          }          }
5809        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5810          unless ($self->{open_elements}->[-1]->[1] eq 'html' and          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and
5811                  @{$self->{open_elements}} == 1) { # redundant, maybe                  @{$self->{open_elements}} == 1) { # redundant, maybe
5812            !!!cp ('t299.1');            !!!cp ('t299.1');
5813            !!!parse-error (type => 'in body:#eof', token => $token);            !!!parse-error (type => 'in body:#eof', token => $token);
# Line 5300  sub _tree_construction_main ($) { Line 5832  sub _tree_construction_main ($) {
5832            unless (length $token->{data}) {            unless (length $token->{data}) {
5833              !!!cp ('t300');              !!!cp ('t300');
5834              !!!next-token;              !!!next-token;
5835              redo B;              next B;
5836            }            }
5837          }          }
5838                    
# Line 5318  sub _tree_construction_main ($) { Line 5850  sub _tree_construction_main ($) {
5850    
5851          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
5852          ## reprocess          ## reprocess
5853          redo B;          next B;
5854        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
5855          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5856            !!!cp ('t303');            !!!cp ('t303');
# Line 5333  sub _tree_construction_main ($) { Line 5865  sub _tree_construction_main ($) {
5865          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'after body:'.$token->{tag_name}, token => $token);
5866    
5867          $self->{insertion_mode} = IN_BODY_IM;          $self->{insertion_mode} = IN_BODY_IM;
5868            !!!ack-later;
5869          ## reprocess          ## reprocess
5870          redo B;          next B;
5871        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5872          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {          if ($self->{insertion_mode} == AFTER_HTML_BODY_IM) {
5873            !!!cp ('t305');            !!!cp ('t305');
# Line 5353  sub _tree_construction_main ($) { Line 5886  sub _tree_construction_main ($) {
5886              !!!parse-error (type => 'unmatched end tag:html', token => $token);              !!!parse-error (type => 'unmatched end tag:html', token => $token);
5887              ## Ignore the token              ## Ignore the token
5888              !!!next-token;              !!!next-token;
5889              redo B;              next B;
5890            } else {            } else {
5891              !!!cp ('t308');              !!!cp ('t308');
5892              $self->{insertion_mode} = AFTER_HTML_BODY_IM;              $self->{insertion_mode} = AFTER_HTML_BODY_IM;
5893              !!!next-token;              !!!next-token;
5894              redo B;              next B;
5895            }            }
5896          } else {          } else {
5897            !!!cp ('t309');            !!!cp ('t309');
# Line 5366  sub _tree_construction_main ($) { Line 5899  sub _tree_construction_main ($) {
5899    
5900            $self->{insertion_mode} = IN_BODY_IM;            $self->{insertion_mode} = IN_BODY_IM;
5901            ## reprocess            ## reprocess
5902            redo B;            next B;
5903          }          }
5904        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
5905          !!!cp ('t309.2');          !!!cp ('t309.2');
# Line 5383  sub _tree_construction_main ($) { Line 5916  sub _tree_construction_main ($) {
5916            unless (length $token->{data}) {            unless (length $token->{data}) {
5917              !!!cp ('t310');              !!!cp ('t310');
5918              !!!next-token;              !!!next-token;
5919              redo B;              next B;
5920            }            }
5921          }          }
5922                    
# Line 5411  sub _tree_construction_main ($) { Line 5944  sub _tree_construction_main ($) {
5944              !!!cp ('t315');              !!!cp ('t315');
5945              !!!next-token;              !!!next-token;
5946            }            }
5947            redo B;            next B;
5948          }          }
5949                    
5950          die qq[$0: Character "$token->{data}"];          die qq[$0: Character "$token->{data}"];
# Line 5429  sub _tree_construction_main ($) { Line 5962  sub _tree_construction_main ($) {
5962          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
5963              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
5964            !!!cp ('t318');            !!!cp ('t318');
5965            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5966              !!!nack ('t318.1');
5967            !!!next-token;            !!!next-token;
5968            redo B;            next B;
5969          } elsif ($token->{tag_name} eq 'frame' and          } elsif ($token->{tag_name} eq 'frame' and
5970                   $self->{insertion_mode} == IN_FRAMESET_IM) {                   $self->{insertion_mode} == IN_FRAMESET_IM) {
5971            !!!cp ('t319');            !!!cp ('t319');
5972            !!!insert-element ($token->{tag_name}, $token->{attributes});            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5973            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
5974              !!!ack ('t319.1');
5975            !!!next-token;            !!!next-token;
5976            redo B;            next B;
5977          } elsif ($token->{tag_name} eq 'noframes') {          } elsif ($token->{tag_name} eq 'noframes') {
5978            !!!cp ('t320');            !!!cp ('t320');
5979            ## NOTE: As if in body.            ## NOTE: As if in body.
5980            $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
5981            redo B;            next B;
5982          } else {          } else {
5983            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
5984              !!!cp ('t321');              !!!cp ('t321');
# Line 5453  sub _tree_construction_main ($) { Line 5988  sub _tree_construction_main ($) {
5988              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'after frameset:'.$token->{tag_name}, token => $token);
5989            }            }
5990            ## Ignore the token            ## Ignore the token
5991              !!!nack ('t322.1');
5992            !!!next-token;            !!!next-token;
5993            redo B;            next B;
5994          }          }
5995        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
5996          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {          if ($self->{insertion_mode} == AFTER_HTML_FRAMESET_IM) {
# Line 5469  sub _tree_construction_main ($) { Line 6005  sub _tree_construction_main ($) {
6005    
6006          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6007              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6008            if ($self->{open_elements}->[-1]->[1] eq 'html' and            if ($self->{open_elements}->[-1]->[1] & HTML_EL and
6009                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6010              !!!cp ('t325');              !!!cp ('t325');
6011              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
# Line 5482  sub _tree_construction_main ($) { Line 6018  sub _tree_construction_main ($) {
6018            }            }
6019    
6020            if (not defined $self->{inner_html_node} and            if (not defined $self->{inner_html_node} and
6021                $self->{open_elements}->[-1]->[1] ne 'frameset') {                not ($self->{open_elements}->[-1]->[1] & FRAMESET_EL)) {
6022              !!!cp ('t327');              !!!cp ('t327');
6023              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
6024            } else {            } else {
6025              !!!cp ('t328');              !!!cp ('t328');
6026            }            }
6027            redo B;            next B;
6028          } elsif ($token->{tag_name} eq 'html' and          } elsif ($token->{tag_name} eq 'html' and
6029                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {                   $self->{insertion_mode} == AFTER_FRAMESET_IM) {
6030            !!!cp ('t329');            !!!cp ('t329');
6031            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;            $self->{insertion_mode} = AFTER_HTML_FRAMESET_IM;
6032            !!!next-token;            !!!next-token;
6033            redo B;            next B;
6034          } else {          } else {
6035            if ($self->{insertion_mode} == IN_FRAMESET_IM) {            if ($self->{insertion_mode} == IN_FRAMESET_IM) {
6036              !!!cp ('t330');              !!!cp ('t330');
# Line 5505  sub _tree_construction_main ($) { Line 6041  sub _tree_construction_main ($) {
6041            }            }
6042            ## Ignore the token            ## Ignore the token
6043            !!!next-token;            !!!next-token;
6044            redo B;            next B;
6045          }          }
6046        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
6047          unless ($self->{open_elements}->[-1]->[1] eq 'html' and          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and
6048                  @{$self->{open_elements}} == 1) { # redundant, maybe                  @{$self->{open_elements}} == 1) { # redundant, maybe
6049            !!!cp ('t331.1');            !!!cp ('t331.1');
6050            !!!parse-error (type => 'in body:#eof', token => $token);            !!!parse-error (type => 'in body:#eof', token => $token);
# Line 5533  sub _tree_construction_main ($) { Line 6069  sub _tree_construction_main ($) {
6069          !!!cp ('t332');          !!!cp ('t332');
6070          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
6071          $script_start_tag->();          $script_start_tag->();
6072          redo B;          next B;
6073        } elsif ($token->{tag_name} eq 'style') {        } elsif ($token->{tag_name} eq 'style') {
6074          !!!cp ('t333');          !!!cp ('t333');
6075          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
6076          $parse_rcdata->(CDATA_CONTENT_MODEL);          $parse_rcdata->(CDATA_CONTENT_MODEL);
6077          redo B;          next B;
6078        } elsif ({        } elsif ({
6079                  base => 1, link => 1,                  base => 1, link => 1,
6080                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6081          !!!cp ('t334');          !!!cp ('t334');
6082          ## NOTE: This is an "as if in head" code clone, only "-t" differs          ## NOTE: This is an "as if in head" code clone, only "-t" differs
6083          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6084          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
6085            !!!ack ('t334.1');
6086          !!!next-token;          !!!next-token;
6087          redo B;          next B;
6088        } elsif ($token->{tag_name} eq 'meta') {        } elsif ($token->{tag_name} eq 'meta') {
6089          ## NOTE: This is an "as if in head" code clone, only "-t" differs          ## NOTE: This is an "as if in head" code clone, only "-t" differs
6090          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6091          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.          my $meta_el = pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec.
6092    
6093          unless ($self->{confident}) {          unless ($self->{confident}) {
6094            if ($token->{attributes}->{charset}) { ## TODO: And if supported            if ($token->{attributes}->{charset}) { ## TODO: And if supported
6095              !!!cp ('t335');              !!!cp ('t335');
6096              $self->{change_encoding}              $self->{change_encoding}
6097                  ->($self, $token->{attributes}->{charset}->{value});                  ->($self, $token->{attributes}->{charset}->{value}, $token);
6098                            
6099              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')              $meta_el->[0]->get_attribute_node_ns (undef, 'charset')
6100                  ->set_user_data (manakai_has_reference =>                  ->set_user_data (manakai_has_reference =>
# Line 5572  sub _tree_construction_main ($) { Line 6109  sub _tree_construction_main ($) {
6109                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {                      ([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) {
6110                !!!cp ('t336');                !!!cp ('t336');
6111                $self->{change_encoding}                $self->{change_encoding}
6112                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3);                    ->($self, defined $1 ? $1 : defined $2 ? $2 : $3, $token);
6113                $meta_el->[0]->get_attribute_node_ns (undef, 'content')                $meta_el->[0]->get_attribute_node_ns (undef, 'content')
6114                    ->set_user_data (manakai_has_reference =>                    ->set_user_data (manakai_has_reference =>
6115                                         $token->{attributes}->{content}                                         $token->{attributes}->{content}
# Line 5596  sub _tree_construction_main ($) { Line 6133  sub _tree_construction_main ($) {
6133            }            }
6134          }          }
6135    
6136            !!!ack ('t338.1');
6137          !!!next-token;          !!!next-token;
6138          redo B;          next B;
6139        } elsif ($token->{tag_name} eq 'title') {        } elsif ($token->{tag_name} eq 'title') {
6140          !!!cp ('t341');          !!!cp ('t341');
6141          ## NOTE: This is an "as if in head" code clone          ## NOTE: This is an "as if in head" code clone
6142          $parse_rcdata->(RCDATA_CONTENT_MODEL);          $parse_rcdata->(RCDATA_CONTENT_MODEL);
6143          redo B;          next B;
6144        } elsif ($token->{tag_name} eq 'body') {        } elsif ($token->{tag_name} eq 'body') {
6145          !!!parse-error (type => 'in body:body', token => $token);          !!!parse-error (type => 'in body:body', token => $token);
6146                                
6147          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6148              $self->{open_elements}->[1]->[1] ne 'body') {              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {
6149            !!!cp ('t342');            !!!cp ('t342');
6150            ## Ignore the token            ## Ignore the token
6151          } else {          } else {
# Line 5621  sub _tree_construction_main ($) { Line 6159  sub _tree_construction_main ($) {
6159              }              }
6160            }            }
6161          }          }
6162            !!!nack ('t343.1');
6163          !!!next-token;          !!!next-token;
6164          redo B;          next B;
6165        } elsif ({        } elsif ({
6166                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
6167                  div => 1, dl => 1, fieldset => 1,                  div => 1, dl => 1, fieldset => 1,
# Line 5637  sub _tree_construction_main ($) { Line 6176  sub _tree_construction_main ($) {
6176            !!!cp ('t350');            !!!cp ('t350');
6177            !!!parse-error (type => 'in form:form', token => $token);            !!!parse-error (type => 'in form:form', token => $token);
6178            ## Ignore the token            ## Ignore the token
6179              !!!nack ('t350.1');
6180            !!!next-token;            !!!next-token;
6181            redo B;            next B;
6182          }          }
6183    
6184          ## has a p element in scope          ## has a p element in scope
6185          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
6186            if ($_->[1] eq 'p') {            if ($_->[1] & P_EL) {
6187              !!!cp ('t344');              !!!cp ('t344');
6188              !!!back-token;              !!!back-token; # <form>
6189              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p',
6190              redo B;                        line => $token->{line}, column => $token->{column}};
6191            } elsif ({              next B;
6192                      applet => 1, table => 1, caption => 1, td => 1, th => 1,            } elsif ($_->[1] & SCOPING_EL) {
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
6193              !!!cp ('t345');              !!!cp ('t345');
6194              last INSCOPE;              last INSCOPE;
6195            }            }
6196          } # INSCOPE          } # INSCOPE
6197                        
6198          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6199          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {          if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') {
6200              !!!nack ('t346.1');
6201            !!!next-token;            !!!next-token;
6202            if ($token->{type} == CHARACTER_TOKEN) {            if ($token->{type} == CHARACTER_TOKEN) {
6203              $token->{data} =~ s/^\x0A//;              $token->{data} =~ s/^\x0A//;
# Line 5675  sub _tree_construction_main ($) { Line 6214  sub _tree_construction_main ($) {
6214            !!!cp ('t347.1');            !!!cp ('t347.1');
6215            $self->{form_element} = $self->{open_elements}->[-1]->[0];            $self->{form_element} = $self->{open_elements}->[-1]->[0];
6216    
6217              !!!nack ('t347.2');
6218            !!!next-token;            !!!next-token;
6219          } elsif ($token->{tag_name} eq 'table') {          } elsif ($token->{tag_name} eq 'table') {
6220            !!!cp ('t382');            !!!cp ('t382');
# Line 5682  sub _tree_construction_main ($) { Line 6222  sub _tree_construction_main ($) {
6222                        
6223            $self->{insertion_mode} = IN_TABLE_IM;            $self->{insertion_mode} = IN_TABLE_IM;
6224    
6225              !!!nack ('t382.1');
6226            !!!next-token;            !!!next-token;
6227          } elsif ($token->{tag_name} eq 'hr') {          } elsif ($token->{tag_name} eq 'hr') {
6228            !!!cp ('t386');            !!!cp ('t386');
6229            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
6230                    
6231              !!!nack ('t386.1');
6232            !!!next-token;            !!!next-token;
6233          } else {          } else {
6234            !!!cp ('t347');            !!!nack ('t347.1');
6235            !!!next-token;            !!!next-token;
6236          }          }
6237          redo B;          next B;
6238        } elsif ({li => 1, dt => 1, dd => 1}->{$token->{tag_name}}) {        } elsif ({li => 1, dt => 1, dd => 1}->{$token->{tag_name}}) {
6239          ## has a p element in scope          ## has a p element in scope
6240          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
6241            if ($_->[1] eq 'p') {            if ($_->[1] & P_EL) {
6242              !!!cp ('t353');              !!!cp ('t353');
6243              !!!back-token;              !!!back-token; # <x>
6244              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p',
6245              redo B;                        line => $token->{line}, column => $token->{column}};
6246            } elsif ({              next B;
6247                      applet => 1, table => 1, caption => 1, td => 1, th => 1,            } elsif ($_->[1] & SCOPING_EL) {
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
6248              !!!cp ('t354');              !!!cp ('t354');
6249              last INSCOPE;              last INSCOPE;
6250            }            }
# Line 5718  sub _tree_construction_main ($) { Line 6258  sub _tree_construction_main ($) {
6258                            dd => {dt => 1, dd => 1}}->{$token->{tag_name}};                            dd => {dt => 1, dd => 1}}->{$token->{tag_name}};
6259          LI: {          LI: {
6260            ## Step 2            ## Step 2
6261            if ($li_or_dtdd->{$node->[1]}) {            if ($li_or_dtdd->{$node->[0]->manakai_local_name}) {
6262              if ($i != -1) {              if ($i != -1) {
6263                !!!cp ('t355');                !!!cp ('t355');
6264                !!!parse-error (type => 'end tag missing:'.                !!!parse-error (type => 'not closed',
6265                                $self->{open_elements}->[-1]->[1], token => $token);                                value => $self->{open_elements}->[-1]->[0]
6266                                      ->manakai_local_name,
6267                                  token => $token);
6268              } else {              } else {
6269                !!!cp ('t356');                !!!cp ('t356');
6270              }              }
# Line 5733  sub _tree_construction_main ($) { Line 6275  sub _tree_construction_main ($) {
6275            }            }
6276                        
6277            ## Step 3            ## Step 3
6278            if (not $formatting_category->{$node->[1]} and            if (not ($node->[1] & FORMATTING_EL) and
6279                #not $phrasing_category->{$node->[1]} and                #not $phrasing_category->{$node->[1]} and
6280                ($special_category->{$node->[1]} or                ($node->[1] & SPECIAL_EL or
6281                 $scoping_category->{$node->[1]}) and                 $node->[1] & SCOPING_EL) and
6282                $node->[1] ne 'address' and $node->[1] ne 'div') {                not ($node->[1] & ADDRESS_EL) and
6283                  not ($node->[1] & DIV_EL)) {
6284              !!!cp ('t358');              !!!cp ('t358');
6285              last LI;              last LI;
6286            }            }
# Line 5749  sub _tree_construction_main ($) { Line 6292  sub _tree_construction_main ($) {
6292            redo LI;            redo LI;
6293          } # LI          } # LI
6294                        
6295          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6296            !!!nack ('t359.1');
6297          !!!next-token;          !!!next-token;
6298          redo B;          next B;
6299        } elsif ($token->{tag_name} eq 'plaintext') {        } elsif ($token->{tag_name} eq 'plaintext') {
6300          ## has a p element in scope          ## has a p element in scope
6301          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
6302            if ($_->[1] eq 'p') {            if ($_->[1] & P_EL) {
6303              !!!cp ('t367');              !!!cp ('t367');
6304              !!!back-token;              !!!back-token; # <plaintext>
6305              $token = {type => END_TAG_TOKEN, tag_name => 'p'};              $token = {type => END_TAG_TOKEN, tag_name => 'p',
6306              redo B;                        line => $token->{line}, column => $token->{column}};
6307            } elsif ({              next B;
6308                      applet => 1, table => 1, caption => 1, td => 1, th => 1,            } elsif ($_->[1] & SCOPING_EL) {
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$_->[1]}) {  
6309              !!!cp ('t368');              !!!cp ('t368');
6310              last INSCOPE;              last INSCOPE;
6311            }            }
6312          } # INSCOPE          } # INSCOPE
6313                        
6314          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6315                        
6316          $self->{content_model} = PLAINTEXT_CONTENT_MODEL;          $self->{content_model} = PLAINTEXT_CONTENT_MODEL;
6317                        
6318            !!!nack ('t368.1');
6319          !!!next-token;          !!!next-token;
6320          redo B;          next B;
6321        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
6322          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
6323            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
6324            if ($node->[1] eq 'a') {            if ($node->[1] & A_EL) {
6325              !!!cp ('t371');              !!!cp ('t371');
6326              !!!parse-error (type => 'in a:a', token => $token);              !!!parse-error (type => 'in a:a', token => $token);
6327                            
6328              !!!back-token;              !!!back-token; # <a>
6329              $token = {type => END_TAG_TOKEN, tag_name => 'a'};              $token = {type => END_TAG_TOKEN, tag_name => 'a',
6330                          line => $token->{line}, column => $token->{column}};
6331              $formatting_end_tag->($token);              $formatting_end_tag->($token);
6332                            
6333              AFE2: for (reverse 0..$#$active_formatting_elements) {              AFE2: for (reverse 0..$#$active_formatting_elements) {
# Line 5809  sub _tree_construction_main ($) { Line 6353  sub _tree_construction_main ($) {
6353                        
6354          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6355    
6356          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6357          push @$active_formatting_elements, $self->{open_elements}->[-1];          push @$active_formatting_elements, $self->{open_elements}->[-1];
6358    
6359            !!!nack ('t374.1');
6360          !!!next-token;          !!!next-token;
6361          redo B;          next B;
6362        } elsif ($token->{tag_name} eq 'nobr') {        } elsif ($token->{tag_name} eq 'nobr') {
6363          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6364    
6365          ## has a |nobr| element in scope          ## has a |nobr| element in scope
6366          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6367            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6368            if ($node->[1] eq 'nobr') {            if ($node->[1] & NOBR_EL) {
6369              !!!cp ('t376');              !!!cp ('t376');
6370              !!!parse-error (type => 'in nobr:nobr', token => $token);              !!!parse-error (type => 'in nobr:nobr', token => $token);
6371              !!!back-token;              !!!back-token; # <nobr>
6372              $token = {type => END_TAG_TOKEN, tag_name => 'nobr'};              $token = {type => END_TAG_TOKEN, tag_name => 'nobr',
6373              redo B;                        line => $token->{line}, column => $token->{column}};
6374            } elsif ({              next B;
6375                      applet => 1, table => 1, caption => 1, td => 1, th => 1,            } elsif ($node->[1] & SCOPING_EL) {
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
6376              !!!cp ('t377');              !!!cp ('t377');
6377              last INSCOPE;              last INSCOPE;
6378            }            }
6379          } # INSCOPE          } # INSCOPE
6380                    
6381          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6382          push @$active_formatting_elements, $self->{open_elements}->[-1];          push @$active_formatting_elements, $self->{open_elements}->[-1];
6383                    
6384            !!!nack ('t377.1');
6385          !!!next-token;          !!!next-token;
6386          redo B;          next B;
6387        } elsif ($token->{tag_name} eq 'button') {        } elsif ($token->{tag_name} eq 'button') {
6388          ## has a button element in scope          ## has a button element in scope
6389          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6390            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6391            if ($node->[1] eq 'button') {            if ($node->[1] & BUTTON_EL) {
6392              !!!cp ('t378');              !!!cp ('t378');
6393              !!!parse-error (type => 'in button:button', token => $token);              !!!parse-error (type => 'in button:button', token => $token);
6394              !!!back-token;              !!!back-token; # <button>
6395              $token = {type => END_TAG_TOKEN, tag_name => 'button'};              $token = {type => END_TAG_TOKEN, tag_name => 'button',
6396              redo B;                        line => $token->{line}, column => $token->{column}};
6397            } elsif ({              next B;
6398                      applet => 1, table => 1, caption => 1, td => 1, th => 1,            } elsif ($node->[1] & SCOPING_EL) {
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
6399              !!!cp ('t379');              !!!cp ('t379');
6400              last INSCOPE;              last INSCOPE;
6401            }            }
# Line 5861  sub _tree_construction_main ($) { Line 6403  sub _tree_construction_main ($) {
6403                        
6404          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6405                        
6406          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6407    
6408          ## TODO: associate with $self->{form_element} if defined          ## TODO: associate with $self->{form_element} if defined
6409    
6410          push @$active_formatting_elements, ['#marker', ''];          push @$active_formatting_elements, ['#marker', ''];
6411    
6412            !!!nack ('t379.1');
6413          !!!next-token;          !!!next-token;
6414          redo B;          next B;
6415        } elsif ({        } elsif ({
6416                  xmp => 1,                  xmp => 1,
6417                  iframe => 1,                  iframe => 1,
# Line 5884  sub _tree_construction_main ($) { Line 6427  sub _tree_construction_main ($) {
6427          }          }
6428          ## NOTE: There is an "as if in body" code clone.          ## NOTE: There is an "as if in body" code clone.
6429          $parse_rcdata->(CDATA_CONTENT_MODEL);          $parse_rcdata->(CDATA_CONTENT_MODEL);
6430          redo B;          next B;
6431        } elsif ($token->{tag_name} eq 'isindex') {        } elsif ($token->{tag_name} eq 'isindex') {
6432          !!!parse-error (type => 'isindex', token => $token);          !!!parse-error (type => 'isindex', token => $token);
6433                    
6434          if (defined $self->{form_element}) {          if (defined $self->{form_element}) {
6435            !!!cp ('t389');            !!!cp ('t389');
6436            ## Ignore the token            ## Ignore the token
6437              !!!nack ('t389'); ## NOTE: Not acknowledged.
6438            !!!next-token;            !!!next-token;
6439            redo B;            next B;
6440          } else {          } else {
6441            my $at = $token->{attributes};            my $at = $token->{attributes};
6442            my $form_attrs;            my $form_attrs;
# Line 5903  sub _tree_construction_main ($) { Line 6447  sub _tree_construction_main ($) {
6447            delete $at->{prompt};            delete $at->{prompt};
6448            my @tokens = (            my @tokens = (
6449                          {type => START_TAG_TOKEN, tag_name => 'form',                          {type => START_TAG_TOKEN, tag_name => 'form',
6450                           attributes => $form_attrs},                           attributes => $form_attrs,
6451                          {type => START_TAG_TOKEN, tag_name => 'hr'},                           line => $token->{line}, column => $token->{column}},
6452                          {type => START_TAG_TOKEN, tag_name => 'p'},                          {type => START_TAG_TOKEN, tag_name => 'hr',
6453                          {type => START_TAG_TOKEN, tag_name => 'label'},                           line => $token->{line}, column => $token->{column}},
6454                            {type => START_TAG_TOKEN, tag_name => 'p',
6455                             line => $token->{line}, column => $token->{column}},
6456                            {type => START_TAG_TOKEN, tag_name => 'label',
6457                             line => $token->{line}, column => $token->{column}},
6458                         );                         );
6459            if ($prompt_attr) {            if ($prompt_attr) {
6460              !!!cp ('t390');              !!!cp ('t390');
6461              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value}};              push @tokens, {type => CHARACTER_TOKEN, data => $prompt_attr->{value},
6462                               #line => $token->{line}, column => $token->{column},
6463                              };
6464            } else {            } else {
6465              !!!cp ('t391');              !!!cp ('t391');
6466              push @tokens, {type => CHARACTER_TOKEN,              push @tokens, {type => CHARACTER_TOKEN,
6467                             data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD                             data => 'This is a searchable index. Insert your search keywords here: ',
6468                               #line => $token->{line}, column => $token->{column},
6469                              }; # SHOULD
6470              ## TODO: make this configurable              ## TODO: make this configurable
6471            }            }
6472            push @tokens,            push @tokens,
6473                          {type => START_TAG_TOKEN, tag_name => 'input', attributes => $at},                          {type => START_TAG_TOKEN, tag_name => 'input', attributes => $at,
6474                             line => $token->{line}, column => $token->{column}},
6475                          #{type => CHARACTER_TOKEN, data => ''}, # SHOULD                          #{type => CHARACTER_TOKEN, data => ''}, # SHOULD
6476                          {type => END_TAG_TOKEN, tag_name => 'label'},                          {type => END_TAG_TOKEN, tag_name => 'label',
6477                          {type => END_TAG_TOKEN, tag_name => 'p'},                           line => $token->{line}, column => $token->{column}},
6478                          {type => START_TAG_TOKEN, tag_name => 'hr'},                          {type => END_TAG_TOKEN, tag_name => 'p',
6479                          {type => END_TAG_TOKEN, tag_name => 'form'};                           line => $token->{line}, column => $token->{column}},
6480            $token = shift @tokens;                          {type => START_TAG_TOKEN, tag_name => 'hr',
6481                             line => $token->{line}, column => $token->{column}},
6482                            {type => END_TAG_TOKEN, tag_name => 'form',
6483                             line => $token->{line}, column => $token->{column}};
6484              !!!nack ('t391.1'); ## NOTE: Not acknowledged.
6485            !!!back-token (@tokens);            !!!back-token (@tokens);
6486            redo B;            !!!next-token;
6487              next B;
6488          }          }
6489        } elsif ($token->{tag_name} eq 'textarea') {        } elsif ($token->{tag_name} eq 'textarea') {
6490          my $tag_name = $token->{tag_name};          my $tag_name = $token->{tag_name};
6491          my $el;          my $el;
6492          !!!create-element ($el, $token->{tag_name}, $token->{attributes});          !!!create-element ($el, $HTML_NS, $token->{tag_name}, $token->{attributes}, $token);
6493                    
6494          ## TODO: $self->{form_element} if defined          ## TODO: $self->{form_element} if defined
6495          $self->{content_model} = RCDATA_CONTENT_MODEL;          $self->{content_model} = RCDATA_CONTENT_MODEL;
# Line 5940  sub _tree_construction_main ($) { Line 6498  sub _tree_construction_main ($) {
6498          $insert->($el);          $insert->($el);
6499                    
6500          my $text = '';          my $text = '';
6501            !!!nack ('t392.1');
6502          !!!next-token;          !!!next-token;
6503          if ($token->{type} == CHARACTER_TOKEN) {          if ($token->{type} == CHARACTER_TOKEN) {
6504            $token->{data} =~ s/^\x0A//;            $token->{data} =~ s/^\x0A//;
# Line 5973  sub _tree_construction_main ($) { Line 6532  sub _tree_construction_main ($) {
6532            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);            !!!parse-error (type => 'in RCDATA:#'.$token->{type}, token => $token);
6533          }          }
6534          !!!next-token;          !!!next-token;
6535          redo B;          next B;
6536          } elsif ($token->{tag_name} eq 'math' or
6537                   $token->{tag_name} eq 'svg') {
6538            $reconstruct_active_formatting_elements->($insert_to_current);
6539    
6540            ## "adjust SVG attributes" ('svg' only) - done in insert-element-f
6541    
6542            ## "adjust foreign attributes" - done in insert-element-f
6543            
6544            !!!insert-element-f ($token->{tag_name} eq 'math' ? $MML_NS : $SVG_NS, $token->{tag_name}, $token->{attributes}, $token);
6545            
6546            if ($self->{self_closing}) {
6547              pop @{$self->{open_elements}};
6548              !!!ack ('t398.1');
6549            } else {
6550              !!!cp ('t398.2');
6551              $self->{insertion_mode} |= IN_FOREIGN_CONTENT_IM;
6552              ## NOTE: |<body><math><mi><svg>| -> "in foreign content" insertion
6553              ## mode, "in body" (not "in foreign content") secondary insertion
6554              ## mode, maybe.
6555            }
6556    
6557            !!!next-token;
6558            next B;
6559        } elsif ({        } elsif ({
6560                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
6561                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
# Line 5983  sub _tree_construction_main ($) { Line 6565  sub _tree_construction_main ($) {
6565          !!!cp ('t401');          !!!cp ('t401');
6566          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'in body:'.$token->{tag_name}, token => $token);
6567          ## Ignore the token          ## Ignore the token
6568            !!!nack ('t401.1'); ## NOTE: |<col/>| or |<frame/>| here is an error.
6569          !!!next-token;          !!!next-token;
6570          redo B;          next B;
6571                    
6572          ## ISSUE: An issue on HTML5 new elements in the spec.          ## ISSUE: An issue on HTML5 new elements in the spec.
6573        } else {        } else {
# Line 5999  sub _tree_construction_main ($) { Line 6582  sub _tree_construction_main ($) {
6582          ## NOTE: There is an "as if <br>" code clone.          ## NOTE: There is an "as if <br>" code clone.
6583          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6584                    
6585          !!!insert-element-t ($token->{tag_name}, $token->{attributes});          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
6586    
6587          if ({          if ({
6588               applet => 1, marquee => 1, object => 1,               applet => 1, marquee => 1, object => 1,
6589              }->{$token->{tag_name}}) {              }->{$token->{tag_name}}) {
6590            !!!cp ('t380');            !!!cp ('t380');
6591            push @$active_formatting_elements, ['#marker', ''];            push @$active_formatting_elements, ['#marker', ''];
6592              !!!nack ('t380.1');
6593          } elsif ({          } elsif ({
6594                    b => 1, big => 1, em => 1, font => 1, i => 1,                    b => 1, big => 1, em => 1, font => 1, i => 1,
6595                    s => 1, small => 1, strile => 1,                    s => 1, small => 1, strile => 1,
# Line 6013  sub _tree_construction_main ($) { Line 6597  sub _tree_construction_main ($) {
6597                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6598            !!!cp ('t375');            !!!cp ('t375');
6599            push @$active_formatting_elements, $self->{open_elements}->[-1];            push @$active_formatting_elements, $self->{open_elements}->[-1];
6600              !!!nack ('t375.1');
6601          } elsif ($token->{tag_name} eq 'input') {          } elsif ($token->{tag_name} eq 'input') {
6602            !!!cp ('t388');            !!!cp ('t388');
6603            ## TODO: associate with $self->{form_element} if defined            ## TODO: associate with $self->{form_element} if defined
6604            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
6605              !!!ack ('t388.2');
6606          } elsif ({          } elsif ({
6607                    area => 1, basefont => 1, bgsound => 1, br => 1,                    area => 1, basefont => 1, bgsound => 1, br => 1,
6608                    embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,                    embed => 1, img => 1, param => 1, spacer => 1, wbr => 1,
# Line 6024  sub _tree_construction_main ($) { Line 6610  sub _tree_construction_main ($) {
6610                   }->{$token->{tag_name}}) {                   }->{$token->{tag_name}}) {
6611            !!!cp ('t388.1');            !!!cp ('t388.1');
6612            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
6613              !!!ack ('t388.3');
6614          } elsif ($token->{tag_name} eq 'select') {          } elsif ($token->{tag_name} eq 'select') {
6615            ## TODO: associate with $self->{form_element} if defined            ## TODO: associate with $self->{form_element} if defined
6616                    
# Line 6036  sub _tree_construction_main ($) { Line 6623  sub _tree_construction_main ($) {
6623              !!!cp ('t400.2');              !!!cp ('t400.2');
6624              $self->{insertion_mode} = IN_SELECT_IM;              $self->{insertion_mode} = IN_SELECT_IM;
6625            }            }
6626              !!!nack ('t400.3');
6627          } else {          } else {
6628            !!!cp ('t402');            !!!nack ('t402');
6629          }          }
6630                    
6631          !!!next-token;          !!!next-token;
6632          redo B;          next B;
6633        }        }
6634      } elsif ($token->{type} == END_TAG_TOKEN) {      } elsif ($token->{type} == END_TAG_TOKEN) {
6635        if ($token->{tag_name} eq 'body') {        if ($token->{tag_name} eq 'body') {
# Line 6049  sub _tree_construction_main ($) { Line 6637  sub _tree_construction_main ($) {
6637          my $i;          my $i;
6638          INSCOPE: {          INSCOPE: {
6639            for (reverse @{$self->{open_elements}}) {            for (reverse @{$self->{open_elements}}) {
6640              if ($_->[1] eq 'body') {              if ($_->[1] & BODY_EL) {
6641                !!!cp ('t405');                !!!cp ('t405');
6642                $i = $_;                $i = $_;
6643                last INSCOPE;                last INSCOPE;
6644              } elsif ({              } elsif ($_->[1] & SCOPING_EL) {
                       applet => 1, table => 1, caption => 1, td => 1, th => 1,  
                       button => 1, marquee => 1, object => 1, html => 1,  
                      }->{$_->[1]}) {  
6645                !!!cp ('t405.1');                !!!cp ('t405.1');
6646                last;                last;
6647              }              }
# Line 6066  sub _tree_construction_main ($) { Line 6651  sub _tree_construction_main ($) {
6651                            value => $token->{tag_name}, token => $token);                            value => $token->{tag_name}, token => $token);
6652            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
6653            !!!next-token;            !!!next-token;
6654            redo B;            next B;
6655          } # INSCOPE          } # INSCOPE
6656    
6657          for (@{$self->{open_elements}}) {          for (@{$self->{open_elements}}) {
6658            unless ({            unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL) {
                    dd => 1, dt => 1, li => 1, p => 1, td => 1,  
                    th => 1, tr => 1, body => 1, html => 1,  
                    tbody => 1, tfoot => 1, thead => 1,  
                   }->{$_->[1]}) {  
6659              !!!cp ('t403');              !!!cp ('t403');
6660              !!!parse-error (type => 'not closed:'.$_->[1], token => $token);              !!!parse-error (type => 'not closed',
6661                                value => $_->[0]->manakai_local_name,
6662                                token => $token);
6663              last;              last;
6664            } else {            } else {
6665              !!!cp ('t404');              !!!cp ('t404');
# Line 6085  sub _tree_construction_main ($) { Line 6668  sub _tree_construction_main ($) {
6668    
6669          $self->{insertion_mode} = AFTER_BODY_IM;          $self->{insertion_mode} = AFTER_BODY_IM;
6670          !!!next-token;          !!!next-token;
6671          redo B;          next B;
6672        } elsif ($token->{tag_name} eq 'html') {        } elsif ($token->{tag_name} eq 'html') {
6673          if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') {          ## TODO: Update this code.  It seems that the code below is not
6674            ## up-to-date, though it has same effect as speced.
6675            if (@{$self->{open_elements}} > 1 and
6676                $self->{open_elements}->[1]->[1] & BODY_EL) {
6677            ## ISSUE: There is an issue in the spec.            ## ISSUE: There is an issue in the spec.
6678            if ($self->{open_elements}->[-1]->[1] ne 'body') {            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {
6679              !!!cp ('t406');              !!!cp ('t406');
6680              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1], token => $token);              !!!parse-error (type => 'not closed',
6681                                value => $self->{open_elements}->[1]->[0]
6682                                    ->manakai_local_name,
6683                                token => $token);
6684            } else {            } else {
6685              !!!cp ('t407');              !!!cp ('t407');
6686            }            }
6687            $self->{insertion_mode} = AFTER_BODY_IM;            $self->{insertion_mode} = AFTER_BODY_IM;
6688            ## reprocess            ## reprocess
6689            redo B;            next B;
6690          } else {          } else {
6691            !!!cp ('t408');            !!!cp ('t408');
6692            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6693            ## Ignore the token            ## Ignore the token
6694            !!!next-token;            !!!next-token;
6695            redo B;            next B;
6696          }          }
6697        } elsif ({        } elsif ({
6698                  address => 1, blockquote => 1, center => 1, dir => 1,                  address => 1, blockquote => 1, center => 1, dir => 1,
# Line 6116  sub _tree_construction_main ($) { Line 6705  sub _tree_construction_main ($) {
6705          my $i;          my $i;
6706          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6707            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6708            if ($node->[1] eq $token->{tag_name}) {            if ($node->[0]->manakai_local_name eq $token->{tag_name}) {
6709              !!!cp ('t410');              !!!cp ('t410');
6710              $i = $_;              $i = $_;
6711              last INSCOPE;              last INSCOPE;
6712            } elsif ({            } elsif ($node->[1] & SCOPING_EL) {
                     applet => 1, table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
6713              !!!cp ('t411');              !!!cp ('t411');
6714              last INSCOPE;              last INSCOPE;
6715            }            }
# Line 6139  sub _tree_construction_main ($) { Line 6725  sub _tree_construction_main ($) {
6725                    dt => ($token->{tag_name} ne 'dt'),                    dt => ($token->{tag_name} ne 'dt'),
6726                    li => ($token->{tag_name} ne 'li'),                    li => ($token->{tag_name} ne 'li'),
6727                    p => 1,                    p => 1,
6728                   }->{$self->{open_elements}->[-1]->[1]}) {                   }->{$self->{open_elements}->[-1]->[0]->manakai_local_name}) {
6729              !!!cp ('t409');              !!!cp ('t409');
6730              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6731            }            }
6732    
6733            ## Step 2.            ## Step 2.
6734            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
6735                      ne $token->{tag_name}) {
6736              !!!cp ('t412');              !!!cp ('t412');
6737              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);              !!!parse-error (type => 'not closed',
6738                                value => $self->{open_elements}->[-1]->[0]
6739                                    ->manakai_local_name,
6740                                token => $token);
6741            } else {            } else {
6742              !!!cp ('t414');              !!!cp ('t414');
6743            }            }
# Line 6162  sub _tree_construction_main ($) { Line 6752  sub _tree_construction_main ($) {
6752                }->{$token->{tag_name}};                }->{$token->{tag_name}};
6753          }          }
6754          !!!next-token;          !!!next-token;
6755          redo B;          next B;
6756        } elsif ($token->{tag_name} eq 'form') {        } elsif ($token->{tag_name} eq 'form') {
6757          undef $self->{form_element};          undef $self->{form_element};
6758    
# Line 6170  sub _tree_construction_main ($) { Line 6760  sub _tree_construction_main ($) {
6760          my $i;          my $i;
6761          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6762            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6763            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] & FORM_EL) {
6764              !!!cp ('t418');              !!!cp ('t418');
6765              $i = $_;              $i = $_;
6766              last INSCOPE;              last INSCOPE;
6767            } elsif ({            } elsif ($node->[1] & SCOPING_EL) {
                     applet => 1, table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
6768              !!!cp ('t419');              !!!cp ('t419');
6769              last INSCOPE;              last INSCOPE;
6770            }            }
# Line 6188  sub _tree_construction_main ($) { Line 6775  sub _tree_construction_main ($) {
6775            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6776          } else {          } else {
6777            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
6778            while ({            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
                   dd => 1, dt => 1, li => 1, p => 1,  
                  }->{$self->{open_elements}->[-1]->[1]}) {  
6779              !!!cp ('t417');              !!!cp ('t417');
6780              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6781            }            }
6782                        
6783            ## Step 2.            ## Step 2.
6784            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
6785                      ne $token->{tag_name}) {
6786              !!!cp ('t417.1');              !!!cp ('t417.1');
6787              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);              !!!parse-error (type => 'not closed',
6788                                value => $self->{open_elements}->[-1]->[0]
6789                                    ->manakai_local_name,
6790                                token => $token);
6791            } else {            } else {
6792              !!!cp ('t420');              !!!cp ('t420');
6793            }              }  
# Line 6208  sub _tree_construction_main ($) { Line 6797  sub _tree_construction_main ($) {
6797          }          }
6798    
6799          !!!next-token;          !!!next-token;
6800          redo B;          next B;
6801        } elsif ({        } elsif ({
6802                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,                  h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,
6803                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 6216  sub _tree_construction_main ($) { Line 6805  sub _tree_construction_main ($) {
6805          my $i;          my $i;
6806          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6807            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6808            if ({            if ($node->[1] & HEADING_EL) {
                h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1,  
               }->{$node->[1]}) {  
6809              !!!cp ('t423');              !!!cp ('t423');
6810              $i = $_;              $i = $_;
6811              last INSCOPE;              last INSCOPE;
6812            } elsif ({            } elsif ($node->[1] & SCOPING_EL) {
                     applet => 1, table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
6813              !!!cp ('t424');              !!!cp ('t424');
6814              last INSCOPE;              last INSCOPE;
6815            }            }
# Line 6236  sub _tree_construction_main ($) { Line 6820  sub _tree_construction_main ($) {
6820            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);            !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6821          } else {          } else {
6822            ## Step 1. generate implied end tags            ## Step 1. generate implied end tags
6823            while ({            while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
                   dd => 1, dt => 1, li => 1, p => 1,  
                  }->{$self->{open_elements}->[-1]->[1]}) {  
6824              !!!cp ('t422');              !!!cp ('t422');
6825              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6826            }            }
6827                        
6828            ## Step 2.            ## Step 2.
6829            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
6830                      ne $token->{tag_name}) {
6831              !!!cp ('t425');              !!!cp ('t425');
6832              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);              !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6833            } else {            } else {
# Line 6256  sub _tree_construction_main ($) { Line 6839  sub _tree_construction_main ($) {
6839          }          }
6840                    
6841          !!!next-token;          !!!next-token;
6842          redo B;          next B;
6843        } elsif ($token->{tag_name} eq 'p') {        } elsif ($token->{tag_name} eq 'p') {
6844          ## has an element in scope          ## has an element in scope
6845          my $i;          my $i;
6846          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6847            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
6848            if ($node->[1] eq $token->{tag_name}) {            if ($node->[1] & P_EL) {
6849              !!!cp ('t410.1');              !!!cp ('t410.1');
6850              $i = $_;              $i = $_;
6851              last INSCOPE;              last INSCOPE;
6852            } elsif ({            } elsif ($node->[1] & SCOPING_EL) {
                     applet => 1, table => 1, caption => 1, td => 1, th => 1,  
                     button => 1, marquee => 1, object => 1, html => 1,  
                    }->{$node->[1]}) {  
6853              !!!cp ('t411.1');              !!!cp ('t411.1');
6854              last INSCOPE;              last INSCOPE;
6855            }            }
6856          } # INSCOPE          } # INSCOPE
6857    
6858          if (defined $i) {          if (defined $i) {
6859            if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) {            if ($self->{open_elements}->[-1]->[0]->manakai_local_name
6860                      ne $token->{tag_name}) {
6861              !!!cp ('t412.1');              !!!cp ('t412.1');
6862              !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);              !!!parse-error (type => 'not closed',
6863                                value => $self->{open_elements}->[-1]->[0]
6864                                    ->manakai_local_name,
6865                                token => $token);
6866            } else {            } else {
6867              !!!cp ('t414.1');              !!!cp ('t414.1');
6868            }            }
# Line 6291  sub _tree_construction_main ($) { Line 6875  sub _tree_construction_main ($) {
6875            !!!cp ('t415.1');            !!!cp ('t415.1');
6876            ## As if <p>, then reprocess the current token            ## As if <p>, then reprocess the current token
6877            my $el;            my $el;
6878            !!!create-element ($el, 'p');            !!!create-element ($el, $HTML_NS, 'p',, $token);
6879            $insert->($el);            $insert->($el);
6880            ## NOTE: Not inserted into |$self->{open_elements}|.            ## NOTE: Not inserted into |$self->{open_elements}|.
6881          }          }
6882    
6883          !!!next-token;          !!!next-token;
6884          redo B;          next B;
6885        } elsif ({        } elsif ({
6886                  a => 1,                  a => 1,
6887                  b => 1, big => 1, em => 1, font => 1, i => 1,                  b => 1, big => 1, em => 1, font => 1, i => 1,
# Line 6306  sub _tree_construction_main ($) { Line 6890  sub _tree_construction_main ($) {
6890                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
6891          !!!cp ('t427');          !!!cp ('t427');
6892          $formatting_end_tag->($token);          $formatting_end_tag->($token);
6893          redo B;          next B;
6894        } elsif ($token->{tag_name} eq 'br') {        } elsif ($token->{tag_name} eq 'br') {
6895          !!!cp ('t428');          !!!cp ('t428');
6896          !!!parse-error (type => 'unmatched end tag:br', token => $token);          !!!parse-error (type => 'unmatched end tag:br', token => $token);
# Line 6315  sub _tree_construction_main ($) { Line 6899  sub _tree_construction_main ($) {
6899          $reconstruct_active_formatting_elements->($insert_to_current);          $reconstruct_active_formatting_elements->($insert_to_current);
6900                    
6901          my $el;          my $el;
6902          !!!create-element ($el, 'br');          !!!create-element ($el, $HTML_NS, 'br',, $token);
6903          $insert->($el);          $insert->($el);
6904                    
6905          ## Ignore the token.          ## Ignore the token.
6906          !!!next-token;          !!!next-token;
6907          redo B;          next B;
6908        } elsif ({        } elsif ({
6909                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
6910                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1, option => 1, optgroup => 1,
# Line 6337  sub _tree_construction_main ($) { Line 6921  sub _tree_construction_main ($) {
6921          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);          !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6922          ## Ignore the token          ## Ignore the token
6923          !!!next-token;          !!!next-token;
6924          redo B;          next B;
6925                    
6926          ## ISSUE: Issue on HTML5 new elements in spec          ## ISSUE: Issue on HTML5 new elements in spec
6927                    
# Line 6348  sub _tree_construction_main ($) { Line 6932  sub _tree_construction_main ($) {
6932    
6933          ## Step 2          ## Step 2
6934          S2: {          S2: {
6935            if ($node->[1] eq $token->{tag_name}) {            if ($node->[0]->manakai_local_name eq $token->{tag_name}) {
6936              ## Step 1              ## Step 1
6937              ## generate implied end tags              ## generate implied end tags
6938              while ({              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
                     dd => 1, dt => 1, li => 1, p => 1,  
                    }->{$self->{open_elements}->[-1]->[1]}) {  
6939                !!!cp ('t430');                !!!cp ('t430');
6940                ## ISSUE: Can this case be reached?                ## ISSUE: Can this case be reached?
6941                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
6942              }              }
6943                    
6944              ## Step 2              ## Step 2
6945              if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) {              if ($self->{open_elements}->[-1]->[0]->manakai_local_name
6946                        ne $token->{tag_name}) {
6947                !!!cp ('t431');                !!!cp ('t431');
6948                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
6949                !!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1], token => $token);                !!!parse-error (type => 'not closed',
6950                                  value => $self->{open_elements}->[-1]->[0]
6951                                      ->manakai_local_name,
6952                                  token => $token);
6953              } else {              } else {
6954                !!!cp ('t432');                !!!cp ('t432');
6955              }              }
# Line 6375  sub _tree_construction_main ($) { Line 6961  sub _tree_construction_main ($) {
6961              last S2;              last S2;
6962            } else {            } else {
6963              ## Step 3              ## Step 3
6964              if (not $formatting_category->{$node->[1]} and              if (not ($node->[1] & FORMATTING_EL) and
6965                  #not $phrasing_category->{$node->[1]} and                  #not $phrasing_category->{$node->[1]} and
6966                  ($special_category->{$node->[1]} or                  ($node->[1] & SPECIAL_EL or
6967                   $scoping_category->{$node->[1]})) {                   $node->[1] & SCOPING_EL)) {
6968                !!!cp ('t433');                !!!cp ('t433');
6969                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);                !!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}, token => $token);
6970                ## Ignore the token                ## Ignore the token
# Line 6396  sub _tree_construction_main ($) { Line 6982  sub _tree_construction_main ($) {
6982            ## Step 5;            ## Step 5;
6983            redo S2;            redo S2;
6984          } # S2          } # S2
6985          redo B;          next B;
6986        }        }
6987      }      }
6988      redo B;      next B;
6989      } continue { # B
6990        if ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM) {
6991          ## NOTE: The code below is executed in cases where it does not have
6992          ## to be, but it it is harmless even in those cases.
6993          ## has an element in scope
6994          INSCOPE: {
6995            for (reverse 0..$#{$self->{open_elements}}) {
6996              my $node = $self->{open_elements}->[$_];
6997              if ($node->[1] & FOREIGN_EL) {
6998                last INSCOPE;
6999              } elsif ($node->[1] & SCOPING_EL) {
7000                last;
7001              }
7002            }
7003            
7004            ## NOTE: No foreign element in scope.
7005            $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
7006          } # INSCOPE
7007        }
7008    } # B    } # B
7009    
7010    ## Stop parsing # MUST    ## Stop parsing # MUST
# Line 6445  sub set_inner_html ($$$) { Line 7050  sub set_inner_html ($$$) {
7050    
7051      ## Step 8 # MUST      ## Step 8 # MUST
7052      my $i = 0;      my $i = 0;
7053      my $line = 1;      $p->{line_prev} = $p->{line} = 1;
7054      my $column = 0;      $p->{column_prev} = $p->{column} = 0;
7055      $p->{set_next_char} = sub {      $p->{set_next_char} = sub {
7056        my $self = shift;        my $self = shift;
7057    
# Line 6455  sub set_inner_html ($$$) { Line 7060  sub set_inner_html ($$$) {
7060    
7061        $self->{next_char} = -1 and return if $i >= length $$s;        $self->{next_char} = -1 and return if $i >= length $$s;
7062        $self->{next_char} = ord substr $$s, $i++, 1;        $self->{next_char} = ord substr $$s, $i++, 1;
7063        $column++;  
7064          ($p->{line_prev}, $p->{column_prev}) = ($p->{line}, $p->{column});
7065          $p->{column}++;
7066    
7067        if ($self->{next_char} == 0x000A) { # LF        if ($self->{next_char} == 0x000A) { # LF
7068          $line++;          $p->{line}++;
7069          $column = 0;          $p->{column} = 0;
7070          !!!cp ('i1');          !!!cp ('i1');
7071        } elsif ($self->{next_char} == 0x000D) { # CR        } elsif ($self->{next_char} == 0x000D) { # CR
7072          $i++ if substr ($$s, $i, 1) eq "\x0A";          $i++ if substr ($$s, $i, 1) eq "\x0A";
7073          $self->{next_char} = 0x000A; # LF # MUST          $self->{next_char} = 0x000A; # LF # MUST
7074          $line++;          $p->{line}++;
7075          $column = 0;          $p->{column} = 0;
7076          !!!cp ('i2');          !!!cp ('i2');
7077        } elsif ($self->{next_char} > 0x10FFFF) {        } elsif ($self->{next_char} > 0x10FFFF) {
7078          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
# Line 6474  sub set_inner_html ($$$) { Line 7081  sub set_inner_html ($$$) {
7081          !!!cp ('i4');          !!!cp ('i4');
7082          !!!parse-error (type => 'NULL');          !!!parse-error (type => 'NULL');
7083          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST          $self->{next_char} = 0xFFFD; # REPLACEMENT CHARACTER # MUST
7084          } elsif ($self->{next_char} <= 0x0008 or
7085                   (0x000E <= $self->{next_char} and
7086                    $self->{next_char} <= 0x001F) or
7087                   (0x007F <= $self->{next_char} and
7088                    $self->{next_char} <= 0x009F) or
7089                   (0xD800 <= $self->{next_char} and
7090                    $self->{next_char} <= 0xDFFF) or
7091                   (0xFDD0 <= $self->{next_char} and
7092                    $self->{next_char} <= 0xFDDF) or
7093                   {
7094                    0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1,
7095                    0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1,
7096                    0x4FFFE => 1, 0x4FFFF => 1, 0x5FFFE => 1, 0x5FFFF => 1,
7097                    0x6FFFE => 1, 0x6FFFF => 1, 0x7FFFE => 1, 0x7FFFF => 1,
7098                    0x8FFFE => 1, 0x8FFFF => 1, 0x9FFFE => 1, 0x9FFFF => 1,
7099                    0xAFFFE => 1, 0xAFFFF => 1, 0xBFFFE => 1, 0xBFFFF => 1,
7100                    0xCFFFE => 1, 0xCFFFF => 1, 0xDFFFE => 1, 0xDFFFF => 1,
7101                    0xEFFFE => 1, 0xEFFFF => 1, 0xFFFFE => 1, 0xFFFFF => 1,
7102                    0x10FFFE => 1, 0x10FFFF => 1,
7103                   }->{$self->{next_char}}) {
7104            !!!cp ('i4.1');
7105            !!!parse-error (type => 'control char', level => $self->{must_level});
7106    ## TODO: error type documentation
7107        }        }
7108      };      };
7109      $p->{prev_char} = [-1, -1, -1];      $p->{prev_char} = [-1, -1, -1];
# Line 6481  sub set_inner_html ($$$) { Line 7111  sub set_inner_html ($$$) {
7111            
7112      my $ponerror = $onerror || sub {      my $ponerror = $onerror || sub {
7113        my (%opt) = @_;        my (%opt) = @_;
7114        warn "Parse error ($opt{type}) at line $opt{line} column $opt{column}\n";        my $line = $opt{line};
7115          my $column = $opt{column};
7116          if (defined $opt{token} and defined $opt{token}->{line}) {
7117            $line = $opt{token}->{line};
7118            $column = $opt{token}->{column};
7119          }
7120          warn "Parse error ($opt{type}) at line $line column $column\n";
7121      };      };
7122      $p->{parse_error} = sub {      $p->{parse_error} = sub {
7123        $ponerror->(@_, line => $line, column => $column);        $ponerror->(line => $p->{line}, column => $p->{column}, @_);
7124      };      };
7125            
7126      $p->_initialize_tokenizer;      $p->_initialize_tokenizer;
# Line 6508  sub set_inner_html ($$$) { Line 7144  sub set_inner_html ($$$) {
7144          unless defined $p->{content_model};          unless defined $p->{content_model};
7145          ## ISSUE: What is "the name of the element"? local name?          ## ISSUE: What is "the name of the element"? local name?
7146    
7147      $p->{inner_html_node} = [$node, $node_ln];      $p->{inner_html_node} = [$node, $el_category->{$node_ln}];
7148          ## TODO: Foreign element OK?
7149    
7150      ## Step 3      ## Step 3
7151      my $root = $doc->create_element_ns      my $root = $doc->create_element_ns
# Line 6518  sub set_inner_html ($$$) { Line 7155  sub set_inner_html ($$$) {
7155      $doc->append_child ($root);      $doc->append_child ($root);
7156    
7157      ## Step 5 # MUST      ## Step 5 # MUST
7158      push @{$p->{open_elements}}, [$root, 'html'];      push @{$p->{open_elements}}, [$root, $el_category->{html}];
7159    
7160      undef $p->{head_element};      undef $p->{head_element};
7161    
# Line 6564  sub set_inner_html ($$$) { Line 7201  sub set_inner_html ($$$) {
7201      ## ISSUE: mutation events?      ## ISSUE: mutation events?
7202    
7203      $p->_terminate_tree_constructor;      $p->_terminate_tree_constructor;
7204    
7205        delete $p->{parse_error}; # delete loop
7206    } else {    } else {
7207      die "$0: |set_inner_html| is not defined for node of type $nt";      die "$0: |set_inner_html| is not defined for node of type $nt";
7208    }    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24