--- test/html-webhacc/WebHACC/Output.pm 2008/07/26 11:27:25 1.8
+++ test/html-webhacc/WebHACC/Output.pm 2008/09/15 02:55:12 1.25
@@ -8,16 +8,27 @@
my $s = $_[0];
$s =~ s/&/&/g;
$s =~ s/</g;
- $s =~ s/>/>/g;
+# $s =~ s/>/>/g;
+ $s =~ s/"/"/g;
+# $s =~ s{([\x00-\x09\x0B-\x1F\x7F-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{
+# sprintf 'U+%04X', ord $1;
+# }ge;
+ return $s;
+};
+
+my $htescape_value = sub ($) {
+ my $s = $_[0];
+ $s =~ s/&/&/g;
+ $s =~ s/</g;
+# $s =~ s/>/>/g;
$s =~ s/"/"/g;
- $s =~ s{([\x00-\x09\x0B-\x1F\x7F-\xA0\x{FEFF}\x{FFFC}-\x{FFFF}])}{
- sprintf 'U+%04X', ord $1;
- }ge;
return $s;
};
sub new ($) {
- return bless {nav => [], section_rank => 1}, shift;
+ require WebHACC::Input;
+ return bless {nav => [], section_rank => 1,
+ input => WebHACC::Input->new}, shift;
} # new
sub input ($;$) {
@@ -25,7 +36,7 @@
if (defined $_[1]) {
$_[0]->{input} = $_[1];
} else {
- delete $_[0]->{input};
+ $_[0]->{input} = WebHACC::Input->new;
}
}
@@ -44,95 +55,149 @@
return $_[0]->{handle};
} # handle
+sub has_error ($;$) {
+ if (@_ > 1) {
+ if (defined $_[1]) {
+ $_[0]->{has_error} = 1;
+ } else {
+ delete $_[0]->{has_error};
+ }
+ }
+
+ return $_[0]->{has_error};
+} # has_error
+
sub set_utf8 ($) {
- binmode shift->{handle}, ':utf8';
+ binmode $_[0]->{handle}, ':utf8';
} # set_utf8
sub set_flush ($) {
- shift->{handle}->autoflush (1);
+ $_[0]->{handle}->autoflush (1);
} # set_flush
sub unset_flush ($) {
- shift->{handle}->autoflush (0);
+ $_[0]->{handle}->autoflush (0);
} # unset_flush
sub html ($$) {
- shift->{handle}->print (shift);
+ $_[0]->{handle}->print ($_[1]);
} # html
sub text ($$) {
- shift->html ($htescape->(shift));
+ $_[0]->{handle}->print ($htescape->($_[1]));
} # text
sub url ($$%) {
my ($self, $url, %opt) = @_;
- $self->html (q[<]);
+ $self->{handle}->print (q[]);
} # url
sub start_tag ($$%) {
my ($self, $tag_name, %opt) = @_;
- $self->html ('<' . $htescape->($tag_name)); # escape for safety
+ $self->{handle}->print ('<' . $tag_name);
if (exists $opt{id}) {
my $id = $self->input->id_prefix . $opt{id};
- $self->html (' id="' . $htescape->($id) . '"');
+ $self->{handle}->print (' id="' . $htescape_value->($id) . '"');
delete $opt{id};
}
- for (keys %opt) { # for safety
- $self->html (' ' . $htescape->($_) . '="' . $htescape->($opt{$_}) . '"');
+ for (keys %opt) {
+ $self->{handle}->print
+ (' ' . $_ . '="' . $htescape_value->($opt{$_}) . '"');
}
- $self->html ('>');
+ $self->{handle}->print ('>');
} # start_tag
sub end_tag ($$) {
- shift->html ('' . $htescape->(shift) . '>');
+ $_[0]->{handle}->print ('' . $_[1] . '>');
} # end_tag
sub start_section ($%) {
my ($self, %opt) = @_;
+ my $class = 'section';
if (defined $opt{role}) {
if ($opt{role} eq 'parse-errors') {
$opt{id} ||= 'parse-errors';
$opt{title} ||= 'Parse Errors Section';
$opt{short_title} ||= 'Parse Errors';
+ $class .= ' errors';
delete $opt{role};
} elsif ($opt{role} eq 'structure-errors') {
$opt{id} ||= 'document-errors';
$opt{title} ||= 'Structural Errors';
$opt{short_title} ||= 'Struct. Errors';
+ $class .= ' errors';
+ delete $opt{role};
+ } elsif ($opt{role} eq 'transfer-errors') {
+ $opt{id} ||= 'transfer-errors';
+ $opt{title} ||= 'Transfer Errors';
+ $opt{short_title} ||= 'Trans. Errors';
+ $class .= ' errors';
delete $opt{role};
} elsif ($opt{role} eq 'reformatted') {
$opt{id} ||= 'document-tree';
$opt{title} ||= 'Reformatted Document Source';
$opt{short_title} ||= 'Reformatted';
+ $class .= ' dump';
delete $opt{role}
} elsif ($opt{role} eq 'tree') {
$opt{id} ||= 'document-tree';
$opt{title} ||= 'Document Tree';
$opt{short_title} ||= 'Tree';
+ $class .= ' dump';
delete $opt{role};
} elsif ($opt{role} eq 'structure') {
$opt{id} ||= 'document-structure';
$opt{title} ||= 'Document Structure';
$opt{short_title} ||= 'Structure';
+ $class .= ' dump';
+ delete $opt{role};
+ } elsif ($opt{role} eq 'subdoc') {
+ $class .= ' subdoc';
+ delete $opt{role};
+ } elsif ($opt{role} eq 'source') {
+ $opt{id} ||= 'source-string';
+ $opt{title} ||= 'Document Source';
+ $opt{short_title} ||= 'Source';
+ $class .= ' source';
+ delete $opt{role};
+ } elsif ($opt{role} eq 'result') {
+ $opt{id} ||= 'result-summary';
+ $opt{title} ||= 'Result';
+ $class .= ' result';
delete $opt{role};
}
}
$self->{section_rank}++;
- $self->html ('<]);
$self->link ($url, %opt, url => $url);
- $self->html (q[>]);
+ $self->{handle}->print (q[>
');
+ $_[0]->{handle}->print ('');
} # start_code_block
sub end_code_block ($) {
- shift->html ('
');
+ $_[0]->{handle}->print ('');
} # end_code_block
sub code ($$;%) {
my ($self, $content, %opt) = @_;
$self->start_tag ('code', %opt);
$self->text ($content);
- $self->html ('');
+ $self->{handle}->print ('');
} # code
sub script ($$;%) {
my ($self, $content, %opt) = @_;
$self->start_tag ('script', %opt);
- $self->html ($content);
- $self->html ('');
+ $self->{handle}->print ($content . '');
} # script
sub dt ($$;%) {
@@ -218,18 +297,53 @@
$self->nl_text ($content, text => $opt{text});
} # dt
+sub select ($$%) {
+ my ($self, $options, %opt) = @_;
+
+ my $selected = $opt{selected};
+ delete $opt{selected};
+
+ $self->start_tag ('select', %opt);
+
+ my @options = @$options;
+ while (@options) {
+ my $opt = shift @options;
+ if ($opt->{options}) {
+ $self->{handle}->print ('