Parent Directory
|
Revision Log
++ ChangeLog 1 May 2007 09:25:27 -0000 * parser.cgi: New file. * .htaccess: New file.
| 1 | #!/usr/bin/perl |
| 2 | use strict; |
| 3 | |
| 4 | use lib qw[.. /home/wakaba/public_html/-temp/wiki/lib]; |
| 5 | |
| 6 | use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module |
| 7 | |
| 8 | my $http = SuikaWiki::Input::HTTP->new; |
| 9 | |
| 10 | ## TODO: _charset_ |
| 11 | |
| 12 | my $mode = $http->meta_variable ('PATH_INFO'); |
| 13 | ## TODO: decode unreserved characters |
| 14 | |
| 15 | if ($mode eq '/html' or $mode eq '/error-and-html') { |
| 16 | require Encode; |
| 17 | require What::HTML; |
| 18 | require What::NanoDOM; |
| 19 | |
| 20 | my $s = $http->parameter ('s'); |
| 21 | if (length $s > 1000_000) { |
| 22 | print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long"; |
| 23 | exit; |
| 24 | } |
| 25 | |
| 26 | $s = Encode::decode ('utf-8', $s); |
| 27 | |
| 28 | print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
| 29 | |
| 30 | my $onerror = $mode eq '/error-and-html' ? sub { |
| 31 | print STDOUT "0,0,", $_[0], "\n"; |
| 32 | } : sub { }; |
| 33 | |
| 34 | my $doc = What::HTML->parse_string |
| 35 | ($s => What::NanoDOM::Document->new, $onerror); |
| 36 | |
| 37 | if ($mode eq '/error-and-html') { |
| 38 | print "--\n"; |
| 39 | } |
| 40 | |
| 41 | my $html = What::HTML->get_inner_html ($doc); |