| 911 |
|
|
| 912 |
INITIAL: { |
INITIAL: { |
| 913 |
if ($token->{type} == DOCTYPE_TOKEN) { |
if ($token->{type} == DOCTYPE_TOKEN) { |
| 914 |
## NOTE: Conformance checkers MAY, instead of reporting "not HTML5" |
## NOTE: Conformance checkers MAY, instead of reporting "not |
| 915 |
## error, switch to a conformance checking mode for another |
## HTML5" error, switch to a conformance checking mode for |
| 916 |
## language. |
## another language. (We don't support such mode switchings; it |
| 917 |
|
## is nonsense to do anything different from what browsers do.) |
| 918 |
my $doctype_name = $token->{name}; |
my $doctype_name = $token->{name}; |
| 919 |
$doctype_name = '' unless defined $doctype_name; |
$doctype_name = '' unless defined $doctype_name; |
| 920 |
$doctype_name =~ tr/a-z/A-Z/; # ASCII case-insensitive |
my $doctype = $self->{document}->create_document_type_definition |
| 921 |
if (not defined $token->{name} or # <!DOCTYPE> |
($doctype_name); |
| 922 |
defined $token->{sysid}) { |
|
| 923 |
|
$doctype_name =~ tr/A-Z/a-z/; # ASCII case-insensitive |
| 924 |
|
if ($doctype_name ne 'html') { |
| 925 |
!!!cp ('t1'); |
!!!cp ('t1'); |
| 926 |
!!!parse-error (type => 'not HTML5', token => $token); |
!!!parse-error (type => 'not HTML5', token => $token); |
| 927 |
} elsif ($doctype_name ne 'HTML') { |
} elsif (defined $token->{pubid}) { |
| 928 |
!!!cp ('t2'); |
!!!cp ('t2'); |
| 929 |
|
## XXX Obsolete permitted DOCTYPEs |
| 930 |
!!!parse-error (type => 'not HTML5', token => $token); |
!!!parse-error (type => 'not HTML5', token => $token); |
| 931 |
} elsif (defined $token->{pubid}) { |
} elsif (defined $token->{sysid}) { |
| 932 |
if ($token->{pubid} eq 'XSLT-compat') { |
if ($token->{sysid} eq 'about:legacy-compat') { |
| 933 |
!!!cp ('t1.2'); |
!!!cp ('t1.2'); ## <!DOCTYPE HTML SYSTEM "about:legacy-compat"> |
| 934 |
!!!parse-error (type => 'XSLT-compat', token => $token, |
!!!parse-error (type => 'XSLT-compat', token => $token, |
| 935 |
level => $self->{level}->{should}); |
level => $self->{level}->{should}); |
| 936 |
} else { |
} else { |
| 937 |
!!!parse-error (type => 'not HTML5', token => $token); |
!!!parse-error (type => 'not HTML5', token => $token); |
| 938 |
} |
} |
| 939 |
} else { |
} else { ## <!DOCTYPE HTML> |
| 940 |
!!!cp ('t3'); |
!!!cp ('t3'); |
| 941 |
# |
# |
| 942 |
} |
} |
| 943 |
|
|
|
my $doctype = $self->{document}->create_document_type_definition |
|
|
($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)? |
|
| 944 |
## NOTE: Default value for both |public_id| and |system_id| attributes |
## NOTE: Default value for both |public_id| and |system_id| attributes |
| 945 |
## are empty strings, so that we don't set any value in missing cases. |
## are empty strings, so that we don't set any value in missing cases. |
| 946 |
$doctype->public_id ($token->{pubid}) if defined $token->{pubid}; |
$doctype->public_id ($token->{pubid}) if defined $token->{pubid}; |
| 947 |
$doctype->system_id ($token->{sysid}) if defined $token->{sysid}; |
$doctype->system_id ($token->{sysid}) if defined $token->{sysid}; |
| 948 |
|
|
| 949 |
## NOTE: Other DocumentType attributes are null or empty lists. |
## NOTE: Other DocumentType attributes are null or empty lists. |
| 950 |
## In Firefox3, |internalSubset| attribute is set to the empty |
## In Firefox3, |internalSubset| attribute is set to the empty |
| 951 |
## string, while |null| is an allowed value for the attribute |
## string, while |null| is an allowed value for the attribute |
| 952 |
## according to DOM3 Core. |
## according to DOM3 Core. |
| 953 |
$self->{document}->append_child ($doctype); |
$self->{document}->append_child ($doctype); |
| 954 |
|
|
| 955 |
if ($token->{quirks} or $doctype_name ne 'HTML') { |
if ($token->{quirks} or $doctype_name ne 'html') { |
| 956 |
!!!cp ('t4'); |
!!!cp ('t4'); |
| 957 |
$self->{document}->manakai_compat_mode ('quirks'); |
$self->{document}->manakai_compat_mode ('quirks'); |
| 958 |
} elsif (defined $token->{pubid}) { |
} elsif (defined $token->{pubid}) { |
| 1438 |
}; # $script_start_tag |
}; # $script_start_tag |
| 1439 |
|
|
| 1440 |
## NOTE: $open_tables->[-1]->[0] is the "current table" element node. |
## NOTE: $open_tables->[-1]->[0] is the "current table" element node. |
| 1441 |
## NOTE: $open_tables->[-1]->[1] is the "tainted" flag. |
## NOTE: $open_tables->[-1]->[1] is the "tainted" flag (OBSOLETE; unused). |
| 1442 |
## NOTE: $open_tables->[-1]->[2] is set false when non-Text node inserted. |
## NOTE: $open_tables->[-1]->[2] is set false when non-Text node inserted. |
| 1443 |
my $open_tables = [[$self->{open_elements}->[0]->[0]]]; |
my $open_tables = [[$self->{open_elements}->[0]->[0]]]; |
| 1444 |
|
|
| 2268 |
|
|
| 2269 |
## NOTE: There is a "as if in head" code clone. |
## NOTE: There is a "as if in head" code clone. |
| 2270 |
$parse_rcdata->(RCDATA_CONTENT_MODEL); |
$parse_rcdata->(RCDATA_CONTENT_MODEL); |
| 2271 |
## ISSUE: A spec bug [Bug 6038] |
|
| 2272 |
|
## NOTE: At this point the stack of open elements contain |
| 2273 |
|
## the |head| element (index == -2) and the |script| element |
| 2274 |
|
## (index == -1). In the "after head" insertion mode the |
| 2275 |
|
## |head| element is inserted only for the purpose of |
| 2276 |
|
## providing the context for the |script| element, and |
| 2277 |
|
## therefore we can now and have to remove the element from |
| 2278 |
|
## the stack. |
| 2279 |
splice @{$self->{open_elements}}, -2, 1, () # <head> |
splice @{$self->{open_elements}}, -2, 1, () # <head> |
| 2280 |
if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM; |
if ($self->{insertion_mode} & IM_MASK) == AFTER_HEAD_IM; |
| 2281 |
next B; |
next B; |
| 3021 |
$insert = $insert_to_current; |
$insert = $insert_to_current; |
| 3022 |
# |
# |
| 3023 |
} elsif ($self->{insertion_mode} & TABLE_IMS) { |
} elsif ($self->{insertion_mode} & TABLE_IMS) { |
| 3024 |
if ($token->{type} == CHARACTER_TOKEN) { |
C: { |
| 3025 |
if (not $open_tables->[-1]->[1] and # tainted |
my $s; |
| 3026 |
$token->{data} =~ s/^([\x09\x0A\x0C\x20]+)//) { |
if ($token->{type} == CHARACTER_TOKEN) { |
| 3027 |
$self->{open_elements}->[-1]->[0]->manakai_append_text ($1); |
!!!cp ('t194'); |
| 3028 |
|
$self->{pending_chars} ||= []; |
| 3029 |
unless (length $token->{data}) { |
push @{$self->{pending_chars}}, $token; |
| 3030 |
!!!cp ('t194'); |
!!!next-token; |
| 3031 |
!!!next-token; |
next B; |
| 3032 |
next B; |
} else { |
| 3033 |
|
if ($self->{pending_chars}) { |
| 3034 |
|
$s = join '', map { $_->{data} } @{$self->{pending_chars}}; |
| 3035 |
|
delete $self->{pending_chars}; |
| 3036 |
|
if ($s =~ /[^\x09\x0A\x0C\x0D\x20]/) { |
| 3037 |
|
!!!cp ('t195'); |
| 3038 |
|
# |
| 3039 |
|
} else { |
| 3040 |
|
!!!cp ('t195.1'); |
| 3041 |
|
#$self->{open_elements}->[-1]->[0]->manakai_append_text ($s); |
| 3042 |
|
$self->{open_elements}->[-1]->[0]->append_child |
| 3043 |
|
($self->{document}->create_text_node ($s)); |
| 3044 |
|
last C; |
| 3045 |
|
} |
| 3046 |
} else { |
} else { |
| 3047 |
!!!cp ('t195'); |
!!!cp ('t195.2'); |
| 3048 |
|
last C; |
| 3049 |
} |
} |
| 3050 |
} |
} |
| 3051 |
|
|
| 3052 |
|
## Foster parenting |
| 3053 |
!!!parse-error (type => 'in table:#text', token => $token); |
!!!parse-error (type => 'in table:#text', token => $token); |
| 3054 |
|
|
| 3055 |
## NOTE: As if in body, but insert into the foster parent element. |
## NOTE: As if in body, but insert into the foster parent element. |
| 3059 |
# MUST |
# MUST |
| 3060 |
my $foster_parent_element; |
my $foster_parent_element; |
| 3061 |
my $next_sibling; |
my $next_sibling; |
| 3062 |
my $prev_sibling; |
#my $prev_sibling; |
| 3063 |
OE: for (reverse 0..$#{$self->{open_elements}}) { |
OE: for (reverse 0..$#{$self->{open_elements}}) { |
| 3064 |
if ($self->{open_elements}->[$_]->[1] == TABLE_EL) { |
if ($self->{open_elements}->[$_]->[1] == TABLE_EL) { |
| 3065 |
my $parent = $self->{open_elements}->[$_]->[0]->parent_node; |
my $parent = $self->{open_elements}->[$_]->[0]->parent_node; |
| 3067 |
$foster_parent_element = $parent; |
$foster_parent_element = $parent; |
| 3068 |
!!!cp ('t196'); |
!!!cp ('t196'); |
| 3069 |
$next_sibling = $self->{open_elements}->[$_]->[0]; |
$next_sibling = $self->{open_elements}->[$_]->[0]; |
| 3070 |
$prev_sibling = $next_sibling->previous_sibling; |
# $prev_sibling = $next_sibling->previous_sibling; |
| 3071 |
# |
# |
| 3072 |
} else { |
} else { |
| 3073 |
!!!cp ('t197'); |
!!!cp ('t197'); |
| 3074 |
$foster_parent_element = $self->{open_elements}->[$_ - 1]->[0]; |
$foster_parent_element = $self->{open_elements}->[$_ - 1]->[0]; |
| 3075 |
$prev_sibling = $foster_parent_element->last_child; |
# $prev_sibling = $foster_parent_element->last_child; |
| 3076 |
# |
# |
| 3077 |
} |
} |
| 3078 |
last OE; |
last OE; |
| 3079 |
} |
} |
| 3080 |
} # OE |
} # OE |
| 3081 |
$foster_parent_element = $self->{open_elements}->[0]->[0] and |
$foster_parent_element = $self->{open_elements}->[0]->[0] #and |
| 3082 |
$prev_sibling = $foster_parent_element->last_child |
#$prev_sibling = $foster_parent_element->last_child |
| 3083 |
unless defined $foster_parent_element; |
unless defined $foster_parent_element; |
| 3084 |
undef $prev_sibling unless $open_tables->[-1]->[2]; # ~node inserted |
#undef $prev_sibling unless $open_tables->[-1]->[2]; # ~node inserted |
| 3085 |
if (defined $prev_sibling and |
#if (defined $prev_sibling and |
| 3086 |
$prev_sibling->node_type == 3) { |
# $prev_sibling->node_type == 3) { |
| 3087 |
!!!cp ('t198'); |
# !!! cp ('t198'); |
| 3088 |
$prev_sibling->manakai_append_text ($token->{data}); |
# $prev_sibling->manakai_append_text ($s); |
| 3089 |
} else { |
#} else { |
| 3090 |
!!!cp ('t199'); |
!!!cp ('t199'); |
| 3091 |
$foster_parent_element->insert_before |
$foster_parent_element->insert_before |
| 3092 |
($self->{document}->create_text_node ($token->{data}), |
($self->{document}->create_text_node ($s), $next_sibling); |
| 3093 |
$next_sibling); |
#} |
|
} |
|
| 3094 |
$open_tables->[-1]->[1] = 1; # tainted |
$open_tables->[-1]->[1] = 1; # tainted |
| 3095 |
$open_tables->[-1]->[2] = 1; # ~node inserted |
$open_tables->[-1]->[2] = 1; # ~node inserted |
| 3096 |
} else { |
} else { |
| 3101 |
## are discarded and fragment parsing does not invoke any |
## are discarded and fragment parsing does not invoke any |
| 3102 |
## script. |
## script. |
| 3103 |
!!!cp ('t200'); |
!!!cp ('t200'); |
| 3104 |
$self->{open_elements}->[-1]->[0]->manakai_append_text |
$self->{open_elements}->[-1]->[0]->manakai_append_text ($s); |
|
($token->{data}); |
|
| 3105 |
} |
} |
| 3106 |
|
} # C |
| 3107 |
!!!next-token; |
|
| 3108 |
next B; |
if ($token->{type} == START_TAG_TOKEN) { |
|
} elsif ($token->{type} == START_TAG_TOKEN) { |
|
| 3109 |
if ({ |
if ({ |
| 3110 |
tr => (($self->{insertion_mode} & IM_MASK) != IN_ROW_IM), |
tr => (($self->{insertion_mode} & IM_MASK) != IN_ROW_IM), |
| 3111 |
th => 1, td => 1, |
th => 1, td => 1, |
| 3929 |
## Reprocess the token. |
## Reprocess the token. |
| 3930 |
next B; |
next B; |
| 3931 |
} |
} |
| 3932 |
|
} elsif ($token->{tag_name} eq 'script') { |
| 3933 |
|
!!!cp ('t281.3'); |
| 3934 |
|
## NOTE: This is an "as if in head" code clone |
| 3935 |
|
$script_start_tag->(); |
| 3936 |
|
next B; |
| 3937 |
} else { |
} else { |
| 3938 |
!!!cp ('t282'); |
!!!cp ('t282'); |
| 3939 |
!!!parse-error (type => 'in select', |
!!!parse-error (type => 'in select', |
| 4453 |
table => 1, |
table => 1, |
| 4454 |
hr => 1, |
hr => 1, |
| 4455 |
}->{$token->{tag_name}}) { |
}->{$token->{tag_name}}) { |
| 4456 |
|
|
| 4457 |
|
## 1. When there is an opening |form| element: |
| 4458 |
if ($token->{tag_name} eq 'form' and defined $self->{form_element}) { |
if ($token->{tag_name} eq 'form' and defined $self->{form_element}) { |
| 4459 |
!!!cp ('t350'); |
!!!cp ('t350'); |
| 4460 |
!!!parse-error (type => 'in form:form', token => $token); |
!!!parse-error (type => 'in form:form', token => $token); |
| 4464 |
next B; |
next B; |
| 4465 |
} |
} |
| 4466 |
|
|
| 4467 |
|
## 2. Close the |p| element, if any. |
| 4468 |
if ($token->{tag_name} ne 'table' or # The Hixie Quirk |
if ($token->{tag_name} ne 'table' or # The Hixie Quirk |
| 4469 |
$self->{document}->manakai_compat_mode ne 'quirks') { |
$self->{document}->manakai_compat_mode ne 'quirks') { |
| 4470 |
## has a p element in scope |
## has a p element in scope |
| 4481 |
} |
} |
| 4482 |
} # INSCOPE |
} # INSCOPE |
| 4483 |
} |
} |
| 4484 |
|
|
| 4485 |
|
## 3. Close the opening <hn> element, if any. |
| 4486 |
|
if ({h1 => 1, h2 => 1, h3 => 1, |
| 4487 |
|
h4 => 1, h5 => 1, h6 => 1}->{$token->{tag_name}}) { |
| 4488 |
|
if ($self->{open_elements}->[-1]->[1] == HEADING_EL) { |
| 4489 |
|
!!!parse-error (type => 'not closed', |
| 4490 |
|
text => $self->{open_elements}->[-1]->[0]->manakai_local_name, |
| 4491 |
|
token => $token); |
| 4492 |
|
pop @{$self->{open_elements}}; |
| 4493 |
|
} |
| 4494 |
|
} |
| 4495 |
|
|
| 4496 |
|
## 4. Insertion. |
| 4497 |
!!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token); |
!!!insert-element-t ($token->{tag_name}, $token->{attributes}, $token); |
| 4498 |
if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') { |
if ($token->{tag_name} eq 'pre' or $token->{tag_name} eq 'listing') { |
| 4499 |
!!!nack ('t346.1'); |
!!!nack ('t346.1'); |
| 4537 |
} elsif ($token->{tag_name} eq 'li') { |
} elsif ($token->{tag_name} eq 'li') { |
| 4538 |
## NOTE: As normal, but imply </li> when there's another <li> ... |
## NOTE: As normal, but imply </li> when there's another <li> ... |
| 4539 |
|
|
| 4540 |
## NOTE: Special, Scope (<li><foo><li> == <li><foo><li/></foo></li>) |
## NOTE: Special, Scope (<li><foo><li> == <li><foo><li/></foo></li>):: |
| 4541 |
## Interpreted as <li><foo/></li><li/> (non-conforming) |
## Interpreted as <li><foo/></li><li/> (non-conforming): |
| 4542 |
## blockquote (O9.27), center (O), dd (Fx3, O, S3.1.2, IE7), |
## blockquote (O9.27), center (O), dd (Fx3, O, S3.1.2, IE7), |
| 4543 |
## dt (Fx, O, S, IE), dl (O), fieldset (O, S, IE), form (Fx, O, S), |
## dt (Fx, O, S, IE), dl (O), fieldset (O, S, IE), form (Fx, O, S), |
| 4544 |
## hn (O), pre (O), applet (O, S), button (O, S), marquee (Fx, O, S), |
## hn (O), pre (O), applet (O, S), button (O, S), marquee (Fx, O, S), |
| 4545 |
## object (Fx) |
## object (Fx) |
| 4546 |
## Generate non-tree (non-conforming) |
## Generate non-tree (non-conforming): |
| 4547 |
## basefont (IE7 (where basefont is non-void)), center (IE), |
## basefont (IE7 (where basefont is non-void)), center (IE), |
| 4548 |
## form (IE), hn (IE) |
## form (IE), hn (IE) |
| 4549 |
## address, div, p (<li><foo><li> == <li><foo/></li><li/>) |
## address, div, p (<li><foo><li> == <li><foo/></li><li/>):: |
| 4550 |
## Interpreted as <li><foo><li/></foo></li> (non-conforming) |
## Interpreted as <li><foo><li/></foo></li> (non-conforming): |
| 4551 |
## div (Fx, S) |
## div (Fx, S) |
| 4552 |
|
|
| 4553 |
my $non_optional; |
my $non_optional; |
| 5083 |
} |
} |
| 5084 |
} elsif ($token->{type} == END_TAG_TOKEN) { |
} elsif ($token->{type} == END_TAG_TOKEN) { |
| 5085 |
if ($token->{tag_name} eq 'body') { |
if ($token->{tag_name} eq 'body') { |
| 5086 |
## has a |body| element in scope |
|
| 5087 |
|
## 1. If not "have an element in scope": |
| 5088 |
|
## "has a |body| element in scope" |
| 5089 |
my $i; |
my $i; |
| 5090 |
INSCOPE: { |
INSCOPE: { |
| 5091 |
for (reverse @{$self->{open_elements}}) { |
for (reverse @{$self->{open_elements}}) { |
| 5108 |
next B; |
next B; |
| 5109 |
} # INSCOPE |
} # INSCOPE |
| 5110 |
|
|
| 5111 |
|
## 2. If unclosed elements: |
| 5112 |
for (@{$self->{open_elements}}) { |
for (@{$self->{open_elements}}) { |
| 5113 |
unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL || |
unless ($_->[1] & ALL_END_TAG_OPTIONAL_EL || |
| 5114 |
$_->[1] == OPTGROUP_EL || |
$_->[1] == OPTGROUP_EL || |
| 5124 |
} |
} |
| 5125 |
} |
} |
| 5126 |
|
|
| 5127 |
|
## 3. Switch the insertion mode. |
| 5128 |
$self->{insertion_mode} = AFTER_BODY_IM; |
$self->{insertion_mode} = AFTER_BODY_IM; |
| 5129 |
!!!next-token; |
!!!next-token; |
| 5130 |
next B; |
next B; |