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