/[pub]/test/html-whatpm/table.cgi
Suika

Contents of /test/html-whatpm/table.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Tue May 6 07:50:28 2008 UTC (16 years, 6 months ago) by wakaba
Branch: MAIN
Changes since 1.5: +5 -2 lines
++ ChangeLog	6 May 2008 07:50:23 -0000
2008-05-06  Wakaba  <wakaba@suika.fam.cx>

	* table-script.js: Support for header cell highlighting.

	* table.cgi: Set |id| to cells; it enables the cell highlighting
	feature.

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     use lib qw[/home/httpd/html/www/markup/html/whatpm
5     /home/wakaba/public_html/-temp/wiki/lib];
6     use CGI::Carp qw[fatalsToBrowser];
7    
8     use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module
9    
10     my $http = SuikaWiki::Input::HTTP->new;
11    
12     ## TODO: _charset_
13    
14     my $mode = $http->meta_variable ('PATH_INFO');
15     ## TODO: decode unreserved characters
16    
17     if ($mode eq '/table') {
18     require Encode;
19     require Whatpm::HTML;
20     require Whatpm::NanoDOM;
21    
22     my $s = $http->parameter ('s');
23     if (length $s > 1000_000) {
24     print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long";
25     exit;
26     }
27    
28     $s = Encode::decode ('utf-8', $s);
29     my $doc = Whatpm::HTML->parse_string
30     ($s => Whatpm::NanoDOM::Document->new);
31    
32     my @table_el;
33     my @node = @{$doc->child_nodes};
34     while (@node) {
35     my $node = shift @node;
36     if ($node->node_type == 1) {
37     if ($node->namespace_uri eq q<http://www.w3.org/1999/xhtml> and
38     $node->manakai_local_name eq 'table') {
39     push @table_el, $node;
40     }
41     }
42     push @node, @{$node->child_nodes};
43     }
44    
45     print STDOUT "Content-Type: text/html; charset=utf-8\n\n";
46    
47     use JSON;
48     require Whatpm::HTMLTable;
49    
50     print STDOUT '<!DOCTYPE html>
51     <html lang="en">
52     <head>
53     <title>HTML5 Table Structure Viewer</title>
54 wakaba 1.2 <!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->
55 wakaba 1.1 <script src="../table-script.js" type="text/javascript"></script>
56     </head>
57     <body>
58 wakaba 1.2 <noscript><p>How great if there were no script at all!</p></noscript>
59 wakaba 1.1 ';
60    
61     my $i = 0;
62     for my $table_el (@table_el) {
63     $i++; print STDOUT "<h1>Table $i</h1>\n";
64    
65     my $table = Whatpm::HTMLTable->form_table ($table_el);
66 wakaba 1.6 Whatpm::HTMLTable->assign_header ($table);
67 wakaba 1.1
68 wakaba 1.6 for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption},
69     @{$table->{row}}) {
70 wakaba 1.1 next unless $_;
71     delete $_->{element};
72     }
73    
74     for (@{$table->{row_group}}) {
75     next unless $_;
76     next unless $_->{element};
77     $_->{type} = $_->{element}->manakai_local_name;
78     delete $_->{element};
79     }
80    
81     for (@{$table->{cell}}) {
82     next unless $_;
83     for (@{$_}) {
84     next unless $_;
85     for (@$_) {
86 wakaba 1.6 $_->{id} = ''.$_->{element} if defined $_->{element};
87 wakaba 1.1 delete $_->{element};
88 wakaba 1.4 $_->{is_header} = $_->{is_header} ? 1 : 0;
89 wakaba 1.1 }
90     }
91     }
92    
93 wakaba 1.2 print STDOUT '<script type="text/javascript">
94 wakaba 1.1 tableToCanvas (
95     ';
96     print STDOUT objToJson ($table);
97 wakaba 1.5 print STDOUT ', document.body, "");
98 wakaba 1.1 </script>';
99     }
100    
101     print STDOUT '</body></html>';
102     } else {
103     print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n404";
104     }
105    
106     exit;
107    
108     =head1 AUTHOR
109    
110     Wakaba <w@suika.fam.cx>.
111    
112     =head1 LICENSE
113    
114 wakaba 1.5 Copyright 2007-2008 Wakaba <w@suika.fam.cx>
115 wakaba 1.1
116     This library is free software; you can redistribute it
117     and/or modify it under the same terms as Perl itself.
118    
119     =cut
120    
121 wakaba 1.6 ## $Date: 2008/02/10 02:30:14 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24