| 161 |
my $el; |
my $el; |
| 162 |
my $cssom; |
my $cssom; |
| 163 |
my $manifest; |
my $manifest; |
| 164 |
|
my $idl; |
| 165 |
my @subdoc; |
my @subdoc; |
| 166 |
|
|
| 167 |
if ($input->{media_type} eq 'text/html') { |
if ($input->{media_type} eq 'text/html') { |
| 196 |
$manifest = print_syntax_error_manifest_section ($input, $result); |
$manifest = print_syntax_error_manifest_section ($input, $result); |
| 197 |
print_source_string_section ($input, \($input->{s}), |
print_source_string_section ($input, \($input->{s}), |
| 198 |
'utf-8'); |
'utf-8'); |
| 199 |
|
} elsif ($input->{media_type} eq 'text/x-webidl') { ## TODO: type |
| 200 |
|
$idl = print_syntax_error_webidl_section ($input, $result); |
| 201 |
|
print_source_string_section ($input, \($input->{s}), |
| 202 |
|
'utf-8'); ## TODO: charset |
| 203 |
} else { |
} else { |
| 204 |
## TODO: Change HTTP status code?? |
## TODO: Change HTTP status code?? |
| 205 |
print_result_unknown_type_section ($input, $result); |
print_result_unknown_type_section ($input, $result); |
| 232 |
} elsif (defined $manifest) { |
} elsif (defined $manifest) { |
| 233 |
print_structure_dump_manifest_section ($input, $manifest); |
print_structure_dump_manifest_section ($input, $manifest); |
| 234 |
print_structure_error_manifest_section ($input, $manifest, $result); |
print_structure_error_manifest_section ($input, $manifest, $result); |
| 235 |
|
} elsif (defined $idl) { |
| 236 |
|
print_structure_dump_webidl_section ($input, $idl); |
| 237 |
|
print_structure_error_webidl_section ($input, $idl, $result); |
| 238 |
} |
} |
| 239 |
|
|
| 240 |
my $id_prefix = 0; |
my $id_prefix = 0; |
| 681 |
return $manifest; |
return $manifest; |
| 682 |
} # print_syntax_error_manifest_section |
} # print_syntax_error_manifest_section |
| 683 |
|
|
| 684 |
|
sub print_syntax_error_webidl_section ($$) { |
| 685 |
|
my ($input, $result) = @_; |
| 686 |
|
|
| 687 |
|
require Whatpm::WebIDL; |
| 688 |
|
|
| 689 |
|
print STDOUT qq[ |
| 690 |
|
<div id="$input->{id_prefix}parse-errors" class="section"> |
| 691 |
|
<h2>Parse Errors</h2> |
| 692 |
|
|
| 693 |
|
<dl id="$input->{id_prefix}parse-errors-list">]; |
| 694 |
|
push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{nested}; |
| 695 |
|
|
| 696 |
|
my $onerror = sub { |
| 697 |
|
my (%opt) = @_; |
| 698 |
|
my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level}); |
| 699 |
|
print STDOUT qq[<dt class="$cls">], get_error_label ($input, \%opt), |
| 700 |
|
qq[</dt>]; |
| 701 |
|
$type =~ tr/ /-/; |
| 702 |
|
$type =~ s/\|/%7C/g; |
| 703 |
|
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
| 704 |
|
print STDOUT qq[<dd class="$cls">], get_error_level_label (\%opt); |
| 705 |
|
print STDOUT qq[$msg</dd>\n]; |
| 706 |
|
|
| 707 |
|
add_error ('syntax', \%opt => $result); |
| 708 |
|
}; |
| 709 |
|
|
| 710 |
|
require Encode; |
| 711 |
|
my $s = $input->{is_char_string} ? $input->{s} : Encode::decode ($input->{charset} || 'utf-8', $input->{s}); ## TODO: charset |
| 712 |
|
my $parser = Whatpm::WebIDL::Parser->new; |
| 713 |
|
my $idl = $parser->parse_char_string ($input->{s}, $onerror); |
| 714 |
|
|
| 715 |
|
print STDOUT qq[</dl></div>]; |
| 716 |
|
|
| 717 |
|
return $idl; |
| 718 |
|
} # print_syntax_error_webidl_section |
| 719 |
|
|
| 720 |
sub print_source_string_section ($$$) { |
sub print_source_string_section ($$$) { |
| 721 |
my $input = shift; |
my $input = shift; |
| 722 |
my $s; |
my $s; |
| 723 |
unless ($input->{is_char_string}) { |
unless ($input->{is_char_string}) { |
| 724 |
require Encode; |
open my $byte_stream, '<', $_[0]; |
| 725 |
my $enc = Encode::find_encoding ($_[1]); ## TODO: charset name -> Perl name |
require Message::Charset::Info; |
| 726 |
return unless $enc; |
my $charset = Message::Charset::Info->get_by_iana_name ($_[1]); |
| 727 |
|
my ($char_stream, $e_status) = $charset->get_decode_handle |
| 728 |
|
($byte_stream, allow_error_reporting => 1, allow_fallback => 1); |
| 729 |
|
return unless $char_stream; |
| 730 |
|
|
| 731 |
|
$char_stream->onerror (sub { |
| 732 |
|
my (undef, $type, %opt) = @_; |
| 733 |
|
if ($opt{octets}) { |
| 734 |
|
${$opt{octets}} = "\x{FFFD}"; |
| 735 |
|
} |
| 736 |
|
}); |
| 737 |
|
|
| 738 |
$s = \($enc->decode (${$_[0]})); |
my $t = ''; |
| 739 |
|
while (1) { |
| 740 |
|
my $c = $char_stream->getc; |
| 741 |
|
last unless defined $c; |
| 742 |
|
$t .= $c; |
| 743 |
|
} |
| 744 |
|
$s = \$t; |
| 745 |
|
## TODO: Output for each line, don't concat all of lines. |
| 746 |
} else { |
} else { |
| 747 |
$s = $_[0]; |
$s = $_[0]; |
| 748 |
} |
} |
| 931 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
| 932 |
} # print_structure_dump_manifest_section |
} # print_structure_dump_manifest_section |
| 933 |
|
|
| 934 |
|
sub print_structure_dump_webidl_section ($$) { |
| 935 |
|
my ($input, $idl) = @_; |
| 936 |
|
|
| 937 |
|
print STDOUT qq[ |
| 938 |
|
<div id="$input->{id_prefix}dump-webidl" class="section"> |
| 939 |
|
<h2>WebIDL</h2> |
| 940 |
|
]; |
| 941 |
|
push @nav, [qq[#$input->{id_prefix}dump-webidl] => 'WebIDL'] |
| 942 |
|
unless $input->{nested}; |
| 943 |
|
|
| 944 |
|
print STDOUT "<pre>"; |
| 945 |
|
print STDOUT htescape ($idl->idl_text); |
| 946 |
|
print STDOUT "</pre>"; |
| 947 |
|
|
| 948 |
|
print STDOUT qq[</div>]; |
| 949 |
|
} # print_structure_dump_webidl_section |
| 950 |
|
|
| 951 |
sub print_structure_error_dom_section ($$$$$) { |
sub print_structure_error_dom_section ($$$$$) { |
| 952 |
my ($input, $doc, $el, $result, $onsubdoc) = @_; |
my ($input, $doc, $el, $result, $onsubdoc) = @_; |
| 953 |
|
|
| 1015 |
print STDOUT qq[</div>]; |
print STDOUT qq[</div>]; |
| 1016 |
} # print_structure_error_manifest_section |
} # print_structure_error_manifest_section |
| 1017 |
|
|
| 1018 |
|
sub print_structure_error_webidl_section ($$$) { |
| 1019 |
|
my ($input, $idl, $result) = @_; |
| 1020 |
|
|
| 1021 |
|
print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section"> |
| 1022 |
|
<h2>Document Errors</h2> |
| 1023 |
|
|
| 1024 |
|
<dl>]; |
| 1025 |
|
push @nav, [qq[#$input->{id_prefix}document-errors] => 'Document Error'] |
| 1026 |
|
unless $input->{nested}; |
| 1027 |
|
|
| 1028 |
|
## TODO: |
| 1029 |
|
|
| 1030 |
|
print STDOUT qq[</div>]; |
| 1031 |
|
} # print_structure_error_webidl_section |
| 1032 |
|
|
| 1033 |
sub print_table_section ($$) { |
sub print_table_section ($$) { |
| 1034 |
my ($input, $tables) = @_; |
my ($input, $tables) = @_; |
| 1035 |
|
|
| 1049 |
require JSON; |
require JSON; |
| 1050 |
|
|
| 1051 |
my $i = 0; |
my $i = 0; |
| 1052 |
for my $table_el (@$tables) { |
for my $table (@$tables) { |
| 1053 |
$i++; |
$i++; |
| 1054 |
print STDOUT qq[<div class="section" id="$input->{id_prefix}table-$i"><h3>] . |
print STDOUT qq[<div class="section" id="$input->{id_prefix}table-$i"><h3>] . |
| 1055 |
get_node_link ($input, $table_el) . q[</h3>]; |
get_node_link ($input, $table->{element}) . q[</h3>]; |
| 1056 |
|
|
| 1057 |
|
delete $table->{element}; |
| 1058 |
|
|
|
## TODO: Make |ContentChecker| return |form_table| result |
|
|
## so that this script don't have to run the algorithm twice. |
|
|
my $table = Whatpm::HTMLTable->form_table ($table_el); |
|
|
|
|
| 1059 |
for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}, |
for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}, |
| 1060 |
@{$table->{row}}) { |
@{$table->{row}}) { |
| 1061 |
next unless $_; |
next unless $_; |
| 1275 |
|
|
| 1276 |
print STDOUT qq[<tr class="@{[$uncertain ? 'uncertain' : '']}"><th scope=row>$label</th><td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{must}$uncertain</td><td class="@{[$result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">$result->{$_->[1]}->{should}$uncertain</td><td>$result->{$_->[1]}->{warning}$uncertain</td>]; |
print STDOUT qq[<tr class="@{[$uncertain ? 'uncertain' : '']}"><th scope=row>$label</th><td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{must}$uncertain</td><td class="@{[$result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">$result->{$_->[1]}->{should}$uncertain</td><td>$result->{$_->[1]}->{warning}$uncertain</td>]; |
| 1277 |
if ($uncertain) { |
if ($uncertain) { |
| 1278 |
print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">−∞..$result->{$_->[1]}->{score_max}</td>]; |
print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : $result->{$_->[1]}->{should} ? 'SEE-RESULT' : '']}">−∞..$result->{$_->[1]}->{score_max}]; |
| 1279 |
} elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { |
} elsif ($result->{$_->[1]}->{score_min} != $result->{$_->[1]}->{score_max}) { |
| 1280 |
print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}</td></tr>]; |
print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : 'SEE-RESULT']}">$result->{$_->[1]}->{score_min}..$result->{$_->[1]}->{score_max}]; |
| 1281 |
} else { |
} else { |
| 1282 |
print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}</td></tr>]; |
print qq[<td class="@{[$result->{$_->[1]}->{must} ? 'FAIL' : '']}">$result->{$_->[1]}->{score_min}]; |
| 1283 |
} |
} |
| 1284 |
|
print qq[ / 20]; |
| 1285 |
} |
} |
| 1286 |
|
|
| 1287 |
$score_max += $score_base; |
$score_max += $score_base; |
| 1288 |
|
|
| 1289 |
print STDOUT qq[ |
print STDOUT qq[ |
| 1290 |
<tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>−∞..$score_base</td></tr> |
<tr class=uncertain><th scope=row>Semantics</th><td>0?</td><td>0?</td><td>0?</td><td>−∞..$score_base / 20 |
| 1291 |
</tbody> |
</tbody> |
| 1292 |
<tfoot><tr class=uncertain><th scope=row>Total</th> |
<tfoot><tr class=uncertain><th scope=row>Total</th> |
| 1293 |
<td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td> |
<td class="@{[$must_error ? 'FAIL' : '']}">$must_error?</td> |
| 1294 |
<td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td> |
<td class="@{[$should_error ? 'SEE-RESULT' : '']}">$should_error?</td> |
| 1295 |
<td>$warning?</td> |
<td>$warning?</td> |
| 1296 |
<td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>−∞..$score_max</strong></td></tr></tfoot> |
<td class="@{[$must_error ? 'FAIL' : $should_error ? 'SEE-RESULT' : '']}"><strong>−∞..$score_max</strong> / 100 |
| 1297 |
</table> |
</table> |
| 1298 |
|
|
| 1299 |
<p><strong>Important</strong>: This conformance checking service |
<p><strong>Important</strong>: This conformance checking service |