- From: Olivier Thereaux via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 23 Mar 2007 03:52:23 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/validator/httpd/cgi-bin In directory hutz:/tmp/cvs-serv20102/httpd/cgi-bin Modified Files: check Log Message: bringing back the document outline, with SAX. Using a <pre> and whitespace to show the level of outline is unfortunate, but is the only sane way of doing it in case of broken markup with unclosed <hx> Index: check =================================================================== RCS file: /sources/public/validator/httpd/cgi-bin/check,v retrieving revision 1.486 retrieving revision 1.487 diff -u -d -r1.486 -r1.487 --- check 22 Mar 2007 14:17:12 -0000 1.486 +++ check 23 Mar 2007 03:52:21 -0000 1.487 @@ -613,7 +613,7 @@ # preparse with XML parser if necessary # we should really be using a SAX ErrorHandler, but I can't find # a way to make it work with XML::LibXML::SAX::Parser... ** FIXME ** -# ditto, we should try using W3C::Validator::ErrorHandler, +# ditto, we should try using W3C::Validator::SAXHandler, # but it's badly linked to opensp at the moment if (&is_xml($File)) { @@ -737,7 +737,7 @@ ], ); - my $h = W3C::Validator::ErrorHandler->new($opensp, $File); + my $h = W3C::Validator::SAXHandler->new($opensp, $File); $opensp->handler($h); $opensp->parse_string(join"\n",@{$File->{Content}}); @@ -873,7 +873,7 @@ # if $File->{Opt}->{'Show Errors'}; #$template->param('file_raw_errors' => &show_errors($File)) # if $template->param('opt_show_raw_errors'); - $T->param(file_outline => &outline($File)) if $T->param('opt_show_outline'); +# $T->param(file_outline => &outline($File)) if $T->param('opt_show_outline'); print $template->output; @@ -1067,6 +1067,10 @@ } elsif (defined $File->{Tentative}) { $T->param(is_tentative => TRUE); } + + if ($File->{Opt}->{'Outline'}) { + $T->param(file_outline => $File->{heading_outline}); + } my $thispage = self_url_file($File); $T->param(file_thispage => $thispage); @@ -2129,18 +2133,64 @@ ##### -sub W3C::Validator::ErrorHandler::new +sub W3C::Validator::SAXHandler::new { my $class = shift; my $parser = shift; my $File = shift; - my $self = { _file => $File, _parser => $parser }; + my $self = { _file => $File, _parser => $parser, + current_heading_level => 0, am_in_heading => 0 }; bless $self, $class; } -sub W3C::Validator::ErrorHandler::error +sub W3C::Validator::SAXHandler::characters +{ + my ($self, $chars) = @_; + if ($self->{am_in_heading} == 1) { + my $data = $chars->{Data}; + $data =~ s/[\r|\n]/ /g; + $self->{_file}->{heading_outline} = $self->{_file}->{heading_outline} . $data; + } + +} + +sub W3C::Validator::SAXHandler::data +{ + my ($self, $chars) = @_; + if ($self->{am_in_heading} == 1) { + my $data = $chars->{Data}; + $data =~ s/[\r|\n]/ /g; + $self->{_file}->{heading_outline} = $self->{_file}->{heading_outline} . $data; + } + +} + + +sub W3C::Validator::SAXHandler::start_element +{ + my ($self, $element) = @_; + if ($element->{Name} =~ /^h([1-6])$/) { + + $self->{_file}->{heading_outline} = $self->{_file}->{heading_outline} . " " x int($1) . "[". $element->{Name}."] "; + $self->{am_in_heading} = 1; + } + +} + + +sub W3C::Validator::SAXHandler::end_element +{ + my ($self, $element) = @_; + if ($element->{Name} =~ /^h[1-6]$/) { + $self->{_file}->{heading_outline} = $self->{_file}->{heading_outline} . "\n"; + $self->{am_in_heading} = 0; + } + +} + +sub W3C::Validator::SAXHandler::error { my $self = shift; my $error = shift;
Received on Friday, 23 March 2007 03:52:33 UTC