--- test/html-webhacc/WebHACC/Output.pm 2008/07/21 12:56:34 1.7 +++ test/html-webhacc/WebHACC/Output.pm 2008/09/14 03:09:23 1.24 @@ -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 => [], 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,6 +55,18 @@ 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'; } # set_utf8 @@ -73,66 +96,108 @@ 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) = @_; + 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 ('