| 247 |
} elsif ($self->{state} eq 'entity data') { |
} elsif ($self->{state} eq 'entity data') { |
| 248 |
## (cannot happen in CDATA state) |
## (cannot happen in CDATA state) |
| 249 |
|
|
| 250 |
my $token = $self->_tokenize_attempt_to_consume_an_entity; |
my $token = $self->_tokenize_attempt_to_consume_an_entity (0); |
| 251 |
|
|
| 252 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 253 |
# next-input-character is already done |
# next-input-character is already done |
| 899 |
redo A; |
redo A; |
| 900 |
} |
} |
| 901 |
} elsif ($self->{state} eq 'entity in attribute value') { |
} elsif ($self->{state} eq 'entity in attribute value') { |
| 902 |
my $token = $self->_tokenize_attempt_to_consume_an_entity; |
my $token = $self->_tokenize_attempt_to_consume_an_entity (1); |
| 903 |
|
|
| 904 |
unless (defined $token) { |
unless (defined $token) { |
| 905 |
$self->{current_attribute}->{value} .= '&'; |
$self->{current_attribute}->{value} .= '&'; |
| 1409 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
!!!parse-error (type => 'unclosed DOCTYPE'); |
| 1410 |
|
|
| 1411 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1412 |
## recomsume |
## reconsume |
| 1413 |
|
|
| 1414 |
delete $self->{current_token}->{correct}; |
delete $self->{current_token}->{correct}; |
| 1415 |
!!!emit ($self->{current_token}); # DOCTYPE |
!!!emit ($self->{current_token}); # DOCTYPE |
| 1452 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
!!!parse-error (type => 'unclosed DOCTYPE'); |
| 1453 |
|
|
| 1454 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1455 |
## recomsume |
## reconsume |
| 1456 |
|
|
| 1457 |
delete $self->{current_token}->{correct}; |
delete $self->{current_token}->{correct}; |
| 1458 |
!!!emit ($self->{current_token}); # DOCTYPE |
!!!emit ($self->{current_token}); # DOCTYPE |
| 1527 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
!!!parse-error (type => 'unclosed DOCTYPE'); |
| 1528 |
|
|
| 1529 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1530 |
## recomsume |
## reconsume |
| 1531 |
|
|
| 1532 |
delete $self->{current_token}->{correct}; |
delete $self->{current_token}->{correct}; |
| 1533 |
!!!emit ($self->{current_token}); # DOCTYPE |
!!!emit ($self->{current_token}); # DOCTYPE |
| 1570 |
die "$0: _get_next_token: unexpected case"; |
die "$0: _get_next_token: unexpected case"; |
| 1571 |
} # _get_next_token |
} # _get_next_token |
| 1572 |
|
|
| 1573 |
sub _tokenize_attempt_to_consume_an_entity ($) { |
sub _tokenize_attempt_to_consume_an_entity ($$) { |
| 1574 |
my $self = shift; |
my ($self, $in_attr) = @_; |
| 1575 |
|
|
| 1576 |
if ({ |
if ({ |
| 1577 |
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF, |
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF, |
| 1584 |
!!!next-input-character; |
!!!next-input-character; |
| 1585 |
if ($self->{next_input_character} == 0x0078 or # x |
if ($self->{next_input_character} == 0x0078 or # x |
| 1586 |
$self->{next_input_character} == 0x0058) { # X |
$self->{next_input_character} == 0x0058) { # X |
| 1587 |
my $num; |
my $code; |
| 1588 |
X: { |
X: { |
| 1589 |
my $x_char = $self->{next_input_character}; |
my $x_char = $self->{next_input_character}; |
| 1590 |
!!!next-input-character; |
!!!next-input-character; |
| 1591 |
if (0x0030 <= $self->{next_input_character} and |
if (0x0030 <= $self->{next_input_character} and |
| 1592 |
$self->{next_input_character} <= 0x0039) { # 0..9 |
$self->{next_input_character} <= 0x0039) { # 0..9 |
| 1593 |
$num ||= 0; |
$code ||= 0; |
| 1594 |
$num *= 0x10; |
$code *= 0x10; |
| 1595 |
$num += $self->{next_input_character} - 0x0030; |
$code += $self->{next_input_character} - 0x0030; |
| 1596 |
redo X; |
redo X; |
| 1597 |
} elsif (0x0061 <= $self->{next_input_character} and |
} elsif (0x0061 <= $self->{next_input_character} and |
| 1598 |
$self->{next_input_character} <= 0x0066) { # a..f |
$self->{next_input_character} <= 0x0066) { # a..f |
| 1599 |
## ISSUE: the spec says U+0078, which is apparently incorrect |
$code ||= 0; |
| 1600 |
$num ||= 0; |
$code *= 0x10; |
| 1601 |
$num *= 0x10; |
$code += $self->{next_input_character} - 0x0060 + 9; |
|
$num += $self->{next_input_character} - 0x0060 + 9; |
|
| 1602 |
redo X; |
redo X; |
| 1603 |
} elsif (0x0041 <= $self->{next_input_character} and |
} elsif (0x0041 <= $self->{next_input_character} and |
| 1604 |
$self->{next_input_character} <= 0x0046) { # A..F |
$self->{next_input_character} <= 0x0046) { # A..F |
| 1605 |
## ISSUE: the spec says U+0058, which is apparently incorrect |
$code ||= 0; |
| 1606 |
$num ||= 0; |
$code *= 0x10; |
| 1607 |
$num *= 0x10; |
$code += $self->{next_input_character} - 0x0040 + 9; |
|
$num += $self->{next_input_character} - 0x0040 + 9; |
|
| 1608 |
redo X; |
redo X; |
| 1609 |
} elsif (not defined $num) { # no hexadecimal digit |
} elsif (not defined $code) { # no hexadecimal digit |
| 1610 |
!!!parse-error (type => 'bare hcro'); |
!!!parse-error (type => 'bare hcro'); |
| 1611 |
$self->{next_input_character} = 0x0023; # # |
$self->{next_input_character} = 0x0023; # # |
| 1612 |
!!!back-next-input-character ($x_char); |
!!!back-next-input-character ($x_char); |
| 1617 |
!!!parse-error (type => 'no refc'); |
!!!parse-error (type => 'no refc'); |
| 1618 |
} |
} |
| 1619 |
|
|
| 1620 |
## TODO: check the definition for |a valid Unicode character|. |
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
| 1621 |
## <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-December/thread.html#8189> |
!!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code); |
| 1622 |
if ($num > 1114111 or $num == 0) { |
$code = 0xFFFD; |
| 1623 |
$num = 0xFFFD; # REPLACEMENT CHARACTER |
} elsif ($code > 0x10FFFF) { |
| 1624 |
## ISSUE: Why this is not an error? |
!!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code); |
| 1625 |
} elsif (0x80 <= $num and $num <= 0x9F) { |
$code = 0xFFFD; |
| 1626 |
!!!parse-error (type => sprintf 'c1 entity:U+%04X', $num); |
} elsif ($code == 0x000D) { |
| 1627 |
$num = $c1_entity_char->{$num}; |
!!!parse-error (type => 'CR character reference'); |
| 1628 |
|
$code = 0x000A; |
| 1629 |
|
} elsif (0x80 <= $code and $code <= 0x9F) { |
| 1630 |
|
!!!parse-error (type => sprintf 'c1 entity:U+%04X', $code); |
| 1631 |
|
$code = $c1_entity_char->{$code}; |
| 1632 |
} |
} |
| 1633 |
|
|
| 1634 |
return {type => 'character', data => chr $num}; |
return {type => 'character', data => chr $code}; |
| 1635 |
} # X |
} # X |
| 1636 |
} elsif (0x0030 <= $self->{next_input_character} and |
} elsif (0x0030 <= $self->{next_input_character} and |
| 1637 |
$self->{next_input_character} <= 0x0039) { # 0..9 |
$self->{next_input_character} <= 0x0039) { # 0..9 |
| 1652 |
!!!parse-error (type => 'no refc'); |
!!!parse-error (type => 'no refc'); |
| 1653 |
} |
} |
| 1654 |
|
|
| 1655 |
## TODO: check the definition for |a valid Unicode character|. |
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
| 1656 |
if ($code > 1114111 or $code == 0) { |
!!!parse-error (type => sprintf 'invalid character reference:U+%04X', $code); |
| 1657 |
$code = 0xFFFD; # REPLACEMENT CHARACTER |
$code = 0xFFFD; |
| 1658 |
## ISSUE: Why this is not an error? |
} elsif ($code > 0x10FFFF) { |
| 1659 |
|
!!!parse-error (type => sprintf 'invalid character reference:U-%08X', $code); |
| 1660 |
|
$code = 0xFFFD; |
| 1661 |
|
} elsif ($code == 0x000D) { |
| 1662 |
|
!!!parse-error (type => 'CR character reference'); |
| 1663 |
|
$code = 0x000A; |
| 1664 |
} elsif (0x80 <= $code and $code <= 0x9F) { |
} elsif (0x80 <= $code and $code <= 0x9F) { |
| 1665 |
!!!parse-error (type => sprintf 'c1 entity:U+%04X', $code); |
!!!parse-error (type => sprintf 'c1 entity:U+%04X', $code); |
| 1666 |
$code = $c1_entity_char->{$code}; |
$code = $c1_entity_char->{$code}; |
| 1696 |
$self->{next_input_character} == 0x003B)) { # ; |
$self->{next_input_character} == 0x003B)) { # ; |
| 1697 |
$entity_name .= chr $self->{next_input_character}; |
$entity_name .= chr $self->{next_input_character}; |
| 1698 |
if (defined $EntityChar->{$entity_name}) { |
if (defined $EntityChar->{$entity_name}) { |
|
$value = $EntityChar->{$entity_name}; |
|
| 1699 |
if ($self->{next_input_character} == 0x003B) { # ; |
if ($self->{next_input_character} == 0x003B) { # ; |
| 1700 |
|
$value = $EntityChar->{$entity_name}; |
| 1701 |
$match = 1; |
$match = 1; |
| 1702 |
!!!next-input-character; |
!!!next-input-character; |
| 1703 |
last; |
last; |
| 1704 |
} else { |
} elsif (not $in_attr) { |
| 1705 |
|
$value = $EntityChar->{$entity_name}; |
| 1706 |
$match = -1; |
$match = -1; |
| 1707 |
|
} else { |
| 1708 |
|
$value .= chr $self->{next_input_character}; |
| 1709 |
} |
} |
| 1710 |
} else { |
} else { |
| 1711 |
$value .= chr $self->{next_input_character}; |
$value .= chr $self->{next_input_character}; |
| 1721 |
} else { |
} else { |
| 1722 |
!!!parse-error (type => 'bare ero'); |
!!!parse-error (type => 'bare ero'); |
| 1723 |
## NOTE: No characters are consumed in the spec. |
## NOTE: No characters are consumed in the spec. |
| 1724 |
!!!back-token ({type => 'character', data => $value}); |
return {type => 'character', data => '&'.$value}; |
|
return undef; |
|
| 1725 |
} |
} |
| 1726 |
} else { |
} else { |
| 1727 |
## no characters are consumed |
## no characters are consumed |
| 1916 |
} elsif ($token->{type} eq 'character') { |
} elsif ($token->{type} eq 'character') { |
| 1917 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
| 1918 |
## Ignore the token |
## Ignore the token |
| 1919 |
|
|
| 1920 |
unless (length $token->{data}) { |
unless (length $token->{data}) { |
| 1921 |
## Stay in the phase |
## Stay in the phase |
| 1922 |
!!!next-token; |
!!!next-token; |
| 1959 |
!!!next-token; |
!!!next-token; |
| 1960 |
redo B; |
redo B; |
| 1961 |
} elsif ($token->{type} eq 'character') { |
} elsif ($token->{type} eq 'character') { |
| 1962 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
| 1963 |
$self->{document}->manakai_append_text ($1); |
## Ignore the token. |
| 1964 |
## ISSUE: DOM3 Core does not allow Document > Text |
|
| 1965 |
unless (length $token->{data}) { |
unless (length $token->{data}) { |
| 1966 |
## Stay in the phase |
## Stay in the phase |
| 1967 |
!!!next-token; |
!!!next-token; |
| 2138 |
} |
} |
| 2139 |
}; # $clear_up_to_marker |
}; # $clear_up_to_marker |
| 2140 |
|
|
| 2141 |
my $style_start_tag = sub { |
my $parse_rcdata = sub ($$) { |
| 2142 |
my $style_el; !!!create-element ($style_el, 'style', $token->{attributes}); |
my ($content_model_flag, $insert) = @_; |
| 2143 |
## $self->{insertion_mode} eq 'in head' and ... (always true) |
|
| 2144 |
(($self->{insertion_mode} eq 'in head' and defined $self->{head_element}) |
## Step 1 |
| 2145 |
? $self->{head_element} : $self->{open_elements}->[-1]->[0]) |
my $start_tag_name = $token->{tag_name}; |
| 2146 |
->append_child ($style_el); |
my $el; |
| 2147 |
$self->{content_model_flag} = 'CDATA'; |
!!!create-element ($el, $start_tag_name, $token->{attributes}); |
| 2148 |
|
|
| 2149 |
|
## Step 2 |
| 2150 |
|
$insert->($el); # /context node/->append_child ($el) |
| 2151 |
|
|
| 2152 |
|
## Step 3 |
| 2153 |
|
$self->{content_model_flag} = $content_model_flag; # CDATA or RCDATA |
| 2154 |
delete $self->{escape}; # MUST |
delete $self->{escape}; # MUST |
| 2155 |
|
|
| 2156 |
|
## Step 4 |
| 2157 |
my $text = ''; |
my $text = ''; |
| 2158 |
!!!next-token; |
!!!next-token; |
| 2159 |
while ($token->{type} eq 'character') { |
while ($token->{type} eq 'character') { # or until stop tokenizing |
| 2160 |
$text .= $token->{data}; |
$text .= $token->{data}; |
| 2161 |
!!!next-token; |
!!!next-token; |
| 2162 |
} # stop if non-character token or tokenizer stops tokenising |
} |
| 2163 |
|
|
| 2164 |
|
## Step 5 |
| 2165 |
if (length $text) { |
if (length $text) { |
| 2166 |
$style_el->manakai_append_text ($text); |
my $text = $self->{document}->create_text_node ($text); |
| 2167 |
|
$el->append_child ($text); |
| 2168 |
} |
} |
| 2169 |
|
|
| 2170 |
|
## Step 6 |
| 2171 |
$self->{content_model_flag} = 'PCDATA'; |
$self->{content_model_flag} = 'PCDATA'; |
| 2172 |
|
|
| 2173 |
if ($token->{type} eq 'end tag' and $token->{tag_name} eq 'style') { |
## Step 7 |
| 2174 |
|
if ($token->{type} eq 'end tag' and $token->{tag_name} eq $start_tag_name) { |
| 2175 |
## Ignore the token |
## Ignore the token |
| 2176 |
} else { |
} else { |
| 2177 |
!!!parse-error (type => 'in CDATA:#'.$token->{type}); |
!!!parse-error (type => 'in '.$content_model_flag.':#'.$token->{type}); |
|
## ISSUE: And ignore? |
|
| 2178 |
} |
} |
| 2179 |
!!!next-token; |
!!!next-token; |
| 2180 |
}; # $style_start_tag |
}; # $parse_rcdata |
| 2181 |
|
|
| 2182 |
my $script_start_tag = sub { |
my $script_start_tag = sub ($) { |
| 2183 |
|
my $insert = $_[0]; |
| 2184 |
my $script_el; |
my $script_el; |
| 2185 |
!!!create-element ($script_el, 'script', $token->{attributes}); |
!!!create-element ($script_el, 'script', $token->{attributes}); |
| 2186 |
## TODO: mark as "parser-inserted" |
## TODO: mark as "parser-inserted" |
| 2214 |
} else { |
} else { |
| 2215 |
## TODO: $old_insertion_point = current insertion point |
## TODO: $old_insertion_point = current insertion point |
| 2216 |
## TODO: insertion point = just before the next input character |
## TODO: insertion point = just before the next input character |
| 2217 |
|
|
| 2218 |
(($self->{insertion_mode} eq 'in head' and defined $self->{head_element}) |
$insert->($script_el); |
|
? $self->{head_element} : $self->{open_elements}->[-1]->[0])->append_child ($script_el); |
|
| 2219 |
|
|
| 2220 |
## TODO: insertion point = $old_insertion_point (might be "undefined") |
## TODO: insertion point = $old_insertion_point (might be "undefined") |
| 2221 |
|
|
| 2409 |
}; # $formatting_end_tag |
}; # $formatting_end_tag |
| 2410 |
|
|
| 2411 |
my $insert_to_current = sub { |
my $insert_to_current = sub { |
| 2412 |
$self->{open_elements}->[-1]->[0]->append_child (shift); |
$self->{open_elements}->[-1]->[0]->append_child ($_[0]); |
| 2413 |
}; # $insert_to_current |
}; # $insert_to_current |
| 2414 |
|
|
| 2415 |
my $insert_to_foster = sub { |
my $insert_to_foster = sub { |
| 2447 |
my $insert = shift; |
my $insert = shift; |
| 2448 |
if ($token->{type} eq 'start tag') { |
if ($token->{type} eq 'start tag') { |
| 2449 |
if ($token->{tag_name} eq 'script') { |
if ($token->{tag_name} eq 'script') { |
| 2450 |
$script_start_tag->(); |
## NOTE: This is an "as if in head" code clone |
| 2451 |
|
$script_start_tag->($insert); |
| 2452 |
return; |
return; |
| 2453 |
} elsif ($token->{tag_name} eq 'style') { |
} elsif ($token->{tag_name} eq 'style') { |
| 2454 |
$style_start_tag->(); |
## NOTE: This is an "as if in head" code clone |
| 2455 |
|
$parse_rcdata->('CDATA', $insert); |
| 2456 |
return; |
return; |
| 2457 |
} elsif ({ |
} elsif ({ |
| 2458 |
base => 1, link => 1, meta => 1, |
base => 1, link => 1, meta => 1, |
| 2459 |
}->{$token->{tag_name}}) { |
}->{$token->{tag_name}}) { |
| 2460 |
## NOTE: This is an "as if in head" code clone |
## NOTE: This is an "as if in head" code clone, only "-t" differs |
| 2461 |
my $el; |
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
| 2462 |
!!!create-element ($el, $token->{tag_name}, $token->{attributes}); |
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
|
if ($self->{insertion_mode} eq 'in head' and |
|
|
defined $self->{head_element}) { |
|
|
$self->{head_element}->append_child ($el); |
|
|
} else { |
|
|
$insert->($el); |
|
|
} |
|
|
|
|
| 2463 |
!!!next-token; |
!!!next-token; |
| 2464 |
|
## TODO: Extracting |charset| from |meta|. |
| 2465 |
return; |
return; |
| 2466 |
} elsif ($token->{tag_name} eq 'title') { |
} elsif ($token->{tag_name} eq 'title') { |
| 2467 |
!!!parse-error (type => 'in body:title'); |
!!!parse-error (type => 'in body:title'); |
| 2468 |
## NOTE: There is an "as if in head" code clone |
## NOTE: This is an "as if in head" code clone |
| 2469 |
my $title_el; |
$parse_rcdata->('RCDATA', $insert); |
|
!!!create-element ($title_el, 'title', $token->{attributes}); |
|
|
(defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0]) |
|
|
->append_child ($title_el); |
|
|
$self->{content_model_flag} = 'RCDATA'; |
|
|
delete $self->{escape}; # MUST |
|
|
|
|
|
my $text = ''; |
|
|
!!!next-token; |
|
|
while ($token->{type} eq 'character') { |
|
|
$text .= $token->{data}; |
|
|
!!!next-token; |
|
|
} |
|
|
if (length $text) { |
|
|
$title_el->manakai_append_text ($text); |
|
|
} |
|
|
|
|
|
$self->{content_model_flag} = 'PCDATA'; |
|
|
|
|
|
if ($token->{type} eq 'end tag' and |
|
|
$token->{tag_name} eq 'title') { |
|
|
## Ignore the token |
|
|
} else { |
|
|
!!!parse-error (type => 'in RCDATA:#'.$token->{type}); |
|
|
## ISSUE: And ignore? |
|
|
} |
|
|
!!!next-token; |
|
| 2470 |
return; |
return; |
| 2471 |
} elsif ($token->{tag_name} eq 'body') { |
} elsif ($token->{tag_name} eq 'body') { |
| 2472 |
!!!parse-error (type => 'in body:body'); |
!!!parse-error (type => 'in body:body'); |
| 2812 |
return; |
return; |
| 2813 |
} elsif ($token->{tag_name} eq 'xmp') { |
} elsif ($token->{tag_name} eq 'xmp') { |
| 2814 |
$reconstruct_active_formatting_elements->($insert_to_current); |
$reconstruct_active_formatting_elements->($insert_to_current); |
| 2815 |
|
$parse_rcdata->('CDATA', $insert); |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
|
|
|
$self->{content_model_flag} = 'CDATA'; |
|
|
delete $self->{escape}; # MUST |
|
|
|
|
|
!!!next-token; |
|
| 2816 |
return; |
return; |
| 2817 |
} elsif ($token->{tag_name} eq 'table') { |
} elsif ($token->{tag_name} eq 'table') { |
| 2818 |
## has a p element in scope |
## has a p element in scope |
| 2921 |
!!!back-token (@tokens); |
!!!back-token (@tokens); |
| 2922 |
return; |
return; |
| 2923 |
} |
} |
| 2924 |
} elsif ({ |
} elsif ($token->{tag_name} eq 'textarea') { |
|
textarea => 1, |
|
|
iframe => 1, |
|
|
noembed => 1, |
|
|
noframes => 1, |
|
|
noscript => 0, ## TODO: 1 if scripting is enabled |
|
|
}->{$token->{tag_name}}) { |
|
| 2925 |
my $tag_name = $token->{tag_name}; |
my $tag_name = $token->{tag_name}; |
| 2926 |
my $el; |
my $el; |
| 2927 |
!!!create-element ($el, $token->{tag_name}, $token->{attributes}); |
!!!create-element ($el, $token->{tag_name}, $token->{attributes}); |
| 2928 |
|
|
| 2929 |
if ($token->{tag_name} eq 'textarea') { |
## TODO: $self->{form_element} if defined |
| 2930 |
## TODO: $self->{form_element} if defined |
$self->{content_model_flag} = 'RCDATA'; |
|
$self->{content_model_flag} = 'RCDATA'; |
|
|
} else { |
|
|
$self->{content_model_flag} = 'CDATA'; |
|
|
} |
|
| 2931 |
delete $self->{escape}; # MUST |
delete $self->{escape}; # MUST |
| 2932 |
|
|
| 2933 |
$insert->($el); |
$insert->($el); |
| 2934 |
|
|
| 2935 |
my $text = ''; |
my $text = ''; |
| 2936 |
if ($token->{tag_name} eq 'textarea') { |
!!!next-token; |
| 2937 |
!!!next-token; |
if ($token->{type} eq 'character') { |
| 2938 |
if ($token->{type} eq 'character') { |
$token->{data} =~ s/^\x0A//; |
| 2939 |
$token->{data} =~ s/^\x0A//; |
unless (length $token->{data}) { |
| 2940 |
unless (length $token->{data}) { |
!!!next-token; |
|
!!!next-token; |
|
|
} |
|
| 2941 |
} |
} |
|
} else { |
|
|
!!!next-token; |
|
| 2942 |
} |
} |
| 2943 |
while ($token->{type} eq 'character') { |
while ($token->{type} eq 'character') { |
| 2944 |
$text .= $token->{data}; |
$text .= $token->{data}; |
| 2954 |
$token->{tag_name} eq $tag_name) { |
$token->{tag_name} eq $tag_name) { |
| 2955 |
## Ignore the token |
## Ignore the token |
| 2956 |
} else { |
} else { |
| 2957 |
if ($token->{tag_name} eq 'textarea') { |
!!!parse-error (type => 'in RCDATA:#'.$token->{type}); |
|
!!!parse-error (type => 'in RCDATA:#'.$token->{type}); |
|
|
} else { |
|
|
!!!parse-error (type => 'in CDATA:#'.$token->{type}); |
|
|
} |
|
|
## ISSUE: And ignore? |
|
| 2958 |
} |
} |
| 2959 |
!!!next-token; |
!!!next-token; |
| 2960 |
return; |
return; |
| 2961 |
|
} elsif ({ |
| 2962 |
|
iframe => 1, |
| 2963 |
|
noembed => 1, |
| 2964 |
|
noframes => 1, |
| 2965 |
|
noscript => 0, ## TODO: 1 if scripting is enabled |
| 2966 |
|
}->{$token->{tag_name}}) { |
| 2967 |
|
$parse_rcdata->('CDATA', $insert); |
| 2968 |
|
return; |
| 2969 |
} elsif ($token->{tag_name} eq 'select') { |
} elsif ($token->{tag_name} eq 'select') { |
| 2970 |
$reconstruct_active_formatting_elements->($insert_to_current); |
$reconstruct_active_formatting_elements->($insert_to_current); |
| 2971 |
|
|
| 3212 |
#not $phrasing_category->{$node->[1]} and |
#not $phrasing_category->{$node->[1]} and |
| 3213 |
($special_category->{$node->[1]} or |
($special_category->{$node->[1]} or |
| 3214 |
$scoping_category->{$node->[1]})) { |
$scoping_category->{$node->[1]})) { |
| 3215 |
!!!parse-error (type => 'not closed:'.$node->[1]); |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
| 3216 |
## Ignore the token |
## Ignore the token |
| 3217 |
!!!next-token; |
!!!next-token; |
| 3218 |
last S2; |
last S2; |
| 3332 |
} else { |
} else { |
| 3333 |
die "$0: $token->{type}: Unknown type"; |
die "$0: $token->{type}: Unknown type"; |
| 3334 |
} |
} |
| 3335 |
} elsif ($self->{insertion_mode} eq 'in head') { |
} elsif ($self->{insertion_mode} eq 'in head' or |
| 3336 |
|
$self->{insertion_mode} eq 'in head noscript' or |
| 3337 |
|
$self->{insertion_mode} eq 'after head') { |
| 3338 |
if ($token->{type} eq 'character') { |
if ($token->{type} eq 'character') { |
| 3339 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
| 3340 |
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
| 3351 |
!!!next-token; |
!!!next-token; |
| 3352 |
redo B; |
redo B; |
| 3353 |
} elsif ($token->{type} eq 'start tag') { |
} elsif ($token->{type} eq 'start tag') { |
| 3354 |
if ($token->{tag_name} eq 'title') { |
if ({base => ($self->{insertion_mode} eq 'in head' or |
| 3355 |
## NOTE: There is an "as if in head" code clone |
$self->{insertion_mode} eq 'after head'), |
| 3356 |
my $title_el; |
link => 1, meta => 1}->{$token->{tag_name}}) { |
| 3357 |
!!!create-element ($title_el, 'title', $token->{attributes}); |
## NOTE: There is a "as if in head" code clone. |
| 3358 |
(defined $self->{head_element} ? $self->{head_element} : $self->{open_elements}->[-1]->[0]) |
if ($self->{insertion_mode} eq 'after head') { |
| 3359 |
->append_child ($title_el); |
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
| 3360 |
$self->{content_model_flag} = 'RCDATA'; |
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
| 3361 |
delete $self->{escape}; # MUST |
} |
| 3362 |
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
| 3363 |
my $text = ''; |
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
| 3364 |
|
## TODO: Extracting |charset| from |meta|. |
| 3365 |
|
pop @{$self->{open_elements}} |
| 3366 |
|
if $self->{insertion_mode} eq 'after head'; |
| 3367 |
!!!next-token; |
!!!next-token; |
| 3368 |
while ($token->{type} eq 'character') { |
redo B; |
| 3369 |
$text .= $token->{data}; |
} elsif ($token->{tag_name} eq 'title' and |
| 3370 |
|
$self->{insertion_mode} eq 'in head') { |
| 3371 |
|
## NOTE: There is a "as if in head" code clone. |
| 3372 |
|
if ($self->{insertion_mode} eq 'after head') { |
| 3373 |
|
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
| 3374 |
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
| 3375 |
|
} |
| 3376 |
|
$parse_rcdata->('RCDATA', $insert_to_current); |
| 3377 |
|
pop @{$self->{open_elements}} |
| 3378 |
|
if $self->{insertion_mode} eq 'after head'; |
| 3379 |
|
redo B; |
| 3380 |
|
} elsif ($token->{tag_name} eq 'style') { |
| 3381 |
|
## NOTE: Or (scripting is enabled and tag_name eq 'noscript' and |
| 3382 |
|
## insertion mode 'in head') |
| 3383 |
|
## NOTE: There is a "as if in head" code clone. |
| 3384 |
|
if ($self->{insertion_mode} eq 'after head') { |
| 3385 |
|
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
| 3386 |
|
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
| 3387 |
|
} |
| 3388 |
|
$parse_rcdata->('CDATA', $insert_to_current); |
| 3389 |
|
pop @{$self->{open_elements}} |
| 3390 |
|
if $self->{insertion_mode} eq 'after head'; |
| 3391 |
|
redo B; |
| 3392 |
|
} elsif ($token->{tag_name} eq 'noscript') { |
| 3393 |
|
if ($self->{insertion_mode} eq 'in head') { |
| 3394 |
|
## NOTE: and scripting is disalbed |
| 3395 |
|
!!!insert-element ($token->{tag_name}, $token->{attributes}); |
| 3396 |
|
$self->{insertion_mode} = 'in head noscript'; |
| 3397 |
!!!next-token; |
!!!next-token; |
| 3398 |
} |
redo B; |
| 3399 |
if (length $text) { |
} elsif ($self->{insertion_mode} eq 'in head noscript') { |
| 3400 |
$title_el->manakai_append_text ($text); |
!!!parse-error (type => 'noscript in noscript'); |
|
} |
|
|
|
|
|
$self->{content_model_flag} = 'PCDATA'; |
|
|
|
|
|
if ($token->{type} eq 'end tag' and |
|
|
$token->{tag_name} eq 'title') { |
|
| 3401 |
## Ignore the token |
## Ignore the token |
| 3402 |
|
redo B; |
| 3403 |
} else { |
} else { |
| 3404 |
!!!parse-error (type => 'in RCDATA:#'.$token->{type}); |
# |
|
## ISSUE: And ignore? |
|
| 3405 |
} |
} |
| 3406 |
|
} elsif ($token->{tag_name} eq 'head' and |
| 3407 |
|
$self->{insertion_mode} ne 'after head') { |
| 3408 |
|
!!!parse-error (type => 'in head:head'); # or in head noscript |
| 3409 |
|
## Ignore the token |
| 3410 |
!!!next-token; |
!!!next-token; |
| 3411 |
redo B; |
redo B; |
| 3412 |
} elsif ($token->{tag_name} eq 'style') { |
} elsif ($self->{insertion_mode} ne 'in head noscript' and |
| 3413 |
$style_start_tag->(); |
$token->{tag_name} eq 'script') { |
| 3414 |
redo B; |
if ($self->{insertion_mode} eq 'after head') { |
| 3415 |
} elsif ($token->{tag_name} eq 'script') { |
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
| 3416 |
$script_start_tag->(); |
push @{$self->{open_elements}}, [$self->{head_element}, 'head']; |
| 3417 |
|
} |
| 3418 |
|
## NOTE: There is a "as if in head" code clone. |
| 3419 |
|
$script_start_tag->($insert_to_current); |
| 3420 |
|
pop @{$self->{open_elements}} |
| 3421 |
|
if $self->{insertion_mode} eq 'after head'; |
| 3422 |
redo B; |
redo B; |
| 3423 |
} elsif ({base => 1, link => 1, meta => 1}->{$token->{tag_name}}) { |
} elsif ($self->{insertion_mode} eq 'after head' and |
| 3424 |
## NOTE: There are "as if in head" code clones |
$token->{tag_name} eq 'body') { |
| 3425 |
my $el; |
!!!insert-element ('body', $token->{attributes}); |
| 3426 |
!!!create-element ($el, $token->{tag_name}, $token->{attributes}); |
$self->{insertion_mode} = 'in body'; |
|
if ($self->{insertion_mode} eq 'in head' and |
|
|
defined $self->{head_element}) { |
|
|
$self->{head_element}->append_child ($el); |
|
|
} else { |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($el); |
|
|
} |
|
|
|
|
| 3427 |
!!!next-token; |
!!!next-token; |
| 3428 |
redo B; |
redo B; |
| 3429 |
} elsif ($token->{tag_name} eq 'head') { |
} elsif ($self->{insertion_mode} eq 'after head' and |
| 3430 |
!!!parse-error (type => 'in head:head'); |
$token->{tag_name} eq 'frameset') { |
| 3431 |
## Ignore the token |
!!!insert-element ('frameset', $token->{attributes}); |
| 3432 |
|
$self->{insertion_mode} = 'in frameset'; |
| 3433 |
!!!next-token; |
!!!next-token; |
| 3434 |
redo B; |
redo B; |
| 3435 |
} else { |
} else { |
| 3436 |
# |
# |
| 3437 |
} |
} |
| 3438 |
} elsif ($token->{type} eq 'end tag') { |
} elsif ($token->{type} eq 'end tag') { |
| 3439 |
if ($token->{tag_name} eq 'head') { |
if ($self->{insertion_mode} eq 'in head' and |
| 3440 |
if ($self->{open_elements}->[-1]->[1] eq 'head') { |
$token->{tag_name} eq 'head') { |
| 3441 |
pop @{$self->{open_elements}}; |
pop @{$self->{open_elements}}; |
|
} else { |
|
|
!!!parse-error (type => 'unmatched end tag:head'); |
|
|
} |
|
| 3442 |
$self->{insertion_mode} = 'after head'; |
$self->{insertion_mode} = 'after head'; |
| 3443 |
!!!next-token; |
!!!next-token; |
| 3444 |
redo B; |
redo B; |
| 3445 |
} elsif ($token->{tag_name} eq 'body' or |
} elsif ($self->{insertion_mode} eq 'in head noscript' and |
| 3446 |
$token->{tag_name} eq 'html') { |
$token->{tag_name} eq 'noscript') { |
| 3447 |
|
pop @{$self->{open_elements}}; |
| 3448 |
|
$self->{insertion_mode} = 'in head'; |
| 3449 |
|
!!!next-token; |
| 3450 |
|
redo B; |
| 3451 |
|
} elsif ($self->{insertion_mode} eq 'in head' and |
| 3452 |
|
($token->{tag_name} eq 'body' or |
| 3453 |
|
$token->{tag_name} eq 'html')) { |
| 3454 |
# |
# |
| 3455 |
} else { |
} elsif ($self->{insertion_mode} ne 'after head') { |
| 3456 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
| 3457 |
## Ignore the token |
## Ignore the token |
| 3458 |
!!!next-token; |
!!!next-token; |
| 3459 |
redo B; |
redo B; |
| 3460 |
|
} else { |
| 3461 |
|
# |
| 3462 |
} |
} |
| 3463 |
} else { |
} else { |
| 3464 |
# |
# |
| 3465 |
} |
} |
| 3466 |
|
|
| 3467 |
if ($self->{open_elements}->[-1]->[1] eq 'head') { |
## As if </head> or </noscript> or <body> |
| 3468 |
## As if </head> |
if ($self->{insertion_mode} eq 'in head') { |
| 3469 |
|
pop @{$self->{open_elements}}; |
| 3470 |
|
$self->{insertion_mode} = 'after head'; |
| 3471 |
|
} elsif ($self->{insertion_mode} eq 'in head noscript') { |
| 3472 |
pop @{$self->{open_elements}}; |
pop @{$self->{open_elements}}; |
| 3473 |
|
!!!parse-error (type => 'in noscript:'.(defined $token->{tag_name} ? ($token->{type} eq 'end tag' ? '/' : '') . $token->{tag_name} : '#' . $token->{type})); |
| 3474 |
|
$self->{insertion_mode} = 'in head'; |
| 3475 |
|
} else { # 'after head' |
| 3476 |
|
!!!insert-element ('body'); |
| 3477 |
|
$self->{insertion_mode} = 'in body'; |
| 3478 |
} |
} |
|
$self->{insertion_mode} = 'after head'; |
|
| 3479 |
## reprocess |
## reprocess |
| 3480 |
redo B; |
redo B; |
| 3481 |
|
|
| 3482 |
## ISSUE: An issue in the spec. |
## ISSUE: An issue in the spec. |
|
} elsif ($self->{insertion_mode} eq 'after head') { |
|
|
if ($token->{type} eq 'character') { |
|
|
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
|
|
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
|
|
unless (length $token->{data}) { |
|
|
!!!next-token; |
|
|
redo B; |
|
|
} |
|
|
} |
|
|
|
|
|
# |
|
|
} elsif ($token->{type} eq 'comment') { |
|
|
my $comment = $self->{document}->create_comment ($token->{data}); |
|
|
$self->{open_elements}->[-1]->[0]->append_child ($comment); |
|
|
!!!next-token; |
|
|
redo B; |
|
|
} elsif ($token->{type} eq 'start tag') { |
|
|
if ($token->{tag_name} eq 'body') { |
|
|
!!!insert-element ('body', $token->{attributes}); |
|
|
$self->{insertion_mode} = 'in body'; |
|
|
!!!next-token; |
|
|
redo B; |
|
|
} elsif ($token->{tag_name} eq 'frameset') { |
|
|
!!!insert-element ('frameset', $token->{attributes}); |
|
|
$self->{insertion_mode} = 'in frameset'; |
|
|
!!!next-token; |
|
|
redo B; |
|
|
} elsif ({ |
|
|
base => 1, link => 1, meta => 1, |
|
|
script => 1, style => 1, title => 1, |
|
|
}->{$token->{tag_name}}) { |
|
|
!!!parse-error (type => 'after head:'.$token->{tag_name}); |
|
|
$self->{insertion_mode} = 'in head'; |
|
|
## reprocess |
|
|
redo B; |
|
|
} else { |
|
|
# |
|
|
} |
|
|
} else { |
|
|
# |
|
|
} |
|
|
|
|
|
## As if <body> |
|
|
!!!insert-element ('body'); |
|
|
$self->{insertion_mode} = 'in body'; |
|
|
## reprocess |
|
|
redo B; |
|
| 3483 |
} elsif ($self->{insertion_mode} eq 'in body') { |
} elsif ($self->{insertion_mode} eq 'in body') { |
| 3484 |
if ($token->{type} eq 'character') { |
if ($token->{type} eq 'character') { |
| 3485 |
## NOTE: There is a code clone of "character in body". |
## NOTE: There is a code clone of "character in body". |
| 5291 |
|
|
| 5292 |
my $nt = $child->node_type; |
my $nt = $child->node_type; |
| 5293 |
if ($nt == 1) { # Element |
if ($nt == 1) { # Element |
| 5294 |
my $tag_name = lc $child->tag_name; ## ISSUE: Definition of "lowercase" |
my $tag_name = $child->tag_name; ## TODO: manakai_tag_name |
| 5295 |
$s .= '<' . $tag_name; |
$s .= '<' . $tag_name; |
| 5296 |
|
## NOTE: Non-HTML case: |
| 5297 |
## ISSUE: Non-html elements |
## <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/11191> |
| 5298 |
|
|
| 5299 |
my @attrs = @{$child->attributes}; # sort order MUST be stable |
my @attrs = @{$child->attributes}; # sort order MUST be stable |
| 5300 |
for my $attr (@attrs) { # order is implementation dependent |
for my $attr (@attrs) { # order is implementation dependent |
| 5301 |
my $attr_name = lc $attr->name; ## ISSUE: Definition of "lowercase" |
my $attr_name = $attr->name; ## TODO: manakai_name |
| 5302 |
$s .= ' ' . $attr_name . '="'; |
$s .= ' ' . $attr_name . '="'; |
| 5303 |
my $attr_value = $attr->value; |
my $attr_value = $attr->value; |
| 5304 |
## escape |
## escape |
| 5322 |
if (not $in_cdata and { |
if (not $in_cdata and { |
| 5323 |
style => 1, script => 1, xmp => 1, iframe => 1, |
style => 1, script => 1, xmp => 1, iframe => 1, |
| 5324 |
noembed => 1, noframes => 1, noscript => 1, |
noembed => 1, noframes => 1, noscript => 1, |
| 5325 |
|
plaintext => 1, |
| 5326 |
}->{$tag_name}) { |
}->{$tag_name}) { |
| 5327 |
unshift @node, 'cdata-out'; |
unshift @node, 'cdata-out'; |
| 5328 |
$in_cdata = 1; |
$in_cdata = 1; |