53 |
## |
## |
54 |
|
|
55 |
## show debug output |
## show debug output |
56 |
my $debug=1; |
my $debug=0; |
57 |
|
|
58 |
## default DOCTYPE added on the slides |
## default DOCTYPE added on the slides |
59 |
$doctype = '<html xmlns="http://www.w3.org/TR/REC-html40">'; |
$doctype = '<html xmlns="http://www.w3.org/TR/REC-html40">'; |
133 |
my %page_data; |
my %page_data; |
134 |
my %overview_data; |
my %overview_data; |
135 |
|
|
136 |
|
my $pack = 0; |
137 |
|
my @pack_additional; # additional files to pack (pictures, logos...) |
138 |
|
|
139 |
############################################################################## |
############################################################################## |
140 |
## reading user input from $infos |
## reading user input from $infos |
141 |
## |
## |
143 |
# of the slidemaker tool |
# of the slidemaker tool |
144 |
#when the parameters were in Makefile or make.bat |
#when the parameters were in Makefile or make.bat |
145 |
|
|
146 |
# read parameters from infos.txt and put them in @PARAM |
my @file; |
147 |
if (open(INFOS, $infos)) { |
|
148 |
print STDOUT "--- Reading parameters file $infos ---\n"; |
############################################################################## |
149 |
local(@file,$counter); |
sub parse_infos { |
150 |
$counter = 0; |
my @file=@_; |
|
@file = <INFOS>; |
|
|
@PARAM = (); |
|
151 |
do { |
do { |
152 |
if ($file[0] && $file[0] =~ /^[^#\n\r]/) { |
if ($file[0] && $file[0] =~ /^[^#\n\r]/) { |
153 |
$file[0] =~ s/\n//; # remove UNIX \n |
$file[0] =~ s/\n//; # remove UNIX \n |
154 |
$file[0] =~ s/\r//; # remove WINDOWS \r |
$file[0] =~ s/\r//; # remove WINDOWS \r |
155 |
$file[0] =~ s/ *= */=/; |
my ($var,$value) = split(/ *= */,$file[0],2); |
156 |
$PARAM[$counter++] = $file[0]; |
$value=~s/'/\\'/g; |
157 |
print "$file[0]\n"; |
$cmd="\$$var = \'$value\';"; |
158 |
|
if (defined($value)) { |
159 |
|
eval($cmd) || warn "problem with eval of: $cmd"; |
160 |
|
} else { |
161 |
|
die "no value defined for $var"; |
162 |
|
} |
163 |
|
print STDERR "$file[0]\n"; |
164 |
} |
} |
165 |
} while (shift(@file)); |
} while (shift(@file)); |
166 |
} |
} |
167 |
## @PARAM is now a table with the user preferences for his presentation |
############################################################################## |
168 |
|
|
169 |
## process arguments |
# read parameters from infos.txt and put them in @PARAM |
170 |
## each preset variable is now re-attributed using the user preferences |
if (open(INFOS, $infos)) { |
171 |
foreach (@PARAM) { |
print STDERR "--- Reading parameters file $infos ---\n"; |
172 |
my ($var,$value) = split(/ *= */,$_,2); |
@file = <INFOS>; |
173 |
$value=~s/'/\\'/g; |
parse_infos(@file); |
174 |
$cmd="\$$var = \'$value\';"; |
} |
175 |
if ($value) { |
|
176 |
eval($cmd) || die "problem with eval of: $cmd"; |
# try to read local infos.txt for template |
177 |
} else { |
if (-f "$template/$infos" && open(INFOS,"$template/$infos")) { |
178 |
die "no value defined for $var"; |
print STDERR "--- Reading template parameters file $template/$infos ---\n"; |
179 |
} |
@file = <INFOS>; |
180 |
|
parse_infos(@file); |
181 |
|
close(INFOS); |
182 |
} |
} |
183 |
|
|
184 |
|
## @PARAM is now a table with the user preferences for his presentation |
185 |
|
|
186 |
## use charset |
## use charset |
187 |
|
|
188 |
if ($charset) { |
if ($charset) { |
191 |
$http_equiv=''; |
$http_equiv=''; |
192 |
} |
} |
193 |
|
|
194 |
|
|
195 |
############################################################################## |
############################################################################## |
196 |
## read the raw html presentation |
## read the raw html presentation |
197 |
## |
## |
201 |
$/ = undef; |
$/ = undef; |
202 |
open(ALL, $all) || die "Error: Cannot open file: $all"; |
open(ALL, $all) || die "Error: Cannot open file: $all"; |
203 |
my $buf = <ALL>; |
my $buf = <ALL>; |
204 |
|
$buf =~ s/\r//g; # remove WINDOWS \r |
205 |
close(ALL); |
close(ALL); |
206 |
$/ = $sep; |
$/ = $sep; |
207 |
|
|
209 |
## they do not need to show up on the slides |
## they do not need to show up on the slides |
210 |
$buf =~ s/<!--.*?-->//sgo; |
$buf =~ s/<!--.*?-->//sgo; |
211 |
|
|
212 |
|
## if $pack is set, output name of css (for inclusion in archive), but |
213 |
|
## reset $cssStandard only to filename (without path) |
214 |
|
|
215 |
|
if ($pack) { |
216 |
|
push @pack_additional,$cssStandard; |
217 |
|
$cssStandard =~ s/^.*\/([^\/]+)$/$1/g; |
218 |
|
} |
219 |
|
|
220 |
## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags |
## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags |
221 |
## if not it will generate a rather weird output |
## if not it will generate a rather weird output |
222 |
## split using <h1...> and </h1...> as separator (ignores attributes!) |
## split using <h1...> and </h1...> as separator (ignores attributes!) |
236 |
############################################################################## |
############################################################################## |
237 |
## processing the slides |
## processing the slides |
238 |
|
|
239 |
print STDOUT "\n--- Processing $total slides ---\n"; |
print STDERR "\n--- Processing $total slides ---\n"; |
240 |
|
|
241 |
## generate the header table of content of the presentation |
## generate the header table of content of the presentation |
242 |
## which is also the first page of the talk |
## which is also the first page of the talk |
253 |
Text::FastTemplate->preload( [ |
Text::FastTemplate->preload( [ |
254 |
{ file => 'slide.html', key => 'slide' }, |
{ file => 'slide.html', key => 'slide' }, |
255 |
{ file => 'overview.html', key => 'overview' }, |
{ file => 'overview.html', key => 'overview' }, |
256 |
|
{ file => 'title.html', key => 'title' }, |
257 |
]); |
]); |
258 |
|
|
259 |
## unroll relative anchors (#something) into links with slides |
## unroll relative anchors (#something) into links with slides |
265 |
my $tmp = $table[($i*2)].$table[($i*2)+1]; |
my $tmp = $table[($i*2)].$table[($i*2)+1]; |
266 |
while ($tmp =~ s,<a +name="*([^>"]+)"*>,,i) { |
while ($tmp =~ s,<a +name="*([^>"]+)"*>,,i) { |
267 |
$anchor_on_slide{$1}=($i+1); |
$anchor_on_slide{$1}=($i+1); |
268 |
print "\tslide ",($i+1)," anchor: $1\n" if ($debug); |
print STDERR "\tslide ",($i+1)," anchor: $1\n" if ($debug); |
269 |
} |
} |
270 |
} |
} |
271 |
|
|
344 |
## and would not work on all platforms (ie would fail on Joe's laptop) |
## and would not work on all platforms (ie would fail on Joe's laptop) |
345 |
&generateTOC; |
&generateTOC; |
346 |
|
|
347 |
|
## print additional files to pack |
348 |
|
print STDOUT join("\n",@pack_additional) if ($pack); |
349 |
|
|
350 |
print STDOUT "--- Finished ---\n"; |
print STDERR "--- Finished ---\n"; |
351 |
exit 0; |
exit 0; |
352 |
## |
## |
353 |
## end of the slidemaker main program |
## end of the slidemaker main program |
361 |
{ |
{ |
362 |
## open the file to write to |
## open the file to write to |
363 |
open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!"; |
open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!"; |
364 |
|
push @pack_additional,"$_[0].html" if ($pack); |
365 |
|
|
366 |
## the style sheet used in the table of content is |
## the style sheet used in the table of content is |
367 |
$stylelink = ""; |
$stylelink = ""; |
394 |
|
|
395 |
date => $date, |
date => $date, |
396 |
|
|
397 |
toc => $loc_toc, |
toc_title => $loc_toc, |
398 |
|
template => $template, |
399 |
); |
); |
400 |
|
|
401 |
} |
} |
438 |
if ($nr % $toc_on_page == 0) { |
if ($nr % $toc_on_page == 0) { |
439 |
my $toc_nr=int($nr/$toc_on_page); |
my $toc_nr=int($nr/$toc_on_page); |
440 |
|
|
441 |
%item = ( |
$item = { |
442 |
pre_html => $pre_ul, |
pre_html => $pre_ul, |
443 |
accesskey => " ", # space |
accesskey => " ", # space |
444 |
href => "index-toc$toc_nr.html", |
href => "index-toc$toc_nr.html", |
445 |
title => "...", |
title => "...", |
446 |
post_html => $post_ul, |
post_html => $post_ul, |
447 |
more => 1, # use style for more pages link (...) |
more => 1, # use style for more pages link (...) |
448 |
) |
}; |
449 |
# push @toc_entries, %item; |
push @toc_entries, $item; |
450 |
|
|
451 |
&closeOverview; |
&closeOverview; |
452 |
|
undef @toc_entries; |
453 |
&openOverview("$overview-toc$toc_nr"); |
&openOverview("$overview-toc$toc_nr"); |
454 |
$last_toc_title=''; |
$last_toc_title=''; |
455 |
} |
} |
456 |
|
|
457 |
$pre_ul=$post_ul=''; |
$pre_ul=$post_ul=''; |
458 |
if ($last_toc_title eq $title) { |
if ($last_toc_title eq $title && $subtitle) { |
459 |
$title = $subtitle; |
$title = $subtitle; |
460 |
$pre_ul='<ul>'; |
$pre_ul='<ul>'; |
461 |
$post_ul='</ul>'; |
$post_ul='</ul>'; |
477 |
}; |
}; |
478 |
push @toc_entries,$item; |
push @toc_entries,$item; |
479 |
} else { |
} else { |
480 |
%item = ( |
$item = { |
481 |
pre_html => $pre_ul, |
pre_html => $pre_ul, |
482 |
tabindex => "$nr", |
tabindex => "$nr", |
483 |
href => "slide$nr.html", |
href => "slide$nr.html", |
484 |
title => $title, |
title => $title, |
485 |
post_html => $post_ul, |
post_html => $post_ul, |
486 |
) |
}; |
487 |
# push @toc_entries,\%item; |
push @toc_entries,$item; |
488 |
} |
} |
489 |
} |
} |
490 |
## |
## |
527 |
|
|
528 |
$status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle; |
$status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle; |
529 |
$status =~ s/<[^>]+>//g; |
$status =~ s/<[^>]+>//g; |
530 |
print STDOUT $status; |
print STDERR $status; |
531 |
|
|
532 |
&verify_html($content); # check the html |
&verify_html($content); # check the html |
533 |
|
|
534 |
## write to the slide |
## write to the slide |
535 |
open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!"; |
open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!"; |
536 |
|
push @pack_additional,"slide$nr.html" if ($pack); |
537 |
|
|
538 |
my $toc_link = "$overview\.html"; |
my $toc_link = "$overview\.html"; |
539 |
|
|
558 |
|
|
559 |
my $slide_html=make_progress_bar($nr,$total); |
my $slide_html=make_progress_bar($nr,$total); |
560 |
|
|
561 |
|
# undefine body if no content is found (so that template can show |
562 |
|
# only title and sub-title |
563 |
|
if ($content !~ m/\S/g) { |
564 |
|
undef $content; |
565 |
|
} |
566 |
|
|
567 |
%page_data = ( |
%page_data = ( |
568 |
doctype => $doctype, |
doctype => $doctype, |
569 |
talkTitle => $talkTitle, |
talkTitle => $talkTitle, |
588 |
toc_link => $toc_link, |
toc_link => $toc_link, |
589 |
next_link => $next_link, |
next_link => $next_link, |
590 |
prev_title => $prev_title, |
prev_title => $prev_title, |
591 |
|
toc_title => $loc_toc, |
592 |
next_title => $next_title, |
next_title => $next_title, |
593 |
|
|
594 |
author => $author, |
author => $author, |
600 |
|
|
601 |
slide_html => $slide_html, |
slide_html => $slide_html, |
602 |
|
|
603 |
|
template => $template, |
604 |
); |
); |
605 |
|
|
606 |
my $page= new Text::FastTemplate key => 'slide'; |
my $page; |
607 |
|
if ($content) { |
608 |
|
$page= new Text::FastTemplate key => 'slide'; |
609 |
|
} else { |
610 |
|
$page= new Text::FastTemplate key => 'title'; |
611 |
|
} |
612 |
print SLIDE $page->output( \%page_data ); |
print SLIDE $page->output( \%page_data ); |
613 |
|
extract_files($page->output( \%page_data )) if ($pack); |
614 |
close(SLIDE); |
close(SLIDE); |
615 |
return 0; |
return 0; |
616 |
} |
} |
658 |
|
|
659 |
if ($_[0] =~ /<img([^>]*)>/im) { |
if ($_[0] =~ /<img([^>]*)>/im) { |
660 |
if (!($1 =~ /ALT=/im)) { |
if (!($1 =~ /ALT=/im)) { |
661 |
print STDOUT "WARNING: <IMG> without ALT\n"; |
print STDERR "WARNING: <IMG> without ALT\n"; |
662 |
print STDOUT " <IMG$1>\n" ; |
print STDERR " <IMG$1>\n" ; |
663 |
} |
} |
664 |
} |
} |
665 |
} |
} |
668 |
# clean the html of the slide |
# clean the html of the slide |
669 |
# remove all <div class="comment">blabla</div> |
# remove all <div class="comment">blabla</div> |
670 |
sub clean_html { |
sub clean_html { |
671 |
$_[0] =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs; |
my $tmp=$_[0]; |
672 |
return $_[0]; |
$tmp =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs; |
673 |
|
$tmp =~ s,</*font[^>]+>,,ig; |
674 |
|
return $tmp; |
675 |
} |
} |
676 |
|
|
677 |
############################################################################## |
############################################################################## |
696 |
my $pcnt_done=int($nr*100/$total); |
my $pcnt_done=int($nr*100/$total); |
697 |
my $pcnt_left=100-$pcnt_done; |
my $pcnt_left=100-$pcnt_done; |
698 |
|
|
699 |
if ($progress_bar) { |
if ($progress_bar && uc($progress_bar) ne "NO") { |
700 |
my $l=$r=" "; |
my $l=$r=" "; |
701 |
my $t="$nr of $total"; |
my $t="$nr of $total"; |
702 |
if ($pcnt_done > 50) { |
if ($pcnt_done > 50) { |
704 |
} else { |
} else { |
705 |
$r=$t; |
$r=$t; |
706 |
} |
} |
707 |
$html='<table border="0" width="50%" cellpadding="0" cellspacing="0" align="right"><tr><td width="'.$pcnt_done.'%" class="pcnt-done">'.$l.'</td><td width="'.$pcnt_left.'%" class="pcnt-left">'.$r.'</td></tr></table>'; |
$html='<table border="0" width="50%" cellpadding="0" cellspacing="0" align="right"><tr>'; |
708 |
|
if ($pcnt_done != 0) { |
709 |
|
$html.='<td width="'.$pcnt_done.'%" class="pcnt-done">'.$l.'</td>'; |
710 |
|
} |
711 |
|
if ($pcnt_left != 0) { |
712 |
|
$html.='<td width="'.$pcnt_left.'%" class="pcnt-left">'.$r.'</td>'; |
713 |
|
} |
714 |
|
$html.='</tr></table>'; |
715 |
} else { |
} else { |
716 |
$html="$loc_slide $nr $loc_of $total"; |
$html="$loc_slide $nr $loc_of $total"; |
717 |
} |
} |
720 |
} |
} |
721 |
|
|
722 |
############################################################################## |
############################################################################## |
723 |
# make slide progress bar |
# remove anchors <a href...> from html (for titles) |
724 |
sub remove_anchor { |
sub remove_anchor { |
725 |
my $foo = $_[0]; |
my $tmp = $_[0]; |
726 |
$foo=~s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig; |
$tmp =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig; |
727 |
return $foo; |
return $tmp; |
728 |
|
} |
729 |
|
|
730 |
|
############################################################################## |
731 |
|
# extract files referenced in presentation |
732 |
|
|
733 |
|
sub extract_files { |
734 |
|
my $tmp = $_[0]; |
735 |
|
while ($tmp =~ s/<a\s+href="*([^"\s]+)"*//ism || |
736 |
|
$tmp =~ s/<img\s+src="*([^"\s]+)"*//ism) { |
737 |
|
if ("$1" !~ m/[hf]t?tp:/ && -f "$1" && !grep(/$1/,@pack_additional)) { |
738 |
|
push @pack_additional,$1; |
739 |
|
} |
740 |
|
} |
741 |
} |
} |