/[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.10 - (show annotations)
Sat May 5 20:21:29 2001 UTC (18 years, 1 month ago) by dpavlin
Branch: MAIN
Changes since 1.9: +14 -11 lines
File MIME type: text/plain
TOC fix-ups, remove <font> tags from source file

1 #!/usr/bin/perl
2 #
3 # PLies 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 # Text::FastTemplate:
47 # Robert Lehr - bozzio@the-lehrs.com
48
49 use Text::FastTemplate;
50
51 ##############################################################################
52 ## default values of variables
53 ##
54
55 ## show debug output
56 my $debug=1;
57
58 ## 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 ## template name
111 $template = '../PLies/default';
112
113 ## 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 ## content hight for each slide
126 $content_hight = "70%";
127
128 ## end of default values for the presentation
129 ##############################################################################
130
131 ## globals
132 my $last_toc_title;
133 my %page_data;
134 my %overview_data;
135
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 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 }
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 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 }
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 open(ALL, $all) || die "Error: Cannot open file: $all";
191 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 ## 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
237 ## 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)].$table[($i*2)+1];
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 ## @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
263 undef $prev_title;
264 undef $next_title;
265
266 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] = remove_anchor($table[0]);
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 if ($table[2]) {
287 $next_title= remove_anchor($table[2]);
288 }
289
290 ## the current slide content is stored $table[1]
291 ## there is an attempt to make sure it's clean HTML
292 ## Pierre Fillault's note: use same piece of as used in http://www.w3.org/Web/Tools/CvsCommitScripting
293 ## to make use of the validation service
294 $slideContent = &clean_html($table[1]) ;
295
296 ## extract slide Sub Title <h2>
297 undef $slideSubTitle;
298 if ($slideContent =~ s/<[hH]2[^>]*>(.+)<\/[hH]2[^>]*>//sm) {
299 $slideSubTitle=remove_anchor($1);
300 }
301
302 ## add the title of the current slide to the table of content
303 &addTitle($slideTitle,$slideSubTitle,$slideCount);
304
305 ## generate the current slide
306 ## parameters are:
307 ## title of the slide, its content, the slide number, the title of the previous slide and the title of the next slide
308 &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$prev_title,$next_title);
309
310 ## save the title of the previous slide to be displayed in the 'previous' navigation button
311 $prev_title=remove_anchor($table[0]);
312 }
313 ## process the next slide
314 while (shift(@table));
315
316 ## close the table of content
317 &closeOverview;
318
319 ## generate more toc with the all the style sheets
320 ## as there's no way of loading a style sheet
321 ## except dynamically, but that would be slow
322 ## and would not work on all platforms (ie would fail on Joe's laptop)
323 &generateTOC;
324
325
326 print STDOUT "--- Finished ---\n";
327 exit 0;
328 ##
329 ## end of the slidemaker main program
330 ##############################################################################
331
332
333 ##############################################################################
334 ## generate the header of the table of content
335
336 sub openOverview
337 {
338 ## open the file to write to
339 open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!";
340
341 ## the style sheet used in the table of content is
342 $stylelink = "";
343 ## here is the standard style sheet
344 $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\" media=\"screen\">";
345
346 %overview_data = (
347 doctype => $doctype,
348 title => $title,
349 http_equiv => $http_equiv,
350 stylelink => $stylelink,
351 body => $body,
352
353 logoLink => $logoLink,
354 logoFile => $logoFile,
355 logoAlt => $logoAlt,
356 logoLink2 => $logoLink2,
357 logoFile2 => $logoFile2,
358 logoAlt2 => $logoAlt2,
359
360 talkTitle => $talkTitle,
361 talkSubTitle => $talkSubTitle,
362
363 content_hight => $content_hight,
364
365 author => $author,
366 authorUrl => $authorUrl,
367 author2 => $author2,
368 authorUrl2 => $authorUrl2,
369
370 date => $date,
371
372 toc => $loc_toc,
373 );
374
375 }
376 ##
377 ## the beginning of the table of content has been generated and saved
378 ##############################################################################
379
380 ##############################################################################
381 ## generate the footer of the table of content
382
383 sub closeOverview
384 {
385 $overview_data{slide_html} = make_progress_bar(0,$total);
386 $overview_data{toc_entries} = [ @toc_entries ];
387
388 my $page= new Text::FastTemplate key => 'overview';
389 print FOO $page->output( \%overview_data );
390
391 close(FOO);
392 }
393 ##
394 ## the toc has been completed and saved
395 ##############################################################################
396
397 ##############################################################################
398 ## add an item in the toc
399
400 sub addTitle
401 {
402 my ($title,$subtitle,$nr) = @_;
403 $title =~ s/\r//ig; # remove the windows CR+LF
404 $title =~ s/<[^>]+>//g;
405
406 if (! $title) {
407 return 1;
408 }
409
410 # split TOC entries to multiple pages
411
412 if ($nr % $toc_on_page == 0) {
413 my $toc_nr=int($nr/$toc_on_page);
414
415 $item = {
416 pre_html => $pre_ul,
417 accesskey => " ", # space
418 href => "index-toc$toc_nr.html",
419 title => "...",
420 post_html => $post_ul,
421 more => 1, # use style for more pages link (...)
422 };
423 push @toc_entries, $item;
424
425 &closeOverview;
426 undef @toc_entries;
427 &openOverview("$overview-toc$toc_nr");
428 $last_toc_title='';
429 }
430
431 $pre_ul=$post_ul='';
432 if ($last_toc_title eq $title) {
433 $title = $subtitle;
434 $pre_ul='<ul>';
435 $post_ul='</ul>';
436 } else {
437 $last_toc_title=$title;
438 }
439
440 # add accesskey for first 9 slides (`1' - `9') or just for first
441 # TOC page, and tabindex for all slides
442 if ($nr < 10 && $nr < $toc_on_page) {
443 $item = {
444 pre_html => $pre_ul,
445 accesskey => "$nr",
446 tabindex => "$nr",
447 href => "slide$nr.html",
448 title => $title,
449 post_html => $post_ul,
450 more => 0,
451 };
452 push @toc_entries,$item;
453 } else {
454 $item = {
455 pre_html => $pre_ul,
456 tabindex => "$nr",
457 href => "slide$nr.html",
458 title => $title,
459 post_html => $post_ul,
460 };
461 push @toc_entries,$item;
462 }
463 }
464 ##
465 ##############################################################################
466
467 ##############################################################################
468 ## generate the current slide
469
470 sub createSlide
471 {
472
473 # parameters are respectively the slide title, its content,
474 # its number, the next slide title and the previous slide title
475
476 my ($title,$subtitle,$content,$nr,$prev_title,$next_title) = @_;
477
478 if (! $title) {
479 return 1;
480 }
481
482 # work the slide title, the previous and next titles
483 chomp $title;
484 $title =~ s/\r//ig; # remove the windows CR+LF
485 $next_title =~ s/\r//ig;
486 $prev_title =~ s/\r//ig;
487
488 # Remove any tags from the prev & next titles
489 $next_title =~ s/<[^>]+>//g;
490 $prev_title =~ s/<[^>]+>//g;
491 $title =~ s/<[^>]+>//g;
492
493 # Replace double quotes
494 # $title =~ s/"/&#34;/g;
495 $next_title =~ s/"/&#34;/g;
496 $prev_title =~ s/"/&#34;/g;
497
498 # work the slide content
499 $content =~ s/<\/body>//i; # remove if any
500 $content =~ s/<\/html>//i; # remove if any
501
502 $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle;
503 $status =~ s/<[^>]+>//g;
504 print STDOUT $status;
505
506 &verify_html($content); # check the html
507
508 ## write to the slide
509 open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!";
510
511 my $toc_link = "$overview\.html";
512
513 ## initialization of the navigation links
514 my $next_link = "";
515 my $prev_link = "";
516
517 if ($nr>1) {
518 $prev_link = "slide".($nr-1).".html";
519 # } else {
520 # ## add a link back to the toc for the first slide --CMN 19991102
521 # $prev_link = "$overview\.html";
522 }
523
524 if ($nr != $total) {
525 $next_link = "slide".($nr+1).".html";
526 }
527
528 $stylelink = "";
529 # here is the standard style sheet
530 $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\">";
531
532 my $slide_html=make_progress_bar($nr,$total);
533
534 %page_data = (
535 doctype => $doctype,
536 talkTitle => $talkTitle,
537 title => $title,
538 subtitle => $subtitle,
539 http_equiv => $http_equiv,
540 stylelink => $stylelink,
541 body => $body,
542
543 logoLink => $logoLink,
544 logoFile => $logoFile,
545 logoAlt => $logoAlt,
546 logoLink2 => $logoLink2,
547 logoFile2 => $logoFile2,
548 logoAlt2 => $logoAlt2,
549
550
551 content_hight => $content_hight,
552 content => $content,
553
554 prev_link => $prev_link,
555 toc_link => $toc_link,
556 next_link => $next_link,
557 prev_title => $prev_title,
558 next_title => $next_title,
559
560 author => $author,
561 authorUrl => $authorUrl,
562 author2 => $author2,
563 authorUrl2 => $authorUrl2,
564
565 date => $date,
566
567 slide_html => $slide_html,
568
569 );
570
571 my $page= new Text::FastTemplate key => 'slide';
572 print SLIDE $page->output( \%page_data );
573
574 close(SLIDE);
575 return 0;
576 }
577
578 ##############################################################################
579 ## generate all the toc of contents needed for each css choosen by the user
580 ## the default toc is not numbered so it can be served by a request to '/'
581 ## (ie it remains Overview.html whereas the other toc are called Overview_#.html)
582
583 sub generateTOC {
584
585 ## read the general toc
586 open(FOO, "<$overview.html");
587 @TOC = <FOO>;
588 close(FOO);
589 $toc = "@TOC";
590
591 ## for each user CSS file
592 ## starting after the default css
593 for ($css=1;$css<$nbCssStandard;$css++) {
594
595 ## create new TOC
596 $newTOC = $toc;
597
598 ## the links on the toc need also to be modified
599 ## to link to the correct slides
600 $newTOC =~ s/<a accesskey=\"(\d)\" tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a accesskey=\"$1\" tabindex=\"$2\" href=\"slide$3-$css\.html">/ig;
601 $newTOC =~ s/<a tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a tabindex=\"$1\" href=\"slide$2-$css\.html">/ig;
602
603 ## write to new TOC
604 $outfile = $overview."-".$css.".html";
605 open(OUT, ">$outfile");
606 print OUT $newTOC;
607 close(OUT)
608 }
609
610
611 }
612
613 ##############################################################################
614 # check that the html of the slide
615 # is correct (ALT tags, ...)
616 # This procedure produces only warning
617 sub verify_html {
618
619 if ($_[0] =~ /<img([^>]*)>/im) {
620 if (!($1 =~ /ALT=/im)) {
621 print STDOUT "WARNING: <IMG> without ALT\n";
622 print STDOUT " <IMG$1>\n" ;
623 }
624 }
625 }
626
627 ##############################################################################
628 # clean the html of the slide
629 # remove all <div class="comment">blabla</div>
630 sub clean_html {
631 my $tmp=$_[0];
632 $tmp =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs;
633 $tmp =~ s,</*font[^>]+>,,ig;
634 return $tmp;
635 }
636
637 ##############################################################################
638 # make transparent 1x1 gif (for layout tricks)
639 sub make_dotgif {
640 @dot_gif=(71,73,70,56,57,97,1,0,1,0,128,0,0,192,192,192,0,0,0,33,
641 249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
642 open(GIF,"> $_[0]") || die "can't write gif $_[0]: $!";
643 my $dotgif;
644 foreach (@dot_gif) {
645 $dotgif.=chr($_);
646 }
647 print GIF $dotgif;
648 close(GIF);
649 }
650
651 ##############################################################################
652 # make slide progress bar
653 sub make_progress_bar {
654 my ($nr,$total) = @_;
655
656 my $pcnt_done=int($nr*100/$total);
657 my $pcnt_left=100-$pcnt_done;
658
659 if ($progress_bar) {
660 my $l=$r="&nbsp;";
661 my $t="$nr of $total";
662 if ($pcnt_done > 50) {
663 $l=$t;
664 } else {
665 $r=$t;
666 }
667 $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>';
668 } else {
669 $html="$loc_slide $nr $loc_of $total";
670 }
671
672 return $html;
673 }
674
675 ##############################################################################
676 # make slide progress bar
677 sub remove_anchor {
678 my $tmp = $_[0];
679 $tmp =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig;
680 return $tmp;
681 }

  ViewVC Help
Powered by ViewVC 1.1.26