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 |
|
my %nesttag = init_nesttag(); |
139 |
|
|
140 |
############################################################################## |
############################################################################## |
141 |
## reading user input from $infos |
## reading user input from $infos |
142 |
## |
## |
143 |
@PARAM = @ARGV; # we keep this for backward compatibility with an old version |
my @file; |
|
# of the slidemaker tool |
|
|
#when the parameters were in Makefile or make.bat |
|
144 |
|
|
145 |
# read parameters from infos.txt and put them in @PARAM |
############################################################################## |
146 |
if (open(INFOS, $infos)) { |
sub parse_infos { |
147 |
print STDOUT "--- Reading parameters file $infos ---\n"; |
my @file=@_; |
|
local(@file,$counter); |
|
|
$counter = 0; |
|
|
@file = <INFOS>; |
|
|
@PARAM = (); |
|
148 |
do { |
do { |
149 |
if ($file[0] && $file[0] =~ /^[^#\n\r]/) { |
if ($file[0] && $file[0] =~ /^[^#\n\r]/) { |
150 |
$file[0] =~ s/\n//; # remove UNIX \n |
$file[0] =~ s/\n//; # remove UNIX \n |
151 |
$file[0] =~ s/\r//; # remove WINDOWS \r |
$file[0] =~ s/\r//; # remove WINDOWS \r |
152 |
$file[0] =~ s/ *= */=/; |
my ($var,$value) = split(/ *= */,$file[0],2); |
153 |
$PARAM[$counter++] = $file[0]; |
$value=~s/'/\\'/g; |
154 |
print "$file[0]\n"; |
$cmd="\$$var = \'$value\';"; |
155 |
|
if (defined($value)) { |
156 |
|
eval($cmd) || warn "problem with eval of: $cmd"; |
157 |
|
} else { |
158 |
|
die "no value defined for $var"; |
159 |
|
} |
160 |
|
print STDERR "$file[0]\n"; |
161 |
} |
} |
162 |
} while (shift(@file)); |
} while (shift(@file)); |
163 |
} |
} |
164 |
## @PARAM is now a table with the user preferences for his presentation |
############################################################################## |
165 |
|
|
166 |
## process arguments |
parse_infos(@ARGV); # backward compatibility and for pack |
167 |
## each preset variable is now re-attributed using the user preferences |
|
168 |
foreach (@PARAM) { |
# read parameters from infos.txt and put them in @PARAM |
169 |
my ($var,$value) = split(/ *= */,$_,2); |
if (open(INFOS, $infos)) { |
170 |
$value=~s/'/\\'/g; |
print STDERR "--- Reading parameters file $infos ---\n"; |
171 |
$cmd="\$$var = \'$value\';"; |
@file = <INFOS>; |
172 |
if ($value) { |
parse_infos(@file); |
|
eval($cmd) || die "problem with eval of: $cmd"; |
|
|
} else { |
|
|
die "no value defined for $var"; |
|
|
} |
|
173 |
} |
} |
174 |
|
|
175 |
|
# try to read local infos.txt for template |
176 |
|
if (-f "$template/$infos" && open(INFOS,"$template/$infos")) { |
177 |
|
print STDERR "--- Reading template parameters file $template/$infos ---\n"; |
178 |
|
@file = <INFOS>; |
179 |
|
parse_infos(@file); |
180 |
|
close(INFOS); |
181 |
|
} |
182 |
|
|
183 |
|
## @PARAM is now a table with the user preferences for his presentation |
184 |
|
|
185 |
## use charset |
## use charset |
186 |
|
|
187 |
if ($charset) { |
if ($charset) { |
190 |
$http_equiv=''; |
$http_equiv=''; |
191 |
} |
} |
192 |
|
|
193 |
|
|
194 |
############################################################################## |
############################################################################## |
195 |
## read the raw html presentation |
## read the raw html presentation |
196 |
## |
## |
200 |
$/ = undef; |
$/ = undef; |
201 |
open(ALL, $all) || die "Error: Cannot open file: $all"; |
open(ALL, $all) || die "Error: Cannot open file: $all"; |
202 |
my $buf = <ALL>; |
my $buf = <ALL>; |
203 |
|
$buf =~ s/\r//g; # remove WINDOWS \r |
204 |
close(ALL); |
close(ALL); |
205 |
$/ = $sep; |
$/ = $sep; |
206 |
|
|
208 |
## they do not need to show up on the slides |
## they do not need to show up on the slides |
209 |
$buf =~ s/<!--.*?-->//sgo; |
$buf =~ s/<!--.*?-->//sgo; |
210 |
|
|
211 |
|
## if $pack is set, output name of css (for inclusion in archive), but |
212 |
|
## reset $cssStandard only to filename (without path) |
213 |
|
|
214 |
|
if ($pack) { |
215 |
|
push @pack_additional,$cssStandard; |
216 |
|
$cssStandard =~ s/^.*\/([^\/]+)$/$1/g; |
217 |
|
} |
218 |
|
|
219 |
## 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 |
220 |
## if not it will generate a rather weird output |
## if not it will generate a rather weird output |
221 |
## split using <h1...> and </h1...> as separator (ignores attributes!) |
## split using <h1...> and </h1...> as separator (ignores attributes!) |
235 |
############################################################################## |
############################################################################## |
236 |
## processing the slides |
## processing the slides |
237 |
|
|
238 |
print STDOUT "\n--- Processing $total slides ---\n"; |
print STDERR "\n--- Processing $total slides ---\n"; |
239 |
|
|
240 |
## generate the header table of content of the presentation |
## generate the header table of content of the presentation |
241 |
## which is also the first page of the talk |
## which is also the first page of the talk |
252 |
Text::FastTemplate->preload( [ |
Text::FastTemplate->preload( [ |
253 |
{ file => 'slide.html', key => 'slide' }, |
{ file => 'slide.html', key => 'slide' }, |
254 |
{ file => 'overview.html', key => 'overview' }, |
{ file => 'overview.html', key => 'overview' }, |
255 |
|
{ file => 'title.html', key => 'title' }, |
256 |
]); |
]); |
257 |
|
|
258 |
## unroll relative anchors (#something) into links with slides |
## unroll relative anchors (#something) into links with slides |
264 |
my $tmp = $table[($i*2)].$table[($i*2)+1]; |
my $tmp = $table[($i*2)].$table[($i*2)+1]; |
265 |
while ($tmp =~ s,<a +name="*([^>"]+)"*>,,i) { |
while ($tmp =~ s,<a +name="*([^>"]+)"*>,,i) { |
266 |
$anchor_on_slide{$1}=($i+1); |
$anchor_on_slide{$1}=($i+1); |
267 |
print "\tslide ",($i+1)," anchor: $1\n" if ($debug); |
print STDERR "\tslide ",($i+1)," anchor: $1\n" if ($debug); |
268 |
} |
} |
269 |
} |
} |
270 |
|
|
343 |
## 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) |
344 |
&generateTOC; |
&generateTOC; |
345 |
|
|
346 |
|
## print additional files to pack |
347 |
|
print STDOUT join("\n",@pack_additional) if ($pack); |
348 |
|
|
349 |
print STDOUT "--- Finished ---\n"; |
print STDERR "--- Finished ---\n"; |
350 |
exit 0; |
exit 0; |
351 |
## |
## |
352 |
## end of the slidemaker main program |
## end of the slidemaker main program |
360 |
{ |
{ |
361 |
## open the file to write to |
## open the file to write to |
362 |
open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!"; |
open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!"; |
363 |
|
push @pack_additional,"$_[0].html" if ($pack); |
364 |
|
|
365 |
## the style sheet used in the table of content is |
## the style sheet used in the table of content is |
366 |
$stylelink = ""; |
$stylelink = ""; |
389 |
author => $author, |
author => $author, |
390 |
authorUrl => $authorUrl, |
authorUrl => $authorUrl, |
391 |
author2 => $author2, |
author2 => $author2, |
392 |
authorUrl2 => $authorUrl2, |
author2Url => $author2Url, |
393 |
|
|
394 |
date => $date, |
date => $date, |
395 |
|
|
396 |
toc => $loc_toc, |
toc_title => $loc_toc, |
397 |
|
template_dir => "$template/", |
398 |
); |
); |
399 |
|
|
400 |
} |
} |
411 |
$overview_data{toc_entries} = [ @toc_entries ]; |
$overview_data{toc_entries} = [ @toc_entries ]; |
412 |
|
|
413 |
my $page= new Text::FastTemplate key => 'overview'; |
my $page= new Text::FastTemplate key => 'overview'; |
414 |
|
$page_data{template_dir}='' if ($pack); |
415 |
print FOO $page->output( \%overview_data ); |
print FOO $page->output( \%overview_data ); |
416 |
|
|
417 |
close(FOO); |
close(FOO); |
428 |
my ($title,$subtitle,$nr) = @_; |
my ($title,$subtitle,$nr) = @_; |
429 |
$title =~ s/\r//ig; # remove the windows CR+LF |
$title =~ s/\r//ig; # remove the windows CR+LF |
430 |
$title =~ s/<[^>]+>//g; |
$title =~ s/<[^>]+>//g; |
431 |
|
$subtitle =~ s/<[^>]+>//g; |
432 |
|
|
433 |
if (! $title) { |
if (! $title) { |
434 |
return 1; |
return 1; |
439 |
if ($nr % $toc_on_page == 0) { |
if ($nr % $toc_on_page == 0) { |
440 |
my $toc_nr=int($nr/$toc_on_page); |
my $toc_nr=int($nr/$toc_on_page); |
441 |
|
|
442 |
%item = ( |
$item = { |
443 |
pre_html => $pre_ul, |
pre_html => $pre_ul, |
444 |
accesskey => " ", # space |
accesskey => " ", # space |
445 |
href => "index-toc$toc_nr.html", |
href => "index-toc$toc_nr.html", |
446 |
title => "...", |
title => "...", |
447 |
post_html => $post_ul, |
post_html => $post_ul, |
448 |
more => 1, # use style for more pages link (...) |
more => 1, # use style for more pages link (...) |
449 |
) |
}; |
450 |
# push @toc_entries, %item; |
push @toc_entries, $item; |
451 |
|
|
452 |
&closeOverview; |
&closeOverview; |
453 |
|
undef @toc_entries; |
454 |
&openOverview("$overview-toc$toc_nr"); |
&openOverview("$overview-toc$toc_nr"); |
455 |
$last_toc_title=''; |
$last_toc_title=''; |
456 |
} |
} |
457 |
|
|
458 |
$pre_ul=$post_ul=''; |
$pre_ul=$post_ul=''; |
459 |
if ($last_toc_title eq $title) { |
if ($last_toc_title eq $title && $subtitle) { |
460 |
$title = $subtitle; |
$title = $subtitle; |
461 |
$pre_ul='<ul>'; |
$pre_ul='<ul>'; |
462 |
$post_ul='</ul>'; |
$post_ul='</ul>'; |
478 |
}; |
}; |
479 |
push @toc_entries,$item; |
push @toc_entries,$item; |
480 |
} else { |
} else { |
481 |
%item = ( |
$item = { |
482 |
pre_html => $pre_ul, |
pre_html => $pre_ul, |
483 |
tabindex => "$nr", |
tabindex => "$nr", |
484 |
href => "slide$nr.html", |
href => "slide$nr.html", |
485 |
title => $title, |
title => $title, |
486 |
post_html => $post_ul, |
post_html => $post_ul, |
487 |
) |
}; |
488 |
# push @toc_entries,\%item; |
push @toc_entries,$item; |
489 |
} |
} |
490 |
} |
} |
491 |
## |
## |
528 |
|
|
529 |
$status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle; |
$status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle; |
530 |
$status =~ s/<[^>]+>//g; |
$status =~ s/<[^>]+>//g; |
531 |
print STDOUT $status; |
print STDERR $status; |
532 |
|
|
533 |
&verify_html($content); # check the html |
&verify_html($content); # check the html |
534 |
|
&check_tags($content); # check open and closed tags |
535 |
|
|
536 |
## write to the slide |
## write to the slide |
537 |
open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!"; |
open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!"; |
538 |
|
push @pack_additional,"slide$nr.html" if ($pack); |
539 |
|
|
540 |
my $toc_link = "$overview\.html"; |
my $toc_link = "$overview\.html"; |
541 |
|
|
560 |
|
|
561 |
my $slide_html=make_progress_bar($nr,$total); |
my $slide_html=make_progress_bar($nr,$total); |
562 |
|
|
563 |
|
# undefine body if no content is found (so that template can show |
564 |
|
# only title and sub-title |
565 |
|
if ($content !~ m/\S/g) { |
566 |
|
undef $content; |
567 |
|
} |
568 |
|
|
569 |
%page_data = ( |
%page_data = ( |
570 |
doctype => $doctype, |
doctype => $doctype, |
571 |
talkTitle => $talkTitle, |
talkTitle => $talkTitle, |
590 |
toc_link => $toc_link, |
toc_link => $toc_link, |
591 |
next_link => $next_link, |
next_link => $next_link, |
592 |
prev_title => $prev_title, |
prev_title => $prev_title, |
593 |
|
toc_title => $loc_toc, |
594 |
next_title => $next_title, |
next_title => $next_title, |
595 |
|
|
596 |
author => $author, |
author => $author, |
597 |
authorUrl => $authorUrl, |
authorUrl => $authorUrl, |
598 |
author2 => $author2, |
author2 => $author2, |
599 |
authorUrl2 => $authorUrl2, |
author2Url => $author2Url, |
600 |
|
|
601 |
date => $date, |
date => $date, |
602 |
|
|
603 |
slide_html => $slide_html, |
slide_html => $slide_html, |
604 |
|
|
605 |
|
template_dir => "$template/", |
606 |
); |
); |
607 |
|
|
608 |
my $page= new Text::FastTemplate key => 'slide'; |
my $page; |
609 |
print SLIDE $page->output( \%page_data ); |
if ($content) { |
610 |
|
$page= new Text::FastTemplate key => 'slide'; |
611 |
|
} else { |
612 |
|
$page= new Text::FastTemplate key => 'title'; |
613 |
|
} |
614 |
|
|
615 |
|
if ($pack) { |
616 |
|
$page_data{template_dir}=''; |
617 |
|
print SLIDE extract_files($page->output( \%page_data )); |
618 |
|
} else { |
619 |
|
print SLIDE $page->output( \%page_data ); |
620 |
|
} |
621 |
|
|
622 |
close(SLIDE); |
close(SLIDE); |
623 |
return 0; |
return 0; |
666 |
|
|
667 |
if ($_[0] =~ /<img([^>]*)>/im) { |
if ($_[0] =~ /<img([^>]*)>/im) { |
668 |
if (!($1 =~ /ALT=/im)) { |
if (!($1 =~ /ALT=/im)) { |
669 |
print STDOUT "WARNING: <IMG> without ALT\n"; |
print STDERR "WARNING: <IMG> without ALT\n"; |
670 |
print STDOUT " <IMG$1>\n" ; |
print STDERR " <IMG$1>\n" ; |
671 |
} |
} |
672 |
} |
} |
673 |
} |
} |
676 |
# clean the html of the slide |
# clean the html of the slide |
677 |
# remove all <div class="comment">blabla</div> |
# remove all <div class="comment">blabla</div> |
678 |
sub clean_html { |
sub clean_html { |
679 |
$_[0] =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs; |
my $tmp=$_[0]; |
680 |
return $_[0]; |
$tmp =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs; |
681 |
|
$tmp =~ s,</*font[^>]+>,,ig; |
682 |
|
return $tmp; |
683 |
} |
} |
684 |
|
|
685 |
############################################################################## |
############################################################################## |
704 |
my $pcnt_done=int($nr*100/$total); |
my $pcnt_done=int($nr*100/$total); |
705 |
my $pcnt_left=100-$pcnt_done; |
my $pcnt_left=100-$pcnt_done; |
706 |
|
|
707 |
if ($progress_bar) { |
if ($progress_bar && uc($progress_bar) ne "NO") { |
708 |
my $l=$r=" "; |
my $l=$r=" "; |
709 |
my $t="$nr of $total"; |
my $t="$nr of $total"; |
710 |
if ($pcnt_done > 50) { |
if ($pcnt_done > 50) { |
712 |
} else { |
} else { |
713 |
$r=$t; |
$r=$t; |
714 |
} |
} |
715 |
$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>'; |
716 |
|
if ($pcnt_done != 0) { |
717 |
|
$html.='<td width="'.$pcnt_done.'%" class="pcnt-done">'.$l.'</td>'; |
718 |
|
} |
719 |
|
if ($pcnt_left != 0) { |
720 |
|
$html.='<td width="'.$pcnt_left.'%" class="pcnt-left">'.$r.'</td>'; |
721 |
|
} |
722 |
|
$html.='</tr></table>'; |
723 |
} else { |
} else { |
724 |
$html="$loc_slide $nr $loc_of $total"; |
$html="$loc_slide $nr $loc_of $total"; |
725 |
} |
} |
728 |
} |
} |
729 |
|
|
730 |
############################################################################## |
############################################################################## |
731 |
# make slide progress bar |
# remove anchors <a href...> from html (for titles) |
732 |
sub remove_anchor { |
sub remove_anchor { |
733 |
my $foo = $_[0]; |
my $tmp = $_[0]; |
734 |
$foo=~s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig; |
$tmp =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig; |
735 |
return $foo; |
return $tmp; |
736 |
|
} |
737 |
|
|
738 |
|
############################################################################## |
739 |
|
# extract files referenced in presentation and remove dirs from slide html |
740 |
|
|
741 |
|
sub extract_files { |
742 |
|
my $tmp = $slide = $_[0]; |
743 |
|
while ($tmp =~ s/href="*([^"\s]+)"*//ism || |
744 |
|
$tmp =~ s/src="*([^"\s]+)"*//ism) { |
745 |
|
if ("$1" !~ m/[hf]t?tp:/ && -f "$1" && !grep(/$1/,@pack_additional)) { |
746 |
|
my $file=$1; |
747 |
|
push @pack_additional,$file; |
748 |
|
if ($file =~ m,^(.+)/([^/]+),) { |
749 |
|
my ($d,$f) = ($1,$2); |
750 |
|
$slide =~ s,${d}/${f},${f},g; |
751 |
|
} |
752 |
|
} |
753 |
|
} |
754 |
|
return $slide; |
755 |
} |
} |
756 |
|
|
757 |
|
############################################################################## |
758 |
|
# check tags in slide |
759 |
|
# based on code from hindent 1.1.2 by Paul Balyoz <pab@domtools.com> |
760 |
|
|
761 |
|
sub init_nesttag { |
762 |
|
# Tags that require their own end tag <TAG>...</TAG> we will nest them |
763 |
|
# properly: (WARNING, you must use lower-case here) |
764 |
|
# All other tags (not on this list) will be ignored for indenting purposes. |
765 |
|
return ( |
766 |
|
'html' => 1, |
767 |
|
'head' => 1, |
768 |
|
'body' => 1, |
769 |
|
'title' => 1, |
770 |
|
|
771 |
|
'a' => 1, |
772 |
|
|
773 |
|
'table' => 1, |
774 |
|
'tr' => 1, |
775 |
|
'th' => 1, |
776 |
|
'td' => 1, |
777 |
|
|
778 |
|
'form' => 1, |
779 |
|
'select' => 1, |
780 |
|
'textarea' => 1, |
781 |
|
|
782 |
|
# 'p' => 1, Don't do this one because many people use <P> but not </P> |
783 |
|
'ul' => 1, |
784 |
|
'ol' => 1, |
785 |
|
'dl' => 1, |
786 |
|
'blockquote' => 1, |
787 |
|
'center' => 1, |
788 |
|
'div' => 1, |
789 |
|
|
790 |
|
'font' => 1, |
791 |
|
'pre' => 1, |
792 |
|
'tt' => 1, |
793 |
|
'i' => 1, |
794 |
|
'b' => 1, |
795 |
|
'u' => 1, |
796 |
|
'strike' => 1, |
797 |
|
'big' => 1, |
798 |
|
'small' => 1, |
799 |
|
'sub' => 1, |
800 |
|
'sup' => 1, |
801 |
|
'em' => 1, |
802 |
|
'strong' => 1, |
803 |
|
'dfn' => 1, |
804 |
|
'code' => 1, |
805 |
|
'samp' => 1, |
806 |
|
'kbd' => 1, |
807 |
|
'var' => 1, |
808 |
|
'cite' => 1, |
809 |
|
|
810 |
|
'h1' => 1, |
811 |
|
'h2' => 1, |
812 |
|
'h3' => 1, |
813 |
|
'h4' => 1, |
814 |
|
'h5' => 1, |
815 |
|
'h6' => 1, |
816 |
|
|
817 |
|
'applet' => 1, |
818 |
|
|
819 |
|
'map' => 1, |
820 |
|
|
821 |
|
'frameset' => 1, |
822 |
|
'noframes' => 1, |
823 |
|
); |
824 |
|
} |
825 |
|
|
826 |
|
sub check_tags { |
827 |
|
my $tmp = $_[0]; |
828 |
|
my @tagstack; |
829 |
|
my $level=0; |
830 |
|
|
831 |
|
while ($tmp =~ /<(.*?)>/gsm) { |
832 |
|
my $tag=$1; $tag=~s/\s.+//g; |
833 |
|
# if regular tag, push it on stack; if end-tag, pop it off stack. |
834 |
|
# but don't do any of this if it's not a special "nesting" tag! |
835 |
|
if ($tag !~ m,^/,) { |
836 |
|
if ($nesttag{lc($tag)}) { |
837 |
|
push @tagstack,$tag; |
838 |
|
$level++; # remember how much for later |
839 |
|
} |
840 |
|
} else { |
841 |
|
$tag =~ s,^/,,; # convert this end-tag to a begin-tag |
842 |
|
$tag = lc($tag); |
843 |
|
if ($nesttag{lc($tag)}) { |
844 |
|
# throw away tags until we find a match |
845 |
|
if ($#tagstack > -1) { |
846 |
|
while ($tag ne lc(pop @tagstack)) { |
847 |
|
$level--; # we threw away extra tags |
848 |
|
last if $#tagstack <= 0; |
849 |
|
} |
850 |
|
$level--; # we threw away extra tags |
851 |
|
if ($level < 0) { |
852 |
|
print STDERR "WARNING: more end than begin tags around </$tag> !\n"; |
853 |
|
} |
854 |
|
} |
855 |
|
} |
856 |
|
} |
857 |
|
} |
858 |
|
|
859 |
|
if ($level > 0) { |
860 |
|
print STDERR "WARNING: level=$level, ", $#tagstack+1," tags left on stack after done parsing! Specifically:\n<",join("> <",@tagstack),">\n"; |
861 |
|
} |
862 |
|
|
863 |
|
} |
864 |
|
|