/[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.19 - (hide annotations)
Tue Sep 4 23:10:55 2001 UTC (22 years, 6 months ago) by dpavlin
Branch: MAIN
Changes since 1.18: +112 -1 lines
File MIME type: text/plain
added check_tags to check open/closed tags

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 dpavlin 1.14 my $debug=0;
57 dpavlin 1.7
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 dpavlin 1.13 my $pack = 0;
137     my @pack_additional; # additional files to pack (pictures, logos...)
138 dpavlin 1.19 my %nesttag = init_nesttag();
139 dpavlin 1.13
140 dpavlin 1.1 ##############################################################################
141     ## reading user input from $infos
142     ##
143 dpavlin 1.16 my @file;
144    
145     ##############################################################################
146     sub parse_infos {
147     my @file=@_;
148 dpavlin 1.7 do {
149     if ($file[0] && $file[0] =~ /^[^#\n\r]/) {
150     $file[0] =~ s/\n//; # remove UNIX \n
151     $file[0] =~ s/\r//; # remove WINDOWS \r
152 dpavlin 1.16 my ($var,$value) = split(/ *= */,$file[0],2);
153     $value=~s/'/\\'/g;
154     $cmd="\$$var = \'$value\';";
155     if (defined($value)) {
156     eval($cmd) || warn "problem with eval of: $cmd";
157     } else {
158     die "no value defined for $var";
159     }
160 dpavlin 1.13 print STDERR "$file[0]\n";
161 dpavlin 1.7 }
162     } while (shift(@file));
163 dpavlin 1.1 }
164 dpavlin 1.16 ##############################################################################
165    
166 dpavlin 1.17 parse_infos(@ARGV); # backward compatibility and for pack
167    
168 dpavlin 1.16 # read parameters from infos.txt and put them in @PARAM
169     if (open(INFOS, $infos)) {
170     print STDERR "--- Reading parameters file $infos ---\n";
171     @file = <INFOS>;
172     parse_infos(@file);
173     }
174 dpavlin 1.1
175 dpavlin 1.16 # try to read local infos.txt for template
176     if (-f "$template/$infos" && open(INFOS,"$template/$infos")) {
177     print STDERR "--- Reading template parameters file $template/$infos ---\n";
178     @file = <INFOS>;
179     parse_infos(@file);
180     close(INFOS);
181 dpavlin 1.1 }
182    
183 dpavlin 1.16 ## @PARAM is now a table with the user preferences for his presentation
184    
185 dpavlin 1.1 ## use charset
186    
187     if ($charset) {
188     $http_equiv='<meta http-equiv="Content-type" content="text/html; charset='.$charset.'">';
189     } else {
190     $http_equiv='';
191     }
192    
193 dpavlin 1.13
194 dpavlin 1.1 ##############################################################################
195     ## read the raw html presentation
196     ##
197    
198     ## copy file in memory
199     my $sep = $/;
200     $/ = undef;
201 dpavlin 1.7 open(ALL, $all) || die "Error: Cannot open file: $all";
202 dpavlin 1.1 my $buf = <ALL>;
203 dpavlin 1.12 $buf =~ s/\r//g; # remove WINDOWS \r
204 dpavlin 1.1 close(ALL);
205     $/ = $sep;
206    
207     ## Remove comments from the raw presentation
208     ## they do not need to show up on the slides
209     $buf =~ s/<!--.*?-->//sgo;
210    
211 dpavlin 1.13 ## if $pack is set, output name of css (for inclusion in archive), but
212     ## reset $cssStandard only to filename (without path)
213    
214     if ($pack) {
215     push @pack_additional,$cssStandard;
216     $cssStandard =~ s/^.*\/([^\/]+)$/$1/g;
217     }
218    
219 dpavlin 1.1 ## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags
220     ## if not it will generate a rather weird output
221     ## split using <h1...> and </h1...> as separator (ignores attributes!)
222     ## h1 or H1 can be used
223     @table = split(/<\/?[hH]1[^>]*>/, $buf);
224    
225     ## compute the total number of slides
226     $total = $#table / 2;
227     if ($#table % 2 != 0) {
228     $total = ($#table +1)/2;
229     }
230    
231     ##
232     ## raw presentation has been read successfully
233     ##############################################################################
234    
235     ##############################################################################
236     ## processing the slides
237    
238 dpavlin 1.13 print STDERR "\n--- Processing $total slides ---\n";
239 dpavlin 1.1
240     ## generate the header table of content of the presentation
241     ## which is also the first page of the talk
242     &openOverview($overview);
243    
244     ## start the slide count so we can number them
245     $slideCount = 1;
246    
247 dpavlin 1.5 ## pre-load template slides using $template dir
248     Text::FastTemplate->defaults(
249     path => [ $template ]
250     );
251    
252     Text::FastTemplate->preload( [
253     { file => 'slide.html', key => 'slide' },
254     { file => 'overview.html', key => 'overview' },
255 dpavlin 1.12 { file => 'title.html', key => 'title' },
256 dpavlin 1.5 ]);
257 dpavlin 1.1
258 dpavlin 1.7 ## unroll relative anchors (#something) into links with slides
259    
260     my %anchor_on_slide;
261    
262     ## step 1: record anchors
263     for($i=0; $i<$total; $i++) {
264 dpavlin 1.9 my $tmp = $table[($i*2)].$table[($i*2)+1];
265 dpavlin 1.7 while ($tmp =~ s,<a +name="*([^>"]+)"*>,,i) {
266     $anchor_on_slide{$1}=($i+1);
267 dpavlin 1.13 print STDERR "\tslide ",($i+1)," anchor: $1\n" if ($debug);
268 dpavlin 1.7 }
269     }
270    
271     ## step 2: fix links
272     for($i=0; $i<$total; $i++) {
273     foreach (keys %anchor_on_slide) {
274     $table[($i*2)] =~ s,href="*#$_"*>,href="slide$anchor_on_slide{$_}\.html#$_">,gi;
275     }
276     }
277    
278 dpavlin 1.1 ## @table is the array containing each slide with its title
279     ## for each slide to be generated
280     ## we delete each slide and its title when generated
281     ## so that the current slide and its title are always at $table[0] (for the title)
282     ## and $table[1] (for the slide content)
283 dpavlin 1.7
284     undef $prev_title;
285     undef $next_title;
286    
287 dpavlin 1.1 do {
288    
289     ## get rid of the first element contained by the raw presentation array
290     shift(@table);
291     ## then $table[0] is the title of the slide to be generated
292     $table[0] =~ s/\n+/ /g; ## replace return character by a white space
293     $table[0] =~ s/\r+/ /g; ## replace lf character by a white space
294     $table[0] =~ s/ +/ /g; ## concatenate several white spaces to only one
295     $table[0] =~ s/^ //; ## remove all the starting white spaces in the title
296     $table[0] =~ s/ $//; ## remove all trailing white spaces in the title
297     ## $slideTitle preserves link(s) in the title
298     $slideTitle = $table[0];
299     ## need to check if the title contains any anchor
300     ## if so it needs to be removed
301     ## because the title is being used in the table of content to link to the corresponding slide
302 dpavlin 1.8 $table[0] = remove_anchor($table[0]);
303 dpavlin 1.1
304     ## grab next slide title $table[2] (if there's a next slide)
305     ## to be able to use in the 'next' navigation button
306     ## keep in mind that $table[1] contains the slide corresponding to the title $table[0]
307 dpavlin 1.7 if ($table[2]) {
308 dpavlin 1.8 $next_title= remove_anchor($table[2]);
309 dpavlin 1.7 }
310 dpavlin 1.1
311     ## the current slide content is stored $table[1]
312     ## there is an attempt to make sure it's clean HTML
313     ## Pierre Fillault's note: use same piece of as used in http://www.w3.org/Web/Tools/CvsCommitScripting
314     ## to make use of the validation service
315     $slideContent = &clean_html($table[1]) ;
316    
317     ## extract slide Sub Title <h2>
318     undef $slideSubTitle;
319 dpavlin 1.8 if ($slideContent =~ s/<[hH]2[^>]*>(.+)<\/[hH]2[^>]*>//sm) {
320     $slideSubTitle=remove_anchor($1);
321 dpavlin 1.1 }
322    
323     ## add the title of the current slide to the table of content
324     &addTitle($slideTitle,$slideSubTitle,$slideCount);
325    
326     ## generate the current slide
327     ## parameters are:
328     ## title of the slide, its content, the slide number, the title of the previous slide and the title of the next slide
329 dpavlin 1.7 &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$prev_title,$next_title);
330 dpavlin 1.1
331     ## save the title of the previous slide to be displayed in the 'previous' navigation button
332 dpavlin 1.8 $prev_title=remove_anchor($table[0]);
333 dpavlin 1.1 }
334     ## process the next slide
335     while (shift(@table));
336    
337     ## close the table of content
338     &closeOverview;
339    
340     ## generate more toc with the all the style sheets
341     ## as there's no way of loading a style sheet
342     ## except dynamically, but that would be slow
343     ## and would not work on all platforms (ie would fail on Joe's laptop)
344     &generateTOC;
345    
346 dpavlin 1.13 ## print additional files to pack
347     print STDOUT join("\n",@pack_additional) if ($pack);
348 dpavlin 1.1
349 dpavlin 1.13 print STDERR "--- Finished ---\n";
350 dpavlin 1.1 exit 0;
351     ##
352     ## end of the slidemaker main program
353     ##############################################################################
354    
355    
356     ##############################################################################
357     ## generate the header of the table of content
358    
359     sub openOverview
360     {
361     ## open the file to write to
362     open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!";
363 dpavlin 1.13 push @pack_additional,"$_[0].html" if ($pack);
364 dpavlin 1.1
365     ## the style sheet used in the table of content is
366     $stylelink = "";
367     ## here is the standard style sheet
368     $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\" media=\"screen\">";
369    
370 dpavlin 1.5 %overview_data = (
371     doctype => $doctype,
372     title => $title,
373     http_equiv => $http_equiv,
374     stylelink => $stylelink,
375     body => $body,
376    
377     logoLink => $logoLink,
378     logoFile => $logoFile,
379     logoAlt => $logoAlt,
380 dpavlin 1.7 logoLink2 => $logoLink2,
381     logoFile2 => $logoFile2,
382     logoAlt2 => $logoAlt2,
383 dpavlin 1.5
384     talkTitle => $talkTitle,
385     talkSubTitle => $talkSubTitle,
386    
387     content_hight => $content_hight,
388    
389     author => $author,
390     authorUrl => $authorUrl,
391     author2 => $author2,
392 dpavlin 1.18 author2Url => $author2Url,
393 dpavlin 1.1
394 dpavlin 1.5 date => $date,
395 dpavlin 1.1
396 dpavlin 1.16 toc_title => $loc_toc,
397 dpavlin 1.17 template_dir => "$template/",
398 dpavlin 1.5 );
399 dpavlin 1.1
400     }
401     ##
402     ## the beginning of the table of content has been generated and saved
403     ##############################################################################
404    
405     ##############################################################################
406     ## generate the footer of the table of content
407    
408     sub closeOverview
409     {
410 dpavlin 1.5 $overview_data{slide_html} = make_progress_bar(0,$total);
411     $overview_data{toc_entries} = [ @toc_entries ];
412    
413     my $page= new Text::FastTemplate key => 'overview';
414 dpavlin 1.17 $page_data{template_dir}='' if ($pack);
415 dpavlin 1.5 print FOO $page->output( \%overview_data );
416 dpavlin 1.1
417     close(FOO);
418     }
419     ##
420     ## the toc has been completed and saved
421     ##############################################################################
422    
423     ##############################################################################
424     ## add an item in the toc
425    
426     sub addTitle
427     {
428     my ($title,$subtitle,$nr) = @_;
429     $title =~ s/\r//ig; # remove the windows CR+LF
430     $title =~ s/<[^>]+>//g;
431    
432     if (! $title) {
433     return 1;
434     }
435    
436     # split TOC entries to multiple pages
437    
438     if ($nr % $toc_on_page == 0) {
439     my $toc_nr=int($nr/$toc_on_page);
440    
441 dpavlin 1.10 $item = {
442 dpavlin 1.5 pre_html => $pre_ul,
443     accesskey => " ", # space
444     href => "index-toc$toc_nr.html",
445     title => "...",
446     post_html => $post_ul,
447     more => 1, # use style for more pages link (...)
448 dpavlin 1.10 };
449     push @toc_entries, $item;
450 dpavlin 1.5
451 dpavlin 1.1 &closeOverview;
452 dpavlin 1.10 undef @toc_entries;
453 dpavlin 1.1 &openOverview("$overview-toc$toc_nr");
454     $last_toc_title='';
455     }
456    
457 dpavlin 1.5 $pre_ul=$post_ul='';
458 dpavlin 1.11 if ($last_toc_title eq $title && $subtitle) {
459 dpavlin 1.1 $title = $subtitle;
460 dpavlin 1.5 $pre_ul='<ul>';
461     $post_ul='</ul>';
462 dpavlin 1.1 } else {
463     $last_toc_title=$title;
464     }
465    
466     # add accesskey for first 9 slides (`1' - `9') or just for first
467     # TOC page, and tabindex for all slides
468     if ($nr < 10 && $nr < $toc_on_page) {
469 dpavlin 1.5 $item = {
470     pre_html => $pre_ul,
471     accesskey => "$nr",
472     tabindex => "$nr",
473     href => "slide$nr.html",
474     title => $title,
475     post_html => $post_ul,
476     more => 0,
477     };
478     push @toc_entries,$item;
479 dpavlin 1.1 } else {
480 dpavlin 1.10 $item = {
481 dpavlin 1.5 pre_html => $pre_ul,
482     tabindex => "$nr",
483     href => "slide$nr.html",
484     title => $title,
485     post_html => $post_ul,
486 dpavlin 1.10 };
487     push @toc_entries,$item;
488 dpavlin 1.1 }
489     }
490     ##
491     ##############################################################################
492    
493     ##############################################################################
494     ## generate the current slide
495    
496     sub createSlide
497     {
498    
499     # parameters are respectively the slide title, its content,
500     # its number, the next slide title and the previous slide title
501    
502 dpavlin 1.7 my ($title,$subtitle,$content,$nr,$prev_title,$next_title) = @_;
503 dpavlin 1.1
504     if (! $title) {
505     return 1;
506     }
507    
508     # work the slide title, the previous and next titles
509     chomp $title;
510     $title =~ s/\r//ig; # remove the windows CR+LF
511     $next_title =~ s/\r//ig;
512     $prev_title =~ s/\r//ig;
513    
514     # Remove any tags from the prev & next titles
515     $next_title =~ s/<[^>]+>//g;
516     $prev_title =~ s/<[^>]+>//g;
517     $title =~ s/<[^>]+>//g;
518    
519     # Replace double quotes
520     # $title =~ s/"/&#34;/g;
521     $next_title =~ s/"/&#34;/g;
522     $prev_title =~ s/"/&#34;/g;
523    
524     # work the slide content
525     $content =~ s/<\/body>//i; # remove if any
526     $content =~ s/<\/html>//i; # remove if any
527    
528     $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle;
529     $status =~ s/<[^>]+>//g;
530 dpavlin 1.13 print STDERR $status;
531 dpavlin 1.1
532 dpavlin 1.19 &verify_html($content); # check the html
533     &check_tags($content); # check open and closed tags
534 dpavlin 1.1
535     ## write to the slide
536     open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!";
537 dpavlin 1.13 push @pack_additional,"slide$nr.html" if ($pack);
538 dpavlin 1.1
539 dpavlin 1.7 my $toc_link = "$overview\.html";
540 dpavlin 1.1
541     ## initialization of the navigation links
542 dpavlin 1.7 my $next_link = "";
543     my $prev_link = "";
544 dpavlin 1.1
545     if ($nr>1) {
546 dpavlin 1.7 $prev_link = "slide".($nr-1).".html";
547 dpavlin 1.1 # } else {
548     # ## add a link back to the toc for the first slide --CMN 19991102
549 dpavlin 1.7 # $prev_link = "$overview\.html";
550 dpavlin 1.1 }
551    
552     if ($nr != $total) {
553 dpavlin 1.7 $next_link = "slide".($nr+1).".html";
554 dpavlin 1.1 }
555    
556     $stylelink = "";
557     # here is the standard style sheet
558     $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\">";
559    
560     my $slide_html=make_progress_bar($nr,$total);
561    
562 dpavlin 1.12 # undefine body if no content is found (so that template can show
563     # only title and sub-title
564     if ($content !~ m/\S/g) {
565     undef $content;
566     }
567    
568 dpavlin 1.5 %page_data = (
569     doctype => $doctype,
570     talkTitle => $talkTitle,
571     title => $title,
572 dpavlin 1.7 subtitle => $subtitle,
573 dpavlin 1.5 http_equiv => $http_equiv,
574     stylelink => $stylelink,
575     body => $body,
576    
577 dpavlin 1.7 logoLink => $logoLink,
578     logoFile => $logoFile,
579     logoAlt => $logoAlt,
580     logoLink2 => $logoLink2,
581     logoFile2 => $logoFile2,
582     logoAlt2 => $logoAlt2,
583    
584    
585 dpavlin 1.5 content_hight => $content_hight,
586     content => $content,
587 dpavlin 1.7
588     prev_link => $prev_link,
589     toc_link => $toc_link,
590     next_link => $next_link,
591     prev_title => $prev_title,
592 dpavlin 1.16 toc_title => $loc_toc,
593 dpavlin 1.7 next_title => $next_title,
594    
595 dpavlin 1.5 author => $author,
596 dpavlin 1.7 authorUrl => $authorUrl,
597     author2 => $author2,
598 dpavlin 1.18 author2Url => $author2Url,
599 dpavlin 1.7
600     date => $date,
601    
602 dpavlin 1.5 slide_html => $slide_html,
603    
604 dpavlin 1.17 template_dir => "$template/",
605 dpavlin 1.5 );
606    
607 dpavlin 1.12 my $page;
608     if ($content) {
609     $page= new Text::FastTemplate key => 'slide';
610     } else {
611     $page= new Text::FastTemplate key => 'title';
612     }
613 dpavlin 1.17 $page_data{template_dir}='' if ($pack);
614 dpavlin 1.5 print SLIDE $page->output( \%page_data );
615 dpavlin 1.13 extract_files($page->output( \%page_data )) if ($pack);
616 dpavlin 1.1 close(SLIDE);
617     return 0;
618     }
619    
620     ##############################################################################
621     ## generate all the toc of contents needed for each css choosen by the user
622     ## the default toc is not numbered so it can be served by a request to '/'
623     ## (ie it remains Overview.html whereas the other toc are called Overview_#.html)
624    
625     sub generateTOC {
626    
627     ## read the general toc
628     open(FOO, "<$overview.html");
629     @TOC = <FOO>;
630     close(FOO);
631     $toc = "@TOC";
632    
633     ## for each user CSS file
634     ## starting after the default css
635     for ($css=1;$css<$nbCssStandard;$css++) {
636    
637     ## create new TOC
638     $newTOC = $toc;
639    
640     ## the links on the toc need also to be modified
641     ## to link to the correct slides
642     $newTOC =~ s/<a accesskey=\"(\d)\" tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a accesskey=\"$1\" tabindex=\"$2\" href=\"slide$3-$css\.html">/ig;
643     $newTOC =~ s/<a tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a tabindex=\"$1\" href=\"slide$2-$css\.html">/ig;
644    
645     ## write to new TOC
646     $outfile = $overview."-".$css.".html";
647     open(OUT, ">$outfile");
648     print OUT $newTOC;
649     close(OUT)
650     }
651    
652    
653     }
654    
655     ##############################################################################
656     # check that the html of the slide
657     # is correct (ALT tags, ...)
658     # This procedure produces only warning
659     sub verify_html {
660    
661     if ($_[0] =~ /<img([^>]*)>/im) {
662     if (!($1 =~ /ALT=/im)) {
663 dpavlin 1.13 print STDERR "WARNING: <IMG> without ALT\n";
664     print STDERR " <IMG$1>\n" ;
665 dpavlin 1.1 }
666     }
667     }
668    
669     ##############################################################################
670     # clean the html of the slide
671     # remove all <div class="comment">blabla</div>
672     sub clean_html {
673 dpavlin 1.10 my $tmp=$_[0];
674     $tmp =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs;
675     $tmp =~ s,</*font[^>]+>,,ig;
676     return $tmp;
677 dpavlin 1.1 }
678    
679     ##############################################################################
680     # make transparent 1x1 gif (for layout tricks)
681     sub make_dotgif {
682     @dot_gif=(71,73,70,56,57,97,1,0,1,0,128,0,0,192,192,192,0,0,0,33,
683     249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
684     open(GIF,"> $_[0]") || die "can't write gif $_[0]: $!";
685     my $dotgif;
686     foreach (@dot_gif) {
687     $dotgif.=chr($_);
688     }
689     print GIF $dotgif;
690     close(GIF);
691     }
692    
693     ##############################################################################
694     # make slide progress bar
695     sub make_progress_bar {
696     my ($nr,$total) = @_;
697    
698     my $pcnt_done=int($nr*100/$total);
699     my $pcnt_left=100-$pcnt_done;
700    
701 dpavlin 1.16 if ($progress_bar && uc($progress_bar) ne "NO") {
702 dpavlin 1.1 my $l=$r="&nbsp;";
703     my $t="$nr of $total";
704     if ($pcnt_done > 50) {
705     $l=$t;
706     } else {
707     $r=$t;
708     }
709 dpavlin 1.15 $html='<table border="0" width="50%" cellpadding="0" cellspacing="0" align="right"><tr>';
710     if ($pcnt_done != 0) {
711     $html.='<td width="'.$pcnt_done.'%" class="pcnt-done">'.$l.'</td>';
712     }
713     if ($pcnt_left != 0) {
714     $html.='<td width="'.$pcnt_left.'%" class="pcnt-left">'.$r.'</td>';
715     }
716     $html.='</tr></table>';
717 dpavlin 1.1 } else {
718     $html="$loc_slide $nr $loc_of $total";
719     }
720    
721     return $html;
722     }
723    
724 dpavlin 1.8 ##############################################################################
725 dpavlin 1.13 # remove anchors <a href...> from html (for titles)
726 dpavlin 1.8 sub remove_anchor {
727 dpavlin 1.10 my $tmp = $_[0];
728     $tmp =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig;
729     return $tmp;
730 dpavlin 1.13 }
731    
732     ##############################################################################
733     # extract files referenced in presentation
734    
735     sub extract_files {
736     my $tmp = $_[0];
737 dpavlin 1.17 while ($tmp =~ s/href="*([^"\s]+)"*//ism ||
738     $tmp =~ s/src="*([^"\s]+)"*//ism) {
739 dpavlin 1.13 if ("$1" !~ m/[hf]t?tp:/ && -f "$1" && !grep(/$1/,@pack_additional)) {
740     push @pack_additional,$1;
741     }
742     }
743 dpavlin 1.8 }
744 dpavlin 1.19
745     ##############################################################################
746     # check tags in slide
747     # based on code from hindent 1.1.2 by Paul Balyoz <pab@domtools.com>
748    
749     sub init_nesttag {
750     # Tags that require their own end tag <TAG>...</TAG> we will nest them
751     # properly: (WARNING, you must use lower-case here)
752     # All other tags (not on this list) will be ignored for indenting purposes.
753     return (
754     'html' => 1,
755     'head' => 1,
756     'body' => 1,
757     'title' => 1,
758    
759     'a' => 1,
760    
761     'table' => 1,
762     'tr' => 1,
763     'th' => 1,
764     'td' => 1,
765    
766     'form' => 1,
767     'select' => 1,
768     'textarea' => 1,
769    
770     # 'p' => 1, Don't do this one because many people use <P> but not </P>
771     'ul' => 1,
772     'ol' => 1,
773     'dl' => 1,
774     'blockquote' => 1,
775     'center' => 1,
776     'div' => 1,
777    
778     'font' => 1,
779     'pre' => 1,
780     'tt' => 1,
781     'i' => 1,
782     'b' => 1,
783     'u' => 1,
784     'strike' => 1,
785     'big' => 1,
786     'small' => 1,
787     'sub' => 1,
788     'sup' => 1,
789     'em' => 1,
790     'strong' => 1,
791     'dfn' => 1,
792     'code' => 1,
793     'samp' => 1,
794     'kbd' => 1,
795     'var' => 1,
796     'cite' => 1,
797    
798     'h1' => 1,
799     'h2' => 1,
800     'h3' => 1,
801     'h4' => 1,
802     'h5' => 1,
803     'h6' => 1,
804    
805     'applet' => 1,
806    
807     'map' => 1,
808    
809     'frameset' => 1,
810     'noframes' => 1,
811     );
812     }
813    
814     sub check_tags {
815     my $tmp = $_[0];
816     my @tagstack;
817     my $level=0;
818    
819     while ($tmp =~ /<(.*?)>/gsm) {
820     my $tag=$1; $tag=~s/\s.+//g;
821     # if regular tag, push it on stack; if end-tag, pop it off stack.
822     # but don't do any of this if it's not a special "nesting" tag!
823     if ($tag !~ m,^/,) {
824     if ($nesttag{lc($tag)}) {
825     push @tagstack,$tag;
826     $level++; # remember how much for later
827     }
828     } else {
829     $tag =~ s,^/,,; # convert this end-tag to a begin-tag
830     $tag = lc($tag);
831     if ($nesttag{lc($tag)}) {
832     # throw away tags until we find a match
833     if ($#tagstack > -1) {
834     while ($tag ne lc(pop @tagstack)) {
835     $level--; # we threw away extra tags
836     last if $#tagstack <= 0;
837     }
838     $level--; # we threw away extra tags
839     if ($level < 0) {
840     print STDERR "WARNING: more end than begin tags around </$tag> !\n";
841     }
842     }
843     }
844     }
845     }
846    
847     if ($level > 0) {
848     print STDERR "WARNING: level=$level, ", $#tagstack+1," tags left on stack after done parsing! Specifically:\n<",join("> <",@tagstack),">\n";
849     }
850    
851     }
852    

  ViewVC Help
Powered by ViewVC 1.1.26