/[webpac2]/Webpacus/lib/Webpacus/Controller/Editor.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Webpacus/lib/Webpacus/Controller/Editor.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 179 by dpavlin, Sun Nov 27 15:14:54 2005 UTC revision 181 by dpavlin, Sun Nov 27 18:18:11 2005 UTC
# Line 4  use strict; Line 4  use strict;
4  use warnings;  use warnings;
5  use base 'Catalyst::Controller';  use base 'Catalyst::Controller';
6    
7    use HTML::Tidy;
8  use Data::Dumper;  use Data::Dumper;
9    
10  =head1 NAME  =head1 NAME
# Line 168  sub record : Local { Line 169  sub record : Local {
169    
170          my $webpac = $c->comp('Model::WebPAC');          my $webpac = $c->comp('Model::WebPAC');
171    
172            my $html = $webpac->record( mfn => $mfn, template => $template_filename );
173    
174            if ($html) {
175                    $c->log->debug('check html with tidy');
176                    my $tidy = new HTML::Tidy;
177                    $tidy->ignore( text => [
178                            qr/DOCTYPE/, qr/unsupported/, qr/proprietary/i,
179                            qr/invalid character code/,
180                            qr/inserting missing 'title' element/,
181                            qr/lacks "summary" attribute/,
182                    ] );
183    
184                    my @lines = split( "\n", $html );
185                    $_ = "$_\n" for @lines;
186    
187                    if ( $tidy->parse('tidy', @lines) ) {
188                            if ( $tidy->messages ) {
189                                    $html .= <<__TIDY_CLOSE__;
190    <div id="tidy_show" class="notice" style="display: none;" onclick="Element.hide('tidy_show'); Element.show('tidy');">?</div>
191    <div id="tidy" class="tidy">
192    <a href="#" onclick="Element.hide('tidy'); Element.show('tidy_show'); return false;">close</a>
193    HTML Tidy output:
194    <br/>
195    __TIDY_CLOSE__
196                                    # Escape <, >, & and ", and to produce valid XML
197                                    my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
198                                    my $escape_re  = join '|' => keys %escape;
199    
200                                    foreach my $m ( $tidy->messages ) {
201                                            my $c = $lines[ ( $m->line - 1 ) ];
202                                            my $txt = $m->as_string;
203                                            $c =~ s/($escape_re)/$escape{$1}/g;
204                                            $txt =~ s/($escape_re)/$escape{$1}/g;
205                                            my $class = '';
206                                            $class = ' class="tidy_'.lc($1).'"' if ($txt =~ /(Warning|Error):/s);
207                                            $html .= 'line ' . $m->line . ":<span${class}>$txt<tt>$c</tt></span>";
208                                    }
209                                    $html .= '</div>';
210                            }
211                    } else {
212                            $html .= qq{<div class="tidy tidy_error">Can't parse this record with HTML Tidy!</div>};
213                    }
214            }
215                    
216                    
217          $c->response->content_type('text/html; charset=utf-8');          $c->response->content_type('text/html; charset=utf-8');
218          $c->res->output(          $c->res->output( $html );
                 $webpac->record( mfn => $mfn, template => $template_filename )  
         );  
219  }  }
220    
221    

Legend:
Removed from v.179  
changed lines
  Added in v.181

  ViewVC Help
Powered by ViewVC 1.1.26