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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Sun May 20 08:14:48 2007 UTC (19 years, 2 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +63 -1 lines
++ ChangeLog	20 May 2007 08:14:29 -0000
2007-05-19  Wakaba  <wakaba@suika.fam.cx>

	* parser-interface.en.html: A checkbox to
	enable DOM5 HTML conformance checking is added.

	* parser.cgi: Check DOM5 HTML conformance
	if |dom5| parameter is specified.

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4 wakaba 1.2 use lib qw[/home/httpd/html/www/markup/html/whatpm
5     /home/wakaba/public_html/-temp/wiki/lib];
6 wakaba 1.1
7     use SuikaWiki::Input::HTTP; ## TODO: Use some better CGI module
8    
9     my $http = SuikaWiki::Input::HTTP->new;
10    
11     ## TODO: _charset_
12    
13     my $mode = $http->meta_variable ('PATH_INFO');
14     ## TODO: decode unreserved characters
15    
16 wakaba 1.2 if ($mode eq '/html' or $mode eq '/test') {
17 wakaba 1.1 require Encode;
18 wakaba 1.3 require Whatpm::HTML;
19     require Whatpm::NanoDOM;
20 wakaba 1.1
21     my $s = $http->parameter ('s');
22     if (length $s > 1000_000) {
23     print STDOUT "Status: 400 Document Too Long\nContent-Type: text/plain; charset=us-ascii\n\nToo long";
24     exit;
25     }
26    
27     $s = Encode::decode ('utf-8', $s);
28    
29     print STDOUT "Content-Type: text/plain; charset=utf-8\n\n";
30    
31 wakaba 1.2 print STDOUT "#errors\n";
32    
33     my $onerror = sub {
34 wakaba 1.4 my (%opt) = @_;
35     print STDOUT "$opt{line},$opt{column},$opt{type}\n";
36 wakaba 1.2 };
37 wakaba 1.1
38 wakaba 1.3 my $doc = Whatpm::HTML->parse_string
39     ($s => Whatpm::NanoDOM::Document->new, $onerror);
40 wakaba 1.1
41 wakaba 1.2 print "#document\n";
42    
43     my $out;
44     if ($mode eq '/html') {
45 wakaba 1.3 $out = Whatpm::HTML->get_inner_html ($doc);
46 wakaba 1.2 } else { # test
47     $out = test_serialize ($doc);
48 wakaba 1.1 }
49 wakaba 1.2 print STDOUT Encode::encode ('utf-8', $$out);
50 wakaba 1.4 print STDOUT "\n";
51    
52     if ($http->parameter ('dom5')) {
53     require Whatpm::ContentChecker;
54     print STDOUT "#domerrors\n";
55