--- burst.pl 2001/05/11 14:17:27 1.16 +++ burst.pl 2001/09/18 12:50:15 1.21 @@ -135,14 +135,11 @@ my $pack = 0; my @pack_additional; # additional files to pack (pictures, logos...) +my %nesttag = init_nesttag(); ############################################################################## ## 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; ############################################################################## @@ -166,6 +163,8 @@ } ############################################################################## +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"; @@ -390,12 +389,12 @@ author => $author, authorUrl => $authorUrl, author2 => $author2, - authorUrl2 => $authorUrl2, + author2Url => $author2Url, date => $date, toc_title => $loc_toc, - template => $template, + template_dir => "$template/", ); } @@ -412,6 +411,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); @@ -428,6 +428,7 @@ my ($title,$subtitle,$nr) = @_; $title =~ s/\r//ig; # remove the windows CR+LF $title =~ s/<[^>]+>//g; + $subtitle =~ s/<[^>]+>//g; if (! $title) { return 1; @@ -525,11 +526,13 @@ $content =~ s/<\/body>//i; # remove if any $content =~ s/<\/html>//i; # remove if any - $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle; + $status = sprintf "Slide %2d: %s %s", $nr, $title, $subtitle; $status =~ s/<[^>]+>//g; - print STDERR $status; + $status =~ s/[\n\r]+/ /g; + print STDERR "$status\n"; - &verify_html($content); # check the html + &verify_html($content); # check the html + &check_tags($content); # check open and closed tags ## write to the slide open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!"; @@ -594,13 +597,13 @@ author => $author, authorUrl => $authorUrl, author2 => $author2, - authorUrl2 => $authorUrl2, + author2Url => $author2Url, date => $date, slide_html => $slide_html, - template => $template, + template_dir => "$template/", ); my $page; @@ -609,8 +612,14 @@ } else { $page= new Text::FastTemplate key => 'title'; } - print SLIDE $page->output( \%page_data ); - extract_files($page->output( \%page_data )) if ($pack); + + if ($pack) { + $page_data{template_dir}=''; + print SLIDE extract_files($page->output( \%page_data )); + } else { + print SLIDE $page->output( \%page_data ); + } + close(SLIDE); return 0; } @@ -728,14 +737,129 @@ } ############################################################################## -# extract files referenced in presentation +# extract files referenced in presentation and remove dirs from slide html sub extract_files { - my $tmp = $_[0]; - while ($tmp =~ s/ + +sub init_nesttag { +# Tags that require their own end tag ... we will nest them +# properly: (WARNING, you must use lower-case here) +# All other tags (not on this list) will be ignored for indenting purposes. +return ( + 'html' => 1, + 'head' => 1, + 'body' => 1, + 'title' => 1, + + 'a' => 1, + + 'table' => 1, + 'tr' => 1, + 'th' => 1, + 'td' => 1, + + 'form' => 1, + 'select' => 1, + 'textarea' => 1, + +# 'p' => 1, Don't do this one because many people use

but not

+ 'ul' => 1, + 'ol' => 1, + 'dl' => 1, + 'blockquote' => 1, + 'center' => 1, + 'div' => 1, + + 'font' => 1, + 'pre' => 1, + 'tt' => 1, + 'i' => 1, + 'b' => 1, + 'u' => 1, + 'strike' => 1, + 'big' => 1, + 'small' => 1, + 'sub' => 1, + 'sup' => 1, + 'em' => 1, + 'strong' => 1, + 'dfn' => 1, + 'code' => 1, + 'samp' => 1, + 'kbd' => 1, + 'var' => 1, + 'cite' => 1, + + 'h1' => 1, + 'h2' => 1, + 'h3' => 1, + 'h4' => 1, + 'h5' => 1, + 'h6' => 1, + + 'applet' => 1, + + 'map' => 1, + + 'frameset' => 1, + 'noframes' => 1, +); } + +sub check_tags { + my $tmp = $_[0]; + my @tagstack; + my $level=0; + + while ($tmp =~ /<(.*?)>/gsm) { + my $tag=$1; $tag=~s/\s.+//g; + # if regular tag, push it on stack; if end-tag, pop it off stack. + # but don't do any of this if it's not a special "nesting" tag! + if ($tag !~ m,^/,) { + if ($nesttag{lc($tag)}) { + push @tagstack,$tag; + $level++; # remember how much for later + } + } else { + $tag =~ s,^/,,; # convert this end-tag to a begin-tag + $tag = lc($tag); + if ($nesttag{lc($tag)}) { + # throw away tags until we find a match + if ($#tagstack > -1) { + while ($tag ne lc(pop @tagstack)) { + $level--; # we threw away extra tags + last if $#tagstack <= 0; + } + $level--; # we threw away extra tags + if ($level < 0) { + print STDERR "WARNING: more end than begin tags around !\n"; + } + } + } + } + } + + if ($level > 0) { + print STDERR "WARNING: level=$level, ", $#tagstack+1," tags left on stack after done parsing! Specifically:\n<",join("> <",@tagstack),">\n"; + } + +} +