use strict; use HTML::TreeBuilder; use Template; use Syntax::Highlight::Perl; use HTML::Entities; # Rechtstreeks uit http://tnx.nl/scribble.plp sub tidy { require Syntax::Highlight::Perl; my ($data) = @_; $data = decode_entities($data); my $hl = Syntax::Highlight::Perl->new; $hl->define_substitution( '<' => '<', '>' => '>', '&' => '&', "\t" => ' ', ' ' => ' ', ); $hl->set_format( $_ => [ "", "" ] ) for qw/Comment Directive Label Quote String Subroutine Variable Keyword Builtin Operator Package Number CodeTerm Symbol DATA/; return $hl->format_string($data); } my $tree = HTML::TreeBuilder->new; $tree->parse_file('slides.html'); my $i = 0; my $sf = 'slide%d.html'; my $tt = Template->new({INCLUDE_PATH => '.'}); my @slides = $tree->look_down(_tag => 'div'); my $index = '
\n?(.*?)\n?<\/pre>/"" . tidy($1) . "<\/pre>"/ges;
$slide =~ s/\[\[\[/</g; # vies.
$tt->process(
'slide.html',
{
title => $title,
slide => $slide,
index => $j,
total => scalar @slides,
indexlink => sprintf($sf, 0),
($i != 0 ? (first => sprintf($sf, 1)) : ()),
($i > 0 ? (prev => sprintf($sf, $j - 1)) : ()),
($i < $#slides ? (next => sprintf($sf, $j + 1),
spoiler => $slides[$i + 1]->look_down(_tag => qr/^h\d$/)->content->[0]) : ())
},
sprintf($sf, $j)
) or die $tt->error;
$index .= sprintf qq[