/[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.12 - (show annotations)
Tue May 8 12:14:35 2001 UTC (18 years, 1 month ago) by dpavlin
Branch: MAIN
Changes since 1.11: +14 -1 lines
File MIME type: text/plain
support for title page (only with <h1>title</h2> and <h2>subtitle</h2>)

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 $buf =~ s/\r//g; # remove WINDOWS \r
193 close(ALL);
194 $/ = $sep;
195
196 ## Remove comments from the raw presentation
197 ## they do not need to show up on the slides
198 $buf =~ s/<!--.*?-->//sgo;
199
200 ## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags
201 ## if not it will generate a rather weird output
202 ## split using <h1...> and </h1...> as separator (ignores attributes!)
203 ## h1 or H1 can be used
204 @table = split(/<\/?[hH]1[^>]*>/, $buf);
205
206 ## compute the total number of slides
207 $total = $#table / 2;
208 if ($#table % 2 != 0) {
209 $total = ($#table +1)/2;
210 }
211
212 ##
213 ## raw presentation has been read successfully
214 ##############################################################################
215
216 ##############################################################################
217 ## processing the slides
218
219 print STDOUT "\n--- Processing $total slides ---\n";
220
221 ## generate the header table of content of the presentation
222 ## which is also the first page of the talk
223 &openOverview($overview);
224
225 ## start the slide count so we can number them
226 $slideCount = 1;
227
228 ## pre-load template slides using $template dir
229 Text::FastTemplate->defaults(
230 path => [ $template ]
231 );
232
233 Text::FastTemplate->preload( [
234 { file => 'slide.html', key => 'slide' },
235 { file => 'overview.html', key => 'overview' },
236 { file => 'title.html', key => 'title' },
237 ]);
238
239 ## unroll relative anchors (#something) into links with slides
240
241 my %anchor_on_slide;
242
243 ## step 1: record anchors
244 for($i=0; $i<$total; $i++) {
245 my $tmp = $table[($i*2)].$table[($i*2)+1];
246 while ($tmp =~ s,<a +name="*([^>"]+)"*>,,i) {
247 $anchor_on_slide{$1}=($i+1);
248 print "\tslide ",($i+1)," anchor: $1\n" if ($debug);
249 }
250 }
251
252 ## step 2: fix links
253 for($i=0; $i<$total; $i++) {
254 foreach (keys %anchor_on_slide) {
255 $table[($i*2)] =~ s,href="*#$_"*>,href="slide$anchor_on_slide{$_}\.html#$_">,gi;
256 }
257 }
258
259 ## @table is the array containing each slide with its title
260 ## for each slide to be generated
261 ## we delete each slide and its title when generated
262 ## so that the current slide and its title are always at $table[0] (for the title)
263 ## and $table[1] (for the slide content)
264
265 undef $prev_title;
266 undef $next_title;
267
268 do {
269
270 ## get rid of the first element contained by the raw presentation array
271 shift(@table);
272 ## then $table[0] is the title of the slide to be generated
273 $table[0] =~ s/\n+/ /g; ## replace return character by a white space
274 $table[0] =~ s/\r+/ /g; ## replace lf character by a white space
275 $table[0] =~ s/ +/ /g; ## concatenate several white spaces to only one
276 $table[0] =~ s/^ //; ## remove all the starting white spaces in the title
277 $table[0] =~ s/ $//; ## remove all trailing white spaces in the title
278 ## $slideTitle preserves link(s) in the title
279 $slideTitle = $table[0];
280 ## need to check if the title contains any anchor
281 ## if so it needs to be removed
282 ## because the title is being used in the table of content to link to the corresponding slide
283 $table[0] = remove_anchor($table[0]);
284
285 ## grab next slide title $table[2] (if there's a next slide)
286 ## to be able to use in the 'next' navigation button
287 ## keep in mind that $table[1] contains the slide corresponding to the title $table[0]
288 if ($table[2]) {
289 $next_title= remove_anchor($table[2]);
290 }
291
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[^>]*>//sm) {
301 $slideSubTitle=remove_anchor($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 &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$prev_title,$next_title);
311
312 ## save the title of the previous slide to be displayed in the 'previous' navigation button
313 $prev_title=remove_anchor($table[0]);
314 }
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 %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 logoLink2 => $logoLink2,
359 logoFile2 => $logoFile2,
360 logoAlt2 => $logoAlt2,
361
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
372 date => $date,
373
374 toc => $loc_toc,
375 );
376
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 $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
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 $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 &closeOverview;
428 undef @toc_entries;
429 &openOverview("$overview-toc$toc_nr");
430 $last_toc_title='';
431 }
432
433 $pre_ul=$post_ul='';
434 if ($last_toc_title eq $title && $subtitle) {
435 $title = $subtitle;
436 $pre_ul='<ul>';
437 $post_ul='</ul>';
438 } else {
439 $last_toc_title=$title;
440 }
441
442 # add accesskey for first 9 slides (`1' - `9') or just for first
443 # TOC page, and tabindex for all slides
444 if ($nr < 10 && $nr < $toc_on_page) {
445 $item = {
446 pre_html => $pre_ul,
447 accesskey => "$nr",
448 tabindex => "$nr",
449 href => "slide$nr.html",
450 title => $title,
451 post_html => $post_ul,
452 more => 0,
453 };
454 push @toc_entries,$item;
455 } else {
456 $item = {
457 pre_html => $pre_ul,
458 tabindex => "$nr",
459 href => "slide$nr.html",
460 title => $title,
461 post_html => $post_ul,
462 };
463 push @toc_entries,$item;
464 }
465 }
466 ##
467 ##############################################################################
468
469 ##############################################################################
470 ## generate the current slide
471
472 sub createSlide
473 {
474
475 # parameters are respectively the slide title, its content,
476 # its number, the next slide title and the previous slide title
477
478 my ($title,$subtitle,$content,$nr,$prev_title,$next_title) = @_;
479
480 if (! $title) {
481 return 1;
482 }
483
484 # work the slide title, the previous and next titles
485 chomp $title;
486 $title =~ s/\r//ig; # remove the windows CR+LF
487 $next_title =~ s/\r//ig;
488 $prev_title =~ s/\r//ig;
489
490 # Remove any tags from the prev & next titles
491 $next_title =~ s/<[^>]+>//g;
492 $prev_title =~ s/<[^>]+>//g;
493 $title =~ s/<[^>]+>//g;
494
495 # Replace double quotes
496 # $title =~ s/"/&#34;/g;
497 $next_title =~ s/"/&#34;/g;
498 $prev_title =~ s/"/&#34;/g;
499
500 # work the slide content
501 $content =~ s/<\/body>//i; # remove if any
502 $content =~ s/<\/html>//i; # remove if any
503
504 $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle;
505 $status =~ s/<[^>]+>//g;
506 print STDOUT $status;
507
508 &verify_html($content); # check the html
509
510 ## write to the slide
511 open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!";
512
513 my $toc_link = "$overview\.html";
514
515 ## initialization of the navigation links
516 my $next_link = "";
517 my $prev_link = "";
518
519 if ($nr>1) {
520 $prev_link = "slide".($nr-1).".html";
521 # } else {
522 # ## add a link back to the toc for the first slide --CMN 19991102
523 # $prev_link = "$overview\.html";
524 }
525
526 if ($nr != $total) {
527 $next_link = "slide".($nr+1).".html";
528 }
529
530 $stylelink = "";
531 # here is the standard style sheet
532 $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\">";
533
534 my $slide_html=make_progress_bar($nr,$total);
535
536 # undefine body if no content is found (so that template can show
537 # only title and sub-title
538 if ($content !~ m/\S/g) {
539 undef $content;
540 }
541
542 %page_data = (
543 doctype => $doctype,
544 talkTitle => $talkTitle,
545 title => $title,
546 subtitle => $subtitle,
547 http_equiv => $http_equiv,
548 stylelink => $stylelink,
549 body => $body,
550
551 logoLink => $logoLink,
552 logoFile => $logoFile,
553 logoAlt => $logoAlt,
554 logoLink2 => $logoLink2,
555 logoFile2 => $logoFile2,
556 logoAlt2 => $logoAlt2,
557
558
559 content_hight => $content_hight,
560 content => $content,
561
562 prev_link => $prev_link,
563 toc_link => $toc_link,
564 next_link => $next_link,
565 prev_title => $prev_title,
566 next_title => $next_title,
567
568 author => $author,
569 authorUrl => $authorUrl,
570 author2 => $author2,
571 authorUrl2 => $authorUrl2,
572
573 date => $date,
574
575 slide_html => $slide_html,
576
577 );
578
579 my $page;
580 if ($content) {
581 $page= new Text::FastTemplate key => 'slide';
582 } else {
583 $page= new Text::FastTemplate key => 'title';
584 }
585 print SLIDE $page->output( \%page_data );
586
587 close(SLIDE);
588 return 0;
589 }
590
591 ##############################################################################
592 ## generate all the toc of contents needed for each css choosen by the user
593 ## the default toc is not numbered so it can be served by a request to '/'
594 ## (ie it remains Overview.html whereas the other toc are called Overview_#.html)
595
596 sub generateTOC {
597
598 ## read the general toc
599 open(FOO, "<$overview.html");
600 @TOC = <FOO>;
601 close(FOO);
602 $toc = "@TOC";
603
604 ## for each user CSS file
605 ## starting after the default css
606 for ($css=1;$css<$nbCssStandard;$css++) {
607
608 ## create new TOC
609 $newTOC = $toc;
610
611 ## the links on the toc need also to be modified
612 ## to link to the correct slides
613 $newTOC =~ s/<a accesskey=\"(\d)\" tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a accesskey=\"$1\" tabindex=\"$2\" href=\"slide$3-$css\.html">/ig;
614 $newTOC =~ s/<a tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a tabindex=\"$1\" href=\"slide$2-$css\.html">/ig;
615
616 ## write to new TOC
617 $outfile = $overview."-".$css.".html";
618 open(OUT, ">$outfile");
619 print OUT $newTOC;
620 close(OUT)
621 }
622
623
624 }
625
626 ##############################################################################
627 # check that the html of the slide
628 # is correct (ALT tags, ...)
629 # This procedure produces only warning
630 sub verify_html {
631
632 if ($_[0] =~ /<img([^>]*)>/im) {
633 if (!($1 =~ /ALT=/im)) {
634 print STDOUT "WARNING: <IMG> without ALT\n";
635 print STDOUT " <IMG$1>\n" ;
636 }
637 }
638 }
639
640 ##############################################################################
641 # clean the html of the slide
642 # remove all <div class="comment">blabla</div>
643 sub clean_html {
644 my $tmp=$_[0];
645 $tmp =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs;
646 $tmp =~ s,</*font[^>]+>,,ig;
647 return $tmp;
648 }
649
650 ##############################################################################
651 # make transparent 1x1 gif (for layout tricks)
652 sub make_dotgif {
653 @dot_gif=(71,73,70,56,57,97,1,0,1,0,128,0,0,192,192,192,0,0,0,33,
654 249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
655 open(GIF,"> $_[0]") || die "can't write gif $_[0]: $!";
656 my $dotgif;
657 foreach (@dot_gif) {
658 $dotgif.=chr($_);
659 }
660 print GIF $dotgif;
661 close(GIF);
662 }
663
664 ##############################################################################
665 # make slide progress bar
666 sub make_progress_bar {
667 my ($nr,$total) = @_;
668
669 my $pcnt_done=int($nr*100/$total);
670 my $pcnt_left=100-$pcnt_done;
671
672 if ($progress_bar) {
673 my $l=$r="&nbsp;";
674 my $t="$nr of $total";
675 if ($pcnt_done > 50) {
676 $l=$t;
677 } else {
678 $r=$t;
679 }
680 $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>';
681 } else {
682 $html="$loc_slide $nr $loc_of $total";
683 }
684
685 return $html;
686 }
687
688 ##############################################################################
689 # make slide progress bar
690 sub remove_anchor {
691 my $tmp = $_[0];
692 $tmp =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig;
693 return $tmp;
694 }

  ViewVC Help
Powered by ViewVC 1.1.26