/[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

Contents of /burst.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Tue Apr 17 09:47:30 2001 UTC (23 years ago) by dpavlin
Branch: MAIN
Changes since 1.1: +5 -2 lines
File MIME type: text/plain
make content hight in slide selectable

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

  ViewVC Help
Powered by ViewVC 1.1.26