--- burst.pl 2001/05/05 19:20:27 1.7 +++ burst.pl 2001/05/11 22:04:54 1.17 @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# SLies Copyright 2001 Dobrica Pavlinusic +# PLies Copyright 2001 Dobrica Pavlinusic # # this tool is based on SlideMaker and XLSies tool # split a all.htm into slide*.htm @@ -53,7 +53,7 @@ ## ## show debug output -my $debug=1; +my $debug=0; ## default DOCTYPE added on the slides $doctype = ''; @@ -133,45 +133,54 @@ my %page_data; my %overview_data; +my $pack = 0; +my @pack_additional; # additional files to pack (pictures, logos...) + ############################################################################## ## reading user input from $infos ## -@PARAM = @ARGV; # we keep this for backward compatibility with an old version - # of the slidemaker tool - #when the parameters were in Makefile or make.bat +my @file; -# read parameters from infos.txt and put them in @PARAM -if (open(INFOS, $infos)) { - print STDOUT "--- Reading parameters file $infos ---\n"; - local(@file,$counter); - $counter = 0; - @file = ; - @PARAM = (); +############################################################################## +sub parse_infos { + my @file=@_; do { if ($file[0] && $file[0] =~ /^[^#\n\r]/) { $file[0] =~ s/\n//; # remove UNIX \n $file[0] =~ s/\r//; # remove WINDOWS \r - $file[0] =~ s/ *= */=/; - $PARAM[$counter++] = $file[0]; - print "$file[0]\n"; + my ($var,$value) = split(/ *= */,$file[0],2); + $value=~s/'/\\'/g; + $cmd="\$$var = \'$value\';"; + if (defined($value)) { + eval($cmd) || warn "problem with eval of: $cmd"; + } else { + die "no value defined for $var"; + } + print STDERR "$file[0]\n"; } } while (shift(@file)); } -## @PARAM is now a table with the user preferences for his presentation +############################################################################## -## process arguments -## each preset variable is now re-attributed using the user preferences -foreach (@PARAM) { - my ($var,$value) = split(/ *= */,$_,2); - $value=~s/'/\\'/g; - $cmd="\$$var = \'$value\';"; - if ($value) { - eval($cmd) || die "problem with eval of: $cmd"; - } else { - die "no value defined for $var"; - } +parse_infos(@ARGV); # backward compatibility and for pack + +# read parameters from infos.txt and put them in @PARAM +if (open(INFOS, $infos)) { + print STDERR "--- Reading parameters file $infos ---\n"; + @file = ; + parse_infos(@file); +} + +# try to read local infos.txt for template +if (-f "$template/$infos" && open(INFOS,"$template/$infos")) { + print STDERR "--- Reading template parameters file $template/$infos ---\n"; + @file = ; + parse_infos(@file); + close(INFOS); } +## @PARAM is now a table with the user preferences for his presentation + ## use charset if ($charset) { @@ -180,6 +189,7 @@ $http_equiv=''; } + ############################################################################## ## read the raw html presentation ## @@ -189,6 +199,7 @@ $/ = undef; open(ALL, $all) || die "Error: Cannot open file: $all"; my $buf = ; +$buf =~ s/\r//g; # remove WINDOWS \r close(ALL); $/ = $sep; @@ -196,6 +207,14 @@ ## they do not need to show up on the slides $buf =~ s///sgo; +## if $pack is set, output name of css (for inclusion in archive), but +## reset $cssStandard only to filename (without path) + +if ($pack) { + push @pack_additional,$cssStandard; + $cssStandard =~ s/^.*\/([^\/]+)$/$1/g; +} + ## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags ## if not it will generate a rather weird output ## split using and as separator (ignores attributes!) @@ -215,7 +234,7 @@ ############################################################################## ## processing the slides -print STDOUT "\n--- Processing $total slides ---\n"; +print STDERR "\n--- Processing $total slides ---\n"; ## generate the header table of content of the presentation ## which is also the first page of the talk @@ -232,6 +251,7 @@ Text::FastTemplate->preload( [ { file => 'slide.html', key => 'slide' }, { file => 'overview.html', key => 'overview' }, + { file => 'title.html', key => 'title' }, ]); ## unroll relative anchors (#something) into links with slides @@ -240,10 +260,10 @@ ## step 1: record anchors for($i=0; $i<$total; $i++) { - my $tmp = $table[($i*2)]; + my $tmp = $table[($i*2)].$table[($i*2)+1]; while ($tmp =~ s,,,i) { $anchor_on_slide{$1}=($i+1); - print "\tslide ",($i+1)," anchor: $1\n" if ($debug); + print STDERR "\tslide ",($i+1)," anchor: $1\n" if ($debug); } } @@ -278,15 +298,13 @@ ## need to check if the title contains any anchor ## if so it needs to be removed ## because the title is being used in the table of content to link to the corresponding slide - $table[0] =~ s/(.*)]*>(.*)<\/A>(.*)/$1$2$3/i; + $table[0] = remove_anchor($table[0]); ## grab next slide title $table[2] (if there's a next slide) ## to be able to use in the 'next' navigation button ## keep in mind that $table[1] contains the slide corresponding to the title $table[0] if ($table[2]) { - $next_title= $table[2]; - ## remove any anchor from the next slide title - $next_title =~ s/(.*)]*>(.*)<\/A>(.*)/$1$2$3/i; + $next_title= remove_anchor($table[2]); } ## the current slide content is stored $table[1] @@ -297,8 +315,8 @@ ## extract slide Sub Title

undef $slideSubTitle; - if ($slideContent =~ s/<[hH]2[^>]*>([^<]+)<\/[hH]2[^>]*>//) { - $slideSubTitle=$1; + if ($slideContent =~ s/<[hH]2[^>]*>(.+)<\/[hH]2[^>]*>//sm) { + $slideSubTitle=remove_anchor($1); } ## add the title of the current slide to the table of content @@ -310,7 +328,7 @@ &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$prev_title,$next_title); ## save the title of the previous slide to be displayed in the 'previous' navigation button - $prev_title="$table[0]"; + $prev_title=remove_anchor($table[0]); } ## process the next slide while (shift(@table)); @@ -324,8 +342,10 @@ ## and would not work on all platforms (ie would fail on Joe's laptop) &generateTOC; +## print additional files to pack +print STDOUT join("\n",@pack_additional) if ($pack); -print STDOUT "--- Finished ---\n"; +print STDERR "--- Finished ---\n"; exit 0; ## ## end of the slidemaker main program @@ -339,6 +359,7 @@ { ## open the file to write to open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!"; + push @pack_additional,"$_[0].html" if ($pack); ## the style sheet used in the table of content is $stylelink = ""; @@ -371,7 +392,8 @@ date => $date, - toc => $loc_toc, + toc_title => $loc_toc, + template_dir => "$template/", ); } @@ -388,6 +410,7 @@ $overview_data{toc_entries} = [ @toc_entries ]; my $page= new Text::FastTemplate key => 'overview'; + $page_data{template_dir}='' if ($pack); print FOO $page->output( \%overview_data ); close(FOO); @@ -414,23 +437,24 @@ if ($nr % $toc_on_page == 0) { my $toc_nr=int($nr/$toc_on_page); - %item = ( + $item = { pre_html => $pre_ul, accesskey => " ", # space href => "index-toc$toc_nr.html", title => "...", post_html => $post_ul, more => 1, # use style for more pages link (...) - ) -# push @toc_entries, %item; + }; + push @toc_entries, $item; &closeOverview; + undef @toc_entries; &openOverview("$overview-toc$toc_nr"); $last_toc_title=''; } $pre_ul=$post_ul=''; - if ($last_toc_title eq $title) { + if ($last_toc_title eq $title && $subtitle) { $title = $subtitle; $pre_ul='
    '; $post_ul='
'; @@ -452,14 +476,14 @@ }; push @toc_entries,$item; } else { - %item = ( + $item = { pre_html => $pre_ul, tabindex => "$nr", href => "slide$nr.html", title => $title, post_html => $post_ul, - ) -# push @toc_entries,\%item; + }; + push @toc_entries,$item; } } ## @@ -502,12 +526,13 @@ $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle; $status =~ s/<[^>]+>//g; - print STDOUT $status; + print STDERR $status; &verify_html($content); # check the html ## write to the slide open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!"; + push @pack_additional,"slide$nr.html" if ($pack); my $toc_link = "$overview\.html"; @@ -532,6 +557,12 @@ my $slide_html=make_progress_bar($nr,$total); + # undefine body if no content is found (so that template can show + # only title and sub-title + if ($content !~ m/\S/g) { + undef $content; + } + %page_data = ( doctype => $doctype, talkTitle => $talkTitle, @@ -556,6 +587,7 @@ toc_link => $toc_link, next_link => $next_link, prev_title => $prev_title, + toc_title => $loc_toc, next_title => $next_title, author => $author, @@ -567,11 +599,18 @@ slide_html => $slide_html, + template_dir => "$template/", ); - my $page= new Text::FastTemplate key => 'slide'; + my $page; + if ($content) { + $page= new Text::FastTemplate key => 'slide'; + } else { + $page= new Text::FastTemplate key => 'title'; + } + $page_data{template_dir}='' if ($pack); print SLIDE $page->output( \%page_data ); - + extract_files($page->output( \%page_data )) if ($pack); close(SLIDE); return 0; } @@ -619,8 +658,8 @@ if ($_[0] =~ /]*)>/im) { if (!($1 =~ /ALT=/im)) { - print STDOUT "WARNING: without ALT\n"; - print STDOUT " \n" ; + print STDERR "WARNING: without ALT\n"; + print STDERR " \n" ; } } } @@ -629,8 +668,10 @@ # clean the html of the slide # remove all
blabla
sub clean_html { - $_[0] =~ s/]|\"comment\").*?<\/div>//igs; - return $_[0]; + my $tmp=$_[0]; + $tmp =~ s/]|\"comment\").*?<\/div>//igs; + $tmp =~ s,]+>,,ig; + return $tmp; } ############################################################################## @@ -655,7 +696,7 @@ my $pcnt_done=int($nr*100/$total); my $pcnt_left=100-$pcnt_done; - if ($progress_bar) { + if ($progress_bar && uc($progress_bar) ne "NO") { my $l=$r=" "; my $t="$nr of $total"; if ($pcnt_done > 50) { @@ -663,7 +704,14 @@ } else { $r=$t; } - $html='
'.$l.''.$r.'
'; + $html=''; + if ($pcnt_done != 0) { + $html.=''; + } + if ($pcnt_left != 0) { + $html.=''; + } + $html.='
'.$l.''.$r.'
'; } else { $html="$loc_slide $nr $loc_of $total"; } @@ -671,3 +719,23 @@ return $html; } +############################################################################## +# remove anchors
from html (for titles) +sub remove_anchor { + my $tmp = $_[0]; + $tmp =~ s/(.*)]*>(.*)<\/A>(.*)/$1$2$3/ig; + return $tmp; +} + +############################################################################## +# extract files referenced in presentation + +sub extract_files { + my $tmp = $_[0]; + while ($tmp =~ s/href="*([^"\s]+)"*//ism || + $tmp =~ s/src="*([^"\s]+)"*//ism) { + if ("$1" !~ m/[hf]t?tp:/ && -f "$1" && !grep(/$1/,@pack_additional)) { + push @pack_additional,$1; + } + } +}