/[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.9 - (hide annotations)
Sat May 5 19:48:33 2001 UTC (22 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.8: +2 -2 lines
File MIME type: text/plain
scan titles for anchors too

1 dpavlin 1.5 #!/usr/bin/perl
2 dpavlin 1.1 #
3 dpavlin 1.9 # PLies Copyright 2001 Dobrica Pavlinusic <dpavlin@rot13.org>
4 dpavlin 1.1 #
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 dpavlin 1.9 my $tmp = $table[($i*2)].$table[($i*2)+1];
244 dpavlin 1.7 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 dpavlin 1.8 $table[0] = remove_anchor($table[0]);
282 dpavlin 1.1
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 dpavlin 1.8 $next_title= remove_anchor($table[2]);
288 dpavlin 1.7 }
289 dpavlin 1.1
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 dpavlin 1.8 if ($slideContent =~ s/<[hH]2[^>]*>(.+)<\/[hH]2[^>]*>//sm) {
299     $slideSubTitle=remove_anchor($1);
300 dpavlin 1.1 }
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 dpavlin 1.7 &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$prev_title,$next_title);
309 dpavlin 1.1
310     ## save the title of the previous slide to be displayed in the 'previous' navigation button
311 dpavlin 1.8 $prev_title=remove_anchor($table[0]);
312 dpavlin 1.1 }
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 dpavlin 1.5 %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 dpavlin 1.7 logoLink2 => $logoLink2,
357     logoFile2 => $logoFile2,
358     logoAlt2 => $logoAlt2,
359 dpavlin 1.5
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 dpavlin 1.1
370 dpavlin 1.5 date => $date,
371 dpavlin 1.1
372 dpavlin 1.5 toc => $loc_toc,
373     );
374 dpavlin 1.1
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 dpavlin 1.5 $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 dpavlin 1.1
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 dpavlin 1.5 %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 dpavlin 1.1 &closeOverview;
426     &openOverview("$overview-toc$toc_nr");
427     $last_toc_title='';
428     }
429    
430 dpavlin 1.5 $pre_ul=$post_ul='';
431 dpavlin 1.1 if ($last_toc_title eq $title) {
432     $title = $subtitle;
433 dpavlin 1.5 $pre_ul='<ul>';
434     $post_ul='</ul>';
435 dpavlin 1.1 } else {
436     $last_toc_title=$title;
437     }
438    
439     # add accesskey for first 9 slides (`1' - `9') or just for first
440     # TOC page, and tabindex for all slides
441     if ($nr < 10 && $nr < $toc_on_page) {
442 dpavlin 1.5 $item = {
443     pre_html => $pre_ul,
444     accesskey => "$nr",
445     tabindex => "$nr",
446     href => "slide$nr.html",
447     title => $title,
448     post_html => $post_ul,
449     more => 0,
450     };
451     push @toc_entries,$item;
452 dpavlin 1.1 } else {
453 dpavlin 1.5 %item = (
454     pre_html => $pre_ul,
455     tabindex => "$nr",
456     href => "slide$nr.html",
457     title => $title,
458     post_html => $post_ul,
459     )
460     # push @toc_entries,\%item;
461 dpavlin 1.1 }
462     }
463     ##
464     ##############################################################################
465    
466     ##############################################################################
467     ## generate the current slide
468    
469     sub createSlide
470     {
471    
472     # parameters are respectively the slide title, its content,
473     # its number, the next slide title and the previous slide title
474    
475 dpavlin 1.7 my ($title,$subtitle,$content,$nr,$prev_title,$next_title) = @_;
476 dpavlin 1.1
477     if (! $title) {
478     return 1;
479     }
480    
481     # work the slide title, the previous and next titles
482     chomp $title;
483     $title =~ s/\r//ig; # remove the windows CR+LF
484     $next_title =~ s/\r//ig;
485     $prev_title =~ s/\r//ig;
486    
487     # Remove any tags from the prev & next titles
488     $next_title =~ s/<[^>]+>//g;
489     $prev_title =~ s/<[^>]+>//g;
490     $title =~ s/<[^>]+>//g;
491    
492     # Replace double quotes
493     # $title =~ s/"/&#34;/g;
494     $next_title =~ s/"/&#34;/g;
495     $prev_title =~ s/"/&#34;/g;
496    
497     # work the slide content
498     $content =~ s/<\/body>//i; # remove if any
499     $content =~ s/<\/html>//i; # remove if any
500    
501     $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle;
502     $status =~ s/<[^>]+>//g;
503     print STDOUT $status;
504    
505     &verify_html($content); # check the html
506    
507     ## write to the slide
508     open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!";
509    
510 dpavlin 1.7 my $toc_link = "$overview\.html";
511 dpavlin 1.1
512     ## initialization of the navigation links
513 dpavlin 1.7 my $next_link = "";
514     my $prev_link = "";
515 dpavlin 1.1
516     if ($nr>1) {
517 dpavlin 1.7 $prev_link = "slide".($nr-1).".html";
518 dpavlin 1.1 # } else {
519     # ## add a link back to the toc for the first slide --CMN 19991102
520 dpavlin 1.7 # $prev_link = "$overview\.html";
521 dpavlin 1.1 }
522    
523     if ($nr != $total) {
524 dpavlin 1.7 $next_link = "slide".($nr+1).".html";
525 dpavlin 1.1 }
526    
527     $stylelink = "";
528     # here is the standard style sheet
529     $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\">";
530    
531     my $slide_html=make_progress_bar($nr,$total);
532    
533 dpavlin 1.5 %page_data = (
534     doctype => $doctype,
535     talkTitle => $talkTitle,
536     title => $title,
537 dpavlin 1.7 subtitle => $subtitle,
538 dpavlin 1.5 http_equiv => $http_equiv,
539     stylelink => $stylelink,
540     body => $body,
541    
542 dpavlin 1.7 logoLink => $logoLink,
543     logoFile => $logoFile,
544     logoAlt => $logoAlt,
545     logoLink2 => $logoLink2,
546     logoFile2 => $logoFile2,
547     logoAlt2 => $logoAlt2,
548    
549    
550 dpavlin 1.5 content_hight => $content_hight,
551     content => $content,
552 dpavlin 1.7
553     prev_link => $prev_link,
554     toc_link => $toc_link,
555     next_link => $next_link,
556     prev_title => $prev_title,
557     next_title => $next_title,
558    
559 dpavlin 1.5 author => $author,
560 dpavlin 1.7 authorUrl => $authorUrl,
561     author2 => $author2,
562     authorUrl2 => $authorUrl2,
563    
564     date => $date,
565    
566 dpavlin 1.5 slide_html => $slide_html,
567    
568     );
569    
570     my $page= new Text::FastTemplate key => 'slide';
571     print SLIDE $page->output( \%page_data );
572 dpavlin 1.1
573     close(SLIDE);
574     return 0;
575     }
576    
577     ##############################################################################
578     ## generate all the toc of contents needed for each css choosen by the user
579     ## the default toc is not numbered so it can be served by a request to '/'
580     ## (ie it remains Overview.html whereas the other toc are called Overview_#.html)
581    
582     sub generateTOC {
583    
584     ## read the general toc
585     open(FOO, "<$overview.html");
586     @TOC = <FOO>;
587     close(FOO);
588     $toc = "@TOC";
589    
590     ## for each user CSS file
591     ## starting after the default css
592     for ($css=1;$css<$nbCssStandard;$css++) {
593    
594     ## create new TOC
595     $newTOC = $toc;
596    
597     ## the links on the toc need also to be modified
598     ## to link to the correct slides
599     $newTOC =~ s/<a accesskey=\"(\d)\" tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a accesskey=\"$1\" tabindex=\"$2\" href=\"slide$3-$css\.html">/ig;
600     $newTOC =~ s/<a tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a tabindex=\"$1\" href=\"slide$2-$css\.html">/ig;
601    
602     ## write to new TOC
603     $outfile = $overview."-".$css.".html";
604     open(OUT, ">$outfile");
605     print OUT $newTOC;
606     close(OUT)
607     }
608    
609    
610     }
611    
612     ##############################################################################
613     # check that the html of the slide
614     # is correct (ALT tags, ...)
615     # This procedure produces only warning
616     sub verify_html {
617    
618     if ($_[0] =~ /<img([^>]*)>/im) {
619     if (!($1 =~ /ALT=/im)) {
620     print STDOUT "WARNING: <IMG> without ALT\n";
621     print STDOUT " <IMG$1>\n" ;
622     }
623     }
624     }
625    
626     ##############################################################################
627     # clean the html of the slide
628     # remove all <div class="comment">blabla</div>
629     sub clean_html {
630     $_[0] =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs;
631     return $_[0];
632     }
633    
634     ##############################################################################
635     # make transparent 1x1 gif (for layout tricks)
636     sub make_dotgif {
637     @dot_gif=(71,73,70,56,57,97,1,0,1,0,128,0,0,192,192,192,0,0,0,33,
638     249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
639     open(GIF,"> $_[0]") || die "can't write gif $_[0]: $!";
640     my $dotgif;
641     foreach (@dot_gif) {
642     $dotgif.=chr($_);
643     }
644     print GIF $dotgif;
645     close(GIF);
646     }
647    
648     ##############################################################################
649     # make slide progress bar
650     sub make_progress_bar {
651     my ($nr,$total) = @_;
652    
653     my $pcnt_done=int($nr*100/$total);
654     my $pcnt_left=100-$pcnt_done;
655    
656     if ($progress_bar) {
657     my $l=$r="&nbsp;";
658     my $t="$nr of $total";
659     if ($pcnt_done > 50) {
660     $l=$t;
661     } else {
662     $r=$t;
663     }
664 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>';
665 dpavlin 1.1 } else {
666     $html="$loc_slide $nr $loc_of $total";
667     }
668    
669     return $html;
670     }
671    
672 dpavlin 1.8 ##############################################################################
673     # make slide progress bar
674     sub remove_anchor {
675     my $foo = $_[0];
676     $foo=~s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig;
677     return $foo;
678     }

  ViewVC Help
Powered by ViewVC 1.1.26