45 |
<body> |
<body> |
46 |
<h1>Web Document Conformance Checker (<em>beta</em>)</h1> |
<h1>Web Document Conformance Checker (<em>beta</em>)</h1> |
47 |
|
|
48 |
<div id="document-info" section="section"> |
<div id="document-info" class="section"> |
49 |
<dl> |
<dl> |
50 |
<dt>Document URI</dt> |
<dt>Document URI</dt> |
51 |
<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> |
82 |
<div id="parse-errors" class="section"> |
<div id="parse-errors" class="section"> |
83 |
<h2>Parse Errors</h2> |
<h2>Parse Errors</h2> |
84 |
|
|
85 |
<ul> |
<dl> |
86 |
]; |
]; |
87 |
push @nav, ['#parse-errors' => 'Parse Error']; |
push @nav, ['#parse-errors' => 'Parse Error']; |
88 |
|
|
89 |
my $onerror = sub { |
my $onerror = sub { |
90 |
my (%opt) = @_; |
my (%opt) = @_; |
91 |
if ($opt{column} > 0) { |
if ($opt{column} > 0) { |
92 |
print STDOUT qq[<li><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}: ]; |
print STDOUT qq[<dt><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n]; |
93 |
} else { |
} else { |
94 |
$opt{line}--; |
$opt{line}--; |
95 |
print STDOUT qq[<li><a href="#line-$opt{line}">Line $opt{line}</a>: ]; |
print STDOUT qq[<dt><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n]; |
96 |
} |
} |
97 |
print STDOUT qq[@{[htescape $opt{type}]}</li>\n]; |
print STDOUT qq[<dd>@{[htescape $opt{type}]}</dd>\n]; |
98 |
}; |
}; |
99 |
|
|
100 |
$doc = $dom->create_document; |
$doc = $dom->create_document; |
107 |
} |
} |
108 |
|
|
109 |
print STDOUT qq[ |
print STDOUT qq[ |
110 |
</ul> |
</dl> |
111 |
</div> |
</div> |
112 |
]; |
]; |
113 |
} elsif ($input_format eq 'application/xhtml+xml') { |
} elsif ($input_format eq 'application/xhtml+xml') { |
133 |
<div id="parse-errors" class="section"> |
<div id="parse-errors" class="section"> |
134 |
<h2>Parse Errors</h2> |
<h2>Parse Errors</h2> |
135 |
|
|
136 |
<ul> |
<dl> |
137 |
]; |
]; |
138 |
push @nav, ['#parse-errors' => 'Parse Error']; |
push @nav, ['#parse-errors' => 'Parse Error']; |
139 |
|
|
140 |
my $onerror = sub { |
my $onerror = sub { |
141 |
my $err = shift; |
my $err = shift; |
142 |
my $line = $err->location->line_number; |
my $line = $err->location->line_number; |
143 |
print STDOUT qq[<li><a href="#line-$line">Line $line</a> column ]; |
print STDOUT qq[<dt><a href="#line-$line">Line $line</a> column ]; |
144 |
print STDOUT $err->location->column_number, ": "; |
print STDOUT $err->location->column_number, "</dt><dd>"; |
145 |
print STDOUT htescape $err->text, "</li>\n"; |
print STDOUT htescape $err->text, "</dd>\n"; |
146 |
return 1; |
return 1; |
147 |
}; |
}; |
148 |
|
|
151 |
($fh => $dom, $onerror, charset => 'utf-8'); |
($fh => $dom, $onerror, charset => 'utf-8'); |
152 |
|
|
153 |
print STDOUT qq[ |
print STDOUT qq[ |
154 |
</ul> |
</dl> |
155 |
</div> |
</div> |
156 |
]; |
]; |
157 |
} else { |
} else { |
158 |
print STDOUT qq[ |
print STDOUT qq[ |
159 |
</dl> |
</dl> |
160 |
|
</div> |
161 |
|
|
162 |
<div id="result-summary" class="section"> |
<div id="result-summary" class="section"> |
163 |
<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> |
182 |
<div id="document-errors" class="section"> |
<div id="document-errors" class="section"> |
183 |
<h2>Document Errors</h2> |
<h2>Document Errors</h2> |
184 |
|
|
185 |
<ul> |
<dl> |
186 |
]; |
]; |
187 |
push @nav, ['#document-errors' => 'Document Error']; |
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}]}">], |
print STDOUT qq[<dt>] . get_node_link ($opt{node}) . |
193 |
htescape get_node_path ($opt{node}), |
"</dt>\n<dd>", htescape $opt{type}, "</dd>\n"; |
|
"</a>: ", htescape $opt{type}, "</li>\n"; |
|
194 |
}; |
}; |
195 |
|
|
196 |
|
my $elements; |
197 |
if ($el) { |
if ($el) { |
198 |
Whatpm::ContentChecker->check_element ($el, $onerror); |
$elements = Whatpm::ContentChecker->check_element ($el, $onerror); |
199 |
} else { |
} else { |
200 |
Whatpm::ContentChecker->check_document ($doc, $onerror); |
$elements = Whatpm::ContentChecker->check_document ($doc, $onerror); |
201 |
} |
} |
202 |
|
|
203 |
print STDOUT qq[ |
print STDOUT qq[ |
204 |
</ul> |
</dl> |
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 |
320 |
my $node_id = 'node-'.refaddr $child; |
my $node_id = 'node-'.refaddr $child; |
321 |
my $nt = $child->node_type; |
my $nt = $child->node_type; |
322 |
if ($nt == $child->ELEMENT_NODE) { |
if ($nt == $child->ELEMENT_NODE) { |
323 |
$r .= qq'<li id="$node_id"><code>' . htescape ($child->tag_name) . |
my $child_nsuri = $child->namespace_uri; |
324 |
|
$r .= qq[<li id="$node_id" class="tree-element"><code title="@{[defined $child_nsuri ? $child_nsuri : '']}">] . htescape ($child->tag_name) . |
325 |
'</code>'; ## ISSUE: case |
'</code>'; ## ISSUE: case |
326 |
|
|
327 |
if ($child->has_attributes) { |
if ($child->has_attributes) { |
328 |
$r .= '<ul class="attributes">'; |
$r .= '<ul class="attributes">'; |
329 |
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 $_] } |
330 |
@{$child->attributes}) { |
@{$child->attributes}) { |
331 |
$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? |
332 |
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
333 |
} |
} |
334 |
$r .= '</ul>'; |
$r .= '</ul>'; |
336 |
|
|
337 |
if ($node->has_child_nodes) { |
if ($node->has_child_nodes) { |
338 |
$r .= '<ol class="children">'; |
$r .= '<ol class="children">'; |
339 |
unshift @node, @{$child->child_nodes}, '</ol>'; |
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
340 |
|
} else { |
341 |
|
$r .= '</li>'; |
342 |
} |
} |
343 |
} elsif ($nt == $child->TEXT_NODE) { |
} elsif ($nt == $child->TEXT_NODE) { |
344 |
$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>'; |
345 |
} elsif ($nt == $child->CDATA_SECTION_NODE) { |
} elsif ($nt == $child->CDATA_SECTION_NODE) { |
346 |
$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>'; |
347 |
} elsif ($nt == $child->COMMENT_NODE) { |
} elsif ($nt == $child->COMMENT_NODE) { |
348 |
$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>'; |
349 |
} elsif ($nt == $child->DOCUMENT_NODE) { |
} elsif ($nt == $child->DOCUMENT_NODE) { |
350 |
$r .= qq'<li id="$node_id">Document</li>'; |
$r .= qq'<li id="$node_id" class="tree-document">Document'; |
351 |
if ($child->has_child_nodes) { |
if ($child->has_child_nodes) { |
352 |
$r .= '<ol>'; |
$r .= '<ol>'; |
353 |
unshift @node, @{$child->child_nodes}, '</ol>'; |
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
354 |
} |
} |
355 |
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) { |
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) { |
356 |
$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">'; |
357 |
$r .= '<li>Name = <q>@{[htescape ($child->name)]}</q></li>'; |
$r .= qq[<li class="tree-doctype-name">Name = <q>@{[htescape ($child->name)]}</q></li>]; |
358 |
$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>]; |
359 |
$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>]; |
360 |
$r .= '</ul></li>'; |
$r .= '</ul></li>'; |
361 |
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) { |
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) { |
362 |
$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>'; |
|
363 |
} else { |
} else { |
364 |
$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 |
365 |
} |
} |
366 |
} |
} |
367 |
|
|
395 |
return join '/', @r; |
return join '/', @r; |
396 |
} # get_node_path |
} # get_node_path |
397 |
|
|
398 |
|
sub get_node_link ($) { |
399 |
|
return qq[<a href="#node-@{[refaddr $_[0]]}">] . |
400 |
|
htescape (get_node_path ($_[0])) . qq[</a>]; |
401 |
|
} # get_node_link |
402 |
|
|
403 |
=head1 AUTHOR |
=head1 AUTHOR |
404 |
|
|
405 |
Wakaba <w@suika.fam.cx>. |
Wakaba <w@suika.fam.cx>. |