/[PLies]/burst.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /burst.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations)
Sat May 5 19:20:27 2001 UTC (22 years, 11 months ago) by dpavlin
Branch: MAIN
Changes since 1.6: +81 -44 lines
File MIME type: text/plain
fixed links, links now display slide titles (as they should),
relative anchors (#something) are resolved accross slides (so that
you can jump from one slide to another)

1 dpavlin 1.5 #!/usr/bin/perl
2 dpavlin 1.1 #
3     # SLies Copyright 2001 Dobrica Pavlinusic <dpavlin@rot13.org>
4     #
5     # this tool is based on SlideMaker and XLSies tool
6     # split a all.htm into slide*.htm
7     #
8     # For more information please see presentation about this tool on
9     # http://www.rot13.org/~dpavlin/presentations/XLSies_to_PLies/
10     #
11     # Copyright 1999 World Wide Web Consortium,
12     # (Massachusetts Institute of Technology, Institut
13     # National de Recherche en Informatique et en
14     # Automatique, Keio University). All Rights Reserved.
15     # This program is distributed under the W3C's
16     # Intellectual Property License. This program is
17     # distributed in the hope that it will be useful, but
18     # WITHOUT ANY WARRANTY; without even the implied
19     # warranty of MERCHANTABILITY or FITNESS FOR A
20     # PARTICULAR PURPOSE. See W3C License
21     # http://www.w3.org/Consortium/Legal/ for more details.
22     #
23     #
24     ##############################################################################
25     #
26     # slidemaker credits:
27     #
28     # Stephan Montigaud - stephan@w3.org
29     # created 970601
30     # modified by Pierre Fillault
31     # check the documentation at http://www.w3.org/Talks/YYMMsub/
32     #
33     # modified 19990505 Bert Bos: ALT text of prev/next arrows is now
34     # "prev"/"next" rather than the title of the prev/next slide; looks better
35     # in lynx.
36     #
37     # version: 4.14 - 19990719
38     # $Id: w3cburst.pl,v 1.41 1999/11/02 17:25:50 charles Exp $
39     #
40     #
41     # XLSies credits:
42     #
43     # Sami Lempinen - lempinen@iki.fi
44     # http://www.snowman.sgic.fi/ssl/xslies/
45 dpavlin 1.5 #
46     # Text::FastTemplate:
47     # Robert Lehr - bozzio@the-lehrs.com
48    
49     use Text::FastTemplate;
50 dpavlin 1.1
51     ##############################################################################
52     ## default values of variables
53     ##
54    
55 dpavlin 1.7 ## show debug output
56     my $debug=1;
57    
58 dpavlin 1.1 ## default DOCTYPE added on the slides
59     $doctype = '<html xmlns="http://www.w3.org/TR/REC-html40">';
60    
61     ## name of raw HTML file containing the slides
62     $all = 'all.htm';
63    
64     ## table of content built from all.htm - also first page of the presentation
65     ## this is only the basename as we need to generate one toc for each style sheets
66     ## the main toc will not bear any more so the server can understand a request for '/'
67     ## the next ones will bear a number corresponding to the slide index
68     #$overview = 'Overview';
69     $overview = 'index';
70    
71     ## name of the file containing the parameters of the presentation
72     $infos = 'infos.txt';
73    
74     ## link to the logo printed on all the slides
75     $logoLink = '';
76    
77     ## default location of the logo - works when slidemaker is used as a package
78     $logoFile = '';
79    
80     ### localization
81     $loc_toc = "Table of contents";
82     $loc_by = "by";
83     $loc_amp = "&amp;"; # author separator
84     $loc_slide = "Slide";
85     $loc_of = "of"; # $loc_slide nr $loc_of total
86    
87     ## alternate representation of the logo
88     $logoAlt = '';
89    
90     ## default values set to none
91     $logoLink2 = ''; # link to a potential second reference
92     $logoFile2 = ''; # location of a second logo
93     $logoAlt2 = ''; # alternate representation of the second logo
94    
95     ## default accesskeys for navigation icons used in the slides
96     $prevKey = 'P'; # accesskey for previous slide
97     $nextKey = 'N'; # accesskey for next slide
98     $tocKey = 'C'; # accesskey for table of contents
99     $styleKey = 'S'; # accesskey for changing style sheets
100    
101     ## default author name
102     $author = 'Staff';
103    
104     ## default presentation title
105     $talkTitle = 'Talk';
106    
107     ## standard style sheets
108     $cssStandard = '../PLies/css/default.css';
109    
110 dpavlin 1.5 ## template name
111     $template = '../PLies/default';
112    
113 dpavlin 1.1 ## default charset use in meta tag http-equiv (undef to skip)
114     #$charset = 'ISO-8859-1';
115    
116     ## default <body> tag
117     $body = '<body>';
118    
119     ## number of entries on each TOC page
120     $toc_on_page = 10;
121    
122     ## use progress bar
123     $progress_bar = 1;
124    
125 dpavlin 1.2 ## content hight for each slide
126     $content_hight = "70%";
127    
128 dpavlin 1.1 ## end of default values for the presentation
129     ##############################################################################
130    
131     ## globals
132     my $last_toc_title;
133 dpavlin 1.5 my %page_data;
134     my %overview_data;
135 dpavlin 1.1
136     ##############################################################################
137     ## reading user input from $infos
138     ##
139     @PARAM = @ARGV; # we keep this for backward compatibility with an old version
140     # of the slidemaker tool
141     #when the parameters were in Makefile or make.bat
142    
143     # read parameters from infos.txt and put them in @PARAM
144     if (open(INFOS, $infos)) {
145 dpavlin 1.7 print STDOUT "--- Reading parameters file $infos ---\n";
146     local(@file,$counter);
147     $counter = 0;
148     @file = <INFOS>;
149     @PARAM = ();
150     do {
151     if ($file[0] && $file[0] =~ /^[^#\n\r]/) {
152     $file[0] =~ s/\n//; # remove UNIX \n
153     $file[0] =~ s/\r//; # remove WINDOWS \r
154     $file[0] =~ s/ *= */=/;
155     $PARAM[$counter++] = $file[0];
156     print "$file[0]\n";
157     }
158     } while (shift(@file));
159 dpavlin 1.1 }
160     ## @PARAM is now a table with the user preferences for his presentation
161    
162     ## process arguments
163     ## each preset variable is now re-attributed using the user preferences
164     foreach (@PARAM) {
165 dpavlin 1.5 my ($var,$value) = split(/ *= */,$_,2);
166     $value=~s/'/\\'/g;
167     $cmd="\$$var = \'$value\';";
168     if ($value) {
169     eval($cmd) || die "problem with eval of: $cmd";
170     } else {
171     die "no value defined for $var";
172     }
173 dpavlin 1.1 }
174    
175     ## use charset
176    
177     if ($charset) {
178     $http_equiv='<meta http-equiv="Content-type" content="text/html; charset='.$charset.'">';
179     } else {
180     $http_equiv='';
181     }
182    
183     ##############################################################################
184     ## read the raw html presentation
185     ##
186    
187     ## copy file in memory
188     my $sep = $/;
189     $/ = undef;
190 dpavlin 1.7 open(ALL, $all) || die "Error: Cannot open file: $all";
191 dpavlin 1.1 my $buf = <ALL>;
192     close(ALL);
193     $/ = $sep;
194    
195     ## Remove comments from the raw presentation
196     ## they do not need to show up on the slides
197     $buf =~ s/<!--.*?-->//sgo;
198    
199     ## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags
200     ## if not it will generate a rather weird output
201     ## split using <h1...> and </h1...> as separator (ignores attributes!)
202     ## h1 or H1 can be used
203     @table = split(/<\/?[hH]1[^>]*>/, $buf);
204    
205     ## compute the total number of slides
206     $total = $#table / 2;
207     if ($#table % 2 != 0) {
208     $total = ($#table +1)/2;
209     }
210    
211     ##
212     ## raw presentation has been read successfully
213     ##############################################################################
214    
215     ##############################################################################
216     ## processing the slides
217    
218     print STDOUT "\n--- Processing $total slides ---\n";
219    
220     ## generate the header table of content of the presentation
221     ## which is also the first page of the talk
222     &openOverview($overview);
223    
224     ## start the slide count so we can number them
225     $slideCount = 1;
226    
227 dpavlin 1.5 ## pre-load template slides using $template dir
228     Text::FastTemplate->defaults(
229     path => [ $template ]
230     );
231    
232     Text::FastTemplate->preload( [
233     { file => 'slide.html', key => 'slide' },
234     { file => 'overview.html', key => 'overview' },
235     ]);
236 dpavlin 1.1
237 dpavlin 1.7 ## unroll relative anchors (#something) into links with slides
238    
239     my %anchor_on_slide;
240    
241     ## step 1: record anchors
242     for($i=0; $i<$total; $i++) {
243     my $tmp = $table[($i*2)];
244     while ($tmp =~ s,<a +name="*([^>"]+)"*>,,i) {
245     $anchor_on_slide{$1}=($i+1);
246     print "\tslide ",($i+1)," anchor: $1\n" if ($debug);
247     }
248     }
249    
250     ## step 2: fix links
251     for($i=0; $i<$total; $i++) {
252     foreach (keys %anchor_on_slide) {
253     $table[($i*2)] =~ s,href="*#$_"*>,href="slide$anchor_on_slide{$_}\.html#$_">,gi;
254     }
255     }
256    
257 dpavlin 1.1 ## @table is the array containing each slide with its title
258     ## for each slide to be generated
259     ## we delete each slide and its title when generated
260     ## so that the current slide and its title are always at $table[0] (for the title)
261     ## and $table[1] (for the slide content)
262 dpavlin 1.7
263     undef $prev_title;
264     undef $next_title;
265    
266 dpavlin 1.1 do {
267    
268     ## get rid of the first element contained by the raw presentation array
269     shift(@table);
270     ## then $table[0] is the title of the slide to be generated
271     $table[0] =~ s/\n+/ /g; ## replace return character by a white space
272     $table[0] =~ s/\r+/ /g; ## replace lf character by a white space
273     $table[0] =~ s/ +/ /g; ## concatenate several white spaces to only one
274     $table[0] =~ s/^ //; ## remove all the starting white spaces in the title
275     $table[0] =~ s/ $//; ## remove all trailing white spaces in the title
276     ## $slideTitle preserves link(s) in the title
277     $slideTitle = $table[0];
278     ## need to check if the title contains any anchor
279     ## if so it needs to be removed
280     ## because the title is being used in the table of content to link to the corresponding slide
281     $table[0] =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/i;
282    
283     ## grab next slide title $table[2] (if there's a next slide)
284     ## to be able to use in the 'next' navigation button
285     ## keep in mind that $table[1] contains the slide corresponding to the title $table[0]
286 dpavlin 1.7 if ($table[2]) {
287     $next_title= $table[2];
288     ## remove any anchor from the next slide title
289     $next_title =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/i;
290     }
291 dpavlin 1.1
292     ## the current slide content is stored $table[1]
293     ## there is an attempt to make sure it's clean HTML
294     ## Pierre Fillault's note: use same piece of as used in http://www.w3.org/Web/Tools/CvsCommitScripting
295     ## to make use of the validation service
296     $slideContent = &clean_html($table[1]) ;
297    
298     ## extract slide Sub Title <h2>
299     undef $slideSubTitle;
300     if ($slideContent =~ s/<[hH]2[^>]*>([^<]+)<\/[hH]2[^>]*>//) {
301     $slideSubTitle=$1;
302     }
303    
304     ## add the title of the current slide to the table of content
305     &addTitle($slideTitle,$slideSubTitle,$slideCount);
306    
307     ## generate the current slide
308     ## parameters are:
309     ## title of the slide, its content, the slide number, the title of the previous slide and the title of the next slide
310 dpavlin 1.7 &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$prev_title,$next_title);
311 dpavlin 1.1
312     ## save the title of the previous slide to be displayed in the 'previous' navigation button
313 dpavlin 1.7 $prev_title="$table[0]";
314 dpavlin 1.1 }
315     ## process the next slide
316     while (shift(@table));
317    
318     ## close the table of content
319     &closeOverview;
320    
321     ## generate more toc with the all the style sheets
322     ## as there's no way of loading a style sheet
323     ## except dynamically, but that would be slow
324     ## and would not work on all platforms (ie would fail on Joe's laptop)
325     &generateTOC;
326    
327    
328     print STDOUT "--- Finished ---\n";
329     exit 0;
330     ##
331     ## end of the slidemaker main program
332     ##############################################################################
333    
334    
335     ##############################################################################
336     ## generate the header of the table of content
337    
338     sub openOverview
339     {
340     ## open the file to write to
341     open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!";
342    
343     ## the style sheet used in the table of content is
344     $stylelink = "";
345     ## here is the standard style sheet
346     $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\" media=\"screen\">";
347    
348 dpavlin 1.5 %overview_data = (
349     doctype => $doctype,
350     title => $title,
351     http_equiv => $http_equiv,
352     stylelink => $stylelink,
353     body => $body,
354    
355     logoLink => $logoLink,
356     logoFile => $logoFile,
357     logoAlt => $logoAlt,
358 dpavlin 1.7 logoLink2 => $logoLink2,
359     logoFile2 => $logoFile2,
360     logoAlt2 => $logoAlt2,
361 dpavlin 1.5
362     talkTitle => $talkTitle,
363     talkSubTitle => $talkSubTitle,
364    
365     content_hight => $content_hight,
366    
367     author => $author,
368     authorUrl => $authorUrl,
369     author2 => $author2,
370     authorUrl2 => $authorUrl2,
371 dpavlin 1.1
372 dpavlin 1.5 date => $date,
373 dpavlin 1.1
374 dpavlin 1.5 toc => $loc_toc,
375     );
376 dpavlin 1.1
377     }
378     ##
379     ## the beginning of the table of content has been generated and saved
380     ##############################################################################
381    
382     ##############################################################################
383     ## generate the footer of the table of content
384    
385     sub closeOverview
386     {
387 dpavlin 1.5 $overview_data{slide_html} = make_progress_bar(0,$total);
388     $overview_data{toc_entries} = [ @toc_entries ];
389    
390     my $page= new Text::FastTemplate key => 'overview';
391     print FOO $page->output( \%overview_data );
392 dpavlin 1.1
393     close(FOO);
394     }
395     ##
396     ## the toc has been completed and saved
397     ##############################################################################
398    
399     ##############################################################################
400     ## add an item in the toc
401    
402     sub addTitle
403     {
404     my ($title,$subtitle,$nr) = @_;
405     $title =~ s/\r//ig; # remove the windows CR+LF
406     $title =~ s/<[^>]+>//g;
407    
408     if (! $title) {
409     return 1;
410     }
411    
412     # split TOC entries to multiple pages
413    
414     if ($nr % $toc_on_page == 0) {
415     my $toc_nr=int($nr/$toc_on_page);
416    
417 dpavlin 1.5 %item = (
418     pre_html => $pre_ul,
419     accesskey => " ", # space
420     href => "index-toc$toc_nr.html",
421     title => "...",
422     post_html => $post_ul,
423     more => 1, # use style for more pages link (...)
424     )
425     # push @toc_entries, %item;
426    
427 dpavlin 1.1 &closeOverview;
428     &openOverview("$overview-toc$toc_nr");
429     $last_toc_title='';
430     }
431    
432 dpavlin 1.5 $pre_ul=$post_ul='';
433 dpavlin 1.1 if ($last_toc_title eq $title) {
434     $title = $subtitle;
435 dpavlin 1.5 $pre_ul='<ul>';
436     $post_ul='</ul>';
437 dpavlin 1.1 } else {
438     $last_toc_title=$title;
439     }
440    
441     # add accesskey for first 9 slides (`1' - `9') or just for first
442     # TOC page, and tabindex for all slides
443     if ($nr < 10 && $nr < $toc_on_page) {
444 dpavlin 1.5 $item = {
445     pre_html => $pre_ul,
446     accesskey => "$nr",
447     tabindex => "$nr",
448     href => "slide$nr.html",
449     title => $title,
450     post_html => $post_ul,
451     more => 0,
452     };
453     push @toc_entries,$item;
454 dpavlin 1.1 } else {
455 dpavlin 1.5 %item = (
456     pre_html => $pre_ul,
457     tabindex => "$nr",
458     href => "slide$nr.html",
459     title => $title,
460     post_html => $post_ul,
461     )
462     # push @toc_entries,\%item;
463 dpavlin 1.1 }
464     }
465     ##
466     ##############################################################################
467    
468     ##############################################################################
469     ## generate the current slide
470    
471     sub createSlide
472     {
473    
474     # parameters are respectively the slide title, its content,
475     # its number, the next slide title and the previous slide title
476    
477 dpavlin 1.7 my ($title,$subtitle,$content,$nr,$prev_title,$next_title) = @_;
478 dpavlin 1.1
479     if (! $title) {
480     return 1;
481     }
482    
483     # work the slide title, the previous and next titles
484     chomp $title;
485     $title =~ s/\r//ig; # remove the windows CR+LF
486     $next_title =~ s/\r//ig;
487     $prev_title =~ s/\r//ig;
488    
489     # Remove any tags from the prev & next titles
490     $next_title =~ s/<[^>]+>//g;
491     $prev_title =~ s/<[^>]+>//g;
492     $title =~ s/<[^>]+>//g;
493    
494     # Replace double quotes
495     # $title =~ s/"/&#34;/g;
496     $next_title =~ s/"/&#34;/g;
497     $prev_title =~ s/"/&#34;/g;
498    
499     # work the slide content
500     $content =~ s/<\/body>//i; # remove if any
501     $content =~ s/<\/html>//i; # remove if any
502    
503     $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle;
504     $status =~ s/<[^>]+>//g;
505     print STDOUT $status;
506    
507     &verify_html($content); # check the html
508    
509     ## write to the slide
510     open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!";
511    
512 dpavlin 1.7 my $toc_link = "$overview\.html";
513 dpavlin 1.1
514     ## initialization of the navigation links
515 dpavlin 1.7 my $next_link = "";
516     my $prev_link = "";
517 dpavlin 1.1
518     if ($nr>1) {
519 dpavlin 1.7 $prev_link = "slide".($nr-1).".html";
520 dpavlin 1.1 # } else {
521     # ## add a link back to the toc for the first slide --CMN 19991102
522 dpavlin 1.7 # $prev_link = "$overview\.html";
523 dpavlin 1.1 }
524    
525     if ($nr != $total) {
526 dpavlin 1.7 $next_link = "slide".($nr+1).".html";
527 dpavlin 1.1 }
528    
529     $stylelink = "";
530     # here is the standard style sheet
531     $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\">";
532    
533     my $slide_html=make_progress_bar($nr,$total);
534    
535 dpavlin 1.5 %page_data = (
536     doctype => $doctype,
537     talkTitle => $talkTitle,
538     title => $title,
539 dpavlin 1.7 subtitle => $subtitle,
540 dpavlin 1.5 http_equiv => $http_equiv,
541     stylelink => $stylelink,
542     body => $body,
543    
544 dpavlin 1.7 logoLink => $logoLink,
545     logoFile => $logoFile,
546     logoAlt => $logoAlt,
547     logoLink2 => $logoLink2,
548     logoFile2 => $logoFile2,
549     logoAlt2 => $logoAlt2,
550    
551    
552 dpavlin 1.5 content_hight => $content_hight,
553     content => $content,
554 dpavlin 1.7
555     prev_link => $prev_link,
556     toc_link => $toc_link,
557     next_link => $next_link,
558     prev_title => $prev_title,
559     next_title => $next_title,
560    
561 dpavlin 1.5 author => $author,
562 dpavlin 1.7 authorUrl => $authorUrl,
563     author2 => $author2,
564     authorUrl2 => $authorUrl2,
565    
566     date => $date,
567    
568 dpavlin 1.5 slide_html => $slide_html,
569    
570     );
571    
572     my $page= new Text::FastTemplate key => 'slide';
573     print SLIDE $page->output( \%page_data );
574 dpavlin 1.1
575     close(SLIDE);
576     return 0;
577     }
578    
579     ##############################################################################
580     ## generate all the toc of contents needed for each css choosen by the user
581     ## the default toc is not numbered so it can be served by a request to '/'
582     ## (ie it remains Overview.html whereas the other toc are called Overview_#.html)
583    
584     sub generateTOC {
585    
586     ## read the general toc
587     open(FOO, "<$overview.html");
588     @TOC = <FOO>;
589     close(FOO);
590     $toc = "@TOC";
591    
592     ## for each user CSS file
593     ## starting after the default css
594     for ($css=1;$css<$nbCssStandard;$css++) {
595    
596     ## create new TOC
597     $newTOC = $toc;
598    
599     ## the links on the toc need also to be modified
600     ## to link to the correct slides
601     $newTOC =~ s/<a accesskey=\"(\d)\" tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a accesskey=\"$1\" tabindex=\"$2\" href=\"slide$3-$css\.html">/ig;
602     $newTOC =~ s/<a tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a tabindex=\"$1\" href=\"slide$2-$css\.html">/ig;
603    
604     ## write to new TOC
605     $outfile = $overview."-".$css.".html";
606     open(OUT, ">$outfile");
607     print OUT $newTOC;
608     close(OUT)
609     }
610    
611    
612     }
613    
614     ##############################################################################
615     # check that the html of the slide
616     # is correct (ALT tags, ...)
617     # This procedure produces only warning
618     sub verify_html {
619    
620     if ($_[0] =~ /<img([^>]*)>/im) {
621     if (!($1 =~ /ALT=/im)) {
622     print STDOUT "WARNING: <IMG> without ALT\n";
623     print STDOUT " <IMG$1>\n" ;
624     }
625     }
626     }
627    
628     ##############################################################################
629     # clean the html of the slide
630     # remove all <div class="comment">blabla</div>
631     sub clean_html {
632     $_[0] =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs;
633     return $_[0];
634     }
635    
636     ##############################################################################
637     # make transparent 1x1 gif (for layout tricks)
638     sub make_dotgif {
639     @dot_gif=(71,73,70,56,57,97,1,0,1,0,128,0,0,192,192,192,0,0,0,33,
640     249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
641     open(GIF,"> $_[0]") || die "can't write gif $_[0]: $!";
642     my $dotgif;
643     foreach (@dot_gif) {
644     $dotgif.=chr($_);
645     }
646     print GIF $dotgif;
647     close(GIF);
648     }
649    
650     ##############################################################################
651     # make slide progress bar
652     sub make_progress_bar {
653     my ($nr,$total) = @_;
654    
655     my $pcnt_done=int($nr*100/$total);
656     my $pcnt_left=100-$pcnt_done;
657    
658     if ($progress_bar) {
659     my $l=$r="&nbsp;";
660     my $t="$nr of $total";
661     if ($pcnt_done > 50) {
662     $l=$t;
663     } else {
664     $r=$t;
665     }
666 dpavlin 1.4 $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>';
667 dpavlin 1.1 } else {
668     $html="$loc_slide $nr $loc_of $total";
669     }
670    
671     return $html;
672     }
673    

  ViewVC Help
Powered by ViewVC 1.1.26