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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Sun May 27 06:37:05 2007 UTC (16 years, 11 months ago) by wakaba
Branch: MAIN
++ ChangeLog	27 May 2007 06:33:22 -0000
2007-05-27  Wakaba  <wakaba@suika.fam.cx>

	* table.cgi, table-interface.en.html. table-script.js: New files.

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 <script src="../table-script.js" type="text/javascript"></script>
55 </head>
56 <body>
57 <noscript><p>How great the world without any script were!</p></noscript>
58 ';
59
60 my $i = 0;
61 for my $table_el (@table_el) {
62 $i++; print STDOUT "<h1>Table $i</h1>\n";
63
64 my $table = Whatpm::HTMLTable->form_table ($table_el);
65
66 for (@{$table->{column_group}}, @{$table->{column}}) {
67 next unless $_;
68 delete $_->{element};
69 }
70
71 for (@{$table->{row_group}}) {
72 next unless $_;
73 next unless $_->{element};
74 $_->{type} = $_->{element}->manakai_local_name;
75 delete $_->{element};
76 }
77
78 for (@{$table->{cell}}) {
79 next unless $_;
80 for (@{$_}) {
81 next unless $_;
82 for (@$_) {
83 delete $_->{element};
84 }
85 }
86 }
87
88 print STDOUT '<script type="text/javascript">
89 tableToCanvas (
90 ';
91 print STDOUT objToJson ($table);
92 print STDOUT ');
93 </script>';
94 }
95
96 print STDOUT '</body></html>';
97 } else {
98 print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n404";
99 }
100
101 exit;
102
103 =head1 AUTHOR
104
105 Wakaba <w@suika.fam.cx>.
106
107 =head1 LICENSE
108
109 Copyright 2007 Wakaba <w@suika.fam.cx>
110
111 This library is free software; you can redistribute it
112 and/or modify it under the same terms as Perl itself.
113
114 =cut
115
116 ## $Date: 2007/05/25 14:24:31 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24