--- Webpacus/lib/Webpacus/Controller/Editor.pm 2005/11/27 15:14:54 179
+++ Webpacus/lib/Webpacus/Controller/Editor.pm 2005/11/27 17:26:43 180
@@ -4,6 +4,7 @@
use warnings;
use base 'Catalyst::Controller';
+use HTML::Tidy;
use Data::Dumper;
=head1 NAME
@@ -168,10 +169,47 @@
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/,
+ ] );
+ if ( $tidy->parse('html', $html) ) {
+ if ( $tidy->messages ) {
+ $html .= '
HTML Tidy output:';
+
+ my @lines = split(/[\n\r]+/, $html);
+
+ # 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 - 2 ) ];
+ 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 .= "
$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 );
}