--- test/html-webhacc/cc.cgi 2007/06/27 14:36:45 1.4
+++ test/html-webhacc/cc.cgi 2007/07/01 06:21:46 1.7
@@ -33,6 +33,8 @@
exit;
}
+ load_text_catalog ('en'); ## TODO: conneg
+
my @nav;
print STDOUT qq[Content-Type: text/html; charset=utf-8
@@ -88,13 +90,14 @@
my $onerror = sub {
my (%opt) = @_;
+ my ($cls, $msg) = get_text ($opt{type}, $opt{level});
if ($opt{column} > 0) {
- print STDOUT qq[
Line $opt{line} column $opt{column}\n];
+ print STDOUT qq[Line $opt{line} column $opt{column}\n];
} else {
- $opt{line}--;
- print STDOUT qq[Line $opt{line}\n];
+ $opt{line} = $opt{line} - 1 || 1;
+ print STDOUT qq[Line $opt{line}\n];
}
- print STDOUT qq[@{[htescape $opt{type}]}\n];
+ print STDOUT qq[$msg\n];
};
$doc = $dom->create_document;
@@ -133,8 +136,7 @@
Parse Errors
-
-];
+];
push @nav, ['#parse-errors' => 'Parse Error'];
my $onerror = sub {
@@ -150,8 +152,7 @@
$doc = Message::DOM::XMLParserTemp->parse_byte_stream
($fh => $dom, $onerror, charset => 'utf-8');
- print STDOUT qq[
-
+ print STDOUT qq[
];
} else {
@@ -182,28 +183,96 @@
Document Errors
-
-];
+];
push @nav, ['#document-errors' => 'Document Error'];
require Whatpm::ContentChecker;
my $onerror = sub {
my %opt = @_;
- print STDOUT qq[- ],
- htescape get_node_path ($opt{node}),
- "
\n- ", htescape $opt{type}, "
\n";
+ my ($cls, $msg) = get_text ($opt{type}, $opt{level});
+ print STDOUT qq[- ] . get_node_link ($opt{node}) .
+ qq[
\n- ], $msg, "
\n";
};
+ my $elements;
if ($el) {
- Whatpm::ContentChecker->check_element ($el, $onerror);
+ $elements = Whatpm::ContentChecker->check_element ($el, $onerror);
} else {
- Whatpm::ContentChecker->check_document ($doc, $onerror);
+ $elements = Whatpm::ContentChecker->check_document ($doc, $onerror);
}
- print STDOUT qq[
-
+ print STDOUT qq[
];
+
+ if (@{$elements->{table}}) {
+ require JSON;
+
+ print STDOUT qq[
+
+
Tables
+
+
+
+
+];
+
+ my $i = 0;
+ for my $table_el (@{$elements->{table}}) {
+ $i++;
+ print STDOUT qq[
] .
+ get_node_link ($table_el) . q[
];
+
+ my $table = Whatpm::HTMLTable->form_table ($table_el);
+
+ for (@{$table->{column_group}}, @{$table->{column}}, $table->{caption}) {
+ next unless $_;
+ delete $_->{element};
+ }
+
+ for (@{$table->{row_group}}) {
+ next unless $_;
+ next unless $_->{element};
+ $_->{type} = $_->{element}->manakai_local_name;
+ delete $_->{element};
+ }
+
+ for (@{$table->{cell}}) {
+ next unless $_;
+ for (@{$_}) {
+ next unless $_;
+ for (@$_) {
+ $_->{id} = refaddr $_->{element} if defined $_->{element};
+ delete $_->{element};
+ }
+ }
+ }
+
+ print STDOUT '];
+ }
+
+ print STDOUT qq[
];
+ }
+
+ if (keys %{$elements->{term}}) {
+ print STDOUT qq[
+
+
Terms
+
+
+];
+ for my $term (sort {$a cmp $b} keys %{$elements->{term}}) {
+ print STDOUT qq[- @{[htescape $term]}
];
+ for (@{$elements->{term}->{$term}}) {
+ print STDOUT qq[- ].get_node_link ($_).qq[
];
+ }
+ }
+ print STDOUT qq[
];
+ }
}
## TODO: Show result
@@ -226,12 +295,16 @@
my $s = $_[0];
my $i = 1;
print STDOUT qq[\n];
- while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {
- print STDOUT qq[- ], htescape $1, "
\n";
- $i++;
- }
- if ($$s =~ /\G([^\x0A]+)/gc) {
- print STDOUT qq[- ], htescape $1, "
\n";
+ if (length $$s) {
+ while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {
+ print STDOUT qq[- ], htescape $1, "
\n";
+ $i++;
+ }
+ if ($$s =~ /\G([^\x0A]+)/gc) {
+ print STDOUT qq[- ], htescape $1, "
\n";
+ }
+ } else {
+ print STDOUT q[];
}
print STDOUT "
";
} # print_input_string
@@ -265,9 +338,11 @@
$r .= '';
}
- if ($node->has_child_nodes) {
+ if ($child->has_child_nodes) {
$r .= '';
- unshift @node, @{$child->child_nodes}, '
';
+ unshift @node, @{$child->child_nodes}, '';
+ } else {
+ $r .= '';
}
} elsif ($nt == $child->TEXT_NODE) {
$r .= qq'' . htescape ($child->data) . '
';
@@ -276,16 +351,20 @@
} elsif ($nt == $child->COMMENT_NODE) {
$r .= qq'';
} elsif ($nt == $child->DOCUMENT_NODE) {
- $r .= qq'Document';
+ $r .= qq'Document';
+ $r .= qq[];
+ $r .= qq[- @{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}
];
+ $r .= qq[- @{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}
];
+ $r .= qq[
];
if ($child->has_child_nodes) {
- $r .= '';
- unshift @node, @{$child->child_nodes}, '
';
+ $r .= '';
+ unshift @node, @{$child->child_nodes}, '
';
}
} elsif ($nt == $child->DOCUMENT_TYPE_NODE) {
- $r .= qq'<!DOCTYPE>
';
- $r .= '- Name =
@{[htescape ($child->name)]}
';
- $r .= '- Public identifier =
@{[htescape ($child->public_id)]}
';
- $r .= '- System identifier =
@{[htescape ($child->system_id)]}
';
+ $r .= qq'<!DOCTYPE>
';
+ $r .= qq[- Name =
@{[htescape ($child->name)]}
];
+ $r .= qq[- Public identifier =
@{[htescape ($child->public_id)]}
];
+ $r .= qq[- System identifier =
@{[htescape ($child->system_id)]}
];
$r .= '
';
} elsif ($nt == $child->PROCESSING_INSTRUCTION_NODE) {
$r .= qq'<?@{[htescape ($child->target)]}
@{[htescape ($child->data)]}
?>
';
@@ -324,6 +403,45 @@
return join '/', @r;
} # get_node_path
+sub get_node_link ($) {
+ return qq[] .
+ htescape (get_node_path ($_[0])) . qq[];
+} # get_node_link
+
+{
+ my $Msg = {};
+
+sub load_text_catalog ($) {
+ my $lang = shift; # MUST be a canonical lang name
+ open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!";
+ while (<$file>) {
+ if (s/^([^;]+);([^;]*);//) {
+ my ($type, $cls, $msg) = ($1, $2, $_);
+ $msg =~ tr/\x0D\x0A//d;
+ $Msg->{$type} = [$cls, $msg];
+ }
+ }
+} # load_text_catalog
+
+sub get_text ($) {
+ my ($type, $level) = @_;
+ $type = $level . ':' . $type if defined $level;
+ my @arg;
+ {
+ if (defined $Msg->{$type}) {
+ my $msg = $Msg->{$type}->[1];
+ $msg =~ s/\$([0-9]+)/defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'/ge;
+ return ($Msg->{$type}->[0], $msg);
+ } elsif ($type =~ s/:([^:]*)$//) {
+ unshift @arg, $1;
+ redo;
+ }
+ }
+ return ('', htescape ($_[0]));
+} # get_text
+
+}
+
=head1 AUTHOR
Wakaba .
@@ -337,4 +455,4 @@
=cut
-## $Date: 2007/06/27 14:36:45 $
+## $Date: 2007/07/01 06:21:46 $