/[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.198 by wakaba, Sat Oct 4 08:58:02 2008 UTC revision 1.207 by wakaba, Mon Oct 13 08:27:44 2008 UTC
# Line 28  my $XLINK_NS = q<http://www.w3.org/1999/ Line 28  my $XLINK_NS = q<http://www.w3.org/1999/
28  my $XML_NS = q<http://www.w3.org/XML/1998/namespace>;  my $XML_NS = q<http://www.w3.org/XML/1998/namespace>;
29  my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>;  my $XMLNS_NS = q<http://www.w3.org/2000/xmlns/>;
30    
31  sub A_EL () { 0b1 }  ## Bits 12-15
32  sub ADDRESS_EL () { 0b10 }  sub SPECIAL_EL () { 0b1_000000000000000 }
33  sub BODY_EL () { 0b100 }  sub SCOPING_EL () { 0b1_00000000000000 }
34  sub BUTTON_EL () { 0b1000 }  sub FORMATTING_EL () { 0b1_0000000000000 }
35  sub CAPTION_EL () { 0b10000 }  sub PHRASING_EL () { 0b1_000000000000 }
36  sub DD_EL () { 0b100000 }  
37  sub DIV_EL () { 0b1000000 }  ## Bits 10-11
38  sub DT_EL () { 0b10000000 }  sub FOREIGN_EL () { 0b1_00000000000 }
39  sub FORM_EL () { 0b100000000 }  sub FOREIGN_FLOW_CONTENT_EL () { 0b1_0000000000 }
40  sub FORMATTING_EL () { 0b1000000000 }  
41  sub FRAMESET_EL () { 0b10000000000 }  ## Bits 6-9
42  sub HEADING_EL () { 0b100000000000 }  sub TABLE_SCOPING_EL () { 0b1_000000000 }
43  sub HTML_EL () { 0b1000000000000 }  sub TABLE_ROWS_SCOPING_EL () { 0b1_00000000 }
44  sub LI_EL () { 0b10000000000000 }  sub TABLE_ROW_SCOPING_EL () { 0b1_0000000 }
45  sub NOBR_EL () { 0b100000000000000 }  sub TABLE_ROWS_EL () { 0b1_000000 }
46  sub OPTION_EL () { 0b1000000000000000 }  
47  sub OPTGROUP_EL () { 0b10000000000000000 }  ## Bit 5
48  sub P_EL () { 0b100000000000000000 }  sub ADDRESS_DIV_P_EL () { 0b1_00000 }
49  sub SELECT_EL () { 0b1000000000000000000 }  
50  sub TABLE_EL () { 0b10000000000000000000 }  ## NOTE: Used in </body> and EOF algorithms.
51  sub TABLE_CELL_EL () { 0b100000000000000000000 }  ## Bit 4
52  sub TABLE_ROW_EL () { 0b1000000000000000000000 }  sub ALL_END_TAG_OPTIONAL_EL () { 0b1_0000 }
 sub TABLE_ROW_GROUP_EL () { 0b10000000000000000000000 }  
 sub MISC_SCOPING_EL () { 0b100000000000000000000000 }  
 sub MISC_SPECIAL_EL () { 0b1000000000000000000000000 }  
 sub FOREIGN_EL () { 0b10000000000000000000000000 }  
 sub FOREIGN_FLOW_CONTENT_EL () { 0b100000000000000000000000000 }  
 sub MML_AXML_EL () { 0b1000000000000000000000000000 }  
 sub RUBY_EL () { 0b10000000000000000000000000000 }  
 sub RUBY_COMPONENT_EL () { 0b100000000000000000000000000000 }  
   
 sub TABLE_ROWS_EL () {  
   TABLE_EL |  
   TABLE_ROW_EL |  
   TABLE_ROW_GROUP_EL  
 }  
53    
54  ## NOTE: Used in "generate implied end tags" algorithm.  ## NOTE: Used in "generate implied end tags" algorithm.
55  ## NOTE: There is a code where a modified version of  ## NOTE: There is a code where a modified version of
56  ## END_TAG_OPTIONAL_EL is used in "generate implied end tags"  ## END_TAG_OPTIONAL_EL is used in "generate implied end tags"
57  ## implementation (search for the algorithm name).  ## implementation (search for the algorithm name).
58  sub END_TAG_OPTIONAL_EL () {  ## Bit 3
59    DD_EL |  sub END_TAG_OPTIONAL_EL () { 0b1_000 }
   DT_EL |  
   LI_EL |  
   OPTION_EL |  
   OPTGROUP_EL |  
   P_EL |  
   RUBY_COMPONENT_EL  
 }  
60    
61  ## NOTE: Used in </body> and EOF algorithms.  ## Bits 0-2
 sub ALL_END_TAG_OPTIONAL_EL () {  
   DD_EL |  
   DT_EL |  
   LI_EL |  
   P_EL |  
   
   BODY_EL |  
   HTML_EL |  
   TABLE_CELL_EL |  
   TABLE_ROW_EL |  
   TABLE_ROW_GROUP_EL  
 }  
62    
63  sub SCOPING_EL () {  sub MISC_SPECIAL_EL () { SPECIAL_EL | 0b000 }
64    BUTTON_EL |  sub FORM_EL () { SPECIAL_EL | 0b001 }
65    CAPTION_EL |  sub FRAMESET_EL () { SPECIAL_EL | 0b010 }
66    HTML_EL |  sub HEADING_EL () { SPECIAL_EL | 0b011 }
67    TABLE_EL |  sub SELECT_EL () { SPECIAL_EL | 0b100 }
68    TABLE_CELL_EL |  sub SCRIPT_EL () { SPECIAL_EL | 0b101 }
69    MISC_SCOPING_EL  
70    sub ADDRESS_DIV_EL () { SPECIAL_EL | ADDRESS_DIV_P_EL | 0b001 }
71    sub BODY_EL () { SPECIAL_EL | ALL_END_TAG_OPTIONAL_EL | 0b001 }
72    
73    sub DTDD_EL () {
74      SPECIAL_EL |
75      END_TAG_OPTIONAL_EL |
76      ALL_END_TAG_OPTIONAL_EL |
77      0b010
78  }  }
79    sub LI_EL () {
80  sub TABLE_SCOPING_EL () {    SPECIAL_EL |
81    HTML_EL |    END_TAG_OPTIONAL_EL |
82    TABLE_EL    ALL_END_TAG_OPTIONAL_EL |
83      0b100
84  }  }
85    sub P_EL () {
86  sub TABLE_ROWS_SCOPING_EL () {    SPECIAL_EL |
87    HTML_EL |    ADDRESS_DIV_P_EL |
88    TABLE_ROW_GROUP_EL    END_TAG_OPTIONAL_EL |
89      ALL_END_TAG_OPTIONAL_EL |
90      0b001
91  }  }
92    
93  sub TABLE_ROW_SCOPING_EL () {  sub TABLE_ROW_EL () {
94    HTML_EL |    SPECIAL_EL |
95    TABLE_ROW_EL    TABLE_ROWS_EL |
96      TABLE_ROW_SCOPING_EL |
97      ALL_END_TAG_OPTIONAL_EL |
98      0b001
99    }
100    sub TABLE_ROW_GROUP_EL () {
101      SPECIAL_EL |
102      TABLE_ROWS_EL |
103      TABLE_ROWS_SCOPING_EL |
104      ALL_END_TAG_OPTIONAL_EL |
105      0b001
106  }  }
107    
108  sub SPECIAL_EL () {  sub MISC_SCOPING_EL () { SCOPING_EL | 0b000 }
109    ADDRESS_EL |  sub BUTTON_EL () { SCOPING_EL | 0b001 }
110    BODY_EL |  sub CAPTION_EL () { SCOPING_EL | 0b010 }
111    DIV_EL |  sub HTML_EL () {
112      SCOPING_EL |
113    DD_EL |    TABLE_SCOPING_EL |
114    DT_EL |    TABLE_ROWS_SCOPING_EL |
115    LI_EL |    TABLE_ROW_SCOPING_EL |
116    P_EL |    ALL_END_TAG_OPTIONAL_EL |
117      0b001
118    FORM_EL |  }
119    FRAMESET_EL |  sub TABLE_EL () {
120    HEADING_EL |    SCOPING_EL |
121    OPTION_EL |    TABLE_ROWS_EL |
122    OPTGROUP_EL |    TABLE_SCOPING_EL |
123    SELECT_EL |    0b001
124    TABLE_ROW_EL |  }
125    TABLE_ROW_GROUP_EL |  sub TABLE_CELL_EL () {
126    MISC_SPECIAL_EL    SCOPING_EL |
127      TABLE_ROW_SCOPING_EL |
128      ALL_END_TAG_OPTIONAL_EL |
129      0b001
130  }  }
131    
132    sub MISC_FORMATTING_EL () { FORMATTING_EL | 0b000 }
133    sub A_EL () { FORMATTING_EL | 0b001 }
134    sub NOBR_EL () { FORMATTING_EL | 0b010 }
135    
136    sub RUBY_EL () { PHRASING_EL | 0b001 }
137    
138    ## ISSUE: ALL_END_TAG_OPTIONAL_EL?
139    sub OPTGROUP_EL () { PHRASING_EL | END_TAG_OPTIONAL_EL | 0b001 }
140    sub OPTION_EL () { PHRASING_EL | END_TAG_OPTIONAL_EL | 0b010 }
141    sub RUBY_COMPONENT_EL () { PHRASING_EL | END_TAG_OPTIONAL_EL | 0b100 }
142    
143    sub MML_AXML_EL () { PHRASING_EL | FOREIGN_EL | 0b001 }
144    
145  my $el_category = {  my $el_category = {
146    a => A_EL | FORMATTING_EL,    a => A_EL,
147    address => ADDRESS_EL,    address => ADDRESS_DIV_EL,
148    applet => MISC_SCOPING_EL,    applet => MISC_SCOPING_EL,
149    area => MISC_SPECIAL_EL,    area => MISC_SPECIAL_EL,
150    article => MISC_SPECIAL_EL,    article => MISC_SPECIAL_EL,
# Line 160  my $el_category = { Line 164  my $el_category = {
164    colgroup => MISC_SPECIAL_EL,    colgroup => MISC_SPECIAL_EL,
165    command => MISC_SPECIAL_EL,    command => MISC_SPECIAL_EL,
166    datagrid => MISC_SPECIAL_EL,    datagrid => MISC_SPECIAL_EL,
167    dd => DD_EL,    dd => DTDD_EL,
168    details => MISC_SPECIAL_EL,    details => MISC_SPECIAL_EL,
169    dialog => MISC_SPECIAL_EL,    dialog => MISC_SPECIAL_EL,
170    dir => MISC_SPECIAL_EL,    dir => MISC_SPECIAL_EL,
171    div => DIV_EL,    div => ADDRESS_DIV_EL,
172    dl => MISC_SPECIAL_EL,    dl => MISC_SPECIAL_EL,
173    dt => DT_EL,    dt => DTDD_EL,
174    em => FORMATTING_EL,    em => FORMATTING_EL,
175    embed => MISC_SPECIAL_EL,    embed => MISC_SPECIAL_EL,
176    eventsource => MISC_SPECIAL_EL,    eventsource => MISC_SPECIAL_EL,
# Line 200  my $el_category = { Line 204  my $el_category = {
204    menu => MISC_SPECIAL_EL,    menu => MISC_SPECIAL_EL,
205    meta => MISC_SPECIAL_EL,    meta => MISC_SPECIAL_EL,
206    nav => MISC_SPECIAL_EL,    nav => MISC_SPECIAL_EL,
207    nobr => NOBR_EL | FORMATTING_EL,    nobr => NOBR_EL,
208    noembed => MISC_SPECIAL_EL,    noembed => MISC_SPECIAL_EL,
209    noframes => MISC_SPECIAL_EL,    noframes => MISC_SPECIAL_EL,
210    noscript => MISC_SPECIAL_EL,    noscript => MISC_SPECIAL_EL,
# Line 242  my $el_category = { Line 246  my $el_category = {
246  my $el_category_f = {  my $el_category_f = {
247    $MML_NS => {    $MML_NS => {
248      'annotation-xml' => MML_AXML_EL,      'annotation-xml' => MML_AXML_EL,
249      mi => FOREIGN_FLOW_CONTENT_EL,      mi => FOREIGN_EL | FOREIGN_FLOW_CONTENT_EL,
250      mo => FOREIGN_FLOW_CONTENT_EL,      mo => FOREIGN_EL | FOREIGN_FLOW_CONTENT_EL,
251      mn => FOREIGN_FLOW_CONTENT_EL,      mn => FOREIGN_EL | FOREIGN_FLOW_CONTENT_EL,
252      ms => FOREIGN_FLOW_CONTENT_EL,      ms => FOREIGN_EL | FOREIGN_FLOW_CONTENT_EL,
253      mtext => FOREIGN_FLOW_CONTENT_EL,      mtext => FOREIGN_EL | FOREIGN_FLOW_CONTENT_EL,
254    },    },
255    $SVG_NS => {    $SVG_NS => {
256      foreignObject => FOREIGN_FLOW_CONTENT_EL,      foreignObject => SCOPING_EL | FOREIGN_EL | FOREIGN_FLOW_CONTENT_EL,
257      desc => FOREIGN_FLOW_CONTENT_EL,      desc => FOREIGN_EL | FOREIGN_FLOW_CONTENT_EL,
258      title => FOREIGN_FLOW_CONTENT_EL,      title => FOREIGN_EL | FOREIGN_FLOW_CONTENT_EL,
259    },    },
260    ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.    ## NOTE: In addition, FOREIGN_EL is set to non-HTML elements.
261  };  };
# Line 918  sub IN_FOREIGN_CONTENT_IM () { 0b1000000 Line 922  sub IN_FOREIGN_CONTENT_IM () { 0b1000000
922      ## NOTE: "in foreign content" insertion mode is special; it is combined      ## NOTE: "in foreign content" insertion mode is special; it is combined
923      ## with the secondary insertion mode.  In this parser, they are stored      ## with the secondary insertion mode.  In this parser, they are stored
924      ## together in the bit-or'ed form.      ## together in the bit-or'ed form.
925    sub IN_CDATA_RCDATA_IM () { 0b1000000000000 }
926        ## NOTE: "in CDATA/RCDATA" insertion mode is also special; it is
927        ## combined with the original insertion mode.  In thie parser,
928        ## they are stored together in the bit-or'ed form.
929    
930  ## NOTE: "initial" and "before html" insertion modes have no constants.  ## NOTE: "initial" and "before html" insertion modes have no constants.
931    
# Line 2987  sub _get_next_token ($) { Line 2995  sub _get_next_token ($) {
2995          redo A;          redo A;
2996        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2997          !!!cp (220);          !!!cp (220);
         !!!parse-error (type => 'unclosed DOCTYPE');  
2998          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
2999          ## reconsume          ## reconsume
3000    
# Line 3467  sub _construct_tree ($) { Line 3474  sub _construct_tree ($) {
3474    ## When an interactive UA render the $self->{document} available    ## When an interactive UA render the $self->{document} available
3475    ## to the user, or when it begin accepting user input, are    ## to the user, or when it begin accepting user input, are
3476    ## not defined.    ## not defined.
   
   ## Append a character: collect it and all subsequent consecutive  
   ## characters and insert one Text node whose data is concatenation  
   ## of all those characters. # MUST  
3477        
3478    !!!next-token;    !!!next-token;
3479    
3480    undef $self->{form_element};    undef $self->{form_element};
3481    undef $self->{head_element};    undef $self->{head_element};
3482      undef $self->{head_element_inserted};
3483    $self->{open_elements} = [];    $self->{open_elements} = [];
3484    undef $self->{inner_html_node};    undef $self->{inner_html_node};
3485      undef $self->{ignore_newline};
3486    
3487    ## NOTE: The "initial" insertion mode.    ## NOTE: The "initial" insertion mode.
3488    $self->_tree_construction_initial; # MUST    $self->_tree_construction_initial; # MUST
# Line 3818  sub _reset_insertion_mode ($) { Line 3823  sub _reset_insertion_mode ($) {
3823          ## SVG elements.  Currently the HTML syntax supports only MathML and          ## SVG elements.  Currently the HTML syntax supports only MathML and
3824          ## SVG elements as foreigners.          ## SVG elements as foreigners.
3825          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;          $new_mode = IN_BODY_IM | IN_FOREIGN_CONTENT_IM;
3826        } elsif ($node->[1] & TABLE_CELL_EL) {        } elsif ($node->[1] == TABLE_CELL_EL) {
3827          if ($last) {          if ($last) {
3828            !!!cp ('t28.2');            !!!cp ('t28.2');
3829            #            #
# Line 3847  sub _reset_insertion_mode ($) { Line 3852  sub _reset_insertion_mode ($) {
3852        $self->{insertion_mode} = $new_mode and return if defined $new_mode;        $self->{insertion_mode} = $new_mode and return if defined $new_mode;
3853                
3854        ## Step 15        ## Step 15
3855        if ($node->[1] & HTML_EL) {        if ($node->[1] == HTML_EL) {
3856          unless (defined $self->{head_element}) {          unless (defined $self->{head_element}) {
3857            !!!cp ('t29');            !!!cp ('t29');
3858            $self->{insertion_mode} = BEFORE_HEAD_IM;            $self->{insertion_mode} = BEFORE_HEAD_IM;
# Line 3979  sub _tree_construction_main ($) { Line 3984  sub _tree_construction_main ($) {
3984    
3985      ## Step 1      ## Step 1
3986      my $start_tag_name = $token->{tag_name};      my $start_tag_name = $token->{tag_name};
3987      my $el;      !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
     !!!create-element ($el, $HTML_NS, $start_tag_name, $token->{attributes}, $token);  
3988    
3989      ## Step 2      ## Step 2
     $insert->($el);  
   
     ## Step 3  
3990      $self->{content_model} = $content_model_flag; # CDATA or RCDATA      $self->{content_model} = $content_model_flag; # CDATA or RCDATA
3991      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
3992    
3993      ## Step 4      ## Step 3, 4
3994      my $text = '';      $self->{insertion_mode} |= IN_CDATA_RCDATA_IM;
     !!!nack ('t40.1');  
     !!!next-token;  
     while ($token->{type} == CHARACTER_TOKEN) { # or until stop tokenizing  
       !!!cp ('t40');  
       $text .= $token->{data};  
       !!!next-token;  
     }  
3995    
3996      ## Step 5      !!!nack ('t40.1');
     if (length $text) {  
       !!!cp ('t41');  
       my $text = $self->{document}->create_text_node ($text);  
       $el->append_child ($text);  
     }  
   
     ## Step 6  
     $self->{content_model} = PCDATA_CONTENT_MODEL;  
   
     ## Step 7  
     if ($token->{type} == END_TAG_TOKEN and  
         $token->{tag_name} eq $start_tag_name) {  
       !!!cp ('t42');  
       ## Ignore the token  
     } else {  
       ## NOTE: An end-of-file token.  
       if ($content_model_flag == CDATA_CONTENT_MODEL) {  
         !!!cp ('t43');  
         !!!parse-error (type => 'in CDATA:#eof', token => $token);  
       } elsif ($content_model_flag == RCDATA_CONTENT_MODEL) {  
         !!!cp ('t44');  
         !!!parse-error (type => 'in RCDATA:#eof', token => $token);  
       } else {  
         die "$0: $content_model_flag in parse_rcdata";  
       }  
     }  
3997      !!!next-token;      !!!next-token;
3998    }; # $parse_rcdata    }; # $parse_rcdata
3999    
4000    my $script_start_tag = sub () {    my $script_start_tag = sub () {
4001        ## Step 1
4002      my $script_el;      my $script_el;
4003      !!!create-element ($script_el, $HTML_NS, 'script', $token->{attributes}, $token);      !!!create-element ($script_el, $HTML_NS, 'script', $token->{attributes}, $token);
4004    
4005        ## Step 2
4006      ## TODO: mark as "parser-inserted"      ## TODO: mark as "parser-inserted"
4007    
4008        ## Step 3
4009        ## TODO: Mark as "already executed", if ...
4010    
4011        ## Step 4
4012        $insert->($script_el);
4013    
4014        ## ISSUE: $script_el is not put into the stack
4015        push @{$self->{open_elements}}, [$script_el, $el_category->{script}];
4016    
4017        ## Step 5
4018      $self->{content_model} = CDATA_CONTENT_MODEL;      $self->{content_model} = CDATA_CONTENT_MODEL;
4019      delete $self->{escape}; # MUST      delete $self->{escape}; # MUST
       
     my $text = '';  
     !!!nack ('t45.1');  
     !!!next-token;  
     while ($token->{type} == CHARACTER_TOKEN) {  
       !!!cp ('t45');  
       $text .= $token->{data};  
       !!!next-token;  
     } # stop if non-character token or tokenizer stops tokenising  
     if (length $text) {  
       !!!cp ('t46');  
       $script_el->manakai_append_text ($text);  
     }  
                 
     $self->{content_model} = PCDATA_CONTENT_MODEL;  
4020    
4021      if ($token->{type} == END_TAG_TOKEN and      ## Step 6-7
4022          $token->{tag_name} eq 'script') {      $self->{insertion_mode} |= IN_CDATA_RCDATA_IM;
       !!!cp ('t47');  
       ## Ignore the token  
     } else {  
       !!!cp ('t48');  
       !!!parse-error (type => 'in CDATA:#eof', token => $token);  
       ## ISSUE: And ignore?  
       ## TODO: mark as "already executed"  
     }  
       
     if (defined $self->{inner_html_node}) {  
       !!!cp ('t49');  
       ## TODO: mark as "already executed"  
     } else {  
       !!!cp ('t50');  
       ## TODO: $old_insertion_point = current insertion point  
       ## TODO: insertion point = just before the next input character  
4023    
4024        $insert->($script_el);      !!!nack ('t40.2');
         
       ## TODO: insertion point = $old_insertion_point (might be "undefined")  
         
       ## TODO: if there is a script that will execute as soon as the parser resume, then...  
     }  
       
4025      !!!next-token;      !!!next-token;
4026    }; # $script_start_tag    }; # $script_start_tag
4027    
4028    ## NOTE: $open_tables->[-1]->[0] is the "current table" element node.    ## NOTE: $open_tables->[-1]->[0] is the "current table" element node.
4029    ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.    ## NOTE: $open_tables->[-1]->[1] is the "tainted" flag.
4030      ## NOTE: $open_tables->[-1]->[2] is set false when non-Text node inserted.
4031    my $open_tables = [[$self->{open_elements}->[0]->[0]]];    my $open_tables = [[$self->{open_elements}->[0]->[0]]];
4032    
4033    my $formatting_end_tag = sub {    my $formatting_end_tag = sub {
# Line 4167  sub _tree_construction_main ($) { Line 4112  sub _tree_construction_main ($) {
4112            !!!cp ('t59');            !!!cp ('t59');
4113            $furthest_block = $node;            $furthest_block = $node;
4114            $furthest_block_i_in_open = $_;            $furthest_block_i_in_open = $_;
4115              ## NOTE: The topmost (eldest) node.
4116          } elsif ($node->[0] eq $formatting_element->[0]) {          } elsif ($node->[0] eq $formatting_element->[0]) {
4117            !!!cp ('t60');            !!!cp ('t60');
4118            last OE;            last OE;
# Line 4253  sub _tree_construction_main ($) { Line 4199  sub _tree_construction_main ($) {
4199          my $foster_parent_element;          my $foster_parent_element;
4200          my $next_sibling;          my $next_sibling;
4201          OE: for (reverse 0..$#{$self->{open_elements}}) {          OE: for (reverse 0..$#{$self->{open_elements}}) {
4202            if ($self->{open_elements}->[$_]->[1] & TABLE_EL) {            if ($self->{open_elements}->[$_]->[1] == TABLE_EL) {
4203                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
4204                               if (defined $parent and $parent->node_type == 1) {                               if (defined $parent and $parent->node_type == 1) {
4205                                 !!!cp ('t65.1');                                 !!!cp ('t65.1');
# Line 4313  sub _tree_construction_main ($) { Line 4259  sub _tree_construction_main ($) {
4259            $i = $_;            $i = $_;
4260          }          }
4261        } # OE        } # OE
4262        splice @{$self->{open_elements}}, $i + 1, 1, $clone;        splice @{$self->{open_elements}}, $i + 1, 0, $clone;
4263                
4264        ## Step 14        ## Step 14
4265        redo FET;        redo FET;
# Line 4331  sub _tree_construction_main ($) { Line 4277  sub _tree_construction_main ($) {
4277        my $foster_parent_element;        my $foster_parent_element;
4278        my $next_sibling;        my $next_sibling;
4279        OE: for (reverse 0..$#{$self->{open_elements}}) {        OE: for (reverse 0..$#{$self->{open_elements}}) {
4280          if ($self->{open_elements}->[$_]->[1] & TABLE_EL) {          if ($self->{open_elements}->[$_]->[1] == TABLE_EL) {
4281                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                               my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
4282                               if (defined $parent and $parent->node_type == 1) {                               if (defined $parent and $parent->node_type == 1) {
4283                                 !!!cp ('t70');                                 !!!cp ('t70');
# Line 4356  sub _tree_construction_main ($) { Line 4302  sub _tree_construction_main ($) {
4302      }      }
4303    }; # $insert_to_foster    }; # $insert_to_foster
4304    
4305      ## NOTE: Insert a character (MUST): When a character is inserted, if
4306      ## the last node that was inserted by the parser is a Text node and
4307      ## the character has to be inserted after that node, then the
4308      ## character is appended to the Text node.  However, if any other
4309      ## node is inserted by the parser, then a new Text node is created
4310      ## and the character is appended as that Text node.  If I'm not
4311      ## wrong, for a parser with scripting disabled, there are only two
4312      ## cases where this occurs.  One is the case where an element node
4313      ## is inserted to the |head| element.  This is covered by using the
4314      ## |$self->{head_element_inserted}| flag.  Another is the case where
4315      ## an element or comment is inserted into the |table| subtree while
4316      ## foster parenting happens.  This is covered by using the [2] flag
4317      ## of the |$open_tables| structure.  All other cases are handled
4318      ## simply by calling |manakai_append_text| method.
4319    
4320      ## TODO: |<body><script>document.write("a<br>");
4321      ## document.body.removeChild (document.body.lastChild);
4322      ## document.write ("b")</script>|
4323    
4324    B: while (1) {    B: while (1) {
4325      if ($token->{type} == DOCTYPE_TOKEN) {      if ($token->{type} == DOCTYPE_TOKEN) {
4326        !!!cp ('t73');        !!!cp ('t73');
# Line 4403  sub _tree_construction_main ($) { Line 4368  sub _tree_construction_main ($) {
4368        } else {        } else {
4369          !!!cp ('t87');          !!!cp ('t87');
4370          $self->{open_elements}->[-1]->[0]->append_child ($comment);          $self->{open_elements}->[-1]->[0]->append_child ($comment);
4371            $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
4372        }        }
4373        !!!next-token;        !!!next-token;
4374        next B;        next B;
4375        } elsif ($self->{insertion_mode} & IN_CDATA_RCDATA_IM) {
4376          if ($token->{type} == CHARACTER_TOKEN) {
4377            $token->{data} =~ s/^\x0A// if $self->{ignore_newline};
4378            delete $self->{ignore_newline};
4379    
4380            if (length $token->{data}) {
4381              !!!cp ('t43');
4382              $self->{open_elements}->[-1]->[0]->manakai_append_text
4383                  ($token->{data});
4384            } else {
4385              !!!cp ('t43.1');
4386            }
4387            !!!next-token;
4388            next B;
4389          } elsif ($token->{type} == END_TAG_TOKEN) {
4390            delete $self->{ignore_newline};
4391    
4392            if ($token->{tag_name} eq 'script') {
4393              !!!cp ('t50');
4394              
4395              ## Para 1-2
4396              my $script = pop @{$self->{open_elements}};
4397              
4398              ## Para 3
4399              $self->{insertion_mode} &= ~ IN_CDATA_RCDATA_IM;
4400    
4401              ## Para 4
4402              ## TODO: $old_insertion_point = $current_insertion_point;
4403              ## TODO: $current_insertion_point = just before $self->{nc};
4404    
4405              ## Para 5
4406              ## TODO: Run the $script->[0].
4407    
4408              ## Para 6
4409              ## TODO: $current_insertion_point = $old_insertion_point;
4410    
4411              ## Para 7
4412              ## TODO: if ($pending_external_script) {
4413                ## TODO: ...
4414              ## TODO: }
4415    
4416              !!!next-token;
4417              next B;
4418            } else {
4419              !!!cp ('t42');
4420    
4421              pop @{$self->{open_elements}};
4422    
4423              $self->{insertion_mode} &= ~ IN_CDATA_RCDATA_IM;
4424              !!!next-token;
4425              next B;
4426            }
4427          } elsif ($token->{type} == END_OF_FILE_TOKEN) {
4428            delete $self->{ignore_newline};
4429    
4430            !!!cp ('t44');
4431            !!!parse-error (type => 'not closed',
4432                            text => $self->{open_elements}->[-1]->[0]
4433                                ->manakai_local_name,
4434                            token => $token);
4435    
4436            #if ($self->{open_elements}->[-1]->[1] == SCRIPT_EL) {
4437            #  ## TODO: Mark as "already executed"
4438            #}
4439    
4440            pop @{$self->{open_elements}};
4441    
4442            $self->{insertion_mode} &= ~ IN_CDATA_RCDATA_IM;
4443            ## Reprocess.
4444            next B;
4445          } else {
4446            die "$0: $token->{type}: In CDATA/RCDATA: Unknown token type";        
4447          }
4448      } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM) {      } elsif ($self->{insertion_mode} & IN_FOREIGN_CONTENT_IM) {
4449        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4450          !!!cp ('t87.1');          !!!cp ('t87.1');
# Line 4417  sub _tree_construction_main ($) { Line 4456  sub _tree_construction_main ($) {
4456               $self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL) or               $self->{open_elements}->[-1]->[1] & FOREIGN_FLOW_CONTENT_EL) or
4457              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or              not ($self->{open_elements}->[-1]->[1] & FOREIGN_EL) or
4458              ($token->{tag_name} eq 'svg' and              ($token->{tag_name} eq 'svg' and
4459               $self->{open_elements}->[-1]->[1] & MML_AXML_EL)) {               $self->{open_elements}->[-1]->[1] == MML_AXML_EL)) {
4460            ## NOTE: "using the rules for secondary insertion mode"then"continue"            ## NOTE: "using the rules for secondary insertion mode"then"continue"
4461            !!!cp ('t87.2');            !!!cp ('t87.2');
4462            #            #
# Line 4518  sub _tree_construction_main ($) { Line 4557  sub _tree_construction_main ($) {
4557          pop @{$self->{open_elements}}          pop @{$self->{open_elements}}
4558              while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;              while $self->{open_elements}->[-1]->[1] & FOREIGN_EL;
4559    
4560            ## NOTE: |<span><svg>| ... two parse errors, |<svg>| ... a parse error.
4561    
4562          $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;          $self->{insertion_mode} &= ~ IN_FOREIGN_CONTENT_IM;
4563          ## Reprocess.          ## Reprocess.
4564          next B;          next B;
# Line 4530  sub _tree_construction_main ($) { Line 4571  sub _tree_construction_main ($) {
4571        if ($token->{type} == CHARACTER_TOKEN) {        if ($token->{type} == CHARACTER_TOKEN) {
4572          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {          if ($token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) {
4573            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {            unless ($self->{insertion_mode} == BEFORE_HEAD_IM) {
4574              !!!cp ('t88.2');              if ($self->{head_element_inserted}) {
4575              $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);                !!!cp ('t88.3');
4576              #                $self->{open_elements}->[-1]->[0]->append_child
4577                    ($self->{document}->create_text_node ($1));
4578                  delete $self->{head_element_inserted};
4579                  ## NOTE: |</head> <link> |
4580                  #
4581                } else {
4582                  !!!cp ('t88.2');
4583                  $self->{open_elements}->[-1]->[0]->manakai_append_text ($1);
4584                  ## NOTE: |</head> &#x20;|
4585                  #
4586                }
4587            } else {            } else {
4588              !!!cp ('t88.1');              !!!cp ('t88.1');
4589              ## Ignore the token.              ## Ignore the token.
# Line 4628  sub _tree_construction_main ($) { Line 4679  sub _tree_construction_main ($) {
4679            !!!cp ('t97');            !!!cp ('t97');
4680          }          }
4681    
4682              if ($token->{tag_name} eq 'base') {          if ($token->{tag_name} eq 'base') {
4683                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {            if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4684                  !!!cp ('t98');              !!!cp ('t98');
4685                  ## As if </noscript>              ## As if </noscript>
4686                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
4687                  !!!parse-error (type => 'in noscript', text => 'base',              !!!parse-error (type => 'in noscript', text => 'base',
4688                                  token => $token);                              token => $token);
4689                            
4690                  $self->{insertion_mode} = IN_HEAD_IM;              $self->{insertion_mode} = IN_HEAD_IM;
4691                  ## Reprocess in the "in head" insertion mode...              ## Reprocess in the "in head" insertion mode...
4692                } else {            } else {
4693                  !!!cp ('t99');              !!!cp ('t99');
4694                }            }
4695    
4696                ## NOTE: There is a "as if in head" code clone.            ## NOTE: There is a "as if in head" code clone.
4697                if ($self->{insertion_mode} == AFTER_HEAD_IM) {            if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4698                  !!!cp ('t100');              !!!cp ('t100');
4699                  !!!parse-error (type => 'after head',              !!!parse-error (type => 'after head',
4700                                  text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
4701                  push @{$self->{open_elements}},              push @{$self->{open_elements}},
4702                      [$self->{head_element}, $el_category->{head}];                  [$self->{head_element}, $el_category->{head}];
4703                } else {              $self->{head_element_inserted} = 1;
4704                  !!!cp ('t101');            } else {
4705                }              !!!cp ('t101');
4706                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);            }
4707                pop @{$self->{open_elements}};            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
4708                pop @{$self->{open_elements}} # <head>            pop @{$self->{open_elements}};
4709                    if $self->{insertion_mode} == AFTER_HEAD_IM;            pop @{$self->{open_elements}} # <head>
4710                !!!nack ('t101.1');                if $self->{insertion_mode} == AFTER_HEAD_IM;
4711                !!!next-token;            !!!nack ('t101.1');
4712                next B;            !!!next-token;
4713              next B;
4714          } elsif ($token->{tag_name} eq 'link') {          } elsif ($token->{tag_name} eq 'link') {
4715            ## NOTE: There is a "as if in head" code clone.            ## NOTE: There is a "as if in head" code clone.
4716            if ($self->{insertion_mode} == AFTER_HEAD_IM) {            if ($self->{insertion_mode} == AFTER_HEAD_IM) {
# Line 4667  sub _tree_construction_main ($) { Line 4719  sub _tree_construction_main ($) {
4719                              text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
4720              push @{$self->{open_elements}},              push @{$self->{open_elements}},
4721                  [$self->{head_element}, $el_category->{head}];                  [$self->{head_element}, $el_category->{head}];
4722                $self->{head_element_inserted} = 1;
4723            } else {            } else {
4724              !!!cp ('t103');              !!!cp ('t103');
4725            }            }
# Line 4699  sub _tree_construction_main ($) { Line 4752  sub _tree_construction_main ($) {
4752              !!!cp ('t103.3');              !!!cp ('t103.3');
4753              #              #
4754            }            }
4755              } elsif ($token->{tag_name} eq 'meta') {          } elsif ($token->{tag_name} eq 'meta') {
4756                ## NOTE: There is a "as if in head" code clone.            ## NOTE: There is a "as if in head" code clone.
4757                if ($self->{insertion_mode} == AFTER_HEAD_IM) {            if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4758                  !!!cp ('t104');              !!!cp ('t104');
4759                  !!!parse-error (type => 'after head',              !!!parse-error (type => 'after head',
4760                                  text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
4761                  push @{$self->{open_elements}},              push @{$self->{open_elements}},
4762                      [$self->{head_element}, $el_category->{head}];                  [$self->{head_element}, $el_category->{head}];
4763                } else {              $self->{head_element_inserted} = 1;
4764                  !!!cp ('t105');            } else {
4765                }              !!!cp ('t105');
4766                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);            }
4767                my $meta_el = pop @{$self->{open_elements}};            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
4768              my $meta_el = pop @{$self->{open_elements}};
4769    
4770                unless ($self->{confident}) {                unless ($self->{confident}) {
4771                  if ($token->{attributes}->{charset}) {                  if ($token->{attributes}->{charset}) {
# Line 4769  sub _tree_construction_main ($) { Line 4823  sub _tree_construction_main ($) {
4823                !!!ack ('t110.1');                !!!ack ('t110.1');
4824                !!!next-token;                !!!next-token;
4825                next B;                next B;
4826              } elsif ($token->{tag_name} eq 'title') {          } elsif ($token->{tag_name} eq 'title') {
4827                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {            if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4828                  !!!cp ('t111');              !!!cp ('t111');
4829                  ## As if </noscript>              ## As if </noscript>
4830                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
4831                  !!!parse-error (type => 'in noscript', text => 'title',              !!!parse-error (type => 'in noscript', text => 'title',
4832                                  token => $token);                              token => $token);
4833                            
4834                  $self->{insertion_mode} = IN_HEAD_IM;              $self->{insertion_mode} = IN_HEAD_IM;
4835                  ## Reprocess in the "in head" insertion mode...              ## Reprocess in the "in head" insertion mode...
4836                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4837                  !!!cp ('t112');              !!!cp ('t112');
4838                  !!!parse-error (type => 'after head',              !!!parse-error (type => 'after head',
4839                                  text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
4840                  push @{$self->{open_elements}},              push @{$self->{open_elements}},
4841                      [$self->{head_element}, $el_category->{head}];                  [$self->{head_element}, $el_category->{head}];
4842                } else {              $self->{head_element_inserted} = 1;
4843                  !!!cp ('t113');            } else {
4844                }              !!!cp ('t113');
4845              }
4846    
4847                ## NOTE: There is a "as if in head" code clone.            ## NOTE: There is a "as if in head" code clone.
4848                my $parent = defined $self->{head_element} ? $self->{head_element}            $parse_rcdata->(RCDATA_CONTENT_MODEL);
4849                    : $self->{open_elements}->[-1]->[0];            ## ISSUE: A spec bug [Bug 6038]
4850                $parse_rcdata->(RCDATA_CONTENT_MODEL);            splice @{$self->{open_elements}}, -2, 1, () # <head>
4851                pop @{$self->{open_elements}} # <head>                if ($self->{insertion_mode} & AFTER_HEAD_IM) == AFTER_HEAD_IM;
4852                    if $self->{insertion_mode} == AFTER_HEAD_IM;            next B;
4853                next B;          } elsif ($token->{tag_name} eq 'style' or
4854              } elsif ($token->{tag_name} eq 'style' or                   $token->{tag_name} eq 'noframes') {
4855                       $token->{tag_name} eq 'noframes') {            ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and
4856                ## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and            ## insertion mode IN_HEAD_IM)
4857                ## insertion mode IN_HEAD_IM)            ## NOTE: There is a "as if in head" code clone.
4858                ## NOTE: There is a "as if in head" code clone.            if ($self->{insertion_mode} == AFTER_HEAD_IM) {
4859                if ($self->{insertion_mode} == AFTER_HEAD_IM) {              !!!cp ('t114');
4860                  !!!cp ('t114');              !!!parse-error (type => 'after head',
4861                  !!!parse-error (type => 'after head',                              text => $token->{tag_name}, token => $token);
4862                                  text => $token->{tag_name}, token => $token);              push @{$self->{open_elements}},
4863                  push @{$self->{open_elements}},                  [$self->{head_element}, $el_category->{head}];
4864                      [$self->{head_element}, $el_category->{head}];              $self->{head_element_inserted} = 1;
4865                } else {            } else {
4866                  !!!cp ('t115');              !!!cp ('t115');
4867                }            }
4868                $parse_rcdata->(CDATA_CONTENT_MODEL);            $parse_rcdata->(CDATA_CONTENT_MODEL);
4869                pop @{$self->{open_elements}} # <head>            ## ISSUE: A spec bug [Bug 6038]
4870                    if $self->{insertion_mode} == AFTER_HEAD_IM;            splice @{$self->{open_elements}}, -2, 1, () # <head>
4871                next B;                if ($self->{insertion_mode} & AFTER_HEAD_IM) == AFTER_HEAD_IM;
4872              } elsif ($token->{tag_name} eq 'noscript') {            next B;
4873            } elsif ($token->{tag_name} eq 'noscript') {
4874                if ($self->{insertion_mode} == IN_HEAD_IM) {                if ($self->{insertion_mode} == IN_HEAD_IM) {
4875                  !!!cp ('t116');                  !!!cp ('t116');
4876                  ## NOTE: and scripting is disalbed                  ## NOTE: and scripting is disalbed
# Line 4835  sub _tree_construction_main ($) { Line 4891  sub _tree_construction_main ($) {
4891                  !!!cp ('t118');                  !!!cp ('t118');
4892                  #                  #
4893                }                }
4894              } elsif ($token->{tag_name} eq 'script') {          } elsif ($token->{tag_name} eq 'script') {
4895                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {            if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4896                  !!!cp ('t119');              !!!cp ('t119');
4897                  ## As if </noscript>              ## As if </noscript>
4898                  pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
4899                  !!!parse-error (type => 'in noscript', text => 'script',              !!!parse-error (type => 'in noscript', text => 'script',
4900                                  token => $token);                              token => $token);
4901                            
4902                  $self->{insertion_mode} = IN_HEAD_IM;              $self->{insertion_mode} = IN_HEAD_IM;
4903                  ## Reprocess in the "in head" insertion mode...              ## Reprocess in the "in head" insertion mode...
4904                } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {            } elsif ($self->{insertion_mode} == AFTER_HEAD_IM) {
4905                  !!!cp ('t120');              !!!cp ('t120');
4906                  !!!parse-error (type => 'after head',              !!!parse-error (type => 'after head',
4907                                  text => $token->{tag_name}, token => $token);                              text => $token->{tag_name}, token => $token);
4908                  push @{$self->{open_elements}},              push @{$self->{open_elements}},
4909                      [$self->{head_element}, $el_category->{head}];                  [$self->{head_element}, $el_category->{head}];
4910                } else {              $self->{head_element_inserted} = 1;
4911                  !!!cp ('t121');            } else {
4912                }              !!!cp ('t121');
4913              }
4914    
4915                ## NOTE: There is a "as if in head" code clone.            ## NOTE: There is a "as if in head" code clone.
4916                $script_start_tag->();            $script_start_tag->();
4917                pop @{$self->{open_elements}} # <head>            ## ISSUE: A spec bug  [Bug 6038]
4918                    if $self->{insertion_mode} == AFTER_HEAD_IM;            splice @{$self->{open_elements}}, -2, 1 # <head>
4919                next B;                if ($self->{insertion_mode} & AFTER_HEAD_IM) == AFTER_HEAD_IM;
4920              } elsif ($token->{tag_name} eq 'body' or            next B;
4921                       $token->{tag_name} eq 'frameset') {          } elsif ($token->{tag_name} eq 'body' or
4922                     $token->{tag_name} eq 'frameset') {
4923                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                if ($self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
4924                  !!!cp ('t122');                  !!!cp ('t122');
4925                  ## As if </noscript>                  ## As if </noscript>
# Line 4996  sub _tree_construction_main ($) { Line 5054  sub _tree_construction_main ($) {
5054              } elsif ({              } elsif ({
5055                        body => 1, html => 1,                        body => 1, html => 1,
5056                       }->{$token->{tag_name}}) {                       }->{$token->{tag_name}}) {
5057                if ($self->{insertion_mode} == BEFORE_HEAD_IM or                ## TODO: This branch is entirely redundant.
5058                  if ($self->{insertion_mode} == BEFORE_HEAD_IM or
5059                    $self->{insertion_mode} == IN_HEAD_IM or                    $self->{insertion_mode} == IN_HEAD_IM or
5060                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {                    $self->{insertion_mode} == IN_HEAD_NOSCRIPT_IM) {
5061                  !!!cp ('t140');                  !!!cp ('t140');
# Line 5187  sub _tree_construction_main ($) { Line 5246  sub _tree_construction_main ($) {
5246                  ## have an element in table scope                  ## have an element in table scope
5247                  for (reverse 0..$#{$self->{open_elements}}) {                  for (reverse 0..$#{$self->{open_elements}}) {
5248                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
5249                    if ($node->[1] & TABLE_CELL_EL) {                    if ($node->[1] == TABLE_CELL_EL) {
5250                      !!!cp ('t151');                      !!!cp ('t151');
5251    
5252                      ## Close the cell                      ## Close the cell
# Line 5221  sub _tree_construction_main ($) { Line 5280  sub _tree_construction_main ($) {
5280                  INSCOPE: {                  INSCOPE: {
5281                    for (reverse 0..$#{$self->{open_elements}}) {                    for (reverse 0..$#{$self->{open_elements}}) {
5282                      my $node = $self->{open_elements}->[$_];                      my $node = $self->{open_elements}->[$_];
5283                      if ($node->[1] & CAPTION_EL) {                      if ($node->[1] == CAPTION_EL) {
5284                        !!!cp ('t155');                        !!!cp ('t155');
5285                        $i = $_;                        $i = $_;
5286                        last INSCOPE;                        last INSCOPE;
# Line 5247  sub _tree_construction_main ($) { Line 5306  sub _tree_construction_main ($) {
5306                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
5307                  }                  }
5308    
5309                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] == CAPTION_EL) {
5310                    !!!cp ('t159');                    !!!cp ('t159');
5311                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5312                                    text => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
# Line 5344  sub _tree_construction_main ($) { Line 5403  sub _tree_construction_main ($) {
5403                  INSCOPE: {                  INSCOPE: {
5404                    for (reverse 0..$#{$self->{open_elements}}) {                    for (reverse 0..$#{$self->{open_elements}}) {
5405                      my $node = $self->{open_elements}->[$_];                      my $node = $self->{open_elements}->[$_];
5406                      if ($node->[1] & CAPTION_EL) {                      if ($node->[1] == CAPTION_EL) {
5407                        !!!cp ('t171');                        !!!cp ('t171');
5408                        $i = $_;                        $i = $_;
5409                        last INSCOPE;                        last INSCOPE;
# Line 5369  sub _tree_construction_main ($) { Line 5428  sub _tree_construction_main ($) {
5428                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
5429                  }                  }
5430                                    
5431                  unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                  unless ($self->{open_elements}->[-1]->[1] == CAPTION_EL) {
5432                    !!!cp ('t175');                    !!!cp ('t175');
5433                    !!!parse-error (type => 'not closed',                    !!!parse-error (type => 'not closed',
5434                                    text => $self->{open_elements}->[-1]->[0]                                    text => $self->{open_elements}->[-1]->[0]
# Line 5419  sub _tree_construction_main ($) { Line 5478  sub _tree_construction_main ($) {
5478                                line => $token->{line},                                line => $token->{line},
5479                                column => $token->{column}};                                column => $token->{column}};
5480                      next B;                      next B;
5481                    } elsif ($node->[1] & TABLE_CELL_EL) {                    } elsif ($node->[1] == TABLE_CELL_EL) {
5482                      !!!cp ('t180');                      !!!cp ('t180');
5483                      $tn = $node->[0]->manakai_local_name;                      $tn = $node->[0]->manakai_local_name;
5484                      ## NOTE: There is exactly one |td| or |th| element                      ## NOTE: There is exactly one |td| or |th| element
# Line 5448  sub _tree_construction_main ($) { Line 5507  sub _tree_construction_main ($) {
5507                my $i;                my $i;
5508                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5509                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5510                  if ($node->[1] & CAPTION_EL) {                  if ($node->[1] == CAPTION_EL) {
5511                    !!!cp ('t184');                    !!!cp ('t184');
5512                    $i = $_;                    $i = $_;
5513                    last INSCOPE;                    last INSCOPE;
# Line 5472  sub _tree_construction_main ($) { Line 5531  sub _tree_construction_main ($) {
5531                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5532                }                }
5533    
5534                unless ($self->{open_elements}->[-1]->[1] & CAPTION_EL) {                unless ($self->{open_elements}->[-1]->[1] == CAPTION_EL) {
5535                  !!!cp ('t188');                  !!!cp ('t188');
5536                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
5537                                  text => $self->{open_elements}->[-1]->[0]                                  text => $self->{open_elements}->[-1]->[0]
# Line 5553  sub _tree_construction_main ($) { Line 5612  sub _tree_construction_main ($) {
5612    
5613          !!!parse-error (type => 'in table:#text', token => $token);          !!!parse-error (type => 'in table:#text', token => $token);
5614    
5615              ## As if in body, but insert into foster parent element          ## NOTE: As if in body, but insert into the foster parent element.
5616              ## ISSUE: Spec says that "whenever a node would be inserted          $reconstruct_active_formatting_elements->($insert_to_foster);
             ## into the current node" while characters might not be  
             ## result in a new Text node.  
             $reconstruct_active_formatting_elements->($insert_to_foster);  
5617                            
5618              if ($self->{open_elements}->[-1]->[1] & TABLE_ROWS_EL) {          if ($self->{open_elements}->[-1]->[1] & TABLE_ROWS_EL) {
5619                # MUST            # MUST
5620                my $foster_parent_element;            my $foster_parent_element;
5621                my $next_sibling;            my $next_sibling;
5622                my $prev_sibling;            my $prev_sibling;
5623                OE: for (reverse 0..$#{$self->{open_elements}}) {            OE: for (reverse 0..$#{$self->{open_elements}}) {
5624                  if ($self->{open_elements}->[$_]->[1] & TABLE_EL) {              if ($self->{open_elements}->[$_]->[1] == TABLE_EL) {
5625                    my $parent = $self->{open_elements}->[$_]->[0]->parent_node;                my $parent = $self->{open_elements}->[$_]->[0]->parent_node;
5626                    if (defined $parent and $parent->node_type == 1) {                if (defined $parent and $parent->node_type == 1) {
5627                      !!!cp ('t196');                  $foster_parent_element = $parent;
5628                      $foster_parent_element = $parent;                  !!!cp ('t196');
5629                      $next_sibling = $self->{open_elements}->[$_]->[0];                  $next_sibling = $self->{open_elements}->[$_]->[0];
5630                      $prev_sibling = $next_sibling->previous_sibling;                  $prev_sibling = $next_sibling->previous_sibling;
5631                    } else {                  #
                     !!!cp ('t197');  
                     $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];  
                     $prev_sibling = $foster_parent_element->last_child;  
                   }  
                   last OE;  
                 }  
               } # OE  
               $foster_parent_element = $self->{open_elements}->[0]->[0] and  
               $prev_sibling = $foster_parent_element->last_child  
                 unless defined $foster_parent_element;  
               if (defined $prev_sibling and  
                   $prev_sibling->node_type == 3) {  
                 !!!cp ('t198');  
                 $prev_sibling->manakai_append_text ($token->{data});  
5632                } else {                } else {
5633                  !!!cp ('t199');                  !!!cp ('t197');
5634                  $foster_parent_element->insert_before                  $foster_parent_element = $self->{open_elements}->[$_ - 1]->[0];
5635                    ($self->{document}->create_text_node ($token->{data}),                  $prev_sibling = $foster_parent_element->last_child;
5636                     $next_sibling);                  #
5637                }                }
5638                  last OE;
5639                }
5640              } # OE
5641              $foster_parent_element = $self->{open_elements}->[0]->[0] and
5642              $prev_sibling = $foster_parent_element->last_child
5643                  unless defined $foster_parent_element;
5644              undef $prev_sibling unless $open_tables->[-1]->[2]; # ~node inserted
5645              if (defined $prev_sibling and
5646                  $prev_sibling->node_type == 3) {
5647                !!!cp ('t198');
5648                $prev_sibling->manakai_append_text ($token->{data});
5649              } else {
5650                !!!cp ('t199');
5651                $foster_parent_element->insert_before
5652                    ($self->{document}->create_text_node ($token->{data}),
5653                     $next_sibling);
5654              }
5655            $open_tables->[-1]->[1] = 1; # tainted            $open_tables->[-1]->[1] = 1; # tainted
5656              $open_tables->[-1]->[2] = 1; # ~node inserted
5657          } else {          } else {
5658              ## NOTE: Fragment case or in a foster parent'ed element
5659              ## (e.g. |<table><span>a|).  In fragment case, whether the
5660              ## character is appended to existing node or a new node is
5661              ## created is irrelevant, since the foster parent'ed nodes
5662              ## are discarded and fragment parsing does not invoke any
5663              ## script.
5664            !!!cp ('t200');            !!!cp ('t200');
5665            $self->{open_elements}->[-1]->[0]->manakai_append_text ($token->{data});            $self->{open_elements}->[-1]->[0]->manakai_append_text
5666                  ($token->{data});
5667          }          }
5668                            
5669          !!!next-token;          !!!next-token;
# Line 5633  sub _tree_construction_main ($) { Line 5700  sub _tree_construction_main ($) {
5700                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5701              }              }
5702                                    
5703                  $self->{insertion_mode} = IN_ROW_IM;              $self->{insertion_mode} = IN_ROW_IM;
5704                  if ($token->{tag_name} eq 'tr') {              if ($token->{tag_name} eq 'tr') {
5705                    !!!cp ('t204');                !!!cp ('t204');
5706                    !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5707                    !!!nack ('t204');                $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
5708                    !!!next-token;                !!!nack ('t204');
5709                    next B;                !!!next-token;
5710                  } else {                next B;
5711                    !!!cp ('t205');              } else {
5712                    !!!insert-element ('tr',, $token);                !!!cp ('t205');
5713                    ## reprocess in the "in row" insertion mode                !!!insert-element ('tr',, $token);
5714                  }                ## reprocess in the "in row" insertion mode
5715                } else {              }
5716                  !!!cp ('t206');            } else {
5717                }              !!!cp ('t206');
5718              }
5719    
5720                ## Clear back to table row context                ## Clear back to table row context
5721                while (not ($self->{open_elements}->[-1]->[1]                while (not ($self->{open_elements}->[-1]->[1]
# Line 5656  sub _tree_construction_main ($) { Line 5724  sub _tree_construction_main ($) {
5724                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5725                }                }
5726                                
5727                !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);            !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5728                $self->{insertion_mode} = IN_CELL_IM;            $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
5729              $self->{insertion_mode} = IN_CELL_IM;
5730    
5731                push @$active_formatting_elements, ['#marker', ''];            push @$active_formatting_elements, ['#marker', ''];
5732                                
5733                !!!nack ('t207.1');            !!!nack ('t207.1');
5734              !!!next-token;
5735              next B;
5736            } elsif ({
5737                      caption => 1, col => 1, colgroup => 1,
5738                      tbody => 1, tfoot => 1, thead => 1,
5739                      tr => 1, # $self->{insertion_mode} == IN_ROW_IM
5740                     }->{$token->{tag_name}}) {
5741              if ($self->{insertion_mode} == IN_ROW_IM) {
5742                ## As if </tr>
5743                ## have an element in table scope
5744                my $i;
5745                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5746                  my $node = $self->{open_elements}->[$_];
5747                  if ($node->[1] == TABLE_ROW_EL) {
5748                    !!!cp ('t208');
5749                    $i = $_;
5750                    last INSCOPE;
5751                  } elsif ($node->[1] & TABLE_SCOPING_EL) {
5752                    !!!cp ('t209');
5753                    last INSCOPE;
5754                  }
5755                } # INSCOPE
5756                unless (defined $i) {
5757                  !!!cp ('t210');
5758                  ## TODO: This type is wrong.
5759                  !!!parse-error (type => 'unmacthed end tag',
5760                                  text => $token->{tag_name}, token => $token);
5761                  ## Ignore the token
5762                  !!!nack ('t210.1');
5763                !!!next-token;                !!!next-token;
5764                next B;                next B;
5765              } elsif ({              }
                       caption => 1, col => 1, colgroup => 1,  
                       tbody => 1, tfoot => 1, thead => 1,  
                       tr => 1, # $self->{insertion_mode} == IN_ROW_IM  
                      }->{$token->{tag_name}}) {  
               if ($self->{insertion_mode} == IN_ROW_IM) {  
                 ## As if </tr>  
                 ## have an element in table scope  
                 my $i;  
                 INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {  
                   my $node = $self->{open_elements}->[$_];  
                   if ($node->[1] & TABLE_ROW_EL) {  
                     !!!cp ('t208');  
                     $i = $_;  
                     last INSCOPE;  
                   } elsif ($node->[1] & TABLE_SCOPING_EL) {  
                     !!!cp ('t209');  
                     last INSCOPE;  
                   }  
                 } # INSCOPE  
                 unless (defined $i) {  
                   !!!cp ('t210');  
 ## TODO: This type is wrong.  
                   !!!parse-error (type => 'unmacthed end tag',  
                                   text => $token->{tag_name}, token => $token);  
                   ## Ignore the token  
                   !!!nack ('t210.1');  
                   !!!next-token;  
                   next B;  
                 }  
5766                                    
5767                  ## Clear back to table row context                  ## Clear back to table row context
5768                  while (not ($self->{open_elements}->[-1]->[1]                  while (not ($self->{open_elements}->[-1]->[1]
# Line 5721  sub _tree_construction_main ($) { Line 5790  sub _tree_construction_main ($) {
5790                  my $i;                  my $i;
5791                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5792                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
5793                    if ($node->[1] & TABLE_ROW_GROUP_EL) {                    if ($node->[1] == TABLE_ROW_GROUP_EL) {
5794                      !!!cp ('t214');                      !!!cp ('t214');
5795                      $i = $_;                      $i = $_;
5796                      last INSCOPE;                      last INSCOPE;
# Line 5763  sub _tree_construction_main ($) { Line 5832  sub _tree_construction_main ($) {
5832                  !!!cp ('t218');                  !!!cp ('t218');
5833                }                }
5834    
5835                if ($token->{tag_name} eq 'col') {            if ($token->{tag_name} eq 'col') {
5836                  ## Clear back to table context              ## Clear back to table context
5837                  while (not ($self->{open_elements}->[-1]->[1]              while (not ($self->{open_elements}->[-1]->[1]
5838                                  & TABLE_SCOPING_EL)) {                              & TABLE_SCOPING_EL)) {
5839                    !!!cp ('t219');                !!!cp ('t219');
5840                    ## ISSUE: Can this state be reached?                ## ISSUE: Can this state be reached?
5841                    pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
5842                  }              }
5843                                
5844                  !!!insert-element ('colgroup',, $token);              !!!insert-element ('colgroup',, $token);
5845                  $self->{insertion_mode} = IN_COLUMN_GROUP_IM;              $self->{insertion_mode} = IN_COLUMN_GROUP_IM;
5846                  ## reprocess              ## reprocess
5847                  !!!ack-later;              $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
5848                  next B;              !!!ack-later;
5849                } elsif ({              next B;
5850                          caption => 1,            } elsif ({
5851                          colgroup => 1,                      caption => 1,
5852                          tbody => 1, tfoot => 1, thead => 1,                      colgroup => 1,
5853                         }->{$token->{tag_name}}) {                      tbody => 1, tfoot => 1, thead => 1,
5854                  ## Clear back to table context                     }->{$token->{tag_name}}) {
5855                ## Clear back to table context
5856                  while (not ($self->{open_elements}->[-1]->[1]                  while (not ($self->{open_elements}->[-1]->[1]
5857                                  & TABLE_SCOPING_EL)) {                                  & TABLE_SCOPING_EL)) {
5858                    !!!cp ('t220');                    !!!cp ('t220');
# Line 5790  sub _tree_construction_main ($) { Line 5860  sub _tree_construction_main ($) {
5860                    pop @{$self->{open_elements}};                    pop @{$self->{open_elements}};
5861                  }                  }
5862                                    
5863                  push @$active_formatting_elements, ['#marker', '']              push @$active_formatting_elements, ['#marker', '']
5864                      if $token->{tag_name} eq 'caption';                  if $token->{tag_name} eq 'caption';
5865                                    
5866                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);              !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5867                  $self->{insertion_mode} = {              $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
5868                                             caption => IN_CAPTION_IM,              $self->{insertion_mode} = {
5869                                             colgroup => IN_COLUMN_GROUP_IM,                                         caption => IN_CAPTION_IM,
5870                                             tbody => IN_TABLE_BODY_IM,                                         colgroup => IN_COLUMN_GROUP_IM,
5871                                             tfoot => IN_TABLE_BODY_IM,                                         tbody => IN_TABLE_BODY_IM,
5872                                             thead => IN_TABLE_BODY_IM,                                         tfoot => IN_TABLE_BODY_IM,
5873                                            }->{$token->{tag_name}};                                         thead => IN_TABLE_BODY_IM,
5874                  !!!next-token;                                        }->{$token->{tag_name}};
5875                  !!!nack ('t220.1');              !!!next-token;
5876                  next B;              !!!nack ('t220.1');
5877                } else {              next B;
5878                  die "$0: in table: <>: $token->{tag_name}";            } else {
5879                }              die "$0: in table: <>: $token->{tag_name}";
5880              }
5881              } elsif ($token->{tag_name} eq 'table') {              } elsif ($token->{tag_name} eq 'table') {
5882                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
5883                                text => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
# Line 5818  sub _tree_construction_main ($) { Line 5889  sub _tree_construction_main ($) {
5889                my $i;                my $i;
5890                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
5891                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
5892                  if ($node->[1] & TABLE_EL) {                  if ($node->[1] == TABLE_EL) {
5893                    !!!cp ('t221');                    !!!cp ('t221');
5894                    $i = $_;                    $i = $_;
5895                    last INSCOPE;                    last INSCOPE;
# Line 5845  sub _tree_construction_main ($) { Line 5916  sub _tree_construction_main ($) {
5916                  pop @{$self->{open_elements}};                  pop @{$self->{open_elements}};
5917                }                }
5918    
5919                unless ($self->{open_elements}->[-1]->[1] & TABLE_EL) {                unless ($self->{open_elements}->[-1]->[1] == TABLE_EL) {
5920                  !!!cp ('t225');                  !!!cp ('t225');
5921                  ## NOTE: |<table><tr><table>|                  ## NOTE: |<table><tr><table>|
5922                  !!!parse-error (type => 'not closed',                  !!!parse-error (type => 'not closed',
# Line 5869  sub _tree_construction_main ($) { Line 5940  sub _tree_construction_main ($) {
5940              !!!cp ('t227.8');              !!!cp ('t227.8');
5941              ## NOTE: This is a "as if in head" code clone.              ## NOTE: This is a "as if in head" code clone.
5942              $parse_rcdata->(CDATA_CONTENT_MODEL);              $parse_rcdata->(CDATA_CONTENT_MODEL);
5943                $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
5944              next B;              next B;
5945            } else {            } else {
5946              !!!cp ('t227.7');              !!!cp ('t227.7');
# Line 5879  sub _tree_construction_main ($) { Line 5951  sub _tree_construction_main ($) {
5951              !!!cp ('t227.6');              !!!cp ('t227.6');
5952              ## NOTE: This is a "as if in head" code clone.              ## NOTE: This is a "as if in head" code clone.
5953              $script_start_tag->();              $script_start_tag->();
5954                $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
5955              next B;              next B;
5956            } else {            } else {
5957              !!!cp ('t227.5');              !!!cp ('t227.5');
# Line 5894  sub _tree_construction_main ($) { Line 5967  sub _tree_construction_main ($) {
5967                                  text => $token->{tag_name}, token => $token);                                  text => $token->{tag_name}, token => $token);
5968    
5969                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);                  !!!insert-element ($token->{tag_name}, $token->{attributes}, $token);
5970                    $open_tables->[-1]->[2] = 0 if @$open_tables; # ~node inserted
5971    
5972                  ## TODO: form element pointer                  ## TODO: form element pointer
5973    
# Line 5931  sub _tree_construction_main ($) { Line 6005  sub _tree_construction_main ($) {
6005                my $i;                my $i;
6006                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6007                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
6008                  if ($node->[1] & TABLE_ROW_EL) {                  if ($node->[1] == TABLE_ROW_EL) {
6009                    !!!cp ('t228');                    !!!cp ('t228');
6010                    $i = $_;                    $i = $_;
6011                    last INSCOPE;                    last INSCOPE;
# Line 5972  sub _tree_construction_main ($) { Line 6046  sub _tree_construction_main ($) {
6046                  my $i;                  my $i;
6047                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6048                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
6049                    if ($node->[1] & TABLE_ROW_EL) {                    if ($node->[1] == TABLE_ROW_EL) {
6050                      !!!cp ('t233');                      !!!cp ('t233');
6051                      $i = $_;                      $i = $_;
6052                      last INSCOPE;                      last INSCOPE;
# Line 6010  sub _tree_construction_main ($) { Line 6084  sub _tree_construction_main ($) {
6084                  my $i;                  my $i;
6085                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6086                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
6087                    if ($node->[1] & TABLE_ROW_GROUP_EL) {                    if ($node->[1] == TABLE_ROW_GROUP_EL) {
6088                      !!!cp ('t237');                      !!!cp ('t237');
6089                      $i = $_;                      $i = $_;
6090                      last INSCOPE;                      last INSCOPE;
# Line 6057  sub _tree_construction_main ($) { Line 6131  sub _tree_construction_main ($) {
6131                my $i;                my $i;
6132                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6133                  my $node = $self->{open_elements}->[$_];                  my $node = $self->{open_elements}->[$_];
6134                  if ($node->[1] & TABLE_EL) {                  if ($node->[1] == TABLE_EL) {
6135                    !!!cp ('t241');                    !!!cp ('t241');
6136                    $i = $_;                    $i = $_;
6137                    last INSCOPE;                    last INSCOPE;
# Line 6116  sub _tree_construction_main ($) { Line 6190  sub _tree_construction_main ($) {
6190                  my $i;                  my $i;
6191                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {                  INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6192                    my $node = $self->{open_elements}->[$_];                    my $node = $self->{open_elements}->[$_];
6193                    if ($node->[1] & TABLE_ROW_EL) {                    if ($node->[1] == TABLE_ROW_EL) {
6194                      !!!cp ('t250');                      !!!cp ('t250');
6195                      $i = $_;                      $i = $_;
6196                      last INSCOPE;                      last INSCOPE;
# Line 6206  sub _tree_construction_main ($) { Line 6280  sub _tree_construction_main ($) {
6280            #            #
6281          }          }
6282        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
6283          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and          unless ($self->{open_elements}->[-1]->[1] == HTML_EL and
6284                  @{$self->{open_elements}} == 1) { # redundant, maybe                  @{$self->{open_elements}} == 1) { # redundant, maybe
6285            !!!parse-error (type => 'in body:#eof', token => $token);            !!!parse-error (type => 'in body:#eof', token => $token);
6286            !!!cp ('t259.1');            !!!cp ('t259.1');
# Line 6248  sub _tree_construction_main ($) { Line 6322  sub _tree_construction_main ($) {
6322              }              }
6323            } elsif ($token->{type} == END_TAG_TOKEN) {            } elsif ($token->{type} == END_TAG_TOKEN) {
6324              if ($token->{tag_name} eq 'colgroup') {              if ($token->{tag_name} eq 'colgroup') {
6325                if ($self->{open_elements}->[-1]->[1] & HTML_EL) {                if ($self->{open_elements}->[-1]->[1] == HTML_EL) {
6326                  !!!cp ('t264');                  !!!cp ('t264');
6327                  !!!parse-error (type => 'unmatched end tag',                  !!!parse-error (type => 'unmatched end tag',
6328                                  text => 'colgroup', token => $token);                                  text => 'colgroup', token => $token);
# Line 6274  sub _tree_construction_main ($) { Line 6348  sub _tree_construction_main ($) {
6348                #                #
6349              }              }
6350        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
6351          if ($self->{open_elements}->[-1]->[1] & HTML_EL and          if ($self->{open_elements}->[-1]->[1] == HTML_EL and
6352              @{$self->{open_elements}} == 1) { # redundant, maybe              @{$self->{open_elements}} == 1) { # redundant, maybe
6353            !!!cp ('t270.2');            !!!cp ('t270.2');
6354            ## Stop parsing.            ## Stop parsing.
# Line 6292  sub _tree_construction_main ($) { Line 6366  sub _tree_construction_main ($) {
6366        }        }
6367    
6368            ## As if </colgroup>            ## As if </colgroup>
6369            if ($self->{open_elements}->[-1]->[1] & HTML_EL) {            if ($self->{open_elements}->[-1]->[1] == HTML_EL) {
6370              !!!cp ('t269');              !!!cp ('t269');
6371  ## TODO: Wrong error type?  ## TODO: Wrong error type?
6372              !!!parse-error (type => 'unmatched end tag',              !!!parse-error (type => 'unmatched end tag',
# Line 6317  sub _tree_construction_main ($) { Line 6391  sub _tree_construction_main ($) {
6391          next B;          next B;
6392        } elsif ($token->{type} == START_TAG_TOKEN) {        } elsif ($token->{type} == START_TAG_TOKEN) {
6393          if ($token->{tag_name} eq 'option') {          if ($token->{tag_name} eq 'option') {
6394            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {            if ($self->{open_elements}->[-1]->[1] == OPTION_EL) {
6395              !!!cp ('t272');              !!!cp ('t272');
6396              ## As if </option>              ## As if </option>
6397              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6330  sub _tree_construction_main ($) { Line 6404  sub _tree_construction_main ($) {
6404            !!!next-token;            !!!next-token;
6405            next B;            next B;
6406          } elsif ($token->{tag_name} eq 'optgroup') {          } elsif ($token->{tag_name} eq 'optgroup') {
6407            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {            if ($self->{open_elements}->[-1]->[1] == OPTION_EL) {
6408              !!!cp ('t274');              !!!cp ('t274');
6409              ## As if </option>              ## As if </option>
6410              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6338  sub _tree_construction_main ($) { Line 6412  sub _tree_construction_main ($) {
6412              !!!cp ('t275');              !!!cp ('t275');
6413            }            }
6414    
6415            if ($self->{open_elements}->[-1]->[1] & OPTGROUP_EL) {            if ($self->{open_elements}->[-1]->[1] == OPTGROUP_EL) {
6416              !!!cp ('t276');              !!!cp ('t276');
6417              ## As if </optgroup>              ## As if </optgroup>
6418              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
# Line 6368  sub _tree_construction_main ($) { Line 6442  sub _tree_construction_main ($) {
6442            my $i;            my $i;
6443            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6444              my $node = $self->{open_elements}->[$_];              my $node = $self->{open_elements}->[$_];
6445              if ($node->[1] & SELECT_EL) {              if ($node->[1] == SELECT_EL) {
6446                !!!cp ('t278');                !!!cp ('t278');
6447                $i = $_;                $i = $_;
6448                last INSCOPE;                last INSCOPE;
# Line 6413  sub _tree_construction_main ($) { Line 6487  sub _tree_construction_main ($) {
6487          }          }
6488        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6489          if ($token->{tag_name} eq 'optgroup') {          if ($token->{tag_name} eq 'optgroup') {
6490            if ($self->{open_elements}->[-1]->[1] & OPTION_EL and            if ($self->{open_elements}->[-1]->[1] == OPTION_EL and
6491                $self->{open_elements}->[-2]->[1] & OPTGROUP_EL) {                $self->{open_elements}->[-2]->[1] == OPTGROUP_EL) {
6492              !!!cp ('t283');              !!!cp ('t283');
6493              ## As if </option>              ## As if </option>
6494              splice @{$self->{open_elements}}, -2;              splice @{$self->{open_elements}}, -2;
6495            } elsif ($self->{open_elements}->[-1]->[1] & OPTGROUP_EL) {            } elsif ($self->{open_elements}->[-1]->[1] == OPTGROUP_EL) {
6496              !!!cp ('t284');              !!!cp ('t284');
6497              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6498            } else {            } else {
# Line 6431  sub _tree_construction_main ($) { Line 6505  sub _tree_construction_main ($) {
6505            !!!next-token;            !!!next-token;
6506            next B;            next B;
6507          } elsif ($token->{tag_name} eq 'option') {          } elsif ($token->{tag_name} eq 'option') {
6508            if ($self->{open_elements}->[-1]->[1] & OPTION_EL) {            if ($self->{open_elements}->[-1]->[1] == OPTION_EL) {
6509              !!!cp ('t286');              !!!cp ('t286');
6510              pop @{$self->{open_elements}};              pop @{$self->{open_elements}};
6511            } else {            } else {
# Line 6448  sub _tree_construction_main ($) { Line 6522  sub _tree_construction_main ($) {
6522            my $i;            my $i;
6523            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6524              my $node = $self->{open_elements}->[$_];              my $node = $self->{open_elements}->[$_];
6525              if ($node->[1] & SELECT_EL) {              if ($node->[1] == SELECT_EL) {
6526                !!!cp ('t288');                !!!cp ('t288');
6527                $i = $_;                $i = $_;
6528                last INSCOPE;                last INSCOPE;
# Line 6510  sub _tree_construction_main ($) { Line 6584  sub _tree_construction_main ($) {
6584            undef $i;            undef $i;
6585            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {            INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
6586              my $node = $self->{open_elements}->[$_];              my $node = $self->{open_elements}->[$_];
6587              if ($node->[1] & SELECT_EL) {              if ($node->[1] == SELECT_EL) {
6588                !!!cp ('t295');                !!!cp ('t295');
6589                $i = $_;                $i = $_;
6590                last INSCOPE;                last INSCOPE;
# Line 6549  sub _tree_construction_main ($) { Line 6623  sub _tree_construction_main ($) {
6623            next B;            next B;
6624          }          }
6625        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
6626          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and          unless ($self->{open_elements}->[-1]->[1] == HTML_EL and
6627                  @{$self->{open_elements}} == 1) { # redundant, maybe                  @{$self->{open_elements}} == 1) { # redundant, maybe
6628            !!!cp ('t299.1');            !!!cp ('t299.1');
6629            !!!parse-error (type => 'in body:#eof', token => $token);            !!!parse-error (type => 'in body:#eof', token => $token);
# Line 6736  sub _tree_construction_main ($) { Line 6810  sub _tree_construction_main ($) {
6810        } elsif ($token->{type} == END_TAG_TOKEN) {        } elsif ($token->{type} == END_TAG_TOKEN) {
6811          if ($token->{tag_name} eq 'frameset' and          if ($token->{tag_name} eq 'frameset' and
6812              $self->{insertion_mode} == IN_FRAMESET_IM) {              $self->{insertion_mode} == IN_FRAMESET_IM) {
6813            if ($self->{open_elements}->[-1]->[1] & HTML_EL and            if ($self->{open_elements}->[-1]->[1] == HTML_EL and
6814                @{$self->{open_elements}} == 1) {                @{$self->{open_elements}} == 1) {
6815              !!!cp ('t325');              !!!cp ('t325');
6816              !!!parse-error (type => 'unmatched end tag',              !!!parse-error (type => 'unmatched end tag',
# Line 6750  sub _tree_construction_main ($) { Line 6824  sub _tree_construction_main ($) {
6824            }            }
6825    
6826            if (not defined $self->{inner_html_node} and            if (not defined $self->{inner_html_node} and
6827                not ($self->{open_elements}->[-1]->[1] & FRAMESET_EL)) {                not ($self->{open_elements}->[-1]->[1] == FRAMESET_EL)) {
6828              !!!cp ('t327');              !!!cp ('t327');
6829              $self->{insertion_mode} = AFTER_FRAMESET_IM;              $self->{insertion_mode} = AFTER_FRAMESET_IM;
6830            } else {            } else {
# Line 6782  sub _tree_construction_main ($) { Line 6856  sub _tree_construction_main ($) {
6856            next B;            next B;
6857          }          }
6858        } elsif ($token->{type} == END_OF_FILE_TOKEN) {        } elsif ($token->{type} == END_OF_FILE_TOKEN) {
6859          unless ($self->{open_elements}->[-1]->[1] & HTML_EL and          unless ($self->{open_elements}->[-1]->[1] == HTML_EL and
6860                  @{$self->{open_elements}} == 1) { # redundant, maybe                  @{$self->{open_elements}} == 1) { # redundant, maybe
6861            !!!cp ('t331.1');            !!!cp ('t331.1');
6862            !!!parse-error (type => 'in body:#eof', token => $token);            !!!parse-error (type => 'in body:#eof', token => $token);
# Line 6885  sub _tree_construction_main ($) { Line 6959  sub _tree_construction_main ($) {
6959          !!!parse-error (type => 'in body', text => 'body', token => $token);          !!!parse-error (type => 'in body', text => 'body', token => $token);
6960                                
6961          if (@{$self->{open_elements}} == 1 or          if (@{$self->{open_elements}} == 1 or
6962              not ($self->{open_elements}->[1]->[1] & BODY_EL)) {              not ($self->{open_elements}->[1]->[1] == BODY_EL)) {
6963            !!!cp ('t342');            !!!cp ('t342');
6964            ## Ignore the token            ## Ignore the token
6965          } else {          } else {
# Line 6931  sub _tree_construction_main ($) { Line 7005  sub _tree_construction_main ($) {
7005    
7006          ## has a p element in scope          ## has a p element in scope
7007          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
7008            if ($_->[1] & P_EL) {            if ($_->[1] == P_EL) {
7009              !!!cp ('t344');              !!!cp ('t344');
7010              !!!back-token; # <form>              !!!back-token; # <form>
7011              $token = {type => END_TAG_TOKEN, tag_name => 'p',              $token = {type => END_TAG_TOKEN, tag_name => 'p',
# Line 7004  sub _tree_construction_main ($) { Line 7078  sub _tree_construction_main ($) {
7078    
7079          ## 1.          ## 1.
7080          for my $node (reverse @{$self->{open_elements}}) {          for my $node (reverse @{$self->{open_elements}}) {
7081            if ($node->[1] & LI_EL) {            if ($node->[1] == LI_EL) {
7082              ## 2. (a) As if </li>              ## 2. (a) As if </li>
7083              {              {
7084                ## If no </li> - not applied                ## If no </li> - not applied
# Line 7035  sub _tree_construction_main ($) { Line 7109  sub _tree_construction_main ($) {
7109                     ($node->[1] & SPECIAL_EL or                     ($node->[1] & SPECIAL_EL or
7110                      $node->[1] & SCOPING_EL) and                      $node->[1] & SCOPING_EL) and
7111                     ## NOTE: "li", "dt", and "dd" are in |SPECIAL_EL|.                     ## NOTE: "li", "dt", and "dd" are in |SPECIAL_EL|.
7112                       (not $node->[1] & ADDRESS_DIV_P_EL)
7113                     (not $node->[1] & ADDRESS_EL) &                    ) {
                    (not $node->[1] & DIV_EL) &  
                    (not $node->[1] & P_EL)) {  
7114              ## 3.              ## 3.
7115              !!!cp ('t357');              !!!cp ('t357');
7116              last; ## goto 5.              last; ## goto 5.
# Line 7057  sub _tree_construction_main ($) { Line 7129  sub _tree_construction_main ($) {
7129    
7130          ## 5. (a) has a |p| element in scope          ## 5. (a) has a |p| element in scope
7131          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
7132            if ($_->[1] & P_EL) {            if ($_->[1] == P_EL) {
7133              !!!cp ('t353');              !!!cp ('t353');
7134    
7135              ## NOTE: |<p><li>|, for example.              ## NOTE: |<p><li>|, for example.
# Line 7086  sub _tree_construction_main ($) { Line 7158  sub _tree_construction_main ($) {
7158    
7159          ## 1.          ## 1.
7160          for my $node (reverse @{$self->{open_elements}}) {          for my $node (reverse @{$self->{open_elements}}) {
7161            if ($node->[1] & DT_EL or $node->[1] & DD_EL) {            if ($node->[1] == DTDD_EL) {
7162              ## 2. (a) As if </li>              ## 2. (a) As if </li>
7163              {              {
7164                ## If no </li> - not applied                ## If no </li> - not applied
# Line 7118  sub _tree_construction_main ($) { Line 7190  sub _tree_construction_main ($) {
7190                      $node->[1] & SCOPING_EL) and                      $node->[1] & SCOPING_EL) and
7191                     ## NOTE: "li", "dt", and "dd" are in |SPECIAL_EL|.                     ## NOTE: "li", "dt", and "dd" are in |SPECIAL_EL|.
7192    
7193                     (not $node->[1] & ADDRESS_EL) &                     (not $node->[1] & ADDRESS_DIV_P_EL)
7194                     (not $node->[1] & DIV_EL) &                    ) {
                    (not $node->[1] & P_EL)) {  
7195              ## 3.              ## 3.
7196              !!!cp ('t357.1');              !!!cp ('t357.1');
7197              last; ## goto 5.              last; ## goto 5.
# Line 7139  sub _tree_construction_main ($) { Line 7210  sub _tree_construction_main ($) {
7210    
7211          ## 5. (a) has a |p| element in scope          ## 5. (a) has a |p| element in scope
7212          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
7213            if ($_->[1] & P_EL) {            if ($_->[1] == P_EL) {
7214              !!!cp ('t353.1');              !!!cp ('t353.1');
7215              !!!back-token; # <x>              !!!back-token; # <x>
7216              $token = {type => END_TAG_TOKEN, tag_name => 'p',              $token = {type => END_TAG_TOKEN, tag_name => 'p',
# Line 7161  sub _tree_construction_main ($) { Line 7232  sub _tree_construction_main ($) {
7232    
7233          ## has a p element in scope          ## has a p element in scope
7234          INSCOPE: for (reverse @{$self->{open_elements}}) {          INSCOPE: for (reverse @{$self->{open_elements}}) {
7235            if ($_->[1] & P_EL) {            if ($_->[1] == P_EL) {
7236              !!!cp ('t367');              !!!cp ('t367');
7237              !!!back-token; # <plaintext>              !!!back-token; # <plaintext>
7238              $token = {type => END_TAG_TOKEN, tag_name => 'p',              $token = {type => END_TAG_TOKEN, tag_name => 'p',
# Line 7183  sub _tree_construction_main ($) { Line 7254  sub _tree_construction_main ($) {
7254        } elsif ($token->{tag_name} eq 'a') {        } elsif ($token->{tag_name} eq 'a') {
7255          AFE: for my $i (reverse 0..$#$active_formatting_elements) {          AFE: for my $i (reverse 0..$#$active_formatting_elements) {
7256            my $node = $active_formatting_elements->[$i];            my $node = $active_formatting_elements->[$i];
7257            if ($node->[1] & A_EL) {            if ($node->[1] == A_EL) {
7258              !!!cp ('t371');              !!!cp ('t371');
7259              !!!parse-error (type => 'in a:a', token => $token);              !!!parse-error (type => 'in a:a', token => $token);
7260                            
# Line 7227  sub _tree_construction_main ($) { Line 7298  sub _tree_construction_main ($) {
7298          ## has a |nobr| element in scope          ## has a |nobr| element in scope
7299          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7300            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
7301            if ($node->[1] & NOBR_EL) {            if ($node->[1] == NOBR_EL) {
7302              !!!cp ('t376');              !!!cp ('t376');
7303              !!!parse-error (type => 'in nobr:nobr', token => $token);              !!!parse-error (type => 'in nobr:nobr', token => $token);
7304              !!!back-token; # <nobr>              !!!back-token; # <nobr>
# Line 7250  sub _tree_construction_main ($) { Line 7321  sub _tree_construction_main ($) {
7321          ## has a button element in scope          ## has a button element in scope
7322          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7323            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
7324            if ($node->[1] & BUTTON_EL) {            if ($node->[1] == BUTTON_EL) {
7325              !!!cp ('t378');              !!!cp ('t378');
7326              !!!parse-error (type => 'in button:button', token => $token);              !!!parse-error (type => 'in button:button', token => $token);
7327              !!!back-token; # <button>              !!!back-token; # <button>
# Line 7350  sub _tree_construction_main ($) { Line 7421  sub _tree_construction_main ($) {
7421            next B;            next B;
7422          }          }
7423        } elsif ($token->{tag_name} eq 'textarea') {        } elsif ($token->{tag_name} eq 'textarea') {
7424          my $tag_name = $token->{tag_name};          ## Step 1
7425          my $el;          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
         !!!create-element ($el, $HTML_NS, $token->{tag_name}, $token->{attributes}, $token);  
7426                    
7427            ## Step 2
7428          ## TODO: $self->{form_element} if defined          ## TODO: $self->{form_element} if defined
7429    
7430            ## Step 3
7431            $self->{ignore_newline} = 1;
7432    
7433            ## Step 4
7434            ## ISSUE: This step is wrong. (r2302 enbugged)
7435    
7436            ## Step 5
7437          $self->{content_model} = RCDATA_CONTENT_MODEL;          $self->{content_model} = RCDATA_CONTENT_MODEL;
7438          delete $self->{escape}; # MUST          delete $self->{escape}; # MUST
7439            
7440          $insert->($el);          ## Step 6-7
7441                    $self->{insertion_mode} |= IN_CDATA_RCDATA_IM;
7442          my $text = '';  
7443          !!!nack ('t392.1');          !!!nack ('t392.1');
7444          !!!next-token;          !!!next-token;
7445          if ($token->{type} == CHARACTER_TOKEN) {          next B;
7446            $token->{data} =~ s/^\x0A//;        } elsif ($token->{tag_name} eq 'optgroup' or
7447            unless (length $token->{data}) {                 $token->{tag_name} eq 'option') {
7448              !!!cp ('t392');          ## has an |option| element in scope
7449              !!!next-token;          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7450            } else {            my $node = $self->{open_elements}->[$_];
7451              !!!cp ('t393');            if ($node->[1] == OPTION_EL) {
7452                !!!cp ('t397.1');
7453                ## NOTE: As if </option>
7454                !!!back-token; # <option> or <optgroup>
7455                $token = {type => END_TAG_TOKEN, tag_name => 'option',
7456                          line => $token->{line}, column => $token->{column}};
7457                next B;
7458              } elsif ($node->[1] & SCOPING_EL) {
7459                !!!cp ('t397.2');
7460                last INSCOPE;
7461            }            }
7462          } else {          } # INSCOPE
7463            !!!cp ('t394');  
7464          }          $reconstruct_active_formatting_elements->($insert_to_current);
7465          while ($token->{type} == CHARACTER_TOKEN) {  
7466            !!!cp ('t395');          !!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token);
7467            $text .= $token->{data};  
7468            !!!next-token;          !!!nack ('t397.3');
         }  
         if (length $text) {  
           !!!cp ('t396');  
           $el->manakai_append_text ($text);  
         }  
           
         $self->{content_model} = PCDATA_CONTENT_MODEL;  
           
         if ($token->{type} == END_TAG_TOKEN and  
             $token->{tag_name} eq $tag_name) {  
           !!!cp ('t397');  
           ## Ignore the token  
         } else {  
           !!!cp ('t398');  
           !!!parse-error (type => 'in RCDATA:#eof', token => $token);  
         }  
7469          !!!next-token;          !!!next-token;
7470          next B;          redo B;
7471        } elsif ($token->{tag_name} eq 'rt' or        } elsif ($token->{tag_name} eq 'rt' or
7472                 $token->{tag_name} eq 'rp') {                 $token->{tag_name} eq 'rp') {
7473          ## has a |ruby| element in scope          ## has a |ruby| element in scope
7474          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7475            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
7476            if ($node->[1] & RUBY_EL) {            if ($node->[1] == RUBY_EL) {
7477              !!!cp ('t398.1');              !!!cp ('t398.1');
7478              ## generate implied end tags              ## generate implied end tags
7479              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
7480                !!!cp ('t398.2');                !!!cp ('t398.2');
7481                pop @{$self->{open_elements}};                pop @{$self->{open_elements}};
7482              }              }
7483              unless ($self->{open_elements}->[-1]->[1] & RUBY_EL) {              unless ($self->{open_elements}->[-1]->[1] == RUBY_EL) {
7484                !!!cp ('t398.3');                !!!cp ('t398.3');
7485                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
7486                                text => $self->{open_elements}->[-1]->[0]                                text => $self->{open_elements}->[-1]->[0]
7487                                    ->manakai_local_name,                                    ->manakai_local_name,
7488                                token => $token);                                token => $token);
7489                pop @{$self->{open_elements}}                pop @{$self->{open_elements}}
7490                    while not $self->{open_elements}->[-1]->[1] & RUBY_EL;                    while not $self->{open_elements}->[-1]->[1] == RUBY_EL;
7491              }              }
7492              last INSCOPE;              last INSCOPE;
7493            } elsif ($node->[1] & SCOPING_EL) {            } elsif ($node->[1] & SCOPING_EL) {
# Line 7443  sub _tree_construction_main ($) { Line 7515  sub _tree_construction_main ($) {
7515                    
7516          if ($self->{self_closing}) {          if ($self->{self_closing}) {
7517            pop @{$self->{open_elements}};            pop @{$self->{open_elements}};
7518            !!!ack ('t398.1');            !!!ack ('t398.6');
7519          } else {          } else {
7520            !!!cp ('t398.2');            !!!cp ('t398.7');
7521            $self->{insertion_mode} |= IN_FOREIGN_CONTENT_IM;            $self->{insertion_mode} |= IN_FOREIGN_CONTENT_IM;
7522            ## NOTE: |<body><math><mi><svg>| -> "in foreign content" insertion            ## NOTE: |<body><math><mi><svg>| -> "in foreign content" insertion
7523            ## mode, "in body" (not "in foreign content") secondary insertion            ## mode, "in body" (not "in foreign content") secondary insertion
# Line 7456  sub _tree_construction_main ($) { Line 7528  sub _tree_construction_main ($) {
7528          next B;          next B;
7529        } elsif ({        } elsif ({
7530                  caption => 1, col => 1, colgroup => 1, frame => 1,                  caption => 1, col => 1, colgroup => 1, frame => 1,
7531                  frameset => 1, head => 1, option => 1, optgroup => 1,                  frameset => 1, head => 1,
7532                  tbody => 1, td => 1, tfoot => 1, th => 1,                  tbody => 1, td => 1, tfoot => 1, th => 1,
7533                  thead => 1, tr => 1,                  thead => 1, tr => 1,
7534                 }->{$token->{tag_name}}) {                 }->{$token->{tag_name}}) {
# Line 7541  sub _tree_construction_main ($) { Line 7613  sub _tree_construction_main ($) {
7613          my $i;          my $i;
7614          INSCOPE: {          INSCOPE: {
7615            for (reverse @{$self->{open_elements}}) {            for (reverse @{$self->{open_elements}}) {
7616              if ($_->[1] & BODY_EL) {              if ($_->[1] == BODY_EL) {
7617                !!!cp ('t405');                !!!cp ('t405');
7618                $i = $_;                $i = $_;
7619                last INSCOPE;                last INSCOPE;
# Line 7551  sub _tree_construction_main ($) { Line 7623  sub _tree_construction_main ($) {
7623              }              }
7624            }            }
7625    
7626            !!!parse-error (type => 'start tag not allowed',            ## NOTE: |<marquee></body>|, |<svg><foreignobject></body>|
7627    
7628              !!!parse-error (type => 'unmatched end tag',
7629                            text => $token->{tag_name}, token => $token);                            text => $token->{tag_name}, token => $token);
7630            ## NOTE: Ignore the token.            ## NOTE: Ignore the token.
7631            !!!next-token;            !!!next-token;
# Line 7577  sub _tree_construction_main ($) { Line 7651  sub _tree_construction_main ($) {
7651          ## TODO: Update this code.  It seems that the code below is not          ## TODO: Update this code.  It seems that the code below is not
7652          ## up-to-date, though it has same effect as speced.          ## up-to-date, though it has same effect as speced.
7653          if (@{$self->{open_elements}} > 1 and          if (@{$self->{open_elements}} > 1 and
7654              $self->{open_elements}->[1]->[1] & BODY_EL) {              $self->{open_elements}->[1]->[1] == BODY_EL) {
7655            unless ($self->{open_elements}->[-1]->[1] & BODY_EL) {            unless ($self->{open_elements}->[-1]->[1] == BODY_EL) {
7656              !!!cp ('t406');              !!!cp ('t406');
7657              !!!parse-error (type => 'not closed',              !!!parse-error (type => 'not closed',
7658                              text => $self->{open_elements}->[1]->[0]                              text => $self->{open_elements}->[1]->[0]
# Line 7685  sub _tree_construction_main ($) { Line 7759  sub _tree_construction_main ($) {
7759          my $i;          my $i;
7760          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7761            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
7762            if ($node->[1] & FORM_EL) {            if ($node->[1] == FORM_EL) {
7763              !!!cp ('t418');              !!!cp ('t418');
7764              $i = $_;              $i = $_;
7765              last INSCOPE;              last INSCOPE;
# Line 7733  sub _tree_construction_main ($) { Line 7807  sub _tree_construction_main ($) {
7807          my $i;          my $i;
7808          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7809            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
7810            if ($node->[1] & HEADING_EL) {            if ($node->[1] == HEADING_EL) {
7811              !!!cp ('t423');              !!!cp ('t423');
7812              $i = $_;              $i = $_;
7813              last INSCOPE;              last INSCOPE;
# Line 7779  sub _tree_construction_main ($) { Line 7853  sub _tree_construction_main ($) {
7853          my $i;          my $i;
7854          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {          INSCOPE: for (reverse 0..$#{$self->{open_elements}}) {
7855            my $node = $self->{open_elements}->[$_];            my $node = $self->{open_elements}->[$_];
7856            if ($node->[1] & P_EL) {            if ($node->[1] == P_EL) {
7857              !!!cp ('t410.1');              !!!cp ('t410.1');
7858              $i = $_;              $i = $_;
7859              last INSCOPE;              last INSCOPE;
# Line 7852  sub _tree_construction_main ($) { Line 7926  sub _tree_construction_main ($) {
7926          ## Ignore the token.          ## Ignore the token.
7927          !!!next-token;          !!!next-token;
7928          next B;          next B;
       } elsif ({  
                 caption => 1, col => 1, colgroup => 1, frame => 1,  
                 frameset => 1, head => 1, option => 1, optgroup => 1,  
                 tbody => 1, td => 1, tfoot => 1, th => 1,  
                 thead => 1, tr => 1,  
                 area => 1, basefont => 1, bgsound => 1,  
                 embed => 1, hr => 1, iframe => 1, image => 1,  
                 img => 1, input => 1, isindex => 1, noembed => 1,  
                 noframes => 1, param => 1, select => 1, spacer => 1,  
                 table => 1, textarea => 1, wbr => 1,  
                 noscript => 0, ## TODO: if scripting is enabled  
                }->{$token->{tag_name}}) {  
         !!!cp ('t429');  
         !!!parse-error (type => 'unmatched end tag',  
                         text => $token->{tag_name}, token => $token);  
         ## Ignore the token  
         !!!next-token;  
         next B;  
7929        } else {        } else {
7930          if ($token->{tag_name} eq 'sarcasm') {          if ($token->{tag_name} eq 'sarcasm') {
7931            sleep 0.001; # take a deep breath            sleep 0.001; # take a deep breath
# Line 7881  sub _tree_construction_main ($) { Line 7937  sub _tree_construction_main ($) {
7937    
7938          ## Step 2          ## Step 2
7939          S2: {          S2: {
7940            if ($node->[0]->manakai_local_name eq $token->{tag_name}) {            my $node_tag_name = $node->[0]->manakai_local_name;
7941              $node_tag_name =~ tr/A-Z/a-z/; # for SVG camelCase tag names
7942              if ($node_tag_name eq $token->{tag_name}) {
7943              ## Step 1              ## Step 1
7944              ## generate implied end tags              ## generate implied end tags
7945              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {              while ($self->{open_elements}->[-1]->[1] & END_TAG_OPTIONAL_EL) {
# Line 7894  sub _tree_construction_main ($) { Line 7952  sub _tree_construction_main ($) {
7952              }              }
7953                    
7954              ## Step 2              ## Step 2
7955              if ($self->{open_elements}->[-1]->[0]->manakai_local_name              my $current_tag_name
7956                      ne $token->{tag_name}) {                  = $self->{open_elements}->[-1]->[0]->manakai_local_name;
7957                $current_tag_name =~ tr/A-Z/a-z/;
7958                if ($current_tag_name ne $token->{tag_name}) {
7959                !!!cp ('t431');                !!!cp ('t431');
7960                ## NOTE: <x><y></x>                ## NOTE: <x><y></x>
7961                !!!parse-error (type => 'not closed',                !!!parse-error (type => 'not closed',
# Line 8165  sub set_inner_html ($$$$;$) { Line 8225  sub set_inner_html ($$$$;$) {
8225      push @{$p->{open_elements}}, [$root, $el_category->{html}];      push @{$p->{open_elements}}, [$root, $el_category->{html}];
8226    
8227      undef $p->{head_element};      undef $p->{head_element};
8228        undef $p->{head_element_inserted};
8229    
8230      ## Step 6 # MUST      ## Step 6 # MUST
8231      $p->_reset_insertion_mode;      $p->_reset_insertion_mode;

Legend:
Removed from v.1.198  
changed lines
  Added in v.1.207

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24