2494 |
} |
} |
2495 |
}; # $insert_to_foster |
}; # $insert_to_foster |
2496 |
|
|
2497 |
my $in_body = sub { |
my $insert; |
|
my $insert = shift; |
|
|
if ($token->{type} eq 'start tag') { |
|
|
if ($token->{tag_name} eq 'script') { |
|
|
## NOTE: This is an "as if in head" code clone |
|
|
$script_start_tag->($insert); |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'style') { |
|
|
## NOTE: This is an "as if in head" code clone |
|
|
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert); |
|
|
return; |
|
|
} elsif ({ |
|
|
base => 1, link => 1, |
|
|
}->{$token->{tag_name}}) { |
|
|
## NOTE: This is an "as if in head" code clone, only "-t" differs |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'meta') { |
|
|
## NOTE: This is an "as if in head" code clone, only "-t" differs |
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
|
|
|
|
|
unless ($self->{confident}) { |
|
|
my $charset; |
|
|
if ($token->{attributes}->{charset}) { ## TODO: And if supported |
|
|
$charset = $token->{attributes}->{charset}->{value}; |
|
|
} |
|
|
if ($token->{attributes}->{'http-equiv'}) { |
|
|
## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition. |
|
|
if ($token->{attributes}->{'http-equiv'}->{value} |
|
|
=~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*= |
|
|
[\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'| |
|
|
([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) { |
|
|
$charset = defined $1 ? $1 : defined $2 ? $2 : $3; |
|
|
} ## TODO: And if supported |
|
|
} |
|
|
## TODO: Change the encoding |
|
|
} |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'title') { |
|
|
!!!parse-error (type => 'in body:title'); |
|
|
## NOTE: This is an "as if in head" code clone |
|
|
$parse_rcdata->(RCDATA_CONTENT_MODEL, sub { |
|
|
if (defined $self->{head_element}) { |
|
|
$self->{head_element}->append_child ($_[0]); |
|
|
} else { |
|
|
$insert->($_[0]); |
|
|
} |
|
|
}); |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'body') { |
|
|
!!!parse-error (type => 'in body:body'); |
|
|
|
|
|
if (@{$self->{open_elements}} == 1 or |
|
|
$self->{open_elements}->[1]->[1] ne 'body') { |
|
|
## Ignore the token |
|
|
} else { |
|
|
my $body_el = $self->{open_elements}->[1]->[0]; |
|
|
for my $attr_name (keys %{$token->{attributes}}) { |
|
|
unless ($body_el->has_attribute_ns (undef, $attr_name)) { |
|
|
$body_el->set_attribute_ns |
|
|
(undef, [undef, $attr_name], |
|
|
$token->{attributes}->{$attr_name}->{value}); |
|
|
} |
|
|
} |
|
|
} |
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ({ |
|
|
address => 1, blockquote => 1, center => 1, dir => 1, |
|
|
div => 1, dl => 1, fieldset => 1, listing => 1, |
|
|
menu => 1, ol => 1, p => 1, ul => 1, |
|
|
pre => 1, |
|
|
}->{$token->{tag_name}}) { |
|
|
## has a p element in scope |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
|
|
if ($_->[1] eq 'p') { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'p'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$_->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
if ($token->{tag_name} eq 'pre') { |
|
|
!!!next-token; |
|
|
if ($token->{type} eq 'character') { |
|
|
$token->{data} =~ s/^\x0A//; |
|
|
unless (length $token->{data}) { |
|
|
!!!next-token; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
!!!next-token; |
|
|
} |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'form') { |
|
|
if (defined $self->{form_element}) { |
|
|
!!!parse-error (type => 'in form:form'); |
|
|
## Ignore the token |
|
|
!!!next-token; |
|
|
return; |
|
|
} else { |
|
|
## has a p element in scope |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
|
|
if ($_->[1] eq 'p') { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'p'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$_->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
$self->{form_element} = $self->{open_elements}->[-1]->[0]; |
|
|
!!!next-token; |
|
|
return; |
|
|
} |
|
|
} elsif ($token->{tag_name} eq 'li') { |
|
|
## has a p element in scope |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
|
|
if ($_->[1] eq 'p') { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'p'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$_->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
## Step 1 |
|
|
my $i = -1; |
|
|
my $node = $self->{open_elements}->[$i]; |
|
|
LI: { |
|
|
## Step 2 |
|
|
if ($node->[1] eq 'li') { |
|
|
if ($i != -1) { |
|
|
!!!parse-error (type => 'end tag missing:'. |
|
|
$self->{open_elements}->[-1]->[1]); |
|
|
} |
|
|
splice @{$self->{open_elements}}, $i; |
|
|
last LI; |
|
|
} |
|
|
|
|
|
## Step 3 |
|
|
if (not $formatting_category->{$node->[1]} and |
|
|
#not $phrasing_category->{$node->[1]} and |
|
|
($special_category->{$node->[1]} or |
|
|
$scoping_category->{$node->[1]}) and |
|
|
$node->[1] ne 'address' and $node->[1] ne 'div') { |
|
|
last LI; |
|
|
} |
|
|
|
|
|
## Step 4 |
|
|
$i--; |
|
|
$node = $self->{open_elements}->[$i]; |
|
|
redo LI; |
|
|
} # LI |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'dd' or $token->{tag_name} eq 'dt') { |
|
|
## has a p element in scope |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
|
|
if ($_->[1] eq 'p') { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'p'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$_->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
## Step 1 |
|
|
my $i = -1; |
|
|
my $node = $self->{open_elements}->[$i]; |
|
|
LI: { |
|
|
## Step 2 |
|
|
if ($node->[1] eq 'dt' or $node->[1] eq 'dd') { |
|
|
if ($i != -1) { |
|
|
!!!parse-error (type => 'end tag missing:'. |
|
|
$self->{open_elements}->[-1]->[1]); |
|
|
} |
|
|
splice @{$self->{open_elements}}, $i; |
|
|
last LI; |
|
|
} |
|
|
|
|
|
## Step 3 |
|
|
if (not $formatting_category->{$node->[1]} and |
|
|
#not $phrasing_category->{$node->[1]} and |
|
|
($special_category->{$node->[1]} or |
|
|
$scoping_category->{$node->[1]}) and |
|
|
$node->[1] ne 'address' and $node->[1] ne 'div') { |
|
|
last LI; |
|
|
} |
|
|
|
|
|
## Step 4 |
|
|
$i--; |
|
|
$node = $self->{open_elements}->[$i]; |
|
|
redo LI; |
|
|
} # LI |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'plaintext') { |
|
|
## has a p element in scope |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
|
|
if ($_->[1] eq 'p') { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'p'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$_->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
|
|
|
$self->{content_model} = PLAINTEXT_CONTENT_MODEL; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ({ |
|
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
|
|
}->{$token->{tag_name}}) { |
|
|
## has a p element in scope |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
|
|
my $node = $self->{open_elements}->[$_]; |
|
|
if ($node->[1] eq 'p') { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'p'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$node->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926> |
|
|
## has an element in scope |
|
|
#my $i; |
|
|
#INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
|
|
# my $node = $self->{open_elements}->[$_]; |
|
|
# if ({ |
|
|
# h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
|
|
# }->{$node->[1]}) { |
|
|
# $i = $_; |
|
|
# last INSCOPE; |
|
|
# } elsif ({ |
|
|
# table => 1, caption => 1, td => 1, th => 1, |
|
|
# button => 1, marquee => 1, object => 1, html => 1, |
|
|
# }->{$node->[1]}) { |
|
|
# last INSCOPE; |
|
|
# } |
|
|
#} # INSCOPE |
|
|
# |
|
|
#if (defined $i) { |
|
|
# !!! parse-error (type => 'in hn:hn'); |
|
|
# splice @{$self->{open_elements}}, $i; |
|
|
#} |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'a') { |
|
|
AFE: for my $i (reverse 0..$#$active_formatting_elements) { |
|
|
my $node = $active_formatting_elements->[$i]; |
|
|
if ($node->[1] eq 'a') { |
|
|
!!!parse-error (type => 'in a:a'); |
|
|
|
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'a'}; |
|
|
$formatting_end_tag->($token->{tag_name}); |
|
|
|
|
|
AFE2: for (reverse 0..$#$active_formatting_elements) { |
|
|
if ($active_formatting_elements->[$_]->[0] eq $node->[0]) { |
|
|
splice @$active_formatting_elements, $_, 1; |
|
|
last AFE2; |
|
|
} |
|
|
} # AFE2 |
|
|
OE: for (reverse 0..$#{$self->{open_elements}}) { |
|
|
if ($self->{open_elements}->[$_]->[0] eq $node->[0]) { |
|
|
splice @{$self->{open_elements}}, $_, 1; |
|
|
last OE; |
|
|
} |
|
|
} # OE |
|
|
last AFE; |
|
|
} elsif ($node->[0] eq '#marker') { |
|
|
last AFE; |
|
|
} |
|
|
} # AFE |
|
|
|
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ({ |
|
|
b => 1, big => 1, em => 1, font => 1, i => 1, |
|
|
s => 1, small => 1, strile => 1, |
|
|
strong => 1, tt => 1, u => 1, |
|
|
}->{$token->{tag_name}}) { |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'nobr') { |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
## has a |nobr| element in scope |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
|
|
my $node = $self->{open_elements}->[$_]; |
|
|
if ($node->[1] eq 'nobr') { |
|
|
!!!parse-error (type => 'not closed:nobr'); |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'nobr'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$node->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'button') { |
|
|
## has a button element in scope |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
|
|
my $node = $self->{open_elements}->[$_]; |
|
|
if ($node->[1] eq 'button') { |
|
|
!!!parse-error (type => 'in button:button'); |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'button'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$node->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
push @$active_formatting_elements, ['#marker', '']; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'marquee' or |
|
|
$token->{tag_name} eq 'object') { |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
push @$active_formatting_elements, ['#marker', '']; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'xmp') { |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert); |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'table') { |
|
|
## has a p element in scope |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
|
|
if ($_->[1] eq 'p') { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'p'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$_->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
|
|
|
$self->{insertion_mode} = 'in table'; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ({ |
|
|
area => 1, basefont => 1, bgsound => 1, br => 1, |
|
|
embed => 1, img => 1, param => 1, spacer => 1, wbr => 1, |
|
|
image => 1, |
|
|
}->{$token->{tag_name}}) { |
|
|
if ($token->{tag_name} eq 'image') { |
|
|
!!!parse-error (type => 'image'); |
|
|
$token->{tag_name} = 'img'; |
|
|
} |
|
|
|
|
|
## NOTE: There is an "as if <br>" code clone. |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
pop @{$self->{open_elements}}; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'hr') { |
|
|
## has a p element in scope |
|
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
|
|
if ($_->[1] eq 'p') { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', tag_name => 'p'}; |
|
|
return; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$_->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
pop @{$self->{open_elements}}; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'input') { |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
## TODO: associate with $self->{form_element} if defined |
|
|
pop @{$self->{open_elements}}; |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'isindex') { |
|
|
!!!parse-error (type => 'isindex'); |
|
|
|
|
|
if (defined $self->{form_element}) { |
|
|
## Ignore the token |
|
|
!!!next-token; |
|
|
return; |
|
|
} else { |
|
|
my $at = $token->{attributes}; |
|
|
my $form_attrs; |
|
|
$form_attrs->{action} = $at->{action} if $at->{action}; |
|
|
my $prompt_attr = $at->{prompt}; |
|
|
$at->{name} = {name => 'name', value => 'isindex'}; |
|
|
delete $at->{action}; |
|
|
delete $at->{prompt}; |
|
|
my @tokens = ( |
|
|
{type => 'start tag', tag_name => 'form', |
|
|
attributes => $form_attrs}, |
|
|
{type => 'start tag', tag_name => 'hr'}, |
|
|
{type => 'start tag', tag_name => 'p'}, |
|
|
{type => 'start tag', tag_name => 'label'}, |
|
|
); |
|
|
if ($prompt_attr) { |
|
|
push @tokens, {type => 'character', data => $prompt_attr->{value}}; |
|
|
} else { |
|
|
push @tokens, {type => 'character', |
|
|
data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD |
|
|
## TODO: make this configurable |
|
|
} |
|
|
push @tokens, |
|
|
{type => 'start tag', tag_name => 'input', attributes => $at}, |
|
|
#{type => 'character', data => ''}, # SHOULD |
|
|
{type => 'end tag', tag_name => 'label'}, |
|
|
{type => 'end tag', tag_name => 'p'}, |
|
|
{type => 'start tag', tag_name => 'hr'}, |
|
|
{type => 'end tag', tag_name => 'form'}; |
|
|
$token = shift @tokens; |
|
|
!!!back-token (@tokens); |
|
|
return; |
|
|
} |
|
|
} elsif ($token->{tag_name} eq 'textarea') { |
|
|
my $tag_name = $token->{tag_name}; |
|
|
my $el; |
|
|
!!!create-element ($el, $token->{tag_name}, $token->{attributes}); |
|
|
|
|
|
## TODO: $self->{form_element} if defined |
|
|
$self->{content_model} = RCDATA_CONTENT_MODEL; |
|
|
delete $self->{escape}; # MUST |
|
|
|
|
|
$insert->($el); |
|
|
|
|
|
my $text = ''; |
|
|
!!!next-token; |
|
|
if ($token->{type} eq 'character') { |
|
|
$token->{data} =~ s/^\x0A//; |
|
|
unless (length $token->{data}) { |
|
|
!!!next-token; |
|
|
} |
|
|
} |
|
|
while ($token->{type} eq 'character') { |
|
|
$text .= $token->{data}; |
|
|
!!!next-token; |
|
|
} |
|
|
if (length $text) { |
|
|
$el->manakai_append_text ($text); |
|
|
} |
|
|
|
|
|
$self->{content_model} = PCDATA_CONTENT_MODEL; |
|
|
|
|
|
if ($token->{type} eq 'end tag' and |
|
|
$token->{tag_name} eq $tag_name) { |
|
|
## Ignore the token |
|
|
} else { |
|
|
!!!parse-error (type => 'in RCDATA:#'.$token->{type}); |
|
|
} |
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ({ |
|
|
iframe => 1, |
|
|
noembed => 1, |
|
|
noframes => 1, |
|
|
noscript => 0, ## TODO: 1 if scripting is enabled |
|
|
}->{$token->{tag_name}}) { |
|
|
## NOTE: There are two "as if in body" code clones. |
|
|
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert); |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'select') { |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
|
|
|
$self->{insertion_mode} = 'in select'; |
|
|
!!!next-token; |
|
|
return; |
|
|
} 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, |
|
|
}->{$token->{tag_name}}) { |
|
|
!!!parse-error (type => 'in body:'.$token->{tag_name}); |
|
|
## Ignore the token |
|
|
!!!next-token; |
|
|
return; |
|
|
|
|
|
## ISSUE: An issue on HTML5 new elements in the spec. |
|
|
} else { |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
|
|
|
|
|
!!!next-token; |
|
|
return; |
|
|
} |
|
|
} elsif ($token->{type} eq 'end tag') { |
|
|
if ($token->{tag_name} eq 'body') { |
|
|
if (@{$self->{open_elements}} > 1 and |
|
|
$self->{open_elements}->[1]->[1] eq 'body') { |
|
|
for (@{$self->{open_elements}}) { |
|
|
unless ({ |
|
|
dd => 1, dt => 1, li => 1, p => 1, td => 1, |
|
|
th => 1, tr => 1, body => 1, html => 1, |
|
|
tbody => 1, tfoot => 1, thead => 1, |
|
|
}->{$_->[1]}) { |
|
|
!!!parse-error (type => 'not closed:'.$_->[1]); |
|
|
} |
|
|
} |
|
|
|
|
|
$self->{insertion_mode} = 'after body'; |
|
|
!!!next-token; |
|
|
return; |
|
|
} else { |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
|
|
## Ignore the token |
|
|
!!!next-token; |
|
|
return; |
|
|
} |
|
|
} elsif ($token->{tag_name} eq 'html') { |
|
|
if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') { |
|
|
## ISSUE: There is an issue in the spec. |
|
|
if ($self->{open_elements}->[-1]->[1] ne 'body') { |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]); |
|
|
} |
|
|
$self->{insertion_mode} = 'after body'; |
|
|
## reprocess |
|
|
return; |
|
|
} else { |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
|
|
## Ignore the token |
|
|
!!!next-token; |
|
|
return; |
|
|
} |
|
|
} elsif ({ |
|
|
address => 1, blockquote => 1, center => 1, dir => 1, |
|
|
div => 1, dl => 1, fieldset => 1, listing => 1, |
|
|
menu => 1, ol => 1, pre => 1, ul => 1, |
|
|
p => 1, |
|
|
dd => 1, dt => 1, li => 1, |
|
|
button => 1, marquee => 1, object => 1, |
|
|
}->{$token->{tag_name}}) { |
|
|
## has an element in scope |
|
|
my $i; |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
|
|
my $node = $self->{open_elements}->[$_]; |
|
|
if ($node->[1] eq $token->{tag_name}) { |
|
|
## generate implied end tags |
|
|
if ({ |
|
|
dd => ($token->{tag_name} ne 'dd'), |
|
|
dt => ($token->{tag_name} ne 'dt'), |
|
|
li => ($token->{tag_name} ne 'li'), |
|
|
p => ($token->{tag_name} ne 'p'), |
|
|
td => 1, th => 1, tr => 1, |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', |
|
|
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
|
|
return; |
|
|
} |
|
|
$i = $_; |
|
|
last INSCOPE unless $token->{tag_name} eq 'p'; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$node->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
|
|
if (defined $i) { |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
|
|
} else { |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
|
|
} |
|
|
} |
|
|
|
|
|
if (defined $i) { |
|
|
splice @{$self->{open_elements}}, $i; |
|
|
} elsif ($token->{tag_name} eq 'p') { |
|
|
## As if <p>, then reprocess the current token |
|
|
my $el; |
|
|
!!!create-element ($el, 'p'); |
|
|
$insert->($el); |
|
|
} |
|
|
$clear_up_to_marker->() |
|
|
if { |
|
|
button => 1, marquee => 1, object => 1, |
|
|
}->{$token->{tag_name}}; |
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'form') { |
|
|
## has an element in scope |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
|
|
my $node = $self->{open_elements}->[$_]; |
|
|
if ($node->[1] eq $token->{tag_name}) { |
|
|
## generate implied end tags |
|
|
if ({ |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
|
|
td => 1, th => 1, tr => 1, |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', |
|
|
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
|
|
return; |
|
|
} |
|
|
last INSCOPE; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$node->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) { |
|
|
pop @{$self->{open_elements}}; |
|
|
} else { |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
|
|
} |
|
|
|
|
|
undef $self->{form_element}; |
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ({ |
|
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
|
|
}->{$token->{tag_name}}) { |
|
|
## has an element in scope |
|
|
my $i; |
|
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
|
|
my $node = $self->{open_elements}->[$_]; |
|
|
if ({ |
|
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
|
|
}->{$node->[1]}) { |
|
|
## generate implied end tags |
|
|
if ({ |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
|
|
td => 1, th => 1, tr => 1, |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', |
|
|
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
|
|
return; |
|
|
} |
|
|
$i = $_; |
|
|
last INSCOPE; |
|
|
} elsif ({ |
|
|
table => 1, caption => 1, td => 1, th => 1, |
|
|
button => 1, marquee => 1, object => 1, html => 1, |
|
|
}->{$node->[1]}) { |
|
|
last INSCOPE; |
|
|
} |
|
|
} # INSCOPE |
|
|
|
|
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
|
|
} |
|
|
|
|
|
splice @{$self->{open_elements}}, $i if defined $i; |
|
|
!!!next-token; |
|
|
return; |
|
|
} elsif ({ |
|
|
a => 1, |
|
|
b => 1, big => 1, em => 1, font => 1, i => 1, |
|
|
nobr => 1, s => 1, small => 1, strile => 1, |
|
|
strong => 1, tt => 1, u => 1, |
|
|
}->{$token->{tag_name}}) { |
|
|
$formatting_end_tag->($token->{tag_name}); |
|
|
return; |
|
|
} elsif ($token->{tag_name} eq 'br') { |
|
|
!!!parse-error (type => 'unmatched end tag:br'); |
|
|
|
|
|
## As if <br> |
|
|
$reconstruct_active_formatting_elements->($insert_to_current); |
|
|
|
|
|
my $el; |
|
|
!!!create-element ($el, 'br'); |
|
|
$insert->($el); |
|
|
|
|
|
## Ignore the token. |
|
|
!!!next-token; |
|
|
return; |
|
|
} 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}}) { |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
|
|
## Ignore the token |
|
|
!!!next-token; |
|
|
return; |
|
|
|
|
|
## ISSUE: Issue on HTML5 new elements in spec |
|
|
|
|
|
} else { |
|
|
## Step 1 |
|
|
my $node_i = -1; |
|
|
my $node = $self->{open_elements}->[$node_i]; |
|
|
|
|
|
## Step 2 |
|
|
S2: { |
|
|
if ($node->[1] eq $token->{tag_name}) { |
|
|
## Step 1 |
|
|
## generate implied end tags |
|
|
if ({ |
|
|
dd => 1, dt => 1, li => 1, p => 1, |
|
|
td => 1, th => 1, tr => 1, |
|
|
tbody => 1, tfoot=> 1, thead => 1, |
|
|
}->{$self->{open_elements}->[-1]->[1]}) { |
|
|
!!!back-token; |
|
|
$token = {type => 'end tag', |
|
|
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
|
|
return; |
|
|
} |
|
|
|
|
|
## Step 2 |
|
|
if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) { |
|
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
|
|
} |
|
|
|
|
|
## Step 3 |
|
|
splice @{$self->{open_elements}}, $node_i; |
|
|
|
|
|
!!!next-token; |
|
|
last S2; |
|
|
} else { |
|
|
## Step 3 |
|
|
if (not $formatting_category->{$node->[1]} and |
|
|
#not $phrasing_category->{$node->[1]} and |
|
|
($special_category->{$node->[1]} or |
|
|
$scoping_category->{$node->[1]})) { |
|
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
|
|
## Ignore the token |
|
|
!!!next-token; |
|
|
last S2; |
|
|
} |
|
|
} |
|
|
|
|
|
## Step 4 |
|
|
$node_i--; |
|
|
$node = $self->{open_elements}->[$node_i]; |
|
|
|
|
|
## Step 5; |
|
|
redo S2; |
|
|
} # S2 |
|
|
return; |
|
|
} |
|
|
} |
|
|
}; # $in_body |
|
2498 |
|
|
2499 |
B: { |
B: { |
2500 |
if ($token->{type} eq 'DOCTYPE') { |
if ($token->{type} eq 'DOCTYPE') { |
3262 |
} else { |
} else { |
3263 |
# |
# |
3264 |
} |
} |
3265 |
} else { |
} else { |
3266 |
# |
die "$0: $token->{type}: Unknown token type"; |
3267 |
} |
} |
3268 |
|
|
3269 |
$in_body->($insert_to_current); |
$insert = $insert_to_current; |
3270 |
redo B; |
# |
3271 |
} elsif ($self->{insertion_mode} eq 'in row' or |
} elsif ($self->{insertion_mode} eq 'in row' or |
3272 |
$self->{insertion_mode} eq 'in table body' or |
$self->{insertion_mode} eq 'in table body' or |
3273 |
$self->{insertion_mode} eq 'in table') { |
$self->{insertion_mode} eq 'in table') { |
3831 |
die "$0: $token->{type}: Unknown token type"; |
die "$0: $token->{type}: Unknown token type"; |
3832 |
} |
} |
3833 |
|
|
3834 |
!!!parse-error (type => 'in table:'.$token->{tag_name}); |
!!!parse-error (type => 'in table:'.$token->{tag_name}); |
3835 |
$in_body->($insert_to_foster); |
|
3836 |
redo B; |
$insert = $insert_to_foster; |
3837 |
|
# |
3838 |
} elsif ($self->{insertion_mode} eq 'in column group') { |
} elsif ($self->{insertion_mode} eq 'in column group') { |
3839 |
if ($token->{type} eq 'character') { |
if ($token->{type} eq 'character') { |
3840 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
4254 |
} else { |
} else { |
4255 |
die "$0: $self->{insertion_mode}: Unknown insertion mode"; |
die "$0: $self->{insertion_mode}: Unknown insertion mode"; |
4256 |
} |
} |
4257 |
|
|
4258 |
|
## "in body" insertion mode |
4259 |
|
my $in_body = sub { |
4260 |
|
if ($token->{type} eq 'start tag') { |
4261 |
|
if ($token->{tag_name} eq 'script') { |
4262 |
|
## NOTE: This is an "as if in head" code clone |
4263 |
|
$script_start_tag->($insert); |
4264 |
|
return; |
4265 |
|
} elsif ($token->{tag_name} eq 'style') { |
4266 |
|
## NOTE: This is an "as if in head" code clone |
4267 |
|
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert); |
4268 |
|
return; |
4269 |
|
} elsif ({ |
4270 |
|
base => 1, link => 1, |
4271 |
|
}->{$token->{tag_name}}) { |
4272 |
|
## NOTE: This is an "as if in head" code clone, only "-t" differs |
4273 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4274 |
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
4275 |
|
!!!next-token; |
4276 |
|
return; |
4277 |
|
} elsif ($token->{tag_name} eq 'meta') { |
4278 |
|
## NOTE: This is an "as if in head" code clone, only "-t" differs |
4279 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4280 |
|
pop @{$self->{open_elements}}; ## ISSUE: This step is missing in the spec. |
4281 |
|
|
4282 |
|
unless ($self->{confident}) { |
4283 |
|
my $charset; |
4284 |
|
if ($token->{attributes}->{charset}) { ## TODO: And if supported |
4285 |
|
$charset = $token->{attributes}->{charset}->{value}; |
4286 |
|
} |
4287 |
|
if ($token->{attributes}->{'http-equiv'}) { |
4288 |
|
## ISSUE: Algorithm name in the spec was incorrect so that not linked to the definition. |
4289 |
|
if ($token->{attributes}->{'http-equiv'}->{value} |
4290 |
|
=~ /\A[^;]*;[\x09-\x0D\x20]*charset[\x09-\x0D\x20]*= |
4291 |
|
[\x09-\x0D\x20]*(?>"([^"]*)"|'([^']*)'| |
4292 |
|
([^"'\x09-\x0D\x20][^\x09-\x0D\x20]*))/x) { |
4293 |
|
$charset = defined $1 ? $1 : defined $2 ? $2 : $3; |
4294 |
|
} ## TODO: And if supported |
4295 |
|
} |
4296 |
|
## TODO: Change the encoding |
4297 |
|
} |
4298 |
|
|
4299 |
|
!!!next-token; |
4300 |
|
return; |
4301 |
|
} elsif ($token->{tag_name} eq 'title') { |
4302 |
|
!!!parse-error (type => 'in body:title'); |
4303 |
|
## NOTE: This is an "as if in head" code clone |
4304 |
|
$parse_rcdata->(RCDATA_CONTENT_MODEL, sub { |
4305 |
|
if (defined $self->{head_element}) { |
4306 |
|
$self->{head_element}->append_child ($_[0]); |
4307 |
|
} else { |
4308 |
|
$insert->($_[0]); |
4309 |
|
} |
4310 |
|
}); |
4311 |
|
return; |
4312 |
|
} elsif ($token->{tag_name} eq 'body') { |
4313 |
|
!!!parse-error (type => 'in body:body'); |
4314 |
|
|
4315 |
|
if (@{$self->{open_elements}} == 1 or |
4316 |
|
$self->{open_elements}->[1]->[1] ne 'body') { |
4317 |
|
## Ignore the token |
4318 |
|
} else { |
4319 |
|
my $body_el = $self->{open_elements}->[1]->[0]; |
4320 |
|
for my $attr_name (keys %{$token->{attributes}}) { |
4321 |
|
unless ($body_el->has_attribute_ns (undef, $attr_name)) { |
4322 |
|
$body_el->set_attribute_ns |
4323 |
|
(undef, [undef, $attr_name], |
4324 |
|
$token->{attributes}->{$attr_name}->{value}); |
4325 |
|
} |
4326 |
|
} |
4327 |
|
} |
4328 |
|
!!!next-token; |
4329 |
|
return; |
4330 |
|
} elsif ({ |
4331 |
|
address => 1, blockquote => 1, center => 1, dir => 1, |
4332 |
|
div => 1, dl => 1, fieldset => 1, listing => 1, |
4333 |
|
menu => 1, ol => 1, p => 1, ul => 1, |
4334 |
|
pre => 1, |
4335 |
|
}->{$token->{tag_name}}) { |
4336 |
|
## has a p element in scope |
4337 |
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4338 |
|
if ($_->[1] eq 'p') { |
4339 |
|
!!!back-token; |
4340 |
|
$token = {type => 'end tag', tag_name => 'p'}; |
4341 |
|
return; |
4342 |
|
} elsif ({ |
4343 |
|
table => 1, caption => 1, td => 1, th => 1, |
4344 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4345 |
|
}->{$_->[1]}) { |
4346 |
|
last INSCOPE; |
4347 |
|
} |
4348 |
|
} # INSCOPE |
4349 |
|
|
4350 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4351 |
|
if ($token->{tag_name} eq 'pre') { |
4352 |
|
!!!next-token; |
4353 |
|
if ($token->{type} eq 'character') { |
4354 |
|
$token->{data} =~ s/^\x0A//; |
4355 |
|
unless (length $token->{data}) { |
4356 |
|
!!!next-token; |
4357 |
|
} |
4358 |
|
} |
4359 |
|
} else { |
4360 |
|
!!!next-token; |
4361 |
|
} |
4362 |
|
return; |
4363 |
|
} elsif ($token->{tag_name} eq 'form') { |
4364 |
|
if (defined $self->{form_element}) { |
4365 |
|
!!!parse-error (type => 'in form:form'); |
4366 |
|
## Ignore the token |
4367 |
|
!!!next-token; |
4368 |
|
return; |
4369 |
|
} else { |
4370 |
|
## has a p element in scope |
4371 |
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4372 |
|
if ($_->[1] eq 'p') { |
4373 |
|
!!!back-token; |
4374 |
|
$token = {type => 'end tag', tag_name => 'p'}; |
4375 |
|
return; |
4376 |
|
} elsif ({ |
4377 |
|
table => 1, caption => 1, td => 1, th => 1, |
4378 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4379 |
|
}->{$_->[1]}) { |
4380 |
|
last INSCOPE; |
4381 |
|
} |
4382 |
|
} # INSCOPE |
4383 |
|
|
4384 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4385 |
|
$self->{form_element} = $self->{open_elements}->[-1]->[0]; |
4386 |
|
!!!next-token; |
4387 |
|
return; |
4388 |
|
} |
4389 |
|
} elsif ($token->{tag_name} eq 'li') { |
4390 |
|
## has a p element in scope |
4391 |
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4392 |
|
if ($_->[1] eq 'p') { |
4393 |
|
!!!back-token; |
4394 |
|
$token = {type => 'end tag', tag_name => 'p'}; |
4395 |
|
return; |
4396 |
|
} elsif ({ |
4397 |
|
table => 1, caption => 1, td => 1, th => 1, |
4398 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4399 |
|
}->{$_->[1]}) { |
4400 |
|
last INSCOPE; |
4401 |
|
} |
4402 |
|
} # INSCOPE |
4403 |
|
|
4404 |
|
## Step 1 |
4405 |
|
my $i = -1; |
4406 |
|
my $node = $self->{open_elements}->[$i]; |
4407 |
|
LI: { |
4408 |
|
## Step 2 |
4409 |
|
if ($node->[1] eq 'li') { |
4410 |
|
if ($i != -1) { |
4411 |
|
!!!parse-error (type => 'end tag missing:'. |
4412 |
|
$self->{open_elements}->[-1]->[1]); |
4413 |
|
} |
4414 |
|
splice @{$self->{open_elements}}, $i; |
4415 |
|
last LI; |
4416 |
|
} |
4417 |
|
|
4418 |
|
## Step 3 |
4419 |
|
if (not $formatting_category->{$node->[1]} and |
4420 |
|
#not $phrasing_category->{$node->[1]} and |
4421 |
|
($special_category->{$node->[1]} or |
4422 |
|
$scoping_category->{$node->[1]}) and |
4423 |
|
$node->[1] ne 'address' and $node->[1] ne 'div') { |
4424 |
|
last LI; |
4425 |
|
} |
4426 |
|
|
4427 |
|
## Step 4 |
4428 |
|
$i--; |
4429 |
|
$node = $self->{open_elements}->[$i]; |
4430 |
|
redo LI; |
4431 |
|
} # LI |
4432 |
|
|
4433 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4434 |
|
!!!next-token; |
4435 |
|
return; |
4436 |
|
} elsif ($token->{tag_name} eq 'dd' or $token->{tag_name} eq 'dt') { |
4437 |
|
## has a p element in scope |
4438 |
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4439 |
|
if ($_->[1] eq 'p') { |
4440 |
|
!!!back-token; |
4441 |
|
$token = {type => 'end tag', tag_name => 'p'}; |
4442 |
|
return; |
4443 |
|
} elsif ({ |
4444 |
|
table => 1, caption => 1, td => 1, th => 1, |
4445 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4446 |
|
}->{$_->[1]}) { |
4447 |
|
last INSCOPE; |
4448 |
|
} |
4449 |
|
} # INSCOPE |
4450 |
|
|
4451 |
|
## Step 1 |
4452 |
|
my $i = -1; |
4453 |
|
my $node = $self->{open_elements}->[$i]; |
4454 |
|
LI: { |
4455 |
|
## Step 2 |
4456 |
|
if ($node->[1] eq 'dt' or $node->[1] eq 'dd') { |
4457 |
|
if ($i != -1) { |
4458 |
|
!!!parse-error (type => 'end tag missing:'. |
4459 |
|
$self->{open_elements}->[-1]->[1]); |
4460 |
|
} |
4461 |
|
splice @{$self->{open_elements}}, $i; |
4462 |
|
last LI; |
4463 |
|
} |
4464 |
|
|
4465 |
|
## Step 3 |
4466 |
|
if (not $formatting_category->{$node->[1]} and |
4467 |
|
#not $phrasing_category->{$node->[1]} and |
4468 |
|
($special_category->{$node->[1]} or |
4469 |
|
$scoping_category->{$node->[1]}) and |
4470 |
|
$node->[1] ne 'address' and $node->[1] ne 'div') { |
4471 |
|
last LI; |
4472 |
|
} |
4473 |
|
|
4474 |
|
## Step 4 |
4475 |
|
$i--; |
4476 |
|
$node = $self->{open_elements}->[$i]; |
4477 |
|
redo LI; |
4478 |
|
} # LI |
4479 |
|
|
4480 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4481 |
|
!!!next-token; |
4482 |
|
return; |
4483 |
|
} elsif ($token->{tag_name} eq 'plaintext') { |
4484 |
|
## has a p element in scope |
4485 |
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4486 |
|
if ($_->[1] eq 'p') { |
4487 |
|
!!!back-token; |
4488 |
|
$token = {type => 'end tag', tag_name => 'p'}; |
4489 |
|
return; |
4490 |
|
} elsif ({ |
4491 |
|
table => 1, caption => 1, td => 1, th => 1, |
4492 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4493 |
|
}->{$_->[1]}) { |
4494 |
|
last INSCOPE; |
4495 |
|
} |
4496 |
|
} # INSCOPE |
4497 |
|
|
4498 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4499 |
|
|
4500 |
|
$self->{content_model} = PLAINTEXT_CONTENT_MODEL; |
4501 |
|
|
4502 |
|
!!!next-token; |
4503 |
|
return; |
4504 |
|
} elsif ({ |
4505 |
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
4506 |
|
}->{$token->{tag_name}}) { |
4507 |
|
## has a p element in scope |
4508 |
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4509 |
|
my $node = $self->{open_elements}->[$_]; |
4510 |
|
if ($node->[1] eq 'p') { |
4511 |
|
!!!back-token; |
4512 |
|
$token = {type => 'end tag', tag_name => 'p'}; |
4513 |
|
return; |
4514 |
|
} elsif ({ |
4515 |
|
table => 1, caption => 1, td => 1, th => 1, |
4516 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4517 |
|
}->{$node->[1]}) { |
4518 |
|
last INSCOPE; |
4519 |
|
} |
4520 |
|
} # INSCOPE |
4521 |
|
|
4522 |
|
## NOTE: See <http://html5.org/tools/web-apps-tracker?from=925&to=926> |
4523 |
|
## has an element in scope |
4524 |
|
#my $i; |
4525 |
|
#INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4526 |
|
# my $node = $self->{open_elements}->[$_]; |
4527 |
|
# if ({ |
4528 |
|
# h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
4529 |
|
# }->{$node->[1]}) { |
4530 |
|
# $i = $_; |
4531 |
|
# last INSCOPE; |
4532 |
|
# } elsif ({ |
4533 |
|
# table => 1, caption => 1, td => 1, th => 1, |
4534 |
|
# button => 1, marquee => 1, object => 1, html => 1, |
4535 |
|
# }->{$node->[1]}) { |
4536 |
|
# last INSCOPE; |
4537 |
|
# } |
4538 |
|
#} # INSCOPE |
4539 |
|
# |
4540 |
|
#if (defined $i) { |
4541 |
|
# !!! parse-error (type => 'in hn:hn'); |
4542 |
|
# splice @{$self->{open_elements}}, $i; |
4543 |
|
#} |
4544 |
|
|
4545 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4546 |
|
|
4547 |
|
!!!next-token; |
4548 |
|
return; |
4549 |
|
} elsif ($token->{tag_name} eq 'a') { |
4550 |
|
AFE: for my $i (reverse 0..$#$active_formatting_elements) { |
4551 |
|
my $node = $active_formatting_elements->[$i]; |
4552 |
|
if ($node->[1] eq 'a') { |
4553 |
|
!!!parse-error (type => 'in a:a'); |
4554 |
|
|
4555 |
|
!!!back-token; |
4556 |
|
$token = {type => 'end tag', tag_name => 'a'}; |
4557 |
|
$formatting_end_tag->($token->{tag_name}); |
4558 |
|
|
4559 |
|
AFE2: for (reverse 0..$#$active_formatting_elements) { |
4560 |
|
if ($active_formatting_elements->[$_]->[0] eq $node->[0]) { |
4561 |
|
splice @$active_formatting_elements, $_, 1; |
4562 |
|
last AFE2; |
4563 |
|
} |
4564 |
|
} # AFE2 |
4565 |
|
OE: for (reverse 0..$#{$self->{open_elements}}) { |
4566 |
|
if ($self->{open_elements}->[$_]->[0] eq $node->[0]) { |
4567 |
|
splice @{$self->{open_elements}}, $_, 1; |
4568 |
|
last OE; |
4569 |
|
} |
4570 |
|
} # OE |
4571 |
|
last AFE; |
4572 |
|
} elsif ($node->[0] eq '#marker') { |
4573 |
|
last AFE; |
4574 |
|
} |
4575 |
|
} # AFE |
4576 |
|
|
4577 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4578 |
|
|
4579 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4580 |
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
4581 |
|
|
4582 |
|
!!!next-token; |
4583 |
|
return; |
4584 |
|
} elsif ({ |
4585 |
|
b => 1, big => 1, em => 1, font => 1, i => 1, |
4586 |
|
s => 1, small => 1, strile => 1, |
4587 |
|
strong => 1, tt => 1, u => 1, |
4588 |
|
}->{$token->{tag_name}}) { |
4589 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4590 |
|
|
4591 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4592 |
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
4593 |
|
|
4594 |
|
!!!next-token; |
4595 |
|
return; |
4596 |
|
} elsif ($token->{tag_name} eq 'nobr') { |
4597 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4598 |
|
|
4599 |
|
## has a |nobr| element in scope |
4600 |
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4601 |
|
my $node = $self->{open_elements}->[$_]; |
4602 |
|
if ($node->[1] eq 'nobr') { |
4603 |
|
!!!parse-error (type => 'not closed:nobr'); |
4604 |
|
!!!back-token; |
4605 |
|
$token = {type => 'end tag', tag_name => 'nobr'}; |
4606 |
|
return; |
4607 |
|
} elsif ({ |
4608 |
|
table => 1, caption => 1, td => 1, th => 1, |
4609 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4610 |
|
}->{$node->[1]}) { |
4611 |
|
last INSCOPE; |
4612 |
|
} |
4613 |
|
} # INSCOPE |
4614 |
|
|
4615 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4616 |
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
4617 |
|
|
4618 |
|
!!!next-token; |
4619 |
|
return; |
4620 |
|
} elsif ($token->{tag_name} eq 'button') { |
4621 |
|
## has a button element in scope |
4622 |
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4623 |
|
my $node = $self->{open_elements}->[$_]; |
4624 |
|
if ($node->[1] eq 'button') { |
4625 |
|
!!!parse-error (type => 'in button:button'); |
4626 |
|
!!!back-token; |
4627 |
|
$token = {type => 'end tag', tag_name => 'button'}; |
4628 |
|
return; |
4629 |
|
} elsif ({ |
4630 |
|
table => 1, caption => 1, td => 1, th => 1, |
4631 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4632 |
|
}->{$node->[1]}) { |
4633 |
|
last INSCOPE; |
4634 |
|
} |
4635 |
|
} # INSCOPE |
4636 |
|
|
4637 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4638 |
|
|
4639 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4640 |
|
push @$active_formatting_elements, ['#marker', '']; |
4641 |
|
|
4642 |
|
!!!next-token; |
4643 |
|
return; |
4644 |
|
} elsif ($token->{tag_name} eq 'marquee' or |
4645 |
|
$token->{tag_name} eq 'object') { |
4646 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4647 |
|
|
4648 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4649 |
|
push @$active_formatting_elements, ['#marker', '']; |
4650 |
|
|
4651 |
|
!!!next-token; |
4652 |
|
return; |
4653 |
|
} elsif ($token->{tag_name} eq 'xmp') { |
4654 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4655 |
|
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert); |
4656 |
|
return; |
4657 |
|
} elsif ($token->{tag_name} eq 'table') { |
4658 |
|
## has a p element in scope |
4659 |
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4660 |
|
if ($_->[1] eq 'p') { |
4661 |
|
!!!back-token; |
4662 |
|
$token = {type => 'end tag', tag_name => 'p'}; |
4663 |
|
return; |
4664 |
|
} elsif ({ |
4665 |
|
table => 1, caption => 1, td => 1, th => 1, |
4666 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4667 |
|
}->{$_->[1]}) { |
4668 |
|
last INSCOPE; |
4669 |
|
} |
4670 |
|
} # INSCOPE |
4671 |
|
|
4672 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4673 |
|
|
4674 |
|
$self->{insertion_mode} = 'in table'; |
4675 |
|
|
4676 |
|
!!!next-token; |
4677 |
|
return; |
4678 |
|
} elsif ({ |
4679 |
|
area => 1, basefont => 1, bgsound => 1, br => 1, |
4680 |
|
embed => 1, img => 1, param => 1, spacer => 1, wbr => 1, |
4681 |
|
image => 1, |
4682 |
|
}->{$token->{tag_name}}) { |
4683 |
|
if ($token->{tag_name} eq 'image') { |
4684 |
|
!!!parse-error (type => 'image'); |
4685 |
|
$token->{tag_name} = 'img'; |
4686 |
|
} |
4687 |
|
|
4688 |
|
## NOTE: There is an "as if <br>" code clone. |
4689 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4690 |
|
|
4691 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4692 |
|
pop @{$self->{open_elements}}; |
4693 |
|
|
4694 |
|
!!!next-token; |
4695 |
|
return; |
4696 |
|
} elsif ($token->{tag_name} eq 'hr') { |
4697 |
|
## has a p element in scope |
4698 |
|
INSCOPE: for (reverse @{$self->{open_elements}}) { |
4699 |
|
if ($_->[1] eq 'p') { |
4700 |
|
!!!back-token; |
4701 |
|
$token = {type => 'end tag', tag_name => 'p'}; |
4702 |
|
return; |
4703 |
|
} elsif ({ |
4704 |
|
table => 1, caption => 1, td => 1, th => 1, |
4705 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4706 |
|
}->{$_->[1]}) { |
4707 |
|
last INSCOPE; |
4708 |
|
} |
4709 |
|
} # INSCOPE |
4710 |
|
|
4711 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4712 |
|
pop @{$self->{open_elements}}; |
4713 |
|
|
4714 |
|
!!!next-token; |
4715 |
|
return; |
4716 |
|
} elsif ($token->{tag_name} eq 'input') { |
4717 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4718 |
|
|
4719 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4720 |
|
## TODO: associate with $self->{form_element} if defined |
4721 |
|
pop @{$self->{open_elements}}; |
4722 |
|
|
4723 |
|
!!!next-token; |
4724 |
|
return; |
4725 |
|
} elsif ($token->{tag_name} eq 'isindex') { |
4726 |
|
!!!parse-error (type => 'isindex'); |
4727 |
|
|
4728 |
|
if (defined $self->{form_element}) { |
4729 |
|
## Ignore the token |
4730 |
|
!!!next-token; |
4731 |
|
return; |
4732 |
|
} else { |
4733 |
|
my $at = $token->{attributes}; |
4734 |
|
my $form_attrs; |
4735 |
|
$form_attrs->{action} = $at->{action} if $at->{action}; |
4736 |
|
my $prompt_attr = $at->{prompt}; |
4737 |
|
$at->{name} = {name => 'name', value => 'isindex'}; |
4738 |
|
delete $at->{action}; |
4739 |
|
delete $at->{prompt}; |
4740 |
|
my @tokens = ( |
4741 |
|
{type => 'start tag', tag_name => 'form', |
4742 |
|
attributes => $form_attrs}, |
4743 |
|
{type => 'start tag', tag_name => 'hr'}, |
4744 |
|
{type => 'start tag', tag_name => 'p'}, |
4745 |
|
{type => 'start tag', tag_name => 'label'}, |
4746 |
|
); |
4747 |
|
if ($prompt_attr) { |
4748 |
|
push @tokens, {type => 'character', data => $prompt_attr->{value}}; |
4749 |
|
} else { |
4750 |
|
push @tokens, {type => 'character', |
4751 |
|
data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD |
4752 |
|
## TODO: make this configurable |
4753 |
|
} |
4754 |
|
push @tokens, |
4755 |
|
{type => 'start tag', tag_name => 'input', attributes => $at}, |
4756 |
|
#{type => 'character', data => ''}, # SHOULD |
4757 |
|
{type => 'end tag', tag_name => 'label'}, |
4758 |
|
{type => 'end tag', tag_name => 'p'}, |
4759 |
|
{type => 'start tag', tag_name => 'hr'}, |
4760 |
|
{type => 'end tag', tag_name => 'form'}; |
4761 |
|
$token = shift @tokens; |
4762 |
|
!!!back-token (@tokens); |
4763 |
|
return; |
4764 |
|
} |
4765 |
|
} elsif ($token->{tag_name} eq 'textarea') { |
4766 |
|
my $tag_name = $token->{tag_name}; |
4767 |
|
my $el; |
4768 |
|
!!!create-element ($el, $token->{tag_name}, $token->{attributes}); |
4769 |
|
|
4770 |
|
## TODO: $self->{form_element} if defined |
4771 |
|
$self->{content_model} = RCDATA_CONTENT_MODEL; |
4772 |
|
delete $self->{escape}; # MUST |
4773 |
|
|
4774 |
|
$insert->($el); |
4775 |
|
|
4776 |
|
my $text = ''; |
4777 |
|
!!!next-token; |
4778 |
|
if ($token->{type} eq 'character') { |
4779 |
|
$token->{data} =~ s/^\x0A//; |
4780 |
|
unless (length $token->{data}) { |
4781 |
|
!!!next-token; |
4782 |
|
} |
4783 |
|
} |
4784 |
|
while ($token->{type} eq 'character') { |
4785 |
|
$text .= $token->{data}; |
4786 |
|
!!!next-token; |
4787 |
|
} |
4788 |
|
if (length $text) { |
4789 |
|
$el->manakai_append_text ($text); |
4790 |
|
} |
4791 |
|
|
4792 |
|
$self->{content_model} = PCDATA_CONTENT_MODEL; |
4793 |
|
|
4794 |
|
if ($token->{type} eq 'end tag' and |
4795 |
|
$token->{tag_name} eq $tag_name) { |
4796 |
|
## Ignore the token |
4797 |
|
} else { |
4798 |
|
!!!parse-error (type => 'in RCDATA:#'.$token->{type}); |
4799 |
|
} |
4800 |
|
!!!next-token; |
4801 |
|
return; |
4802 |
|
} elsif ({ |
4803 |
|
iframe => 1, |
4804 |
|
noembed => 1, |
4805 |
|
noframes => 1, |
4806 |
|
noscript => 0, ## TODO: 1 if scripting is enabled |
4807 |
|
}->{$token->{tag_name}}) { |
4808 |
|
## NOTE: There are two "as if in body" code clones. |
4809 |
|
$parse_rcdata->(CDATA_CONTENT_MODEL, $insert); |
4810 |
|
return; |
4811 |
|
} elsif ($token->{tag_name} eq 'select') { |
4812 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4813 |
|
|
4814 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4815 |
|
|
4816 |
|
$self->{insertion_mode} = 'in select'; |
4817 |
|
!!!next-token; |
4818 |
|
return; |
4819 |
|
} elsif ({ |
4820 |
|
caption => 1, col => 1, colgroup => 1, frame => 1, |
4821 |
|
frameset => 1, head => 1, option => 1, optgroup => 1, |
4822 |
|
tbody => 1, td => 1, tfoot => 1, th => 1, |
4823 |
|
thead => 1, tr => 1, |
4824 |
|
}->{$token->{tag_name}}) { |
4825 |
|
!!!parse-error (type => 'in body:'.$token->{tag_name}); |
4826 |
|
## Ignore the token |
4827 |
|
!!!next-token; |
4828 |
|
return; |
4829 |
|
|
4830 |
|
## ISSUE: An issue on HTML5 new elements in the spec. |
4831 |
|
} else { |
4832 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
4833 |
|
|
4834 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
4835 |
|
|
4836 |
|
!!!next-token; |
4837 |
|
return; |
4838 |
|
} |
4839 |
|
} elsif ($token->{type} eq 'end tag') { |
4840 |
|
if ($token->{tag_name} eq 'body') { |
4841 |
|
if (@{$self->{open_elements}} > 1 and |
4842 |
|
$self->{open_elements}->[1]->[1] eq 'body') { |
4843 |
|
for (@{$self->{open_elements}}) { |
4844 |
|
unless ({ |
4845 |
|
dd => 1, dt => 1, li => 1, p => 1, td => 1, |
4846 |
|
th => 1, tr => 1, body => 1, html => 1, |
4847 |
|
tbody => 1, tfoot => 1, thead => 1, |
4848 |
|
}->{$_->[1]}) { |
4849 |
|
!!!parse-error (type => 'not closed:'.$_->[1]); |
4850 |
|
} |
4851 |
|
} |
4852 |
|
|
4853 |
|
$self->{insertion_mode} = 'after body'; |
4854 |
|
!!!next-token; |
4855 |
|
return; |
4856 |
|
} else { |
4857 |
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4858 |
|
## Ignore the token |
4859 |
|
!!!next-token; |
4860 |
|
return; |
4861 |
|
} |
4862 |
|
} elsif ($token->{tag_name} eq 'html') { |
4863 |
|
if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') { |
4864 |
|
## ISSUE: There is an issue in the spec. |
4865 |
|
if ($self->{open_elements}->[-1]->[1] ne 'body') { |
4866 |
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[1]->[1]); |
4867 |
|
} |
4868 |
|
$self->{insertion_mode} = 'after body'; |
4869 |
|
## reprocess |
4870 |
|
return; |
4871 |
|
} else { |
4872 |
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4873 |
|
## Ignore the token |
4874 |
|
!!!next-token; |
4875 |
|
return; |
4876 |
|
} |
4877 |
|
} elsif ({ |
4878 |
|
address => 1, blockquote => 1, center => 1, dir => 1, |
4879 |
|
div => 1, dl => 1, fieldset => 1, listing => 1, |
4880 |
|
menu => 1, ol => 1, pre => 1, ul => 1, |
4881 |
|
p => 1, |
4882 |
|
dd => 1, dt => 1, li => 1, |
4883 |
|
button => 1, marquee => 1, object => 1, |
4884 |
|
}->{$token->{tag_name}}) { |
4885 |
|
## has an element in scope |
4886 |
|
my $i; |
4887 |
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4888 |
|
my $node = $self->{open_elements}->[$_]; |
4889 |
|
if ($node->[1] eq $token->{tag_name}) { |
4890 |
|
## generate implied end tags |
4891 |
|
if ({ |
4892 |
|
dd => ($token->{tag_name} ne 'dd'), |
4893 |
|
dt => ($token->{tag_name} ne 'dt'), |
4894 |
|
li => ($token->{tag_name} ne 'li'), |
4895 |
|
p => ($token->{tag_name} ne 'p'), |
4896 |
|
td => 1, th => 1, tr => 1, |
4897 |
|
tbody => 1, tfoot=> 1, thead => 1, |
4898 |
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4899 |
|
!!!back-token; |
4900 |
|
$token = {type => 'end tag', |
4901 |
|
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
4902 |
|
return; |
4903 |
|
} |
4904 |
|
$i = $_; |
4905 |
|
last INSCOPE unless $token->{tag_name} eq 'p'; |
4906 |
|
} elsif ({ |
4907 |
|
table => 1, caption => 1, td => 1, th => 1, |
4908 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4909 |
|
}->{$node->[1]}) { |
4910 |
|
last INSCOPE; |
4911 |
|
} |
4912 |
|
} # INSCOPE |
4913 |
|
|
4914 |
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
4915 |
|
if (defined $i) { |
4916 |
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
4917 |
|
} else { |
4918 |
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
4919 |
|
} |
4920 |
|
} |
4921 |
|
|
4922 |
|
if (defined $i) { |
4923 |
|
splice @{$self->{open_elements}}, $i; |
4924 |
|
} elsif ($token->{tag_name} eq 'p') { |
4925 |
|
## As if <p>, then reprocess the current token |
4926 |
|
my $el; |
4927 |
|
!!!create-element ($el, 'p'); |
4928 |
|
$insert->($el); |
4929 |
|
} |
4930 |
|
$clear_up_to_marker->() |
4931 |
|
if { |
4932 |
|
button => 1, marquee => 1, object => 1, |
4933 |
|
}->{$token->{tag_name}}; |
4934 |
|
!!!next-token; |
4935 |
|
return; |
4936 |
|
} elsif ($token->{tag_name} eq 'form') { |
4937 |
|
## has an element in scope |
4938 |
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4939 |
|
my $node = $self->{open_elements}->[$_]; |
4940 |
|
if ($node->[1] eq $token->{tag_name}) { |
4941 |
|
## generate implied end tags |
4942 |
|
if ({ |
4943 |
|
dd => 1, dt => 1, li => 1, p => 1, |
4944 |
|
td => 1, th => 1, tr => 1, |
4945 |
|
tbody => 1, tfoot=> 1, thead => 1, |
4946 |
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4947 |
|
!!!back-token; |
4948 |
|
$token = {type => 'end tag', |
4949 |
|
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
4950 |
|
return; |
4951 |
|
} |
4952 |
|
last INSCOPE; |
4953 |
|
} elsif ({ |
4954 |
|
table => 1, caption => 1, td => 1, th => 1, |
4955 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4956 |
|
}->{$node->[1]}) { |
4957 |
|
last INSCOPE; |
4958 |
|
} |
4959 |
|
} # INSCOPE |
4960 |
|
|
4961 |
|
if ($self->{open_elements}->[-1]->[1] eq $token->{tag_name}) { |
4962 |
|
pop @{$self->{open_elements}}; |
4963 |
|
} else { |
4964 |
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
4965 |
|
} |
4966 |
|
|
4967 |
|
undef $self->{form_element}; |
4968 |
|
!!!next-token; |
4969 |
|
return; |
4970 |
|
} elsif ({ |
4971 |
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
4972 |
|
}->{$token->{tag_name}}) { |
4973 |
|
## has an element in scope |
4974 |
|
my $i; |
4975 |
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
4976 |
|
my $node = $self->{open_elements}->[$_]; |
4977 |
|
if ({ |
4978 |
|
h1 => 1, h2 => 1, h3 => 1, h4 => 1, h5 => 1, h6 => 1, |
4979 |
|
}->{$node->[1]}) { |
4980 |
|
## generate implied end tags |
4981 |
|
if ({ |
4982 |
|
dd => 1, dt => 1, li => 1, p => 1, |
4983 |
|
td => 1, th => 1, tr => 1, |
4984 |
|
tbody => 1, tfoot=> 1, thead => 1, |
4985 |
|
}->{$self->{open_elements}->[-1]->[1]}) { |
4986 |
|
!!!back-token; |
4987 |
|
$token = {type => 'end tag', |
4988 |
|
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
4989 |
|
return; |
4990 |
|
} |
4991 |
|
$i = $_; |
4992 |
|
last INSCOPE; |
4993 |
|
} elsif ({ |
4994 |
|
table => 1, caption => 1, td => 1, th => 1, |
4995 |
|
button => 1, marquee => 1, object => 1, html => 1, |
4996 |
|
}->{$node->[1]}) { |
4997 |
|
last INSCOPE; |
4998 |
|
} |
4999 |
|
} # INSCOPE |
5000 |
|
|
5001 |
|
if ($self->{open_elements}->[-1]->[1] ne $token->{tag_name}) { |
5002 |
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
5003 |
|
} |
5004 |
|
|
5005 |
|
splice @{$self->{open_elements}}, $i if defined $i; |
5006 |
|
!!!next-token; |
5007 |
|
return; |
5008 |
|
} elsif ({ |
5009 |
|
a => 1, |
5010 |
|
b => 1, big => 1, em => 1, font => 1, i => 1, |
5011 |
|
nobr => 1, s => 1, small => 1, strile => 1, |
5012 |
|
strong => 1, tt => 1, u => 1, |
5013 |
|
}->{$token->{tag_name}}) { |
5014 |
|
$formatting_end_tag->($token->{tag_name}); |
5015 |
|
return; |
5016 |
|
} elsif ($token->{tag_name} eq 'br') { |
5017 |
|
!!!parse-error (type => 'unmatched end tag:br'); |
5018 |
|
|
5019 |
|
## As if <br> |
5020 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
5021 |
|
|
5022 |
|
my $el; |
5023 |
|
!!!create-element ($el, 'br'); |
5024 |
|
$insert->($el); |
5025 |
|
|
5026 |
|
## Ignore the token. |
5027 |
|
!!!next-token; |
5028 |
|
return; |
5029 |
|
} elsif ({ |
5030 |
|
caption => 1, col => 1, colgroup => 1, frame => 1, |
5031 |
|
frameset => 1, head => 1, option => 1, optgroup => 1, |
5032 |
|
tbody => 1, td => 1, tfoot => 1, th => 1, |
5033 |
|
thead => 1, tr => 1, |
5034 |
|
area => 1, basefont => 1, bgsound => 1, |
5035 |
|
embed => 1, hr => 1, iframe => 1, image => 1, |
5036 |
|
img => 1, input => 1, isindex => 1, noembed => 1, |
5037 |
|
noframes => 1, param => 1, select => 1, spacer => 1, |
5038 |
|
table => 1, textarea => 1, wbr => 1, |
5039 |
|
noscript => 0, ## TODO: if scripting is enabled |
5040 |
|
}->{$token->{tag_name}}) { |
5041 |
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
5042 |
|
## Ignore the token |
5043 |
|
!!!next-token; |
5044 |
|
return; |
5045 |
|
|
5046 |
|
## ISSUE: Issue on HTML5 new elements in spec |
5047 |
|
|
5048 |
|
} else { |
5049 |
|
## Step 1 |
5050 |
|
my $node_i = -1; |
5051 |
|
my $node = $self->{open_elements}->[$node_i]; |
5052 |
|
|
5053 |
|
## Step 2 |
5054 |
|
S2: { |
5055 |
|
if ($node->[1] eq $token->{tag_name}) { |
5056 |
|
## Step 1 |
5057 |
|
## generate implied end tags |
5058 |
|
if ({ |
5059 |
|
dd => 1, dt => 1, li => 1, p => 1, |
5060 |
|
td => 1, th => 1, tr => 1, |
5061 |
|
tbody => 1, tfoot=> 1, thead => 1, |
5062 |
|
}->{$self->{open_elements}->[-1]->[1]}) { |
5063 |
|
!!!back-token; |
5064 |
|
$token = {type => 'end tag', |
5065 |
|
tag_name => $self->{open_elements}->[-1]->[1]}; # MUST |
5066 |
|
return; |
5067 |
|
} |
5068 |
|
|
5069 |
|
## Step 2 |
5070 |
|
if ($token->{tag_name} ne $self->{open_elements}->[-1]->[1]) { |
5071 |
|
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
5072 |
|
} |
5073 |
|
|
5074 |
|
## Step 3 |
5075 |
|
splice @{$self->{open_elements}}, $node_i; |
5076 |
|
|
5077 |
|
!!!next-token; |
5078 |
|
last S2; |
5079 |
|
} else { |
5080 |
|
## Step 3 |
5081 |
|
if (not $formatting_category->{$node->[1]} and |
5082 |
|
#not $phrasing_category->{$node->[1]} and |
5083 |
|
($special_category->{$node->[1]} or |
5084 |
|
$scoping_category->{$node->[1]})) { |
5085 |
|
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
5086 |
|
## Ignore the token |
5087 |
|
!!!next-token; |
5088 |
|
last S2; |
5089 |
|
} |
5090 |
|
} |
5091 |
|
|
5092 |
|
## Step 4 |
5093 |
|
$node_i--; |
5094 |
|
$node = $self->{open_elements}->[$node_i]; |
5095 |
|
|
5096 |
|
## Step 5; |
5097 |
|
redo S2; |
5098 |
|
} # S2 |
5099 |
|
return; |
5100 |
|
} |
5101 |
|
} |
5102 |
|
}; # $in_body |
5103 |
|
$in_body->($insert_to_current); |
5104 |
|
redo B; |
5105 |
} # B |
} # B |
5106 |
|
|
5107 |
## NOTE: The "trailing end" phase in HTML5 is split into |
## NOTE: The "trailing end" phase in HTML5 is split into |