5 |
/home/wakaba/work/manakai/lib |
/home/wakaba/work/manakai/lib |
6 |
/home/wakaba/public_html/-temp/wiki/lib]; |
/home/wakaba/public_html/-temp/wiki/lib]; |
7 |
use CGI::Carp qw[fatalsToBrowser]; |
use CGI::Carp qw[fatalsToBrowser]; |
8 |
use Time::HiRes qw/time/; |
use Scalar::Util qw[refaddr]; |
9 |
|
|
10 |
use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module |
use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module |
11 |
|
|
12 |
|
sub htescape ($) { |
13 |
|
my $s = $_[0]; |
14 |
|
$s =~ s/&/&/g; |
15 |
|
$s =~ s/</</g; |
16 |
|
$s =~ s/>/>/g; |
17 |
|
$s =~ s/"/"/g; |
18 |
|
$s =~ s!([\x00-\x09\x0B-\x1F\x7F-\x80])!sprintf '<var>U+%04X</var>', ord $1!ge; |
19 |
|
return $s; |
20 |
|
} # htescape |
21 |
|
|
22 |
my $http = SuikaWiki::Input::HTTP->new; |
my $http = SuikaWiki::Input::HTTP->new; |
23 |
|
|
24 |
## TODO: _charset_ |
## TODO: _charset_ |
25 |
|
|
26 |
my @mode = split m#/#, scalar $http->meta_variable ('PATH_INFO'), -1; |
if ($http->meta_variable ('PATH_INFO') ne '/') { |
27 |
shift @mode if @mode and $mode[0] == ''; |
print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; |
28 |
## TODO: decode unreserved characters |
exit; |
29 |
|
} |
30 |
|
|
31 |
|
my $input_format = $http->parameter ('i') || 'text/html'; |
32 |
|
my $inner_html_element = $http->parameter ('e'); |
33 |
|
my $input_uri = 'thismessage:/'; |
34 |
|
|
35 |
my $s = $http->parameter ('s'); |
my $s = $http->parameter ('s'); |
36 |
if (length $s > 1000_000) { |
if (length $s > 1000_000) { |
37 |
print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long"; |
print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long"; |
38 |
exit; |
exit; |
39 |
} |
} |
40 |
my $char_length = length $s; |
|
41 |
my %time; |
load_text_catalog ('en'); ## TODO: conneg |
42 |
my $time1; |
|
43 |
my $time2; |
my @nav; |
44 |
|
print STDOUT qq[Content-Type: text/html; charset=utf-8 |
45 |
|
|
46 |
|
<!DOCTYPE html> |
47 |
|
<html lang="en"> |
48 |
|
<head> |
49 |
|
<title>Web Document Conformance Checker (BETA)</title> |
50 |
|
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
51 |
|
</head> |
52 |
|
<body> |
53 |
|
<h1>Web Document Conformance Checker (<em>beta</em>)</h1> |
54 |
|
|
55 |
|
<div id="document-info" class="section"> |
56 |
|
<dl> |
57 |
|
<dt>Document URI</dt> |
58 |
|
<dd><code class="URI" lang=""><<a href="@{[htescape $input_uri]}">@{[htescape $input_uri]}</a>></code></dd> |
59 |
|
<dt>Internet Media Type</dt> |
60 |
|
<dd><code class="MIME" lang="en">@{[htescape $input_format]}</code></dd> |
61 |
|
]; # no </dl> yet |
62 |
|
push @nav, ['#document-info' => 'Information']; |
63 |
|
|
64 |
require Message::DOM::DOMImplementation; |
require Message::DOM::DOMImplementation; |
65 |
my $dom = Message::DOM::DOMImplementation->____new; |
my $dom = Message::DOM::DOMImplementation->____new; |
|
# $| = 1; |
|
66 |
my $doc; |
my $doc; |
67 |
my $el; |
my $el; |
68 |
|
|
69 |
if (@mode == 3 and $mode[0] eq 'html' and |
if ($input_format eq 'text/html') { |
70 |
($mode[2] eq 'html' or $mode[2] eq 'test')) { |
require Encode; |
71 |
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
require Whatpm::HTML; |
72 |
|
|
73 |
require Encode; |
$s = Encode::decode ('utf-8', $s); |
74 |
require Whatpm::HTML; |
|
75 |
|
print STDOUT qq[ |
76 |
$time1 = time; |
<dt>Character Encoding</dt> |
77 |
$s = Encode::decode ('utf-8', $s); |
<dd>(none)</dd> |
78 |
$time2 = time; |
</dl> |
79 |
$time{decode} = $time2 - $time1; |
</div> |
80 |
|
|
81 |
|
<div id="source-string" class="section"> |
82 |
print STDOUT "#errors\n"; |
<h2>Document Source</h2> |
83 |
|
]; |
84 |
|
push @nav, ['#source-string' => 'Source']; |
85 |
|
print_source_string (\$s); |
86 |
|
print STDOUT qq[ |
87 |
|
</div> |
88 |
|
|
89 |
|
<div id="parse-errors" class="section"> |
90 |
|
<h2>Parse Errors</h2> |
91 |
|
|
92 |
|
<dl> |
93 |
|
]; |
94 |
|
push @nav, ['#parse-errors' => 'Parse Error']; |
95 |
|
|
96 |
my $onerror = sub { |
my $onerror = sub { |
97 |
my (%opt) = @_; |
my (%opt) = @_; |
98 |
print STDOUT "$opt{line},$opt{column},$opt{type}\n"; |
my ($cls, $msg) = get_text ($opt{type}, $opt{level}); |
99 |
|
if ($opt{column} > 0) { |
100 |
|
print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n]; |
101 |
|
} else { |
102 |
|
$opt{line} = $opt{line} - 1 || 1; |
103 |
|
print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n]; |
104 |
|
} |
105 |
|
$opt{type} =~ tr/ /-/; |
106 |
|
$opt{type} =~ s/\|/%7C/g; |
107 |
|
$msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]]; |
108 |
|
print STDOUT qq[<dd class="$cls">$msg</dd>\n]; |
109 |
}; |
}; |
110 |
|
|
111 |
$doc = $dom->create_document; |
$doc = $dom->create_document; |
112 |
$time1 = time; |
if (defined $inner_html_element and length $inner_html_element) { |
|
if (length $mode[1]) { |
|
113 |
$el = $doc->create_element_ns |
$el = $doc->create_element_ns |
114 |
('http://www.w3.org/1999/xhtml', [undef, $mode[1]]); |
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
115 |
Whatpm::HTML->set_inner_html ($el, $s, $onerror); |
Whatpm::HTML->set_inner_html ($el, $s, $onerror); |
116 |
} else { |
} else { |
117 |
Whatpm::HTML->parse_string ($s => $doc, $onerror); |
Whatpm::HTML->parse_string ($s => $doc, $onerror); |
118 |
} |
} |
|
$time2 = time; |
|
|
$time{parse} = $time2 - $time1; |
|
119 |
|
|
120 |
print "#document\n"; |
print STDOUT qq[ |
121 |
|
</dl> |
122 |
|
</div> |
123 |
|
]; |
124 |
|
} elsif ($input_format eq 'application/xhtml+xml') { |
125 |
|
require Message::DOM::XMLParserTemp; |
126 |
|
require Encode; |
127 |
|
|
128 |
|
my $t = Encode::decode ('utf-8', $s); |
129 |
|
|
130 |
|
print STDOUT qq[ |
131 |
|
<dt>Character Encoding</dt> |
132 |
|
<dd>(none)</dd> |
133 |
|
</dl> |
134 |
|
</div> |
135 |
|
|
136 |
|
<div id="source-string" class="section"> |
137 |
|
<h2>Document Source</h2> |
138 |
|
]; |
139 |
|
push @nav, ['#source-string' => 'Source']; |
140 |
|
print_source_string (\$t); |
141 |
|
print STDOUT qq[ |
142 |
|
</div> |
143 |
|
|
144 |
my $out; |
<div id="parse-errors" class="section"> |
145 |
if ($mode[2] eq 'html') { |
<h2>Parse Errors</h2> |
|
$time1 = time; |
|
|
$out = Whatpm::HTML->get_inner_html ($el || $doc); |
|
|
$time2 = time; |
|
|
$time{serialize_html} = $time2 - $time1; |
|
|
} else { # test |
|
|
$time1 = time; |
|
|
$out = test_serialize ($el || $doc); |
|
|
$time2 = time; |
|
|
$time{serialize_test} = $time2 - $time1; |
|
|
} |
|
|
print STDOUT Encode::encode ('utf-8', $$out); |
|
|
print STDOUT "\n"; |
|
|
} elsif (@mode == 3 and $mode[0] eq 'xhtml' and |
|
|
($mode[2] eq 'html' or $mode[2] eq 'test')) { |
|
|
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
|
146 |
|
|
147 |
require Message::DOM::XMLParserTemp; |
<dl>]; |
148 |
print STDOUT "#errors\n"; |
push @nav, ['#parse-errors' => 'Parse Error']; |
149 |
|
|
150 |
my $onerror = sub { |
my $onerror = sub { |
151 |
my $err = shift; |
my $err = shift; |
152 |
print STDOUT $err->location->line_number, ","; |
my $line = $err->location->line_number; |
153 |
print STDOUT $err->location->column_number, ","; |
print STDOUT qq[<dt><a href="#line-$line">Line $line</a> column ]; |
154 |
print STDOUT $err->text, "\n"; |
print STDOUT $err->location->column_number, "</dt><dd>"; |
155 |
|
print STDOUT htescape $err->text, "</dd>\n"; |
156 |
return 1; |
return 1; |
157 |
}; |
}; |
158 |
|
|
159 |
open my $fh, '<', \$s; |
open my $fh, '<', \$s; |
|
my $time1 = time; |
|
160 |
$doc = Message::DOM::XMLParserTemp->parse_byte_stream |
$doc = Message::DOM::XMLParserTemp->parse_byte_stream |
161 |
($fh => $dom, $onerror, charset => 'utf-8'); |
($fh => $dom, $onerror, charset => 'utf-8'); |
|
my $time2 = time; |
|
|
$time{parse_xml} = $time2 - $time1; |
|
162 |
|
|
163 |
print "#document\n"; |
print STDOUT qq[</dl> |
164 |
|
</div> |
165 |
|
]; |
166 |
|
} else { |
167 |
|
print STDOUT qq[ |
168 |
|
</dl> |
169 |
|
</div> |
170 |
|
|
171 |
|
<div id="result-summary" class="section"> |
172 |
|
<p><em>Media type <code class="MIME" lang="en">@{[htescape $input_format]}</code> is not supported!</em></p> |
173 |
|
</div> |
174 |
|
]; |
175 |
|
push @nav, ['#result-summary' => 'Result']; |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
my $out; |
if (defined $doc or defined $el) { |
180 |
if ($mode[2] eq 'html') { |
print STDOUT qq[ |
181 |
## TODO: Use XHTML serializer |
<div id="document-tree" class="section"> |
182 |
#$out = Whatpm::HTML->get_inner_html ($doc); |
<h2>Document Tree</h2> |
183 |
} else { # test |
]; |
184 |
$time1 = time; |
push @nav, ['#document-tree' => 'Tree']; |
185 |
$out = test_serialize ($doc); |
|
186 |
$time2 = time; |
print_document_tree ($el || $doc); |
187 |
$time{serialize_test} = $time2 - $time1; |
|
188 |
} |
print STDOUT qq[ |
189 |
print STDOUT Encode::encode ('utf-8', $$out); |
</div> |
190 |
print STDOUT "\n"; |
|
191 |
} else { |
<div id="document-errors" class="section"> |
192 |
print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n404"; |
<h2>Document Errors</h2> |
193 |
exit; |
|
194 |
} |
<dl>]; |
195 |
|
push @nav, ['#document-errors' => 'Document Error']; |
196 |
|
|
|
if ($http->parameter ('dom5')) { |
|
197 |
require Whatpm::ContentChecker; |
require Whatpm::ContentChecker; |
198 |
my $onerror = sub { |
my $onerror = sub { |
199 |
my %opt = @_; |
my %opt = @_; |
200 |
print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n"; |
my ($cls, $msg) = get_text ($opt{type}, $opt{level}); |
201 |
|
$opt{type} = $opt{level} . ':' . $opt{type} if defined $opt{level}; |
202 |
|
$opt{type} =~ tr/ /-/; |
203 |
|
$opt{type} =~ s/\|/%7C/g; |
204 |
|
$msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]]; |
205 |
|
print STDOUT qq[<dt class="$cls">] . get_node_link ($opt{node}) . |
206 |
|
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
207 |
}; |
}; |
208 |
print STDOUT "#domerrors\n"; |
|
209 |
$time1 = time; |
my $elements; |
210 |
if ($el) { |
if ($el) { |
211 |
Whatpm::ContentChecker->check_element ($el, $onerror); |
$elements = Whatpm::ContentChecker->check_element ($el, $onerror); |
212 |
} else { |
} else { |
213 |
Whatpm::ContentChecker->check_document ($doc, $onerror); |
$elements = Whatpm::ContentChecker->check_document ($doc, $onerror); |
214 |
|
} |
215 |
|
|
216 |
|
print STDOUT qq[</dl> |
217 |
|
</div> |
218 |
|
]; |
219 |
|
|
220 |
|
if (@{$elements->{table}}) { |
221 |
|
require JSON; |
222 |
|
|
223 |
|
print STDOUT qq[ |
224 |
|
<div id="tables" class="section"> |
225 |
|
<h2>Tables</h2> |
226 |
|
|
227 |
|
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]--> |
228 |
|
<script src="../table-script.js" type="text/javascript"></script> |
229 |
|
<noscript> |
230 |
|
<p><em>Structure of tables are visualized here if scripting is enabled.</em></p> |
231 |
|
</noscript> |
232 |
|
]; |
233 |
|
|
234 |
|
my $i = 0; |
235 |
|
for my $table_el (@{$elements->{table}}) { |
236 |
|
$i++; |
237 |
|
print STDOUT qq[<div class="section" id="table-$i"><h3>] . |
238 |
|
get_node_link ($table_el) . q[</h3>]; |
239 |
|
|
240 |
|
my $table = Whatpm::HTMLTable->form_table ($table_el); |
241 |
|
|
242 |
|
for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) { |
243 |
|
next unless $_; |
244 |
|
delete $_->{element}; |
245 |
|
} |
246 |
|
|
247 |
|
for (@{$table->{row_group}}) { |
248 |
|
next unless $_; |
249 |
|
next unless $_->{element}; |
250 |
|
$_->{type} = $_->{element}->manakai_local_name; |
251 |
|
delete $_->{element}; |
252 |
|
} |
253 |
|
|
254 |
|
for (@{$table->{cell}}) { |
255 |
|
next unless $_; |
256 |
|
for (@{$_}) { |
257 |
|
next unless $_; |
258 |
|
for (@$_) { |
259 |
|
$_->{id} = refaddr $_->{element} if defined $_->{element}; |
260 |
|
delete $_->{element}; |
261 |
|
} |
262 |
|
} |
263 |
|
} |
264 |
|
|
265 |
|
print STDOUT '</div><script type="text/javascript">tableToCanvas ('; |
266 |
|
print STDOUT JSON::objToJson ($table); |
267 |
|
print STDOUT qq[, document.getElementById ('table-$i'));</script>]; |
268 |
|
} |
269 |
|
|
270 |
|
print STDOUT qq[</div>]; |
271 |
|
} |
272 |
|
|
273 |
|
if (keys %{$elements->{term}}) { |
274 |
|
print STDOUT qq[ |
275 |
|
<div id="terms" class="section"> |
276 |
|
<h2>Terms</h2> |
277 |
|
|
278 |
|
<dl> |
279 |
|
]; |
280 |
|
for my $term (sort {$a cmp $b} keys %{$elements->{term}}) { |
281 |
|
print STDOUT qq[<dt>@{[htescape $term]}</dt>]; |
282 |
|
for (@{$elements->{term}->{$term}}) { |
283 |
|
print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>]; |
284 |
|
} |
285 |
|
} |
286 |
|
print STDOUT qq[</dl></div>]; |
287 |
} |
} |
|
$time2 = time; |
|
|
$time{check} = $time2 - $time1; |
|
288 |
} |
} |
289 |
|
|
290 |
print STDOUT "#log\n"; |
## TODO: Show result |
291 |
for (qw/decode parse parse_xml serialize_html serialize_xml serialize_test |
|
292 |
check/) { |
print STDOUT qq[ |
293 |
next unless defined $time{$_}; |
<ul class="navigation" id="nav-items"> |
294 |
print STDOUT { |
]; |
295 |
decode => 'bytes->chars', |
for (@nav) { |
296 |
parse => 'html5(chars)->dom5', |
print STDOUT qq[<li><a href="$_->[0]">$_->[1]</a></li>]; |
|
parse_xml => 'xml1(chars)->dom5', |
|
|
serialize_html => 'dom5->html5(char)', |
|
|
serialize_xml => 'dom5->xml1(char)', |
|
|
serialize_test => 'dom5->test(char)', |
|
|
check => 'dom5 check', |
|
|
}->{$_}; |
|
|
print STDOUT "\t", $time{$_}, "s\n"; |
|
|
open my $file, '>>', ".manakai-$_.txt" or die ".manakai-$_.txt: $!"; |
|
|
print $file $char_length, "\t", $time{$_}, "\n"; |
|
297 |
} |
} |
298 |
|
print STDOUT qq[ |
299 |
|
</ul> |
300 |
|
</body> |
301 |
|
</html> |
302 |
|
]; |
303 |
|
|
304 |
exit; |
exit; |
305 |
|
|
306 |
sub test_serialize ($) { |
sub print_source_string ($) { |
307 |
|
my $s = $_[0]; |
308 |
|
my $i = 1; |
309 |
|
print STDOUT qq[<ol lang="">\n]; |
310 |
|
if (length $$s) { |
311 |
|
while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { |
312 |
|
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
313 |
|
$i++; |
314 |
|
} |
315 |
|
if ($$s =~ /\G([^\x0A]+)/gc) { |
316 |
|
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
317 |
|
} |
318 |
|
} else { |
319 |
|
print STDOUT q[<li id="line-1"></li>]; |
320 |
|
} |
321 |
|
print STDOUT "</ol>"; |
322 |
|
} # print_input_string |
323 |
|
|
324 |
|
sub print_document_tree ($) { |
325 |
my $node = shift; |
my $node = shift; |
326 |
my $r = ''; |
my $r = '<ol class="xoxo">'; |
327 |
|
|
328 |
my @node = map { [$_, ''] } @{$node->child_nodes}; |
my @node = ($node); |
329 |
while (@node) { |
while (@node) { |
330 |
my $child = shift @node; |
my $child = shift @node; |
331 |
my $nt = $child->[0]->node_type; |
unless (ref $child) { |
332 |
if ($nt == $child->[0]->ELEMENT_NODE) { |
$r .= $child; |
333 |
$r .= '| ' . $child->[1] . '<' . $child->[0]->tag_name . ">\x0A"; ## ISSUE: case? |
next; |
334 |
|
} |
335 |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value] } |
|
336 |
@{$child->[0]->attributes}) { |
my $node_id = 'node-'.refaddr $child; |
337 |
$r .= '| ' . $child->[1] . ' ' . $attr->[0] . '="'; ## ISSUE: case? |
my $nt = $child->node_type; |
338 |
$r .= $attr->[1] . '"' . "\x0A"; |
if ($nt == $child->ELEMENT_NODE) { |
339 |
|
my $child_nsuri = $child->namespace_uri; |
340 |
|
$r .= qq[<li id="$node_id" class="tree-element"><code title="@{[defined $child_nsuri ? $child_nsuri : '']}">] . htescape ($child->tag_name) . |
341 |
|
'</code>'; ## ISSUE: case |
342 |
|
|
343 |
|
if ($child->has_attributes) { |
344 |
|
$r .= '<ul class="attributes">'; |
345 |
|
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] } |
346 |
|
@{$child->attributes}) { |
347 |
|
$r .= qq[<li id="$attr->[3]" class="tree-attribute"><code title="@{[defined $_->[2] ? $_->[2] : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case? |
348 |
|
$r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children |
349 |
|
} |
350 |
|
$r .= '</ul>'; |
351 |
|
} |
352 |
|
|
353 |
|
if ($child->has_child_nodes) { |
354 |
|
$r .= '<ol class="children">'; |
355 |
|
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
356 |
|
} else { |
357 |
|
$r .= '</li>'; |
358 |
|
} |
359 |
|
} elsif ($nt == $child->TEXT_NODE) { |
360 |
|
$r .= qq'<li id="$node_id" class="tree-text"><q lang="">' . htescape ($child->data) . '</q></li>'; |
361 |
|
} elsif ($nt == $child->CDATA_SECTION_NODE) { |
362 |
|
$r .= qq'<li id="$node_id" class="tree-cdata"><code><[CDATA[</code><q lang="">' . htescape ($child->data) . '</q><code>]]></code></li>'; |
363 |
|
} elsif ($nt == $child->COMMENT_NODE) { |
364 |
|
$r .= qq'<li id="$node_id" class="tree-comment"><code><!--</code><q lang="">' . htescape ($child->data) . '</q><code>--></code></li>'; |
365 |
|
} elsif ($nt == $child->DOCUMENT_NODE) { |
366 |
|
$r .= qq'<li id="$node_id" class="tree-document">Document'; |
367 |
|
$r .= qq[<ul class="attributes">]; |
368 |
|
$r .= qq[<li>@{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}</li>]; |
369 |
|
$r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>]; |
370 |
|
$r .= qq[</ul>]; |
371 |
|
if ($child->has_child_nodes) { |
372 |
|
$r .= '<ol class="children">'; |
373 |
|
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
374 |
} |
} |
375 |
|
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) { |
376 |
unshift @node, |
$r .= qq'<li id="$node_id" class="tree-doctype"><code><!DOCTYPE></code><ul class="attributes">'; |
377 |
map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes}; |
$r .= qq[<li class="tree-doctype-name">Name = <q>@{[htescape ($child->name)]}</q></li>]; |
378 |
} elsif ($nt == $child->[0]->TEXT_NODE) { |
$r .= qq[<li class="tree-doctype-publicid">Public identifier = <q>@{[htescape ($child->public_id)]}</q></li>]; |
379 |
$r .= '| ' . $child->[1] . '"' . $child->[0]->data . '"' . "\x0A"; |
$r .= qq[<li class="tree-doctype-systemid">System identifier = <q>@{[htescape ($child->system_id)]}</q></li>]; |
380 |
} elsif ($nt == $child->[0]->CDATA_SECTION_NODE) { |
$r .= '</ul></li>'; |
381 |
$r .= '| ' . $child->[1] . '<![CDATA[' . $child->[0]->data . "]]>\x0A"; |
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) { |
382 |
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
$r .= qq'<li id="$node_id" class="tree-id"><code><?@{[htescape ($child->target)]}</code> <q>@{[htescape ($child->data)]}</q><code>?></code></li>'; |
|
$r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
|
|
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
|
|
$r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name . ">\x0A"; |
|
|
} elsif ($nt == $child->[0]->PROCESSING_INSTRUCTION_NODE) { |
|
|
$r .= '| ' . $child->[1] . '<?' . $child->[0]->target . ' ' . |
|
|
$child->[0]->data . "?>\x0A"; |
|
383 |
} else { |
} else { |
384 |
$r .= '| ' . $child->[1] . $child->[0]->node_type . "\x0A"; # error |
$r .= qq'<li id="$node_id" class="tree-unknown">@{[$child->node_type]} @{[htescape ($child->node_name)]}</li>'; # error |
385 |
} |
} |
386 |
} |
} |
387 |
|
|
388 |
return \$r; |
$r .= '</ol>'; |
389 |
} # test_serialize |
print STDOUT $r; |
390 |
|
} # print_document_tree |
391 |
|
|
392 |
sub get_node_path ($) { |
sub get_node_path ($) { |
393 |
my $node = shift; |
my $node = shift; |
415 |
return join '/', @r; |
return join '/', @r; |
416 |
} # get_node_path |
} # get_node_path |
417 |
|
|
418 |
|
sub get_node_link ($) { |
419 |
|
return qq[<a href="#node-@{[refaddr $_[0]]}">] . |
420 |
|
htescape (get_node_path ($_[0])) . qq[</a>]; |
421 |
|
} # get_node_link |
422 |
|
|
423 |
|
{ |
424 |
|
my $Msg = {}; |
425 |
|
|
426 |
|
sub load_text_catalog ($) { |
427 |
|
my $lang = shift; # MUST be a canonical lang name |
428 |
|
open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!"; |
429 |
|
while (<$file>) { |
430 |
|
if (s/^([^;]+);([^;]*);//) { |
431 |
|
my ($type, $cls, $msg) = ($1, $2, $_); |
432 |
|
$msg =~ tr/\x0D\x0A//d; |
433 |
|
$Msg->{$type} = [$cls, $msg]; |
434 |
|
} |
435 |
|
} |
436 |
|
} # load_text_catalog |
437 |
|
|
438 |
|
sub get_text ($) { |
439 |
|
my ($type, $level) = @_; |
440 |
|
$type = $level . ':' . $type if defined $level; |
441 |
|
my @arg; |
442 |
|
{ |
443 |
|
if (defined $Msg->{$type}) { |
444 |
|
my $msg = $Msg->{$type}->[1]; |
445 |
|
$msg =~ s/\$([0-9]+)/defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'/ge; |
446 |
|
return ($Msg->{$type}->[0], $msg); |
447 |
|
} elsif ($type =~ s/:([^:]*)$//) { |
448 |
|
unshift @arg, $1; |
449 |
|
redo; |
450 |
|
} |
451 |
|
} |
452 |
|
return ('', htescape ($_[0])); |
453 |
|
} # get_text |
454 |
|
|
455 |
|
} |
456 |
|
|
457 |
=head1 AUTHOR |
=head1 AUTHOR |
458 |
|
|
459 |
Wakaba <w@suika.fam.cx>. |
Wakaba <w@suika.fam.cx>. |