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 |
140 |
|
|
141 |
$c->stash->{'css_content'} = $webpac->load_html( $css_full_path ); |
$c->stash->{'css_content'} = $webpac->load_html( $css_full_path ); |
142 |
|
|
143 |
|
$c->stash->{'css_list'} = [ qw/user.css foobar.css/ ]; |
144 |
|
|
145 |
$c->stash->{template} = 'editor/css.tt'; |
$c->stash->{template} = 'editor/css.tt'; |
146 |
} |
} |
147 |
|
|
171 |
|
|
172 |
my $webpac = $c->comp('Model::WebPAC'); |
my $webpac = $c->comp('Model::WebPAC'); |
173 |
|
|
174 |
|
my $html = $webpac->record( mfn => $mfn, template => $template_filename ); |
175 |
|
|
176 |
|
if ($html) { |
177 |
|
$c->log->debug('check html with tidy'); |
178 |
|
my $tidy = new HTML::Tidy; |
179 |
|
$tidy->ignore( text => [ |
180 |
|
qr/DOCTYPE/, qr/unsupported/, qr/proprietary/i, |
181 |
|
qr/invalid character code/, |
182 |
|
qr/inserting missing 'title' element/, |
183 |
|
qr/lacks "summary" attribute/, |
184 |
|
] ); |
185 |
|
|
186 |
|
my @lines = split( "\n", $html ); |
187 |
|
$_ = "$_\n" for @lines; |
188 |
|
|
189 |
|
if ( $tidy->parse('tidy', @lines) ) { |
190 |
|
if ( $tidy->messages ) { |
191 |
|
$html .= <<__TIDY_CLOSE__; |
192 |
|
<div id="tidy_show" class="notice" style="display: none;" onclick="Element.hide('tidy_show'); Element.show('tidy');">?</div> |
193 |
|
<div id="tidy" class="tidy"> |
194 |
|
<a href="#" onclick="Element.hide('tidy'); Element.show('tidy_show'); return false;">close</a> |
195 |
|
HTML Tidy output: |
196 |
|
<br/> |
197 |
|
__TIDY_CLOSE__ |
198 |
|
# Escape <, >, & and ", and to produce valid XML |
199 |
|
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
200 |
|
my $escape_re = join '|' => keys %escape; |
201 |
|
|
202 |
|
foreach my $m ( $tidy->messages ) { |
203 |
|
my $c = $lines[ ( $m->line - 1 ) ]; |
204 |
|
my $txt = $m->as_string; |
205 |
|
$c =~ s/($escape_re)/$escape{$1}/g; |
206 |
|
$txt =~ s/($escape_re)/$escape{$1}/g; |
207 |
|
my $class = ''; |
208 |
|
$class = ' class="tidy_'.lc($1).'"' if ($txt =~ /(Warning|Error):/s); |
209 |
|
$html .= 'line ' . $m->line . ":<span${class}>$txt<tt>$c</tt></span>"; |
210 |
|
} |
211 |
|
$html .= '</div>'; |
212 |
|
} |
213 |
|
} else { |
214 |
|
$html .= qq{<div class="tidy tidy_error">Can't parse this record with HTML Tidy!</div>}; |
215 |
|
} |
216 |
|
} else { |
217 |
|
$html .= qq{<div class="no_results">Can't find record</div>}; |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
$c->response->content_type('text/html; charset=utf-8'); |
$c->response->content_type('text/html; charset=utf-8'); |
222 |
$c->res->output( |
$c->response->body( $html ); |
|
$webpac->record( mfn => $mfn, template => $template_filename ) |
|
|
); |
|
223 |
} |
} |
224 |
|
|
225 |
|
|