33 |
exit; |
exit; |
34 |
} |
} |
35 |
|
|
36 |
|
load_text_catalog ('en'); ## TODO: conneg |
37 |
|
|
38 |
|
my @nav; |
39 |
print STDOUT qq[Content-Type: text/html; charset=utf-8 |
print STDOUT qq[Content-Type: text/html; charset=utf-8 |
40 |
|
|
41 |
<!DOCTYPE html> |
<!DOCTYPE html> |
42 |
<html lang="en"> |
<html lang="en"> |
43 |
<head> |
<head> |
44 |
<title>Web Document Conformance Checker (BETA)</title> |
<title>Web Document Conformance Checker (BETA)</title> |
45 |
<link rel="stylesheet" href="/www/style/html/xhtml"> |
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
|
<style> |
|
|
q { |
|
|
white-space: pre; |
|
|
white-space: -moz-pre-wrap; |
|
|
white-space: pre-wrap; |
|
|
} |
|
|
</style> |
|
46 |
</head> |
</head> |
47 |
<body> |
<body> |
48 |
<h1>Web Document Conformance Checker (<em>beta</em>)</h1> |
<h1>Web Document Conformance Checker (<em>beta</em>)</h1> |
49 |
|
|
50 |
|
<div id="document-info" class="section"> |
51 |
<dl> |
<dl> |
52 |
<dt>Document URI</dt> |
<dt>Document URI</dt> |
53 |
<dd><code class="URI" lang=""><<a href="@{[htescape $input_uri]}">@{[htescape $input_uri]}</a>></code></dd> |
<dd><code class="URI" lang=""><<a href="@{[htescape $input_uri]}">@{[htescape $input_uri]}</a>></code></dd> |
54 |
<dt>Internet Media Type</dt> |
<dt>Internet Media Type</dt> |
55 |
<dd><code class="MIME" lang="en">@{[htescape $input_format]}</code></dd> |
<dd><code class="MIME" lang="en">@{[htescape $input_format]}</code></dd> |
56 |
]; # no </dl> yet |
]; # no </dl> yet |
57 |
|
push @nav, ['#document-info' => 'Information']; |
58 |
|
|
59 |
require Message::DOM::DOMImplementation; |
require Message::DOM::DOMImplementation; |
60 |
my $dom = Message::DOM::DOMImplementation->____new; |
my $dom = Message::DOM::DOMImplementation->____new; |
71 |
<dt>Character Encoding</dt> |
<dt>Character Encoding</dt> |
72 |
<dd>(none)</dd> |
<dd>(none)</dd> |
73 |
</dl> |
</dl> |
74 |
|
</div> |
75 |
|
|
76 |
<div id="source-string" class="section"> |
<div id="source-string" class="section"> |
77 |
|
<h2>Document Source</h2> |
78 |
]; |
]; |
79 |
|
push @nav, ['#source-string' => 'Source']; |
80 |
print_source_string (\$s); |
print_source_string (\$s); |
81 |
print STDOUT qq[ |
print STDOUT qq[ |
82 |
</div> |
</div> |
84 |
<div id="parse-errors" class="section"> |
<div id="parse-errors" class="section"> |
85 |
<h2>Parse Errors</h2> |
<h2>Parse Errors</h2> |
86 |
|
|
87 |
<ul> |
<dl> |
88 |
]; |
]; |
89 |
|
push @nav, ['#parse-errors' => 'Parse Error']; |
90 |
|
|
91 |
my $onerror = sub { |
my $onerror = sub { |
92 |
my (%opt) = @_; |
my (%opt) = @_; |
93 |
|
my ($cls, $msg) = get_text ($opt{type}, $opt{level}); |
94 |
if ($opt{column} > 0) { |
if ($opt{column} > 0) { |
95 |
print STDOUT qq[<li><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}: ]; |
print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n]; |
96 |
} else { |
} else { |
97 |
$opt{line}--; |
$opt{line} = $opt{line} - 1 || 1; |
98 |
print STDOUT qq[<li><a href="#line-$opt{line}">Line $opt{line}</a>: ]; |
print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n]; |
99 |
} |
} |
100 |
print STDOUT qq[@{[htescape $opt{type}]}</li>\n]; |
print STDOUT qq[<dd class="$cls">$msg</dd>\n]; |
101 |
}; |
}; |
102 |
|
|
103 |
$doc = $dom->create_document; |
$doc = $dom->create_document; |
110 |
} |
} |
111 |
|
|
112 |
print STDOUT qq[ |
print STDOUT qq[ |
113 |
</ul> |
</dl> |
114 |
</div> |
</div> |
115 |
]; |
]; |
116 |
} elsif ($input_format eq 'application/xhtml+xml') { |
} elsif ($input_format eq 'application/xhtml+xml') { |
123 |
<dt>Character Encoding</dt> |
<dt>Character Encoding</dt> |
124 |
<dd>(none)</dd> |
<dd>(none)</dd> |
125 |
</dl> |
</dl> |
126 |
|
</div> |
127 |
|
|
128 |
<div id="source-string" class="section"> |
<div id="source-string" class="section"> |
129 |
|
<h2>Document Source</h2> |
130 |
]; |
]; |
131 |
|
push @nav, ['#source-string' => 'Source']; |
132 |
print_source_string (\$t); |
print_source_string (\$t); |
133 |
print STDOUT qq[ |
print STDOUT qq[ |
134 |
</div> |
</div> |
136 |
<div id="parse-errors" class="section"> |
<div id="parse-errors" class="section"> |
137 |
<h2>Parse Errors</h2> |
<h2>Parse Errors</h2> |
138 |
|
|
139 |
<ul> |
<dl>]; |
140 |
]; |
push @nav, ['#parse-errors' => 'Parse Error']; |
141 |
|
|
142 |
my $onerror = sub { |
my $onerror = sub { |
143 |
my $err = shift; |
my $err = shift; |
144 |
my $line = $err->location->line_number; |
my $line = $err->location->line_number; |
145 |
print STDOUT qq[<li><a href="#line-$line">Line $line</a> column ]; |
print STDOUT qq[<dt><a href="#line-$line">Line $line</a> column ]; |
146 |
print STDOUT $err->location->column_number, ": "; |
print STDOUT $err->location->column_number, "</dt><dd>"; |
147 |
print STDOUT htescape $err->text, "</li>\n"; |
print STDOUT htescape $err->text, "</dd>\n"; |
148 |
return 1; |
return 1; |
149 |
}; |
}; |
150 |
|
|
152 |
$doc = Message::DOM::XMLParserTemp->parse_byte_stream |
$doc = Message::DOM::XMLParserTemp->parse_byte_stream |
153 |
($fh => $dom, $onerror, charset => 'utf-8'); |
($fh => $dom, $onerror, charset => 'utf-8'); |
154 |
|
|
155 |
print STDOUT qq[ |
print STDOUT qq[</dl> |
|
</ul> |
|
156 |
</div> |
</div> |
157 |
]; |
]; |
158 |
} else { |
} else { |
159 |
print STDOUT qq[ |
print STDOUT qq[ |
160 |
</dl> |
</dl> |
161 |
|
</div> |
162 |
|
|
163 |
|
<div id="result-summary" class="section"> |
164 |
<p><em>Media type <code class="MIME" lang="en">@{[htescape $input_format]}</code> is not supported!</em></p> |
<p><em>Media type <code class="MIME" lang="en">@{[htescape $input_format]}</code> is not supported!</em></p> |
165 |
|
</div> |
166 |
]; |
]; |
167 |
|
push @nav, ['#result-summary' => 'Result']; |
168 |
} |
} |
169 |
|
|
170 |
|
|
173 |
<div id="document-tree" class="section"> |
<div id="document-tree" class="section"> |
174 |
<h2>Document Tree</h2> |
<h2>Document Tree</h2> |
175 |
]; |
]; |
176 |
|
push @nav, ['#document-tree' => 'Tree']; |
177 |
|
|
178 |
print_document_tree ($el || $doc); |
print_document_tree ($el || $doc); |
179 |
|
|
183 |
<div id="document-errors" class="section"> |
<div id="document-errors" class="section"> |
184 |
<h2>Document Errors</h2> |
<h2>Document Errors</h2> |
185 |
|
|
186 |
<ul> |
<dl>]; |
187 |
]; |
push @nav, ['#document-errors' => 'Document Error']; |
188 |
|
|
189 |
require Whatpm::ContentChecker; |
require Whatpm::ContentChecker; |
190 |
my $onerror = sub { |
my $onerror = sub { |
191 |
my %opt = @_; |
my %opt = @_; |
192 |
print STDOUT qq[<li><a href="#node-@{[refaddr $opt{node}]}">], |
my ($cls, $msg) = get_text ($opt{type}, $opt{level}); |
193 |
htescape get_node_path ($opt{node}), |
print STDOUT qq[<dt class="$cls">] . get_node_link ($opt{node}) . |
194 |
"</a>: ", htescape $opt{type}, "</li>\n"; |
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
195 |
}; |
}; |
196 |
|
|
197 |
|
my $elements; |
198 |
if ($el) { |
if ($el) { |
199 |
Whatpm::ContentChecker->check_element ($el, $onerror); |
$elements = Whatpm::ContentChecker->check_element ($el, $onerror); |
200 |
} else { |
} else { |
201 |
Whatpm::ContentChecker->check_document ($doc, $onerror); |
$elements = Whatpm::ContentChecker->check_document ($doc, $onerror); |
202 |
} |
} |
203 |
|
|
204 |
print STDOUT qq[ |
print STDOUT qq[</dl> |
|
</ul> |
|
205 |
</div> |
</div> |
206 |
]; |
]; |
207 |
|
|
208 |
|
if (@{$elements->{table}}) { |
209 |
|
require JSON; |
210 |
|
|
211 |
|
print STDOUT qq[ |
212 |
|
<div id="tables" class="section"> |
213 |
|
<h2>Tables</h2> |
214 |
|
|
215 |
|
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]--> |
216 |
|
<script src="../table-script.js" type="text/javascript"></script> |
217 |
|
<noscript> |
218 |
|
<p><em>Structure of tables are visualized here if scripting is enabled.</em></p> |
219 |
|
</noscript> |
220 |
|
]; |
221 |
|
|
222 |
|
my $i = 0; |
223 |
|
for my $table_el (@{$elements->{table}}) { |
224 |
|
$i++; |
225 |
|
print STDOUT qq[<div class="section" id="table-$i"><h3>] . |
226 |
|
get_node_link ($table_el) . q[</h3>]; |
227 |
|
|
228 |
|
my $table = Whatpm::HTMLTable->form_table ($table_el); |
229 |
|
|
230 |
|
for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) { |
231 |
|
next unless $_; |
232 |
|
delete $_->{element}; |
233 |
|
} |
234 |
|
|
235 |
|
for (@{$table->{row_group}}) { |
236 |
|
next unless $_; |
237 |
|
next unless $_->{element}; |
238 |
|
$_->{type} = $_->{element}->manakai_local_name; |
239 |
|
delete $_->{element}; |
240 |
|
} |
241 |
|
|
242 |
|
for (@{$table->{cell}}) { |
243 |
|
next unless $_; |
244 |
|
for (@{$_}) { |
245 |
|
next unless $_; |
246 |
|
for (@$_) { |
247 |
|
$_->{id} = refaddr $_->{element} if defined $_->{element}; |
248 |
|
delete $_->{element}; |
249 |
|
} |
250 |
|
} |
251 |
|
} |
252 |
|
|
253 |
|
print STDOUT '</div><script type="text/javascript">tableToCanvas ('; |
254 |
|
print STDOUT JSON::objToJson ($table); |
255 |
|
print STDOUT qq[, document.getElementById ('table-$i'));</script>]; |
256 |
|
} |
257 |
|
|
258 |
|
print STDOUT qq[</div>]; |
259 |
|
} |
260 |
|
|
261 |
|
if (keys %{$elements->{term}}) { |
262 |
|
print STDOUT qq[ |
263 |
|
<div id="terms" class="section"> |
264 |
|
<h2>Terms</h2> |
265 |
|
|
266 |
|
<dl> |
267 |
|
]; |
268 |
|
for my $term (sort {$a cmp $b} keys %{$elements->{term}}) { |
269 |
|
print STDOUT qq[<dt>@{[htescape $term]}</dt>]; |
270 |
|
for (@{$elements->{term}->{$term}}) { |
271 |
|
print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>]; |
272 |
|
} |
273 |
|
} |
274 |
|
print STDOUT qq[</dl></div>]; |
275 |
|
} |
276 |
} |
} |
277 |
|
|
278 |
## TODO: Show result |
## TODO: Show result |
279 |
|
|
280 |
|
print STDOUT qq[ |
281 |
|
<ul class="navigation" id="nav-items"> |
282 |
|
]; |
283 |
|
for (@nav) { |
284 |
|
print STDOUT qq[<li><a href="$_->[0]">$_->[1]</a></li>]; |
285 |
|
} |
286 |
print STDOUT qq[ |
print STDOUT qq[ |
287 |
|
</ul> |
288 |
</body> |
</body> |
289 |
</html> |
</html> |
290 |
]; |
]; |
295 |
my $s = $_[0]; |
my $s = $_[0]; |
296 |
my $i = 1; |
my $i = 1; |
297 |
print STDOUT qq[<ol lang="">\n]; |
print STDOUT qq[<ol lang="">\n]; |
298 |
while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { |
if (length $$s) { |
299 |
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { |
300 |
$i++; |
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
301 |
} |
$i++; |
302 |
if ($$s =~ /\G([^\x0A]+)/gc) { |
} |
303 |
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
if ($$s =~ /\G([^\x0A]+)/gc) { |
304 |
|
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
305 |
|
} |
306 |
|
} else { |
307 |
|
print STDOUT q[<li id="line-1"></li>]; |
308 |
} |
} |
309 |
print STDOUT "</ol>"; |
print STDOUT "</ol>"; |
310 |
} # print_input_string |
} # print_input_string |
324 |
my $node_id = 'node-'.refaddr $child; |
my $node_id = 'node-'.refaddr $child; |
325 |
my $nt = $child->node_type; |
my $nt = $child->node_type; |
326 |
if ($nt == $child->ELEMENT_NODE) { |
if ($nt == $child->ELEMENT_NODE) { |
327 |
$r .= qq'<li id="$node_id"><code>' . htescape ($child->tag_name) . |
my $child_nsuri = $child->namespace_uri; |
328 |
|
$r .= qq[<li id="$node_id" class="tree-element"><code title="@{[defined $child_nsuri ? $child_nsuri : '']}">] . htescape ($child->tag_name) . |
329 |
'</code>'; ## ISSUE: case |
'</code>'; ## ISSUE: case |
330 |
|
|
331 |
if ($child->has_attributes) { |
if ($child->has_attributes) { |
332 |
$r .= '<ul class="attributes">'; |
$r .= '<ul class="attributes">'; |
333 |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, 'node-'.refaddr $_] } |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] } |
334 |
@{$child->attributes}) { |
@{$child->attributes}) { |
335 |
$r .= qq'<li id="$attr->[2]"><code>' . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
$r .= qq[<li id="$attr->[3]" class="tree-attribute"><code title="@{[defined $_->[2] ? $_->[2] : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
336 |
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
337 |
} |
} |
338 |
$r .= '</ul>'; |
$r .= '</ul>'; |
339 |
} |
} |
340 |
|
|
341 |
if ($node->has_child_nodes) { |
if ($child->has_child_nodes) { |
342 |
$r .= '<ol class="children">'; |
$r .= '<ol class="children">'; |
343 |
unshift @node, @{$child->child_nodes}, '</ol>'; |
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
344 |
|
} else { |
345 |
|
$r .= '</li>'; |
346 |
} |
} |
347 |
} elsif ($nt == $child->TEXT_NODE) { |
} elsif ($nt == $child->TEXT_NODE) { |
348 |
$r .= qq'<li id="$node_id"><q>' . htescape ($child->data) . '</q></li>'; |
$r .= qq'<li id="$node_id" class="tree-text"><q lang="">' . htescape ($child->data) . '</q></li>'; |
349 |
} elsif ($nt == $child->CDATA_SECTION_NODE) { |
} elsif ($nt == $child->CDATA_SECTION_NODE) { |
350 |
$r .= qq'<li id="$node_id"><code><[CDATA[</code><q>' . htescape ($child->data) . '</q><code>]]></code></li>'; |
$r .= qq'<li id="$node_id" class="tree-cdata"><code><[CDATA[</code><q lang="">' . htescape ($child->data) . '</q><code>]]></code></li>'; |
351 |
} elsif ($nt == $child->COMMENT_NODE) { |
} elsif ($nt == $child->COMMENT_NODE) { |
352 |
$r .= qq'<li id="$node_id"><code><!--</code><q>' . htescape ($child->data) . '</q><code>--></code></li>'; |
$r .= qq'<li id="$node_id" class="tree-comment"><code><!--</code><q lang="">' . htescape ($child->data) . '</q><code>--></code></li>'; |
353 |
} elsif ($nt == $child->DOCUMENT_NODE) { |
} elsif ($nt == $child->DOCUMENT_NODE) { |
354 |
$r .= qq'<li id="$node_id">Document</li>'; |
$r .= qq'<li id="$node_id" class="tree-document">Document'; |
355 |
|
$r .= qq[<ul class="attributes">]; |
356 |
|
$r .= qq[<li>@{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}</li>]; |
357 |
|
$r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>]; |
358 |
|
$r .= qq[</ul>]; |
359 |
if ($child->has_child_nodes) { |
if ($child->has_child_nodes) { |
360 |
$r .= '<ol>'; |
$r .= '<ol class="children">'; |
361 |
unshift @node, @{$child->child_nodes}, '</ol>'; |
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
362 |
} |
} |
363 |
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) { |
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) { |
364 |
$r .= qq'<li id="$node_id"><code><!DOCTYPE></code><ul>'; |
$r .= qq'<li id="$node_id" class="tree-doctype"><code><!DOCTYPE></code><ul class="attributes">'; |
365 |
$r .= '<li>Name = <q>@{[htescape ($child->name)]}</q></li>'; |
$r .= qq[<li class="tree-doctype-name">Name = <q>@{[htescape ($child->name)]}</q></li>]; |
366 |
$r .= '<li>Public identifier = <q>@{[htescape ($child->public_id)]}</q></li>'; |
$r .= qq[<li class="tree-doctype-publicid">Public identifier = <q>@{[htescape ($child->public_id)]}</q></li>]; |
367 |
$r .= '<li>System identifier = <q>@{[htescape ($child->system_id)]}</q></li>'; |
$r .= qq[<li class="tree-doctype-systemid">System identifier = <q>@{[htescape ($child->system_id)]}</q></li>]; |
368 |
$r .= '</ul></li>'; |
$r .= '</ul></li>'; |
369 |
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) { |
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) { |
370 |
$r .= qq'<li id="$node_id"><code><?@{[htescape ($child->target)]}?></code>'; |
$r .= qq'<li id="$node_id" class="tree-id"><code><?@{[htescape ($child->target)]}</code> <q>@{[htescape ($child->data)]}</q><code>?></code></li>'; |
|
$r .= '<ul><li>@{[htescape ($child->data)]}</li></ul></li>'; |
|
371 |
} else { |
} else { |
372 |
$r .= qq'<li id="$node_id">@{[$child->node_type]} @{[htescape ($child->node_name)]}</li>'; # error |
$r .= qq'<li id="$node_id" class="tree-unknown">@{[$child->node_type]} @{[htescape ($child->node_name)]}</li>'; # error |
373 |
} |
} |
374 |
} |
} |
375 |
|
|
403 |
return join '/', @r; |
return join '/', @r; |
404 |
} # get_node_path |
} # get_node_path |
405 |
|
|
406 |
|
sub get_node_link ($) { |
407 |
|
return qq[<a href="#node-@{[refaddr $_[0]]}">] . |
408 |
|
htescape (get_node_path ($_[0])) . qq[</a>]; |
409 |
|
} # get_node_link |
410 |
|
|
411 |
|
{ |
412 |
|
my $Msg = {}; |
413 |
|
|
414 |
|
sub load_text_catalog ($) { |
415 |
|
my $lang = shift; # MUST be a canonical lang name |
416 |
|
open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!"; |
417 |
|
while (<$file>) { |
418 |
|
if (s/^([^;]+);([^;]*);//) { |
419 |
|
my ($type, $cls, $msg) = ($1, $2, $_); |
420 |
|
$msg =~ tr/\x0D\x0A//d; |
421 |
|
$Msg->{$type} = [$cls, $msg]; |
422 |
|
} |
423 |
|
} |
424 |
|
} # load_text_catalog |
425 |
|
|
426 |
|
sub get_text ($) { |
427 |
|
my ($type, $level) = @_; |
428 |
|
$type = $level . ':' . $type if defined $level; |
429 |
|
my @arg; |
430 |
|
{ |
431 |
|
if (defined $Msg->{$type}) { |
432 |
|
my $msg = $Msg->{$type}->[1]; |
433 |
|
$msg =~ s/\$([0-9]+)/defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'/ge; |
434 |
|
return ($Msg->{$type}->[0], $msg); |
435 |
|
} elsif ($type =~ s/:([^:]*)$//) { |
436 |
|
unshift @arg, $1; |
437 |
|
redo; |
438 |
|
} |
439 |
|
} |
440 |
|
return ('', htescape ($_[0])); |
441 |
|
} # get_text |
442 |
|
|
443 |
|
} |
444 |
|
|
445 |
=head1 AUTHOR |
=head1 AUTHOR |
446 |
|
|
447 |
Wakaba <w@suika.fam.cx>. |
Wakaba <w@suika.fam.cx>. |