Parent Directory
|
Revision Log
|
Patch
| revision 1.1 by wakaba, Tue May 1 09:25:31 2007 UTC | revision 1.5 by wakaba, Fri May 25 14:24:31 2007 UTC | |
|---|---|---|
| # | Line 1 | Line 1 |
| 1 | #!/usr/bin/perl | #!/usr/bin/perl |
| 2 | use strict; | use strict; |
| 3 | ||
| 4 | use lib qw[.. /home/wakaba/public_html/-temp/wiki/lib]; | 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 | use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module |
| 9 | ||
| # | Line 12 my $http = SuikaWiki::Input::HTTP->new; | Line 14 my $http = SuikaWiki::Input::HTTP->new; |
| 14 | my $mode = $http->meta_variable ('PATH_INFO'); | my $mode = $http->meta_variable ('PATH_INFO'); |
| 15 | ## TODO: decode unreserved characters | ## TODO: decode unreserved characters |
| 16 | ||
| 17 | if ($mode eq '/html' or $mode eq '/error-and-html') { | if ($mode eq '/html' or $mode eq '/test') { |
| 18 | require Encode; | require Encode; |
| 19 | require What::HTML; | require Whatpm::HTML; |
| 20 | require What::NanoDOM; | require Whatpm::NanoDOM; |
| 21 | ||
| 22 | my $s = $http->parameter ('s'); | my $s = $http->parameter ('s'); |
| 23 | if (length $s > 1000_000) { | if (length $s > 1000_000) { |
| # | Line 27 if ($mode eq '/html' or $mode eq '/error | Line 29 if ($mode eq '/html' or $mode eq '/error |
| 29 | ||
| 30 | print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; | print STDOUT "Content-Type: text/plain; charset=utf-8\n\n"; |
| 31 | ||
| 32 | my $onerror = $mode eq '/error-and-html' ? sub { | print STDOUT "#errors\n"; |
| print STDOUT "0,0,", $_[0], "\n"; | ||
| } : sub { }; | ||
| 33 | ||
| 34 | my $doc = What::HTML->parse_string | my $onerror = sub { |
| 35 | ($s => What::NanoDOM::Document->new, $onerror); | my (%opt) = @_; |
| 36 | print STDOUT "$opt{line},$opt{column},$opt{type}\n"; | |
| 37 | if ($mode eq '/error-and-html') { | }; |
| 38 | print "--\n"; | |
| 39 | my $doc = Whatpm::HTML->parse_string | |
| 40 | ($s => Whatpm::NanoDOM::Document->new, $onerror); | |
| 41 | ||
| 42 | print "#document\n"; | |
| 43 | ||
| 44 | my $out; | |
| 45 | if ($mode eq '/html') { | |
| 46 | $out = Whatpm::HTML->get_inner_html ($doc); | |
| 47 | } else { # test | |
| 48 | $out = test_serialize ($doc); | |
| 49 | } | } |
| 50 | print STDOUT Encode::encode ('utf-8', $$out); | |
| 51 | print STDOUT "\n"; | |
| 52 | ||
| 53 | my $html = What::HTML->get_inner_html ($doc); | if ($http->parameter ('dom5')) { |
| 54 | print STDOUT Encode::encode ('utf-8', $$html); | require Whatpm::ContentChecker; |
| 55 | print STDOUT "#domerrors\n"; | |
| 56 | my $docel = $doc->document_element; | |
| 57 | my $docel_nsuri = $docel->namespace_uri; | |
| 58 | if (defined $docel_nsuri and | |
| 59 | $docel_nsuri eq q<http://www.w3.org/1999/xhtml> and | |
| 60 | $docel->manakai_local_name eq 'html') { | |
| 61 | # | |
| 62 | } else { | |
| 63 | print STDOUT get_node_path ($docel) . ";element not allowed\n"; | |
| 64 | } | |
| 65 | my $cc = Whatpm::ContentChecker->new; | |
| 66 | $cc->check_element ($docel, sub { | |
| 67 | my %opt = @_; | |
| 68 | print STDOUT get_node_path ($opt{node}) . ';' . $opt{type} . "\n"; | |
| 69 | }); | |
| 70 | } | |
| 71 | } else { | } else { |
| 72 | print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n404"; | print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n404"; |
| 73 | } | } |
| 74 | ||
| 75 | exit; | |
| 76 | ||
| 77 | sub test_serialize ($) { | |
| 78 | my $node = shift; | |
| 79 | my $r = ''; | |
| 80 | ||
| 81 | my @node = map { [$_, ''] } @{$node->child_nodes}; | |
| 82 | while (@node) { | |
| 83 | my $child = shift @node; | |
| 84 | my $nt = $child->[0]->node_type; |