--- Webpacus/lib/Webpacus/Controller/Editor.pm 2005/11/27 15:14:54 179 +++ Webpacus/lib/Webpacus/Controller/Editor.pm 2005/11/27 18:18:11 181 @@ -4,6 +4,7 @@ use warnings; use base 'Catalyst::Controller'; +use HTML::Tidy; use Data::Dumper; =head1 NAME @@ -168,10 +169,53 @@ my $webpac = $c->comp('Model::WebPAC'); + my $html = $webpac->record( mfn => $mfn, template => $template_filename ); + + if ($html) { + $c->log->debug('check html with tidy'); + my $tidy = new HTML::Tidy; + $tidy->ignore( text => [ + qr/DOCTYPE/, qr/unsupported/, qr/proprietary/i, + qr/invalid character code/, + qr/inserting missing 'title' element/, + qr/lacks "summary" attribute/, + ] ); + + my @lines = split( "\n", $html ); + $_ = "$_\n" for @lines; + + if ( $tidy->parse('tidy', @lines) ) { + if ( $tidy->messages ) { + $html .= <<__TIDY_CLOSE__; + +
+close +HTML Tidy output: +
+__TIDY_CLOSE__ + # Escape <, >, & and ", and to produce valid XML + my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); + my $escape_re = join '|' => keys %escape; + + foreach my $m ( $tidy->messages ) { + my $c = $lines[ ( $m->line - 1 ) ]; + my $txt = $m->as_string; + $c =~ s/($escape_re)/$escape{$1}/g; + $txt =~ s/($escape_re)/$escape{$1}/g; + my $class = ''; + $class = ' class="tidy_'.lc($1).'"' if ($txt =~ /(Warning|Error):/s); + $html .= 'line ' . $m->line . ":$txt$c"; + } + $html .= '
'; + } + } else { + $html .= qq{
Can't parse this record with HTML Tidy!
}; + } + } + + $c->response->content_type('text/html; charset=utf-8'); - $c->res->output( - $webpac->record( mfn => $mfn, template => $template_filename ) - ); + $c->res->output( $html ); }