/[suikacvs]/test/html-webhacc/WebHACC/Output.pm
Suika

Contents of /test/html-webhacc/WebHACC/Output.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations) (download)
Wed Sep 17 03:56:43 2008 UTC (16 years, 2 months ago) by wakaba
Branch: MAIN
Changes since 1.25: +1 -0 lines
++ ChangeLog	17 Sep 2008 03:55:55 -0000
2008-09-17  Wakaba  <wakaba@suika.fam.cx>

	* cc.cgi: Support for |text/x-css-inline| type is added.

2008-09-17  Wakaba  <wakaba@suika.fam.cx>

	* standards.en.html: Updated.

++ html/WebHACC/Language/ChangeLog	17 Sep 2008 03:56:41 -0000
2008-09-17  Wakaba  <wakaba@suika.fam.cx>

	* CSSInline.pm: New module.

++ html/WebHACC/ChangeLog	17 Sep 2008 03:56:25 -0000
2008-09-17  Wakaba  <wakaba@suika.fam.cx>

	* Output.pm: Support for the |text/x-css-inline| type is added.

1 wakaba 1.1 package WebHACC::Output;
2     use strict;
3 wakaba 1.3
4 wakaba 1.1 require IO::Handle;
5 wakaba 1.3 use Scalar::Util qw/refaddr/;
6 wakaba 1.1
7     my $htescape = sub ($) {
8     my $s = $_[0];
9     $s =~ s/&/&amp;/g;
10     $s =~ s/</&lt;/g;
11 wakaba 1.25 # $s =~ s/>/&gt;/g;
12 wakaba 1.1 $s =~ s/"/&quot;/g;
13 wakaba 1.25 # $s =~ s{([\x00-\x09\x0B-\x1F\x7F-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{
14     # sprintf '<var>U+%04X</var>', ord $1;
15     # }ge;
16 wakaba 1.1 return $s;
17     };
18    
19 wakaba 1.10 my $htescape_value = sub ($) {
20     my $s = $_[0];
21     $s =~ s/&/&amp;/g;
22     $s =~ s/</&lt;/g;
23 wakaba 1.25 # $s =~ s/>/&gt;/g;
24 wakaba 1.10 $s =~ s/"/&quot;/g;
25     return $s;
26     };
27    
28 wakaba 1.1 sub new ($) {
29 wakaba 1.9 require WebHACC::Input;
30     return bless {nav => [], section_rank => 1,
31     input => WebHACC::Input->new}, shift;
32 wakaba 1.1 } # new
33    
34     sub input ($;$) {
35     if (@_ > 1) {
36     if (defined $_[1]) {
37     $_[0]->{input} = $_[1];
38     } else {
39 wakaba 1.9 $_[0]->{input} = WebHACC::Input->new;
40 wakaba 1.1 }
41     }
42    
43     return $_[0]->{input};
44     } # input
45    
46     sub handle ($;$) {
47     if (@_ > 1) {
48     if (defined $_[1]) {
49     $_[0]->{handle} = $_[1];
50     } else {
51     delete $_[0]->{handle};
52     }
53     }
54    
55     return $_[0]->{handle};
56     } # handle
57    
58 wakaba 1.16 sub has_error ($;$) {
59     if (@_ > 1) {
60     if (defined $_[1]) {
61     $_[0]->{has_error} = 1;
62     } else {
63     delete $_[0]->{has_error};
64     }
65     }
66    
67     return $_[0]->{has_error};
68     } # has_error
69    
70 wakaba 1.1 sub set_utf8 ($) {
71 wakaba 1.25 binmode $_[0]->{handle}, ':utf8';
72 wakaba 1.1 } # set_utf8
73    
74     sub set_flush ($) {
75 wakaba 1.25 $_[0]->{handle}->autoflush (1);
76 wakaba 1.1 } # set_flush
77    
78     sub unset_flush ($) {
79 wakaba 1.25 $_[0]->{handle}->autoflush (0);
80 wakaba 1.1 } # unset_flush
81    
82     sub html ($$) {
83 wakaba 1.25 $_[0]->{handle}->print ($_[1]);
84 wakaba 1.1 } # html
85    
86     sub text ($$) {
87 wakaba 1.25 $_[0]->{handle}->print ($htescape->($_[1]));
88 wakaba 1.1 } # text
89    
90     sub url ($$%) {
91     my ($self, $url, %opt) = @_;
92 wakaba 1.25 $self->{handle}->print (q[<code class=uri>&lt;]);
93 wakaba 1.1 $self->link ($url, %opt, url => $url);
94 wakaba 1.25 $self->{handle}->print (q[></code>]);
95 wakaba 1.1 } # url
96    
97     sub start_tag ($$%) {
98     my ($self, $tag_name, %opt) = @_;
99 wakaba 1.25 $self->{handle}->print ('<' . $tag_name);
100 wakaba 1.1 if (exists $opt{id}) {
101     my $id = $self->input->id_prefix . $opt{id};
102 wakaba 1.25 $self->{handle}->print (' id="' . $htescape_value->($id) . '"');
103 wakaba 1.1 delete $opt{id};
104     }
105 wakaba 1.25 for (keys %opt) {
106     $self->{handle}->print
107     (' ' . $_ . '="' . $htescape_value->($opt{$_}) . '"');
108 wakaba 1.1 }
109 wakaba 1.25 $self->{handle}->print ('>');
110 wakaba 1.1 } # start_tag
111    
112     sub end_tag ($$) {
113 wakaba 1.25 $_[0]->{handle}->print ('</' . $_[1] . '>');
114 wakaba 1.1 } # end_tag
115    
116     sub start_section ($%) {
117     my ($self, %opt) = @_;
118 wakaba 1.4
119 wakaba 1.13 my $class = 'section';
120 wakaba 1.4 if (defined $opt{role}) {
121     if ($opt{role} eq 'parse-errors') {
122     $opt{id} ||= 'parse-errors';
123 wakaba 1.7 $opt{title} ||= 'Parse Errors Section';
124     $opt{short_title} ||= 'Parse Errors';
125 wakaba 1.14 $class .= ' errors';
126 wakaba 1.4 delete $opt{role};
127     } elsif ($opt{role} eq 'structure-errors') {
128     $opt{id} ||= 'document-errors';
129     $opt{title} ||= 'Structural Errors';
130     $opt{short_title} ||= 'Struct. Errors';
131 wakaba 1.14 $class .= ' errors';
132 wakaba 1.4 delete $opt{role};
133 wakaba 1.15 } elsif ($opt{role} eq 'transfer-errors') {
134     $opt{id} ||= 'transfer-errors';
135     $opt{title} ||= 'Transfer Errors';
136     $opt{short_title} ||= 'Trans. Errors';
137     $class .= ' errors';
138     delete $opt{role};
139 wakaba 1.4 } elsif ($opt{role} eq 'reformatted') {
140     $opt{id} ||= 'document-tree';
141     $opt{title} ||= 'Reformatted Document Source';
142     $opt{short_title} ||= 'Reformatted';
143 wakaba 1.14 $class .= ' dump';
144 wakaba 1.4 delete $opt{role}
145     } elsif ($opt{role} eq 'tree') {
146     $opt{id} ||= 'document-tree';
147     $opt{title} ||= 'Document Tree';
148     $opt{short_title} ||= 'Tree';
149 wakaba 1.14 $class .= ' dump';
150 wakaba 1.4 delete $opt{role};
151     } elsif ($opt{role} eq 'structure') {
152     $opt{id} ||= 'document-structure';
153     $opt{title} ||= 'Document Structure';
154     $opt{short_title} ||= 'Structure';
155 wakaba 1.14 $class .= ' dump';
156 wakaba 1.4 delete $opt{role};
157 wakaba 1.13 } elsif ($opt{role} eq 'subdoc') {
158     $class .= ' subdoc';
159 wakaba 1.14 delete $opt{role};
160     } elsif ($opt{role} eq 'source') {
161     $opt{id} ||= 'source-string';
162     $opt{title} ||= 'Document Source';
163     $opt{short_title} ||= 'Source';
164     $class .= ' source';
165 wakaba 1.15 delete $opt{role};
166     } elsif ($opt{role} eq 'result') {
167     $opt{id} ||= 'result-summary';
168     $opt{title} ||= 'Result';
169     $class .= ' result';
170 wakaba 1.13 delete $opt{role};
171 wakaba 1.4 }
172     }
173    
174     $self->{section_rank}++;
175 wakaba 1.13 $self->html (qq[<div class="$class"]);
176 wakaba 1.1 if (defined $opt{id}) {
177 wakaba 1.13 my $prefix = $self->input->id_prefix;
178     $opt{parent_id} ||= $prefix;
179     my $id = $prefix . $opt{id};
180 wakaba 1.11 $self->html (' id="' . $htescape->($id) . '">');
181 wakaba 1.13 if ($self->{section_rank} == 2 or length $opt{parent_id}) {
182 wakaba 1.11 my $st = $opt{short_title} || $opt{title};
183     push @{$self->{nav}},
184 wakaba 1.20 [$id => $st => $opt{text}] if $self->{section_rank} == 2;
185 wakaba 1.11
186     $self->start_tag ('script');
187 wakaba 1.13 $self->html (qq[ addSectionLink ('$id', ']);
188 wakaba 1.11 $self->nl_text ($st, text => $opt{text});
189 wakaba 1.12 if (defined $opt{parent_id}) {
190     $self->html (q[', '] . $opt{parent_id});
191     }
192 wakaba 1.11 $self->html (q[') ]);
193     $self->end_tag ('script');
194     }
195     } else {
196     $self->html ('>');
197 wakaba 1.1 }
198 wakaba 1.4 my $section_rank = $self->{section_rank};
199     $section_rank = 6 if $section_rank > 6;
200 wakaba 1.11 $self->html ('<h' . $section_rank . '>');
201 wakaba 1.7 $self->nl_text ($opt{title}, text => $opt{text});
202     $self->html ('</h' . $section_rank . '>');
203 wakaba 1.1 } # start_section
204    
205     sub end_section ($) {
206     my $self = shift;
207     $self->html ('</div>');
208     $self->{handle}->flush;
209 wakaba 1.4 $self->{section_rank}--;
210 wakaba 1.1 } # end_section
211 wakaba 1.4
212     sub start_error_list ($%) {
213     my ($self, %opt) = @_;
214    
215     if (defined $opt{role}) {
216     if ($opt{role} eq 'parse-errors') {
217     $opt{id} ||= 'parse-errors-list';
218     delete $opt{role};
219     } elsif ($opt{role} eq 'structure-errors') {
220     $opt{id} ||= 'document-errors-list';
221     delete $opt{role};
222 wakaba 1.16 } elsif ($opt{role} eq 'transfer-errors') {
223     $opt{id} ||= 'transfer-errors-list';
224     delete $opt{role};
225 wakaba 1.4 }
226     }
227    
228     $self->start_tag ('dl', %opt);
229 wakaba 1.16
230     delete $self->{has_error}; # reset
231 wakaba 1.4 } # start_error_list
232    
233     sub end_error_list ($%) {
234     my ($self, %opt) = @_;
235    
236 wakaba 1.16 my $no_error_message = 'No error found.';
237    
238 wakaba 1.4 if (defined $opt{role}) {
239     if ($opt{role} eq 'parse-errors') {
240     $self->end_tag ('dl');
241     ## NOTE: For parse error list, the |add_source_to_parse_error_list|
242     ## method is invoked at the end of |generate_source_string_section|,
243     ## since that generation method is invoked after the error list
244     ## is generated.
245 wakaba 1.16 $no_error_message = 'No parse error found.';
246 wakaba 1.4 } elsif ($opt{role} eq 'structure-errors') {
247     $self->end_tag ('dl');
248     $self->add_source_to_parse_error_list ('document-errors-list');
249 wakaba 1.16 $no_error_message = 'No structural error found.';
250     } elsif ($opt{role} eq 'transfer-errors') {
251     $self->end_tag ('dl');
252     $no_error_message = 'No transfer error found.';
253 wakaba 1.4 } else {
254     $self->end_tag ('dl');
255     }
256     } else {
257     $self->end_tag ('dl');
258     }
259 wakaba 1.16
260     unless ($self->{has_error}) {
261     $self->start_tag ('p', class => 'no-errors');
262     $self->nl_text ($no_error_message);
263     }
264 wakaba 1.4 } # end_error_list
265    
266     sub add_source_to_parse_error_list ($$) {
267     my $self = shift;
268    
269     $self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix .
270 wakaba 1.9 q[', '] . shift () . q[')]);
271 wakaba 1.4 } # add_source_to_parse_error_list
272 wakaba 1.1
273     sub start_code_block ($) {
274 wakaba 1.25 $_[0]->{handle}->print ('<pre><code>');
275 wakaba 1.1 } # start_code_block
276    
277     sub end_code_block ($) {
278 wakaba 1.25 $_[0]->{handle}->print ('</code></pre>');
279 wakaba 1.1 } # end_code_block
280    
281 wakaba 1.3 sub code ($$;%) {
282     my ($self, $content, %opt) = @_;
283     $self->start_tag ('code', %opt);
284     $self->text ($content);
285 wakaba 1.25 $self->{handle}->print ('</code>');
286 wakaba 1.1 } # code
287    
288 wakaba 1.3 sub script ($$;%) {
289     my ($self, $content, %opt) = @_;
290     $self->start_tag ('script', %opt);
291 wakaba 1.25 $self->{handle}->print ($content . '</script>');
292 wakaba 1.3 } # script
293    
294     sub dt ($$;%) {
295     my ($self, $content, %opt) = @_;
296     $self->start_tag ('dt', %opt);
297 wakaba 1.7 $self->nl_text ($content, text => $opt{text});
298 wakaba 1.3 } # dt
299    
300 wakaba 1.9 sub select ($$%) {
301     my ($self, $options, %opt) = @_;
302    
303     my $selected = $opt{selected};
304     delete $opt{selected};
305    
306     $self->start_tag ('select', %opt);
307    
308     my @options = @$options;
309     while (@options) {
310     my $opt = shift @options;
311     if ($opt->{options}) {
312 wakaba 1.25 $self->{handle}->print ('<optgroup label="');
313 wakaba 1.9 $self->nl_text ($opt->{label});
314 wakaba 1.25 $self->{handle}->print ('">');
315 wakaba 1.9 unshift @options, @{$opt->{options}}, {end_options => 1};
316     } elsif ($opt->{end_options}) {
317     $self->end_tag ('optgroup');
318     } else {
319     $self->start_tag ('option', value => $opt->{value},
320     ((defined $selected and $opt->{value} eq $selected)
321     ? (selected => '') : ()));
322     $self->nl_text (defined $opt->{label} ? $opt->{label} : $opt->{value});
323     }
324     }
325    
326     $self->end_tag ('select');
327     } # select
328    
329 wakaba 1.1 sub link ($$%) {
330     my ($self, $content, %opt) = @_;
331 wakaba 1.2 $self->start_tag ('a', %opt, href => $opt{url});
332 wakaba 1.25 $self->{handle}->print ($htescape->($content) . '</a>');
333 wakaba 1.1 } # link
334    
335     sub xref ($$%) {
336     my ($self, $content, %opt) = @_;
337 wakaba 1.25 $self->{handle}->print
338     ('<a href="#' . $htescape->($self->input->id_prefix . $opt{target}) . '">');
339 wakaba 1.7 $self->nl_text ($content, text => $opt{text});
340 wakaba 1.25 $self->{handle}->print ('</a>');
341 wakaba 1.1 } # xref
342    
343 wakaba 1.19 sub xref_text ($$%) {
344     my ($self, $content, %opt) = @_;
345     $self->html ('<a href="#' . $htescape->($self->input->id_prefix . $opt{target}) . '">');
346 wakaba 1.25 $self->{handle}->print ($htescape->($content) . '</a>');
347 wakaba 1.19 } # xref
348    
349 wakaba 1.2 sub link_to_webhacc ($$%) {
350     my ($self, $content, %opt) = @_;
351     $opt{url} = './?uri=' . $self->encode_url_component ($opt{url});
352     $self->link ($content, %opt);
353     } # link_to_webhacc
354    
355 wakaba 1.3 my $get_node_path = sub ($) {
356     my $node = shift;
357     my @r;
358     while (defined $node) {
359     my $rs;
360     if ($node->node_type == 1) {
361     $rs = $node->node_name;
362     $node = $node->parent_node;
363     } elsif ($node->node_type == 2) {
364     $rs = '@' . $node->node_name;
365     $node = $node->owner_element;
366     } elsif ($node->node_type == 3) {
367     $rs = '"' . $node->data . '"';
368     $node = $node->parent_node;
369     } elsif ($node->node_type == 9) {
370     @r = ('') unless @r;
371     $rs = '';
372     $node = $node->parent_node;
373     } else {
374     $rs = '#' . $node->node_type;
375     $node = $node->parent_node;
376     }
377     unshift @r, $rs;
378     }
379     return join '/', @r;
380     }; # $get_node_path
381    
382 wakaba 1.10 my $get_object_path = sub ($) {
383     my $node = shift;
384     my @r;
385     while (defined $node) {
386     my $ref = ref $node;
387     $ref =~ /([^:]+)$/;
388     my $rs = $1;
389     my $node_name = $node->node_name;
390     if (defined $node_name) {
391     $rs .= ' <code>' . $htescape->($node_name) . '</code>';
392     }
393     $node = undef;
394     unshift @r, $rs;
395     }
396     return join '/', @r;
397     }; # $get_object_path
398    
399 wakaba 1.3 sub node_link ($$) {
400     my ($self, $node) = @_;
401 wakaba 1.10 if ($node->isa ('Message::IF::Node')) {
402 wakaba 1.19 $self->xref_text ($get_node_path->($node),
403     target => 'node-' . refaddr $node);
404 wakaba 1.10 } else {
405 wakaba 1.25 $self->{handle}->print ($get_object_path->($node));
406 wakaba 1.10 }
407 wakaba 1.3 } # node_link
408    
409 wakaba 1.7 {
410     my $Msg = {};
411    
412     sub load_text_catalog ($$) {
413     my $self = shift;
414    
415     my $lang = shift; # MUST be a canonical lang name
416     my $file_name = qq[cc-msg.$lang.txt];
417     $lang = 'en' unless -f $file_name;
418     $self->{primary_language} = $lang;
419    
420     open my $file, '<:utf8', $file_name or die "$0: $file_name: $!";
421     while (<$file>) {
422     if (s/^([^;]+);([^;]*);//) {
423     my ($type, $cls, $msg) = ($1, $2, $_);
424     $msg =~ tr/\x0D\x0A//d;
425     $Msg->{$type} = [$cls, $msg];
426     }
427     }
428     } # load_text_catalog
429    
430     sub nl_text ($$;%) {
431     my ($self, $type, %opt) = @_;
432     my $node = $opt{node};
433    
434 wakaba 1.21 if (defined $Msg->{$type}) {
435     my $msg = $Msg->{$type}->[1];
436     if ($msg =~ /<var>/) {
437     $msg =~ s{<var>{\@([A-Za-z0-9:_.-]+)}</var>}{
438     UNIVERSAL::can ($node, 'get_attribute_ns')
439     ? $htescape->($node->get_attribute_ns (undef, $1)) : ''
440     }ge;
441     $msg =~ s{<var>{\@}</var>}{
442     UNIVERSAL::can ($node, 'value') ? $htescape->($node->value) : ''
443     }ge;
444     $msg =~ s{<var>{text}</var>}{
445     defined $opt{text} ? $htescape->($opt{text}) : ''
446     }ge;
447     $msg =~ s{<var>{value}</var>}{
448     defined $opt{value} ? $htescape->($opt{value}) : ''
449     }ge;
450 wakaba 1.23 $msg =~ s{<var>{octets}</var>}{
451     if (defined $opt{octets}) {
452     join ', ', map {sprintf '0x%02X', ord $_} split //, ${$opt{octets}};
453     } else {
454     '';
455     }
456     }ge;
457     $msg =~ s{<var>{char}</var>}{
458     defined $opt{char} ? $htescape->(${$opt{char}}) : ''
459     }ge;
460     $msg =~ s{<var>{char:hexref}</var>}{
461     if (defined $opt{char}) {
462     join '', map {sprintf '&amp;#x%02X;', ord $_} split //, ${$opt{char}};
463     } else {
464     '';
465     }
466     }ge;
467 wakaba 1.21 $msg =~ s{<var>{local-name}</var>}{
468     UNIVERSAL::can ($node, 'manakai_local_name')
469 wakaba 1.7 ? $htescape->($node->manakai_local_name) : ''
470 wakaba 1.21 }ge;
471     $msg =~ s{<var>{element-local-name}</var>}{
472     (UNIVERSAL::can ($node, 'owner_element') and $node->owner_element)
473 wakaba 1.7 ? $htescape->($node->owner_element->manakai_local_name) : ''
474 wakaba 1.21 }ge;
475 wakaba 1.7 }
476 wakaba 1.25 $self->{handle}->print ($msg);
477 wakaba 1.21 } else {
478 wakaba 1.25 $self->{handle}->print ($htescape->($type));
479 wakaba 1.7 }
480     } # nl_text
481    
482     }
483    
484 wakaba 1.1 sub nav_list ($) {
485 wakaba 1.25 # my $self = shift;
486     # $self->html (q[<ul class="navigation" id="nav-items">]);
487     # for (@{$self->{nav}}) {
488     # $self->html (qq[<li><a href="#@{[$htescape->($_->[0])]}">]);
489     # $self->nl_text ($_->[1], text => $_->[2]);
490     # $self->html ('</a>');
491     # }
492     # $self->html ('</ul>');
493 wakaba 1.1 } # nav_list
494 wakaba 1.2
495 wakaba 1.5 sub http_header ($) {
496 wakaba 1.25 $_[0]->{handle}->print (qq[Content-Type: text/html; charset=utf-8\n\n]);
497 wakaba 1.5 } # http_header
498    
499     sub http_error ($$) {
500     my $self = shift;
501     my $code = 0+shift;
502     my $text = {
503     404 => 'Not Found',
504     }->{$code};
505 wakaba 1.25 $self->{handle}->print
506     (qq[Status: $code $text\nContent-Type: text/html ; charset=us-ascii\n\n$code $text]);
507 wakaba 1.5 } # http_error
508    
509     sub html_header ($) {
510     my $self = shift;
511 wakaba 1.25 $self->{handle}->print (q[<!DOCTYPE html>]);
512 wakaba 1.7 $self->start_tag ('html', lang => $self->{primary_language});
513 wakaba 1.25 $self->{handle}->print (q[<head><title>]);
514 wakaba 1.7 $self->nl_text (q[WebHACC:Title]);
515 wakaba 1.25 $self->{handle}->print (q[</title>
516 wakaba 1.5 <link rel="stylesheet" href="../cc-style.css" type="text/css">
517 wakaba 1.8 <script src="../cc-script.js"></script>
518 wakaba 1.5 </head>
519 wakaba 1.11 <body onclick=" return onbodyclick (event) " onload=" onbodyload () ">
520 wakaba 1.7 <h1>]);
521     $self->nl_text (q[WebHACC:Heading]);
522 wakaba 1.25 $self->{handle}->print (q[</h1><script> insertNavSections () </script>]);
523 wakaba 1.5 } # html_header
524 wakaba 1.9
525     sub generate_input_section ($$) {
526     my ($out, $cgi) = @_;
527    
528 wakaba 1.16 require Encode;
529     my $decode = sub ($) {
530     if (defined $_[0]) {
531     return Encode::decode ('utf-8', $_[0]);
532     } else {
533     return undef;
534     }
535     }; # $decode
536    
537 wakaba 1.9 my $options = sub ($) {
538     my $context = shift;
539    
540 wakaba 1.25 $out->{handle}->print (q[<div class="details default"><p class=legend onclick="nextSibling.style.display = nextSibling.style.display == 'block' ? 'none' : 'block'; parentNode.className = nextSibling.style.display == 'none' ? 'details' : 'details open'" tabindex=0>]);
541 wakaba 1.9 $out->nl_text (q[Options]);
542     $out->start_tag ('div');
543    
544     if ($context eq 'url') {
545     $out->start_tag ('p');
546     $out->start_tag ('label');
547     $out->start_tag ('input', type => 'checkbox', name => 'error-page',
548     value => 1,
549     ($cgi->get_parameter ('error-page')
550     ? (checked => '') : ()));
551     $out->nl_text ('Check error page');
552     $out->end_tag ('label');
553     }
554    
555     $out->start_tag ('p');
556     $out->start_tag ('label');
557     $out->nl_text (q[Content type]);
558     $out->text (': ');
559     $out->select ([
560     {value => '', label => 'As specified'},
561     {value => 'application/atom+xml'},
562 wakaba 1.22 {value => 'text/cache-manifest'},
563     {value => 'text/css'},
564 wakaba 1.26 {value => 'text/x-css-inline'},
565 wakaba 1.22 {value => 'text/x-h2h'},
566     {value => 'text/html'},
567     {value => 'text/x-webidl'},
568 wakaba 1.9 {value => 'application/xhtml+xml'},
569     {value => 'application/xml'},
570     {value => 'text/xml'},
571     ], name => 'i', selected => scalar $cgi->get_parameter ('i'));
572     $out->end_tag ('label');
573    
574     if ($context ne 'text') {
575     $out->start_tag ('p');
576     $out->start_tag ('label');
577     $out->nl_text (q[Charset]);
578     $out->text (q[: ]);
579     $out->select ([
580     {value => '', label => 'As specified'},
581     {label => 'Japanese charsets', options => [
582     {value => 'Windows-31J'},
583     {value => 'Shift_JIS'},
584 wakaba 1.23 {value => 'x-sjis'},
585 wakaba 1.9 {value => 'EUC-JP'},
586 wakaba 1.23 {value => 'x-euc-jp'},
587 wakaba 1.9 {value => 'ISO-2022-JP'},
588 wakaba 1.23 {value => 'ISO-2022-JP-1'},
589     {value => 'ISO-2022-JP-2'},
590 wakaba 1.9 ]},
591 wakaba 1.23 {label => 'Latin charsets', options => [
592     {value => 'Windows-1250'},
593 wakaba 1.9 {value => 'Windows-1252'},
594 wakaba 1.23 {value => 'Windows-1254'},
595     {value => 'Windows-1257'},
596     {value => 'Windows-1258'},
597 wakaba 1.9 {value => 'ISO-8859-1'},
598 wakaba 1.23 {value => 'ISO-8859-2'},
599     {value => 'ISO-8859-3'},
600     {value => 'ISO-8859-4'},
601     {value => 'ISO-8859-9'},
602     {value => 'ISO-8859-10'},
603     {value => 'ISO-8859-13'},
604     {value => 'ISO-8859-14'},
605     {value => 'ISO-8859-15'},
606     {value => 'ISO-8859-16'},
607 wakaba 1.9 {value => 'US-ASCII'},
608     ]},
609 wakaba 1.23 {label => 'Greek charsets', options => [
610     {value => 'Windows-1253'},
611     {value => 'ISO-8859-7'},
612     ]},
613     {label => 'Cyrillic charsets', options => [
614     {value => 'Windows-1251'},
615     {value => 'ISO-8859-5'},
616     ]},
617     {label => 'Arabic charsets', options => [
618     {value => 'Windows-1256'},
619     {value => 'ISO-8859-6'},
620     ]},
621     {label => 'Hebrew charsets', options => [
622     {value => 'Windows-1255'},
623     {value => 'ISO-8859-8'},
624     ]},
625     {label => 'Thai charsets', options => [
626 wakaba 1.9 {value => 'Windows-874'},
627     {value => 'ISO-8859-11'},
628     {value => 'TIS-620'},
629     ]},
630 wakaba 1.23 {label => 'Chinese charsets', options => [
631     {value => 'Big5'},
632     {value => 'x-x-big5'},
633     {value => 'Big5-HKSCS'},
634     {value => 'GBK'},
635     {value => 'GB2312'},
636     {value => 'GB_2312-80'},
637     {value => 'ISO-2022-CN'},
638     {value => 'ISO-2022-CN-EXT'},
639     ]},
640     {label => 'Korean charsets', options => [
641     {value => 'Windows-949'},
642     {value => 'EUC-KR'},
643     {value => 'KS_C_5601-1987'},
644     {value => 'ISO-2022-KR'},
645     ]},
646 wakaba 1.9 {label => 'Unicode charsets', options => [
647     {value => 'UTF-8'},
648     {value => 'UTF-8n'},
649 wakaba 1.23 {value => 'UTF-16'},
650     {value => 'UTF-16BE'},
651     {value => 'UTF-16LE'},
652     ]},
653 wakaba 1.9 ], name => 'charset',
654     selected => scalar $cgi->get_parameter ('charset'));
655     $out->end_tag ('label');
656     }
657    
658     if ($context eq 'text') {
659     $out->start_tag ('p');
660     $out->start_tag ('label');
661     $out->nl_text ('Setting innerHTML');
662     $out->text (': ');
663     $out->start_tag ('input', name => 'e',
664 wakaba 1.16 value => $decode->(scalar $cgi->get_parameter ('e')));
665 wakaba 1.9 $out->end_tag ('label');
666     }
667    
668 wakaba 1.25 $out->{handle}->print (q[</div></div>]);
669 wakaba 1.9 }; # $options
670    
671     $out->start_section (id => 'input', title => 'Input');
672 wakaba 1.12 $out->html (q[<script> insertNavSections ('input') </script>]);
673 wakaba 1.9
674 wakaba 1.12 $out->start_section (id => 'input-url', title => 'By URL',
675     parent_id => 'input');
676 wakaba 1.10 $out->start_tag ('form', action => './#result-summary',
677     'accept-charset' => 'utf-8',
678 wakaba 1.9 method => 'get');
679     $out->start_tag ('input', type => 'hidden', name => '_charset_');
680    
681     $out->start_tag ('p');
682     $out->start_tag ('label');
683     $out->nl_text ('URL');
684     $out->text (': ');
685     $out->start_tag ('input',
686     name => 'uri',
687     type => 'url',
688 wakaba 1.16 value => $decode->(scalar $cgi->get_parameter ('uri')));
689 wakaba 1.9 $out->end_tag ('label');
690    
691     $out->start_tag ('p');
692     $out->start_tag ('button', type => 'submit');
693     $out->nl_text ('Check');
694 wakaba 1.12 $out->end_tag ('button');
695    
696     $options->('url');
697 wakaba 1.9
698     $out->end_tag ('form');
699     $out->end_section;
700    
701     ## TODO: File upload
702    
703 wakaba 1.12 $out->start_section (id => 'input-text', title => 'By direct input',
704     parent_id => 'input');
705 wakaba 1.10 $out->start_tag ('form', action => './#result-summary',
706     'accept-charset' => 'utf-8',
707 wakaba 1.9 method => 'post');
708     $out->start_tag ('input', type => 'hidden', name => '_charset_');
709    
710     $out->start_tag ('p');
711     $out->start_tag ('label');
712     $out->nl_text ('Document source to check');
713     $out->text (': ');
714     $out->start_tag ('br');
715     $out->start_tag ('textarea',
716     name => 's');
717 wakaba 1.16 my $s = $decode->($cgi->get_parameter ('s'));
718 wakaba 1.10 $out->html ($htescape_value->($s)) if defined $s;
719 wakaba 1.9 $out->end_tag ('textarea');
720     $out->end_tag ('label');
721    
722     $out->start_tag ('p');
723     $out->start_tag ('button', type => 'submit',
724     onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"');
725     $out->nl_text ('Check');
726     $out->end_tag ('button');
727    
728 wakaba 1.12 $options->('text');
729    
730 wakaba 1.9 $out->end_tag ('form');
731     $out->end_section;
732 wakaba 1.12
733     $out->script (q[
734     if (!document.webhaccNavigated &&
735     document.getElementsByTagName ('textarea')[0].value.length > 0) {
736     showTab ('input-text');
737     document.webhaccNavigated = false;
738     }
739     ]);
740 wakaba 1.9
741     $out->end_section;
742     } # generate_input_section
743 wakaba 1.2
744     sub encode_url_component ($$) {
745     shift;
746     require Encode;
747     my $s = Encode::encode ('utf8', shift);
748     $s =~ s/([^0-9A-Za-z_.~-])/sprintf '%%%02X', ord $1/ge;
749     return $s;
750     } # encode_url_component
751 wakaba 1.1
752     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24