source: trunk/essentials/dev-lang/python/Doc/perl/l2hinit.perl@ 3298

Last change on this file since 3298 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 27.8 KB
Line 
1# LaTeX2HTML support base for use with Python documentation.
2
3package main;
4
5use L2hos;
6
7$HTML_VERSION = 4.01;
8$LOWER_CASE_TAGS = 1;
9$NO_FRENCH_QUOTES = 1;
10
11# '' in \code{...} is still converted, so we can't use this yet.
12#$USE_CURLY_QUOTES = 1;
13
14# Force Unicode support to be loaded; request UTF-8 output.
15do_require_extension('unicode');
16do_require_extension('utf8');
17$HTML_OPTIONS = 'utf8';
18
19$MAX_LINK_DEPTH = 2;
20$ADDRESS = '';
21
22$NO_FOOTNODE = 1;
23$NUMBERED_FOOTNOTES = 1;
24
25# Python documentation uses section numbers to support references to match
26# in the printed and online versions.
27#
28$SHOW_SECTION_NUMBERS = 1;
29
30$ICONSERVER = '.';
31$IMAGE_TYPE = 'gif';
32
33# Control where the navigation bars should show up:
34$TOP_NAVIGATION = 1;
35$BOTTOM_NAVIGATION = 1;
36$AUTO_NAVIGATION = 0;
37
38$BODYTEXT = '';
39$CHILDLINE = "\n<p><br /></p><hr class='online-navigation' />\n";
40$VERBOSITY = 0;
41
42# default # of columns for the indexes
43$INDEX_COLUMNS = 2;
44$MODULE_INDEX_COLUMNS = 4;
45
46$HAVE_MODULE_INDEX = 0;
47$HAVE_GENERAL_INDEX = 0;
48$HAVE_TABLE_OF_CONTENTS = 0;
49
50$AESOP_META_TYPE = 'information';
51
52
53# A little painful, but lets us clean up the top level directory a little,
54# and not be tied to the current directory (as far as I can tell). Testing
55# an existing definition of $mydir is needed since it cannot be computed when
56# run under mkhowto with recent versions of LaTeX2HTML, since this file is
57# not read directly by LaTeX2HTML any more. mkhowto is required to prepend
58# the required definition at the top of the actual input file.
59#
60if (!defined $mydir) {
61 use Cwd;
62 use File::Basename;
63 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
64 chop $mydir; # remove trailing '/'
65 $mydir = getcwd() . "$dd$mydir"
66 unless $mydir =~ s|^/|/|;
67}
68$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
69push (@INC, $mydir);
70
71($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
72chop $myrootdir;
73
74
75# Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
76# pass in the paper size (a4 or letter) as the environment variable PAPER
77# to add the right directory. If not given, the current directory is
78# added instead for use with HOWTO processing.
79#
80if (defined $ENV{'PAPER'}) {
81 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
82}
83else {
84 $mytexinputs = getcwd() . $envkey;
85}
86$mytexinputs .= "$myrootdir${dd}texinputs";
87
88
89# Change this variable to change the text added in "About this document...";
90# this should be an absolute pathname to get it right.
91#
92$ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat";
93
94
95sub custom_driver_hook {
96 #
97 # This adds the directory of the main input file to $TEXINPUTS; it
98 # seems to be sufficiently general that it should be fine for HOWTO
99 # processing.
100 #
101 # XXX This still isn't quite right; we should actually be inserting
102 # $mytexinputs just before any empty entry in TEXINPUTS is one
103 # exists instead of just concatenating the pieces like we do here.
104 #
105 my $file = $_[0];
106 my($jobname, $dir, $ext) = fileparse($file, '\..*');
107 $dir = L2hos->Make_directory_absolute($dir);
108 $dir =~ s/$dd$//;
109 $TEXINPUTS = "$dir$envkey$mytexinputs";
110 # Push everything into $TEXINPUTS since LaTeX2HTML doesn't pick
111 # this up on its own; we clear $ENV{'TEXINPUTS'} so the value set
112 # for this by the main LaTeX2HTML script doesn't contain duplicate
113 # directories.
114 if ($ENV{'TEXINPUTS'}) {
115 $TEXINPUTS .= "$envkey$ENV{'TEXINPUTS'}";
116 $ENV{'TEXINPUTS'} = undef;
117 }
118 print "\nSetting \$TEXINPUTS to $TEXINPUTS\n";
119
120 # Not sure why we need to deal with this both here and at the top,
121 # but this is needed to actually make it work.
122 do_require_extension('utf8');
123 $charset = $utf8_str;
124 $CHARSET = $utf8_str;
125 $USE_UTF = 1;
126}
127
128
129# $CUSTOM_BUTTONS is only used for the module index link.
130$CUSTOM_BUTTONS = '';
131
132sub make_nav_sectref($$$) {
133 my($label, $linktype, $title) = @_;
134 if ($title) {
135 if ($title =~ /\<[aA] /) {
136 $title =~ s/\<[aA] /<a class="sectref" rel="$linktype" /;
137 $title =~ s/ HREF=/ href=/;
138 }
139 else {
140 $title = "<span class=\"sectref\">$title</span>";
141 }
142 return "<b class=\"navlabel\">$label:</b>\n$title\n";
143 }
144 return '';
145}
146
147@my_icon_tags = ();
148$my_icon_tags{'next'} = 'Next Page';
149$my_icon_tags{'next_page'} = 'Next Page';
150$my_icon_tags{'previous'} = 'Previous Page';
151$my_icon_tags{'previous_page'} = 'Previous Page';
152$my_icon_tags{'up'} = 'Up One Level';
153$my_icon_tags{'contents'} = 'Contents';
154$my_icon_tags{'index'} = 'Index';
155$my_icon_tags{'modules'} = 'Module Index';
156
157@my_icon_names = ();
158$my_icon_names{'previous_page'} = 'previous';
159$my_icon_names{'next_page'} = 'next';
160
161sub get_my_icon($) {
162 my $name = $_[0];
163 my $text = $my_icon_tags{$name};
164 if ($my_icon_names{$name}) {
165 $name = $my_icon_names{$name};
166 }
167 if ($text eq '') {
168 $name = 'blank';
169 }
170 my $iconserver = ($ICONSERVER eq '.') ? '' : "$ICONSERVER/";
171 return "<img src='$iconserver$name.$IMAGE_TYPE'\n border='0'"
172 . " height='32' alt='$text' width='32' />";
173}
174
175sub unlinkify($) {
176 my $text = "$_[0]";
177 $text =~ s|</[aA]>||;
178 $text =~ s|<a\s+[^>]*>||i;
179 return $text;
180}
181
182sub use_icon($$$) {
183 my($rel,$str,$title) = @_;
184 if ($str) {
185 my $s = "$str";
186 if ($s =~ /\<tex2html_([a-z_]+)_visible_mark\>/) {
187 my $r = get_my_icon($1);
188 $s =~ s/\<tex2html_[a-z_]+_visible_mark\>/$r/;
189 }
190 $s =~ s/<[aA] /<a rel="$rel" title="$title"\n /;
191 $s =~ s/ HREF=/ href=/;
192 return $s;
193 }
194 else {
195 return get_my_icon('blank');
196 }
197}
198
199sub make_nav_panel() {
200 my $s;
201 # new iconic rel iconic page title
202 my $next = use_icon('next', $NEXT, unlinkify($NEXT_TITLE));
203 my $up = use_icon('parent', $UP, unlinkify($UP_TITLE));
204 my $previous = use_icon('prev', $PREVIOUS, unlinkify($PREVIOUS_TITLE));
205 my $contents = use_icon('contents', $CONTENTS, 'Table of Contents');
206 my $index = use_icon('index', $INDEX, 'Index');
207 if (!$CUSTOM_BUTTONS) {
208 $CUSTOM_BUTTONS = get_my_icon('blank');
209 }
210 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
211 . "\n<tr>"
212 # left-hand side
213 . "\n<td class='online-navigation'>$previous</td>"
214 . "\n<td class='online-navigation'>$up</td>"
215 . "\n<td class='online-navigation'>$next</td>"
216 # title box
217 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
218 # right-hand side
219 . "\n<td class='online-navigation'>$contents</td>"
220 # module index
221 . "\n<td class='online-navigation'>$CUSTOM_BUTTONS</td>"
222 . "\n<td class='online-navigation'>$index</td>"
223 . "\n</tr></table>\n"
224 # textual navigation
225 . "<div class='online-navigation'>\n"
226 . make_nav_sectref("Previous", "prev", $PREVIOUS_TITLE)
227 . make_nav_sectref("Up", "parent", $UP_TITLE)
228 . make_nav_sectref("Next", "next", $NEXT_TITLE)
229 . "</div>\n"
230 );
231 # remove these; they are unnecessary and cause errors from validation
232 $s =~ s/ NAME="tex2html\d+"\n */ /g;
233 return $s;
234}
235
236sub add_child_links {
237 my $toc = add_real_child_links(@_);
238 $toc =~ s|\s*</[aA]>|</a>|g;
239 $toc =~ s/ NAME=\"tex2html\d+\"\s*href=/ href=/gi;
240 $toc =~ s|</UL>(\s*<BR( /)?>)?|</ul>|gi;
241 if ($toc =~ / NAME=["']CHILD_LINKS["']/) {
242 return "<div class='online-navigation'>\n$toc</div>\n";
243 }
244 return $toc;
245}
246
247sub get_version_text() {
248 if ($PACKAGE_VERSION ne '' && $t_date) {
249 return ("<span class=\"release-info\">"
250 . "Release $PACKAGE_VERSION$RELEASE_INFO,"
251 . " documentation updated on $t_date.</span>");
252 }
253 if ($PACKAGE_VERSION ne '') {
254 return ("<span class=\"release-info\">"
255 . "Release $PACKAGE_VERSION$RELEASE_INFO.</span>");
256 }
257 if ($t_date) {
258 return ("<span class=\"release-info\">Documentation released on "
259 . "$t_date.</span>");
260 }
261 return '';
262}
263
264
265sub top_navigation_panel() {
266 return "\n<div id='top-navigation-panel' xml:id='top-navigation-panel'>\n"
267 . make_nav_panel()
268 . "<hr /></div>\n";
269}
270
271sub bot_navigation_panel() {
272 return "\n<div class='online-navigation'>\n"
273 . "<p></p><hr />\n"
274 . make_nav_panel()
275 . "</div>\n"
276 . "<hr />\n"
277 . get_version_text()
278 . "\n";
279}
280
281sub add_link {
282 # Returns a pair (iconic link, textual link)
283 my($icon, $current_file, @link) = @_;
284 my($dummy, $file, $title) = split($delim,
285 $section_info{join(' ',@link)});
286 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
287 my $r = get_my_icon($1);
288 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
289 }
290 if ($title && ($file ne $current_file)) {
291 $title = purify($title);
292 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
293 return (make_href($file, $icon), make_href($file, "$title"))
294 }
295 elsif ($icon eq get_my_icon('up') && $EXTERNAL_UP_LINK) {
296 return (make_href($EXTERNAL_UP_LINK, $icon),
297 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
298 }
299 elsif ($icon eq get_my_icon('previous')
300 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
301 return (make_href($EXTERNAL_PREV_LINK, $icon),
302 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
303 }
304 elsif ($icon eq get_my_icon('next')
305 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
306 return (make_href($EXTERNAL_DOWN_LINK, $icon),
307 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
308 }
309 return (&inactive_img($icon), "");
310}
311
312sub add_special_link($$$) {