--- test/html-webhacc/WebHACC/Output.pm 2008/07/21 05:24:32 1.3
+++ test/html-webhacc/WebHACC/Output.pm 2008/08/10 11:49:43 1.11
@@ -16,8 +16,19 @@
return $s;
};
+my $htescape_value = sub ($) {
+ my $s = $_[0];
+ $s =~ s/&/&/g;
+ $s =~ s/</g;
+ $s =~ s/>/>/g;
+ $s =~ s/"/"/g;
+ return $s;
+};
+
sub new ($) {
- return bless {nav => []}, 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;
}
}
@@ -73,40 +84,135 @@
sub start_tag ($$%) {
my ($self, $tag_name, %opt) = @_;
- $self->html ('<' . $htescape->($tag_name)); # escape for safety
+ $self->html ('<' . $htescape_value->($tag_name)); # escape for safety
if (exists $opt{id}) {
my $id = $self->input->id_prefix . $opt{id};
- $self->html (' id="' . $htescape->($id) . '"');
+ $self->html (' id="' . $htescape_value->($id) . '"');
delete $opt{id};
}
for (keys %opt) { # for safety
- $self->html (' ' . $htescape->($_) . '="' . $htescape->($opt{$_}) . '"');
+ $self->html (' ' . $htescape_value->($_) . '="' .
+ $htescape_value->($opt{$_}) . '"');
}
$self->html ('>');
} # start_tag
sub end_tag ($$) {
- shift->html ('' . $htescape->(shift) . '>');
+ shift->html ('' . $htescape_value->(shift) . '>');
} # end_tag
sub start_section ($%) {
my ($self, %opt) = @_;
+
+ if (defined $opt{role}) {
+ if ($opt{role} eq 'parse-errors') {
+ $opt{id} ||= 'parse-errors';
+ $opt{title} ||= 'Parse Errors Section';
+ $opt{short_title} ||= 'Parse Errors';
+ delete $opt{role};
+ } elsif ($opt{role} eq 'structure-errors') {
+ $opt{id} ||= 'document-errors';
+ $opt{title} ||= 'Structural Errors';
+ $opt{short_title} ||= 'Struct. Errors';
+ delete $opt{role};
+ } elsif ($opt{role} eq 'reformatted') {
+ $opt{id} ||= 'document-tree';
+ $opt{title} ||= 'Reformatted Document Source';
+ $opt{short_title} ||= 'Reformatted';
+ delete $opt{role}
+ } elsif ($opt{role} eq 'tree') {
+ $opt{id} ||= 'document-tree';
+ $opt{title} ||= 'Document Tree';
+ $opt{short_title} ||= 'Tree';
+ delete $opt{role};
+ } elsif ($opt{role} eq 'structure') {
+ $opt{id} ||= 'document-structure';
+ $opt{title} ||= 'Document Structure';
+ $opt{short_title} ||= 'Structure';
+ delete $opt{role};
+ }
+ }
+
+ $self->{section_rank}++;
$self->html ('
input->id_prefix . $opt{id};
- $self->html (' id="' . $htescape->($id) . '"');
- push @{$self->{nav}}, [$id => $opt{short_title} || $opt{title}]
- unless $self->input->nested;
+ $self->html (' id="' . $htescape->($id) . '">');
+ if ($self->{section_rank} == 2) {
+ my $st = $opt{short_title} || $opt{title};
+ push @{$self->{nav}},
+ [$id => $st => $opt{text}];
+
+ $self->start_tag ('script');
+ $self->html (qq[ addSectionLink ('] . $self->input->id_prefix .
+ qq[$id', ']);
+ $self->nl_text ($st, text => $opt{text});
+ $self->html (q[') ]);
+ $self->end_tag ('script');
+ }
+ } else {
+ $self->html ('>');
}
- $self->html ('>
' . $htescape->($opt{title}) . '
');
+ my $section_rank = $self->{section_rank};
+ $section_rank = 6 if $section_rank > 6;
+ $self->html ('');
+ $self->nl_text ($opt{title}, text => $opt{text});
+ $self->html ('');
} # start_section
sub end_section ($) {
my $self = shift;
$self->html ('');
$self->{handle}->flush;
+ $self->{section_rank}--;
} # end_section
+sub start_error_list ($%) {
+ my ($self, %opt) = @_;
+
+ if (defined $opt{role}) {
+ if ($opt{role} eq 'parse-errors') {
+ $opt{id} ||= 'parse-errors-list';
+ delete $opt{role};
+ } elsif ($opt{role} eq 'structure-errors') {
+ $opt{id} ||= 'document-errors-list';
+ delete $opt{role};
+ }
+ }
+
+ $self->start_tag ('dl', %opt);
+} # start_error_list
+
+sub end_error_list ($%) {
+ my ($self, %opt) = @_;
+
+ if (defined $opt{role}) {
+ if ($opt{role} eq 'parse-errors') {
+ delete $opt{role};
+ $self->end_tag ('dl');
+ ## NOTE: For parse error list, the |add_source_to_parse_error_list|
+ ## method is invoked at the end of |generate_source_string_section|,
+ ## since that generation method is invoked after the error list
+ ## is generated.
+ } elsif ($opt{role} eq 'structure-errors') {
+ delete $opt{role};
+ $self->end_tag ('dl');
+ $self->add_source_to_parse_error_list ('document-errors-list');
+ } else {
+ $self->end_tag ('dl');
+ }
+ } else {
+ $self->end_tag ('dl');
+ }
+} # end_error_list
+
+sub add_source_to_parse_error_list ($$) {
+ my $self = shift;
+
+ $self->script (q[addSourceToParseErrorList ('] . $self->input->id_prefix .
+ q[', '] . shift () . q[')]);
+} # add_source_to_parse_error_list
+
sub start_code_block ($) {
shift->html ('');
} # start_code_block
@@ -132,9 +238,38 @@
sub dt ($$;%) {
my ($self, $content, %opt) = @_;
$self->start_tag ('dt', %opt);
- $self->text ($content);
+ $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->html ('