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; |
my $input_format = $http->parameter ('i') || 'text/html'; |
27 |
shift @mode if @mode and $mode[0] == ''; |
my $inner_html_element = $http->parameter ('e'); |
28 |
## TODO: decode unreserved characters |
my $input_uri = 'thismessage:/'; |
29 |
|
|
30 |
my $s = $http->parameter ('s'); |
my $s = $http->parameter ('s'); |
31 |
if (length $s > 1000_000) { |
if (length $s > 1000_000) { |
32 |
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"; |
33 |
exit; |
exit; |
34 |
} |
} |
35 |
my $char_length = length $s; |
|
36 |
my %time; |
load_text_catalog ('en'); ## TODO: conneg |
37 |
my $time1; |
|
38 |
my $time2; |
my @nav; |
39 |
|
print STDOUT qq[Content-Type: text/html; charset=utf-8 |
40 |
|
|
41 |
|
<!DOCTYPE html> |
42 |
|
<html lang="en"> |
43 |
|
<head> |
44 |
|
<title>Web Document Conformance Checker (BETA)</title> |
45 |
|
<link rel="stylesheet" href="../cc-style.css" type="text/css"> |
46 |
|
</head> |
47 |
|
<body> |
48 |
|
<h1>Web Document Conformance Checker (<em>beta</em>)</h1> |
49 |
|
|
50 |
|
<div id="document-info" class="section"> |
51 |
|
<dl> |
52 |
|
<dt>Document URI</dt> |
53 |
|
<dd><code class="URI" lang=""><<a href="@{[htescape $input_uri]}">@{[htescape $input_uri]}</a>></code></dd> |
54 |
|
<dt>Internet Media Type</dt> |
55 |
|
<dd><code class="MIME" lang="en">@{[htescape $input_format]}</code></dd> |
56 |
|
]; # 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; |
|
# $| = 1; |
|
61 |
my $doc; |
my $doc; |
62 |
my $el; |
my $el; |
63 |
|
|
64 |
if (@mode == 3 and $mode[0] eq 'html' and |
if ($input_format eq 'text/html') { |
65 |
($mode[2] eq 'html' or $mode[2] eq 'test')) { |
require Encode; |
66 |
print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
require Whatpm::HTML; |
67 |
|
|
68 |
require Encode; |
$s = Encode::decode ('utf-8', $s); |
69 |
require Whatpm::HTML; |
|
70 |
|
print STDOUT qq[ |
71 |
$time1 = time; |
<dt>Character Encoding</dt> |
72 |
$s = Encode::decode ('utf-8', $s); |
<dd>(none)</dd> |
73 |
$time2 = time; |
</dl> |
74 |
$time{decode} = $time2 - $time1; |
</div> |
75 |
|
|
76 |
|
<div id="source-string" class="section"> |
77 |
print STDOUT "#errors\n"; |
<h2>Document Source</h2> |
78 |
|
]; |
79 |
|
push @nav, ['#source-string' => 'Source']; |
80 |
|
print_source_string (\$s); |
81 |
|
print STDOUT qq[ |
82 |
|
</div> |
83 |
|
|
84 |
|
<div id="parse-errors" class="section"> |
85 |
|
<h2>Parse Errors</h2> |
86 |
|
|
87 |
|
<dl> |
88 |
|
]; |
89 |
|
push @nav, ['#parse-errors' => 'Parse Error']; |
90 |
|
|
91 |
my $onerror = sub { |
my $onerror = sub { |
92 |
my (%opt) = @_; |
my (%opt) = @_; |
93 |
print STDOUT "$opt{line},$opt{column},$opt{type}\n"; |
my ($cls, $msg) = get_text ($opt{type}, $opt{level}); |
94 |
|
if ($opt{column} > 0) { |
95 |
|
print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n]; |
96 |
|
} else { |
97 |
|
$opt{line} = $opt{line} - 1 || 1; |
98 |
|
print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n]; |
99 |
|
} |
100 |
|
print STDOUT qq[<dd class="$cls">$msg</dd>\n]; |
101 |
}; |
}; |
102 |
|
|
103 |
$doc = $dom->create_document; |
$doc = $dom->create_document; |
104 |
$time1 = time; |
if (defined $inner_html_element and length $inner_html_element) { |
|
if (length $mode[1]) { |
|
105 |
$el = $doc->create_element_ns |
$el = $doc->create_element_ns |
106 |
('http://www.w3.org/1999/xhtml', [undef, $mode[1]]); |
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
107 |
Whatpm::HTML->set_inner_html ($el, $s, $onerror); |
Whatpm::HTML->set_inner_html ($el, $s, $onerror); |
108 |
} else { |
} else { |
109 |
Whatpm::HTML->parse_string ($s => $doc, $onerror); |
Whatpm::HTML->parse_string ($s => $doc, $onerror); |
110 |
} |
} |
|
$time2 = time; |
|
|
$time{parse} = $time2 - $time1; |
|
111 |
|
|
112 |
print "#document\n"; |
print STDOUT qq[ |
113 |
|
</dl> |
114 |
|
</div> |
115 |
|
]; |
116 |
|
} elsif ($input_format eq 'application/xhtml+xml') { |
117 |
|
require Message::DOM::XMLParserTemp; |
118 |
|
require Encode; |
119 |
|
|
120 |
|
my $t = Encode::decode ('utf-8', $s); |
121 |
|
|
122 |
|
print STDOUT qq[ |
123 |
|
<dt>Character Encoding</dt> |
124 |
|
<dd>(none)</dd> |
125 |
|
</dl> |
126 |
|
</div> |
127 |
|
|
128 |
|
<div id="source-string" class="section"> |
129 |
|
<h2>Document Source</h2> |
130 |
|
]; |
131 |
|
push @nav, ['#source-string' => 'Source']; |
132 |
|
print_source_string (\$t); |
133 |
|
print STDOUT qq[ |
134 |
|
</div> |
135 |
|
|
136 |
my $out; |
<div id="parse-errors" class="section"> |
137 |
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"; |
|
138 |
|
|
139 |
require Message::DOM::XMLParserTemp; |
<dl>]; |
140 |
print STDOUT "#errors\n"; |
push @nav, ['#parse-errors' => 'Parse Error']; |
141 |
|
|
142 |
my $onerror = sub { |
my $onerror = sub { |
143 |
my $err = shift; |
my $err = shift; |
144 |
print STDOUT $err->location->line_number, ","; |
my $line = $err->location->line_number; |
145 |
print STDOUT $err->location->column_number, ","; |
print STDOUT qq[<dt><a href="#line-$line">Line $line</a> column ]; |
146 |
print STDOUT $err->text, "\n"; |
print STDOUT $err->location->column_number, "</dt><dd>"; |
147 |
|
print STDOUT htescape $err->text, "</dd>\n"; |
148 |
return 1; |
return 1; |
149 |
}; |
}; |
150 |
|
|
151 |
open my $fh, '<', \$s; |
open my $fh, '<', \$s; |
|
my $time1 = time; |
|
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'); |
|
my $time2 = time; |
|
|
$time{parse_xml} = $time2 - $time1; |
|
154 |
|
|
155 |
print "#document\n"; |
print STDOUT qq[</dl> |
156 |
|
</div> |
157 |
|
]; |
158 |
|
} else { |
159 |
|
print STDOUT qq[ |
160 |
|
</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> |
165 |
|
</div> |
166 |
|
]; |
167 |
|
push @nav, ['#result-summary' => 'Result']; |
168 |
|
} |
169 |
|
|
|
my $out; |
|
|
if ($mode[2] eq 'html') { |
|
|
## TODO: Use XHTML serializer |
|
|
#$out = Whatpm::HTML->get_inner_html ($doc); |
|
|
} else { # test |
|
|
$time1 = time; |
|
|
$out = test_serialize ($doc); |
|
|
$time2 = time; |
|
|
$time{serialize_test} = $time2 - $time1; |
|
|
} |
|
|
print STDOUT Encode::encode ('utf-8', $$out); |
|
|
print STDOUT "\n"; |
|
|
} else { |
|
|
print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n404"; |
|
|
exit; |
|
|
} |
|
170 |
|
|
171 |
if ($http->parameter ('dom5')) { |
if (defined $doc or defined $el) { |
172 |
|
print STDOUT qq[ |
173 |
|
<div id="document-tree" class="section"> |
174 |
|
<h2>Document Tree</h2> |
175 |
|
]; |
176 |
|
push @nav, ['#document-tree' => 'Tree']; |
177 |
|
|
178 |
|
print_document_tree ($el || $doc); |
179 |
|
|
180 |
|
print STDOUT qq[ |
181 |
|
</div> |
182 |
|
|
183 |
|
<div id="document-errors" class="section"> |
184 |
|
<h2>Document Errors</h2> |
185 |
|
|
186 |
|
<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 get_node_path ($opt{node}) . ';' . $opt{type} . "\n"; |
my ($cls, $msg) = get_text ($opt{type}, $opt{level}); |
193 |
|
print STDOUT qq[<dt class="$cls">] . get_node_link ($opt{node}) . |
194 |
|
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
195 |
}; |
}; |
196 |
print STDOUT "#domerrors\n"; |
|
197 |
$time1 = time; |
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[</dl> |
205 |
|
</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 |
} |
} |
|
$time2 = time; |
|
|
$time{check} = $time2 - $time1; |
|
276 |
} |
} |
277 |
|
|
278 |
print STDOUT "#log\n"; |
## TODO: Show result |
279 |
for (qw/decode parse parse_xml serialize_html serialize_xml serialize_test |
|
280 |
check/) { |
print STDOUT qq[ |
281 |
next unless defined $time{$_}; |
<ul class="navigation" id="nav-items"> |
282 |
print STDOUT { |
]; |
283 |
decode => 'bytes->chars', |
for (@nav) { |
284 |
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"; |
|
285 |
} |
} |
286 |
|
print STDOUT qq[ |
287 |
|
</ul> |
288 |
|
</body> |
289 |
|
</html> |
290 |
|
]; |
291 |
|
|
292 |
exit; |
exit; |
293 |
|
|
294 |
sub test_serialize ($) { |
sub print_source_string ($) { |
295 |
|
my $s = $_[0]; |
296 |
|
my $i = 1; |
297 |
|
print STDOUT qq[<ol lang="">\n]; |
298 |
|
if (length $$s) { |
299 |
|
while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { |
300 |
|
print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n"; |
301 |
|
$i++; |
302 |
|
} |
303 |
|
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>"; |
310 |
|
} # print_input_string |
311 |
|
|
312 |
|
sub print_document_tree ($) { |
313 |
my $node = shift; |
my $node = shift; |
314 |
my $r = ''; |
my $r = '<ol class="xoxo">'; |
315 |
|
|
316 |
my @node = map { [$_, ''] } @{$node->child_nodes}; |
my @node = ($node); |
317 |
while (@node) { |
while (@node) { |
318 |
my $child = shift @node; |
my $child = shift @node; |
319 |
my $nt = $child->[0]->node_type; |
unless (ref $child) { |
320 |
if ($nt == $child->[0]->ELEMENT_NODE) { |
$r .= $child; |
321 |
$r .= '| ' . $child->[1] . '<' . $child->[0]->tag_name . ">\x0A"; ## ISSUE: case? |
next; |
322 |
|
} |
323 |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value] } |
|
324 |
@{$child->[0]->attributes}) { |
my $node_id = 'node-'.refaddr $child; |
325 |
$r .= '| ' . $child->[1] . ' ' . $attr->[0] . '="'; ## ISSUE: case? |
my $nt = $child->node_type; |
326 |
$r .= $attr->[1] . '"' . "\x0A"; |
if ($nt == $child->ELEMENT_NODE) { |
327 |
|
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 |
330 |
|
|
331 |
|
if ($child->has_attributes) { |
332 |
|
$r .= '<ul class="attributes">'; |
333 |
|
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] } |
334 |
|
@{$child->attributes}) { |
335 |
|
$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 |
337 |
|
} |
338 |
|
$r .= '</ul>'; |
339 |
|
} |
340 |
|
|
341 |
|
if ($child->has_child_nodes) { |
342 |
|
$r .= '<ol class="children">'; |
343 |
|
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
344 |
|
} else { |
345 |
|
$r .= '</li>'; |
346 |
} |
} |
347 |
|
} elsif ($nt == $child->TEXT_NODE) { |
348 |
unshift @node, |
$r .= qq'<li id="$node_id" class="tree-text"><q lang="">' . htescape ($child->data) . '</q></li>'; |
349 |
map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes}; |
} elsif ($nt == $child->CDATA_SECTION_NODE) { |
350 |
} elsif ($nt == $child->[0]->TEXT_NODE) { |
$r .= qq'<li id="$node_id" class="tree-cdata"><code><[CDATA[</code><q lang="">' . htescape ($child->data) . '</q><code>]]></code></li>'; |
351 |
$r .= '| ' . $child->[1] . '"' . $child->[0]->data . '"' . "\x0A"; |
} elsif ($nt == $child->COMMENT_NODE) { |
352 |
} elsif ($nt == $child->[0]->CDATA_SECTION_NODE) { |
$r .= qq'<li id="$node_id" class="tree-comment"><code><!--</code><q lang="">' . htescape ($child->data) . '</q><code>--></code></li>'; |
353 |
$r .= '| ' . $child->[1] . '<![CDATA[' . $child->[0]->data . "]]>\x0A"; |
} elsif ($nt == $child->DOCUMENT_NODE) { |
354 |
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
$r .= qq'<li id="$node_id" class="tree-document">Document'; |
355 |
$r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
$r .= qq[<ul class="attributes">]; |
356 |
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
$r .= qq[<li>@{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}</li>]; |
357 |
$r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name . ">\x0A"; |
$r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>]; |
358 |
} elsif ($nt == $child->[0]->PROCESSING_INSTRUCTION_NODE) { |
$r .= qq[</ul>]; |
359 |
$r .= '| ' . $child->[1] . '<?' . $child->[0]->target . ' ' . |
if ($child->has_child_nodes) { |
360 |
$child->[0]->data . "?>\x0A"; |
$r .= '<ol class="children">'; |
361 |
|
unshift @node, @{$child->child_nodes}, '</ol></li>'; |
362 |
|
} |
363 |
|
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) { |
364 |
|
$r .= qq'<li id="$node_id" class="tree-doctype"><code><!DOCTYPE></code><ul class="attributes">'; |
365 |
|
$r .= qq[<li class="tree-doctype-name">Name = <q>@{[htescape ($child->name)]}</q></li>]; |
366 |
|
$r .= qq[<li class="tree-doctype-publicid">Public identifier = <q>@{[htescape ($child->public_id)]}</q></li>]; |
367 |
|
$r .= qq[<li class="tree-doctype-systemid">System identifier = <q>@{[htescape ($child->system_id)]}</q></li>]; |
368 |
|
$r .= '</ul></li>'; |
369 |
|
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) { |
370 |
|
$r .= qq'<li id="$node_id" class="tree-id"><code><?@{[htescape ($child->target)]}</code> <q>@{[htescape ($child->data)]}</q><code>?></code></li>'; |
371 |
} else { |
} else { |
372 |
$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 |
373 |
} |
} |
374 |
} |
} |
375 |
|
|
376 |
return \$r; |
$r .= '</ol>'; |
377 |
} # test_serialize |
print STDOUT $r; |
378 |
|
} # print_document_tree |
379 |
|
|
380 |
sub get_node_path ($) { |
sub get_node_path ($) { |
381 |
my $node = shift; |
my $node = shift; |
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>. |