Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 1 | # LaTeX2HTML support base for use with Python documentation. |
Fred Drake | 41814bc | 1998-05-11 18:23:35 +0000 | [diff] [blame] | 2 | |
| 3 | package main; |
| 4 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 5 | use L2hos; |
| 6 | |
Fred Drake | 28e7b4c | 1998-10-20 18:14:20 +0000 | [diff] [blame] | 7 | $HTML_VERSION = 4.0; |
| 8 | |
Fred Drake | 6aa5d48 | 1998-08-11 03:14:50 +0000 | [diff] [blame] | 9 | $MAX_LINK_DEPTH = 2; |
Fred Drake | d757165 | 1998-04-23 20:06:24 +0000 | [diff] [blame] | 10 | $ADDRESS = ''; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 11 | |
Fred Drake | e194beb | 1998-05-19 19:38:49 +0000 | [diff] [blame] | 12 | $NO_FOOTNODE = 1; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 13 | $NUMBERED_FOOTNOTES = 1; |
| 14 | |
| 15 | # Python documentation uses section numbers to support references to match |
| 16 | # in the printed and online versions. |
| 17 | # |
| 18 | $SHOW_SECTION_NUMBERS = 1; |
| 19 | |
| 20 | $ICONSERVER = '../icons'; |
Fred Drake | f730fc3 | 2000-08-31 07:19:07 +0000 | [diff] [blame^] | 21 | $IMAGE_TYPE = 'gif'; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 22 | |
Fred Drake | 6aa5d48 | 1998-08-11 03:14:50 +0000 | [diff] [blame] | 23 | # Control where the navigation bars should show up: |
| 24 | $TOP_NAVIGATION = 1; |
| 25 | $BOTTOM_NAVIGATION = 1; |
| 26 | $AUTO_NAVIGATION = 0; |
| 27 | |
Fred Drake | 191439a | 1999-09-22 19:50:51 +0000 | [diff] [blame] | 28 | # these exactly match the python.org colors |
| 29 | $BODYTEXT = ('bgcolor="#ffffff" text="#000000"' |
| 30 | . ' link="#0000bb" vlink="#551a8b" alink="#ff0000"'); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 31 | $CHILDLINE = "\n<p><hr>\n"; |
| 32 | $VERBOSITY = 0; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 33 | |
Fred Drake | 4d10b43 | 1998-08-07 20:51:58 +0000 | [diff] [blame] | 34 | # default # of columns for the indexes |
Fred Drake | aa3f9fb | 1998-08-07 19:52:37 +0000 | [diff] [blame] | 35 | $INDEX_COLUMNS = 2; |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 36 | $MODULE_INDEX_COLUMNS = 4; |
Fred Drake | aa3f9fb | 1998-08-07 19:52:37 +0000 | [diff] [blame] | 37 | |
Fred Drake | c9f2c14 | 1998-03-11 12:08:21 +0000 | [diff] [blame] | 38 | |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 39 | # A little painful, but lets us clean up the top level directory a little, |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 40 | # and not be tied to the current directory (as far as I can tell). Testing |
| 41 | # an existing definition of $mydir is needed since it cannot be computed when |
| 42 | # run under mkhowto with recent versions of LaTeX2HTML, since this file is |
| 43 | # not read directly by LaTeX2HTML any more. mkhowto is required to prepend |
| 44 | # the required definition at the top of the actual input file. |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 45 | # |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 46 | if (!defined $mydir) { |
| 47 | use Cwd; |
| 48 | use File::Basename; |
| 49 | ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*'); |
| 50 | chop $mydir; # remove trailing '/' |
| 51 | $mydir = getcwd() . "$dd$mydir" |
| 52 | unless $mydir =~ s|^/|/|; |
| 53 | } |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 54 | $LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES"; |
Fred Drake | b3a3ed8 | 1998-07-24 22:17:34 +0000 | [diff] [blame] | 55 | push (@INC, $mydir); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 56 | |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 57 | ($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*'); |
| 58 | chop $myrootdir; |
| 59 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 60 | |
Fred Drake | a4565b0 | 1998-05-15 17:14:17 +0000 | [diff] [blame] | 61 | # Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS; |
| 62 | # pass in the paper size (a4 or letter) as the environment variable PAPER |
| 63 | # to add the right directory. If not given, the current directory is |
| 64 | # added instead for use with HOWTO processing. |
| 65 | # |
| 66 | if (defined $ENV{'PAPER'}) { |
| 67 | $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey"; |
| 68 | } |
| 69 | else { |
| 70 | $mytexinputs = getcwd() . $envkey; |
| 71 | } |
| 72 | $mytexinputs .= "$myrootdir${dd}texinputs"; |
| 73 | |
| 74 | |
Fred Drake | b35f2b7 | 1999-09-23 16:53:09 +0000 | [diff] [blame] | 75 | # Change this variable to change the text added in "About this document..."; |
| 76 | # this should be an absolute pathname to get it right. |
| 77 | # |
| 78 | $ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat"; |
| 79 | |
| 80 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 81 | sub custom_driver_hook { |
Fred Drake | a4565b0 | 1998-05-15 17:14:17 +0000 | [diff] [blame] | 82 | # |
| 83 | # This adds the directory of the main input file to $TEXINPUTS; it |
| 84 | # seems to be sufficiently general that it should be fine for HOWTO |
| 85 | # processing. |
| 86 | # |
| 87 | my $file = @_[0]; |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 88 | my($jobname, $dir, $ext) = fileparse($file, '\..*'); |
| 89 | $dir = L2hos->Make_directory_absolute($dir); |
Fred Drake | a4565b0 | 1998-05-15 17:14:17 +0000 | [diff] [blame] | 90 | $dir =~ s/$dd$//; |
| 91 | $TEXINPUTS = "$dir$envkey$mytexinputs"; |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 92 | print "\nAdding $dir to \$TEXINPUTS\n"; |
Fred Drake | 191439a | 1999-09-22 19:50:51 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Fred Drake | a4565b0 | 1998-05-15 17:14:17 +0000 | [diff] [blame] | 95 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 96 | $CUSTOM_BUTTONS = ''; |
Fred Drake | 062bc6e | 1998-08-13 22:03:46 +0000 | [diff] [blame] | 97 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 98 | sub make_nav_sectref { |
Fred Drake | beb27bf | 1999-02-16 17:22:32 +0000 | [diff] [blame] | 99 | my($label,$title) = @_; |
| 100 | if ($title) { |
Fred Drake | e15956b | 2000-04-03 04:51:13 +0000 | [diff] [blame] | 101 | return ("<b class='navlabel'>$label:</b> " |
| 102 | . "<span class='sectref'>$title</span>\n"); |
Fred Drake | beb27bf | 1999-02-16 17:22:32 +0000 | [diff] [blame] | 103 | } |
| 104 | return ''; |
| 105 | } |
| 106 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 107 | sub make_my_icon { |
| 108 | my($name, $text) = @_; |
| 109 | my $iconserver = ($ICONSERVER eq '.') ? '' : "$ICONSERVER/"; |
| 110 | return "<img src=\"$iconserver$name.$IMAGE_TYPE\" border=\"0\"" |
| 111 | . " height=\"32\"\n alt=\"$text\" width=\"32\">"; |
| 112 | } |
| 113 | |
Fred Drake | f730fc3 | 2000-08-31 07:19:07 +0000 | [diff] [blame^] | 114 | $BLANK_ICON = make_my_icon('blank', ''); |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 115 | |
| 116 | @my_icons = (); |
| 117 | $my_icons{'next_page_inactive'} = $BLANK_ICON; |
| 118 | $my_icons{'previous_page_inactive'} = $BLANK_ICON; |
| 119 | $my_icons{'up_page_inactive'} = $BLANK_ICON; |
Fred Drake | f730fc3 | 2000-08-31 07:19:07 +0000 | [diff] [blame^] | 120 | $x = make_my_icon('next', 'Next Page'); |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 121 | $my_icons{'next_page'} = $x; |
| 122 | $my_icons{'next'} = $x; |
Fred Drake | f730fc3 | 2000-08-31 07:19:07 +0000 | [diff] [blame^] | 123 | $x = make_my_icon('previous', 'Previous Page'); |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 124 | $my_icons{'previous_page'} = $x; |
| 125 | $my_icons{'previous'} = $x; |
Fred Drake | f730fc3 | 2000-08-31 07:19:07 +0000 | [diff] [blame^] | 126 | $my_icons{'up'} = make_my_icon('up', 'Up One Level'); |
| 127 | $my_icons{'contents'} = make_my_icon('contents', 'Contents'); |
| 128 | $my_icons{'index'} = make_my_icon('index', 'Index'); |
| 129 | $my_icons{'modules'} = make_my_icon('modules', 'Module Index'); |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 130 | |
| 131 | |
| 132 | sub use_my_icon { |
| 133 | my $s = @_[0]; |
| 134 | $s =~ s/\<tex2html_([a-z_]+)_visible_mark\>/$my_icons{$1}/; |
Fred Drake | a007544 | 1999-04-29 19:06:56 +0000 | [diff] [blame] | 135 | return $s; |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 138 | sub make_nav_panel { |
| 139 | my $s; |
Fred Drake | f730fc3 | 2000-08-31 07:19:07 +0000 | [diff] [blame^] | 140 | $NEXT = $NEXT_TITLE ? use_my_icon("$NEXT") : $BLANK_ICON; |
| 141 | $UP = $UP_TITLE ? use_my_icon("$UP") : $BLANK_ICON; |
| 142 | $PREVIOUS = $PREVIOUS_TITLE ? use_my_icon("$PREVIOUS") : $BLANK_ICON; |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 143 | $CONTENTS = use_my_icon("$CONTENTS"); |
| 144 | $INDEX = $INDEX ? use_my_icon("$INDEX") : $BLANK_ICON; |
| 145 | if (!$CUSTOM_BUTTONS) { |
| 146 | $CUSTOM_BUTTONS = $BLANK_ICON; |
| 147 | } |
| 148 | $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">' |
| 149 | . "\n<tr>" |
| 150 | # left-hand side |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 151 | . "\n<td>$PREVIOUS</td>" |
Fred Drake | 4640e13 | 2000-07-31 20:13:23 +0000 | [diff] [blame] | 152 | . "\n<td>$UP</td>" |
| 153 | . "\n<td>$NEXT</td>" |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 154 | # title box |
Fred Drake | f730fc3 | 2000-08-31 07:19:07 +0000 | [diff] [blame^] | 155 | . "\n<td align=\"center\" width=\"100%\">$t_title</td>" |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 156 | # right-hand side |
| 157 | . "\n<td>$CONTENTS</td>" |
| 158 | . "\n<td>$CUSTOM_BUTTONS</td>" # module index |
| 159 | . "\n<td>$INDEX</td>" |
| 160 | . "\n</tr></table>\n" |
| 161 | # textual navigation |
Fred Drake | 4640e13 | 2000-07-31 20:13:23 +0000 | [diff] [blame] | 162 | . make_nav_sectref("Previous", $PREVIOUS_TITLE) |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 163 | . make_nav_sectref("Up", $UP_TITLE) |
Fred Drake | 4640e13 | 2000-07-31 20:13:23 +0000 | [diff] [blame] | 164 | . make_nav_sectref("Next", $NEXT_TITLE) |
| 165 | ); |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 166 | # remove these; they are unnecessary and cause errors from validation |
| 167 | $s =~ s/ NAME="tex2html\d+"\n */ /g; |
| 168 | return $s; |
| 169 | } |
| 170 | |
| 171 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 172 | sub top_navigation_panel { |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 173 | return make_nav_panel() |
| 174 | . '<br><hr>'; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | sub bot_navigation_panel { |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 178 | return "<p><hr>" |
| 179 | . make_nav_panel(); |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | sub add_link { |
| 183 | # Returns a pair (iconic link, textual link) |
| 184 | my($icon, $current_file, @link) = @_; |
| 185 | my($dummy, $file, $title) = split($delim, |
Fred Drake | 28e7b4c | 1998-10-20 18:14:20 +0000 | [diff] [blame] | 186 | $section_info{join(' ',@link)}); |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 187 | $icon =~ s/\<tex2html_([_a-z]+)_visible_mark\>/$my_icons{$1}/; |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 188 | if ($title && ($file ne $current_file)) { |
| 189 | $title = purify($title); |
| 190 | $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES); |
| 191 | return (make_href($file, $icon), make_href($file, "$title")) |
| 192 | } |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 193 | elsif ($icon eq $my_icons{"up"} && $EXTERNAL_UP_LINK) { |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 194 | return (make_href($EXTERNAL_UP_LINK, $icon), |
| 195 | make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE")) |
| 196 | } |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 197 | elsif ($icon eq $my_icons{"previous"} |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 198 | && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) { |
| 199 | return (make_href($EXTERNAL_PREV_LINK, $icon), |
| 200 | make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE")) |
| 201 | } |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 202 | elsif ($icon eq $my_icons{"next"} |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 203 | && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) { |
| 204 | return (make_href($EXTERNAL_DOWN_LINK, $icon), |
| 205 | make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE")) |
| 206 | } |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 207 | return (&inactive_img($icon), ""); |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | sub add_special_link { |
| 211 | my($icon, $file, $current_file) = @_; |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 212 | $icon =~ s/\<tex2html_([_a-z]+)_visible_mark\>/$my_icons{$1}/; |
| 213 | return (($file && ($file ne $current_file)) |
| 214 | ? make_href($file, $icon) |
| 215 | : undef) |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 218 | # The img_tag() function seems only to be called with the parameter |
| 219 | # 'anchor_invisible_mark', which we want to turn into ''. Since |
| 220 | # replace_icon_marks() is the only interesting caller, and all it really |
| 221 | # does is call img_tag(), we can just define the hook alternative to be |
| 222 | # a no-op instead. |
| 223 | # |
| 224 | sub replace_icons_hook {} |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 225 | |
Fred Drake | 50cdd97 | 1999-02-19 23:04:59 +0000 | [diff] [blame] | 226 | sub do_cmd_arabic { |
| 227 | # get rid of that nasty <SPAN CLASS="arabic">...</SPAN> |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 228 | my($ctr, $val, $id, $text) = &read_counter_value(@_[0]); |
| 229 | return ($val ? farabic($val) : "0") . $text; |
Fred Drake | 50cdd97 | 1999-02-19 23:04:59 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 233 | sub gen_index_id { |
| 234 | # this is used to ensure common index key generation and a stable sort |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 235 | my($str,$extra) = @_; |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 236 | sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'}); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 239 | sub insert_index { |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 240 | my($mark,$datafile,$columns,$letters,$prefix) = @_; |
Fred Drake | 4d10b43 | 1998-08-07 20:51:58 +0000 | [diff] [blame] | 241 | my $prog = "$myrootdir/tools/buildindex.py"; |
| 242 | my $index; |
| 243 | if ($letters) { |
| 244 | $index = `$prog --columns $columns --letters $datafile`; |
| 245 | } |
| 246 | else { |
| 247 | $index = `$prog --columns $columns $datafile`; |
| 248 | } |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 249 | s/$mark/$prefix$index/; |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 252 | sub add_idx { |
Fred Drake | 9bbdce5 | 1999-01-19 16:30:10 +0000 | [diff] [blame] | 253 | print "\nBuilding HTML for the index ..."; |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 254 | close(IDXFILE); |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 255 | insert_index($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, ''); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 256 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 257 | |
| 258 | |
| 259 | $idx_module_mark = '<tex2html_idx_module_mark>'; |
| 260 | $idx_module_title = 'Module Index'; |
| 261 | |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 262 | sub add_module_idx { |
Fred Drake | 9bbdce5 | 1999-01-19 16:30:10 +0000 | [diff] [blame] | 263 | print "\nBuilding HTML for the module index ..."; |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 264 | my $key; |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 265 | my $first = 1; |
| 266 | my $prevplat = ''; |
| 267 | my $allthesame = 1; |
| 268 | my $prefix = ''; |
| 269 | foreach $key (keys %Modules) { |
| 270 | $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\1/; |
| 271 | my $plat = "$ModulePlatforms{$key}"; |
| 272 | $plat = '' |
Fred Drake | 62cc360 | 1999-03-04 18:41:17 +0000 | [diff] [blame] | 273 | if ($plat eq $IGNORE_PLATFORM_ANNOTATION); |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 274 | if (!$first) { |
| 275 | $allthesame = 0 |
| 276 | if ($prevplat ne $plat); |
| 277 | } |
| 278 | else { $first = 0; } |
| 279 | $prevplat = $plat; |
| 280 | } |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 281 | open(MODIDXFILE, '>modindex.dat') || die "\n$!\n"; |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 282 | foreach $key (keys %Modules) { |
| 283 | # dump the line in the data file; just use a dummy seqno field |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 284 | my $nkey = $1; |
| 285 | my $moditem = "$Modules{$key}"; |
| 286 | my $plat = ''; |
| 287 | $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\1/; |
| 288 | if ($ModulePlatforms{$key} && !$allthesame) { |
Fred Drake | e15956b | 2000-04-03 04:51:13 +0000 | [diff] [blame] | 289 | $plat = (" <em>(<span class='platform'>$ModulePlatforms{$key}" |
Fred Drake | bb584d3 | 1999-03-25 22:18:30 +0000 | [diff] [blame] | 290 | . '</span>)</em>'); |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 291 | } |
Fred Drake | e15956b | 2000-04-03 04:51:13 +0000 | [diff] [blame] | 292 | print MODIDXFILE $moditem . $IDXFILE_FIELD_SEP |
| 293 | . "<tt class='module'>$key</tt>$plat###\n"; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 294 | } |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 295 | close(MODIDXFILE); |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 296 | if (!$allthesame) { |
| 297 | $prefix = <<PLAT_DISCUSS; |
| 298 | |
| 299 | |
| 300 | <p> Some module names are followed by an annotation indicating what |
| 301 | platform they are available on.</p> |
| 302 | |
| 303 | PLAT_DISCUSS |
| 304 | } |
| 305 | insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0, |
| 306 | $prefix); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 309 | # replace both indexes as needed: |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 310 | sub add_idx_hook { |
Fred Drake | b3a3ed8 | 1998-07-24 22:17:34 +0000 | [diff] [blame] | 311 | add_idx() if (/$idx_mark/); |
| 312 | add_module_idx() if (/$idx_module_mark/); |
Fred Drake | 2383f6d | 1999-03-02 16:00:37 +0000 | [diff] [blame] | 313 | process_python_state(); |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 314 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 315 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 316 | |
Fred Drake | 191439a | 1999-09-22 19:50:51 +0000 | [diff] [blame] | 317 | # In addition to the standard stuff, add label to allow named node files and |
| 318 | # support suppression of the page complete (for HTML Help use). |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 319 | sub do_cmd_tableofcontents { |
| 320 | local($_) = @_; |
| 321 | $TITLE = $toc_title; |
| 322 | $tocfile = $CURRENT_FILE; |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 323 | my($closures,$reopens) = preserve_open_tags(); |
| 324 | anchor_label('contents', $CURRENT_FILE, $_); # this is added |
Fred Drake | beb27bf | 1999-02-16 17:22:32 +0000 | [diff] [blame] | 325 | join('', "<BR>\n\\tableofchildlinks[off]", $closures |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 326 | , make_section_heading($toc_title, 'H2'), $toc_mark |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 327 | , $reopens, $_); |
| 328 | } |
| 329 | # In addition to the standard stuff, add label to allow named node files. |
| 330 | sub do_cmd_listoffigures { |
| 331 | local($_) = @_; |
| 332 | $TITLE = $lof_title; |
| 333 | $loffile = $CURRENT_FILE; |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 334 | my($closures,$reopens) = preserve_open_tags(); |
| 335 | anchor_label('lof', $CURRENT_FILE, $_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 336 | join('', "<BR>\n", $closures |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 337 | , make_section_heading($lof_title, 'H2'), $lof_mark |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 338 | , $reopens, $_); |
| 339 | } |
| 340 | # In addition to the standard stuff, add label to allow named node files. |
| 341 | sub do_cmd_listoftables { |
| 342 | local($_) = @_; |
| 343 | $TITLE = $lot_title; |
| 344 | $lotfile = $CURRENT_FILE; |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 345 | my($closures,$reopens) = preserve_open_tags(); |
| 346 | anchor_label('lot', $CURRENT_FILE, $_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 347 | join('', "<BR>\n", $closures |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 348 | , make_section_heading($lot_title, 'H2'), $lot_mark |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 349 | , $reopens, $_); |
| 350 | } |
| 351 | # In addition to the standard stuff, add label to allow named node files. |
| 352 | sub do_cmd_textohtmlinfopage { |
| 353 | local($_) = @_; |
| 354 | if ($INFO) { # |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 355 | anchor_label("about",$CURRENT_FILE,$_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 356 | } # |
Fred Drake | 15796f7 | 1998-11-30 19:25:47 +0000 | [diff] [blame] | 357 | my $the_version = ''; # and the rest is |
| 358 | if ($t_date) { # mostly ours |
| 359 | $the_version = ",\n$t_date"; |
| 360 | if ($PYTHON_VERSION) { |
| 361 | $the_version .= ", Release $PYTHON_VERSION"; |
| 362 | } |
| 363 | } |
| 364 | $_ = (($INFO == 1) |
Fred Drake | b35f2b7 | 1999-09-23 16:53:09 +0000 | [diff] [blame] | 365 | ? join('', |
| 366 | $close_all, |
| 367 | "<strong>$t_title</strong>$the_version\n", |
| 368 | `cat $ABOUT_FILE`, |
| 369 | $open_all, $_) |
| 370 | : join('', $close_all, $INFO,"\n", $open_all, $_)); |
Fred Drake | 15796f7 | 1998-11-30 19:25:47 +0000 | [diff] [blame] | 371 | $_; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | # $idx_mark will be replaced with the real index at the end |
| 375 | sub do_cmd_textohtmlindex { |
| 376 | local($_) = @_; |
| 377 | $TITLE = $idx_title; |
| 378 | $idxfile = $CURRENT_FILE; |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 379 | if (%index_labels) { make_index_labels(); } |
| 380 | if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 381 | else { $preindex = ''; } |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 382 | my $heading = make_section_heading($idx_title, 'h2') . $idx_mark; |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 383 | my($pre,$post) = minimize_open_tags($heading); |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 384 | anchor_label('genindex',$CURRENT_FILE,$_); # this is added |
| 385 | '<br>\n' . $pre . $_; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | # $idx_module_mark will be replaced with the real index at the end |
| 389 | sub do_cmd_textohtmlmoduleindex { |
| 390 | local($_) = @_; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 391 | $TITLE = $idx_module_title; |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 392 | anchor_label("modindex",$CURRENT_FILE,$_); |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 393 | '<p>' . make_section_heading($idx_module_title, "h2") |
| 394 | . $idx_module_mark . $_; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | # The bibliography and the index should be treated as separate sections |
| 398 | # in their own HTML files. The \bibliography{} command acts as a sectioning command |
| 399 | # that has the desired effect. But when the bibliography is constructed |
| 400 | # manually using the thebibliography environment, or when using the |
| 401 | # theindex environment it is not possible to use the normal sectioning |
| 402 | # mechanism. This subroutine inserts a \bibliography{} or a dummy |
| 403 | # \textohtmlindex command just before the appropriate environments |
| 404 | # to force sectioning. |
| 405 | |
| 406 | # XXX This *assumes* that if there are two {theindex} environments, the |
| 407 | # first is the module index and the second is the standard index. This |
| 408 | # is sufficient for the current Python documentation, but that's about |
| 409 | # it. |
| 410 | |
| 411 | sub add_bbl_and_idx_dummy_commands { |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 412 | my $id = $global{'max_id'}; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 413 | |
| 414 | s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg; |
Fred Drake | 191439a | 1999-09-22 19:50:51 +0000 | [diff] [blame] | 415 | s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo; |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 416 | my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/); |
| 417 | if (scalar(@parts) == 3) { |
| 418 | # Be careful to re-write the string in place, since $_ is *not* |
| 419 | # returned explicity; *** nasty side-effect dependency! *** |
| 420 | print "\nadd_bbl_and_idx_dummy_commands ==> adding module index"; |
| 421 | my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)" |
| 422 | . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)"; |
| 423 | s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o; |
| 424 | # Add a button to the navigation areas: |
| 425 | $CUSTOM_BUTTONS .= $my_icons{'modules'}; |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 426 | } |
| 427 | else { |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 428 | $CUSTOM_BUTTONS .= $BLANK_ICON; |
| 429 | $global{'max_id'} = $id; # not sure why.... |
| 430 | s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o; |
Fred Drake | 191439a | 1999-09-22 19:50:51 +0000 | [diff] [blame] | 431 | s/[\\]printindex/\\textohtmlindex /o; |
| 432 | } |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 433 | #---------------------------------------------------------------------- |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 434 | lib_add_bbl_and_idx_dummy_commands() |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 435 | if defined(&lib_add_bbl_and_idx_dummy_commands); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | # The bibliographic references, the appendices, the lists of figures and tables |
| 439 | # etc. must appear in the contents table at the same level as the outermost |
| 440 | # sectioning command. This subroutine finds what is the outermost level and |
| 441 | # sets the above to the same level; |
| 442 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 443 | sub set_depth_levels { |
| 444 | # Sets $outermost_level |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 445 | my $level; |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 446 | #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH |
| 447 | foreach $level ("part", "chapter", "section", "subsection", |
| 448 | "subsubsection", "paragraph") { |
| 449 | last if (($outermost_level) = /\\($level)$delimiter_rx/); |
| 450 | } |
| 451 | $level = ($outermost_level ? $section_commands{$outermost_level} : |
| 452 | do {$outermost_level = 'section'; 3;}); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 453 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 454 | #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given |
| 455 | if ($REL_DEPTH && $MAX_SPLIT_DEPTH) { |
| 456 | $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH; |
| 457 | } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 }; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 458 | |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 459 | %unnumbered_section_commands = ('tableofcontents' => $level, |
| 460 | 'listoffigures' => $level, |
| 461 | 'listoftables' => $level, |
| 462 | 'bibliography' => $level, |
| 463 | 'textohtmlindex' => $level, |
| 464 | 'textohtmlmoduleindex' => $level); |
| 465 | $section_headings{'textohtmlmoduleindex'} = 'h1'; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 466 | |
Fred Drake | 64bdc24 | 1998-04-17 02:14:12 +0000 | [diff] [blame] | 467 | %section_commands = (%unnumbered_section_commands, |
| 468 | %section_commands); |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 469 | |
| 470 | make_sections_rx(); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 471 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 472 | |
| 473 | |
Fred Drake | 1072e46 | 1998-04-12 02:16:34 +0000 | [diff] [blame] | 474 | # This changes the markup used for {verbatim} environments, and is the |
Fred Drake | 95474f9 | 1999-02-09 18:45:50 +0000 | [diff] [blame] | 475 | # best way I've found that ensures the <dl> goes on the outside of the |
Fred Drake | 1072e46 | 1998-04-12 02:16:34 +0000 | [diff] [blame] | 476 | # <pre>...</pre>. |
| 477 | # |
| 478 | # Note that this *must* be done in the init file, not the python.perl |
| 479 | # style support file. The %declarations must be set before initialize() |
Fred Drake | e15956b | 2000-04-03 04:51:13 +0000 | [diff] [blame] | 480 | # is called in the main LaTeX2HTML script (which happens before style files |
| 481 | # are loaded). |
Fred Drake | 1072e46 | 1998-04-12 02:16:34 +0000 | [diff] [blame] | 482 | # |
Fred Drake | e15956b | 2000-04-03 04:51:13 +0000 | [diff] [blame] | 483 | %declarations = ('preform' => '<dl><dd><pre class="verbatim"></pre></dl>', |
Fred Drake | 1072e46 | 1998-04-12 02:16:34 +0000 | [diff] [blame] | 484 | %declarations); |
| 485 | |
Fred Drake | e15956b | 2000-04-03 04:51:13 +0000 | [diff] [blame] | 486 | |
| 487 | # This is added to get rid of the long comment that follows the doctype |
| 488 | # declaration; MSIE5 on NT4 SP4 barfs on it and drops the content of the |
| 489 | # page. |
| 490 | sub make_head_and_body { |
Fred Drake | 85d14c9 | 2000-07-31 17:53:45 +0000 | [diff] [blame] | 491 | my($title, $body) = @_; |
| 492 | my $DTDcomment = ''; |
| 493 | my($version, $isolanguage) = ($HTML_VERSION, 'EN'); |
| 494 | my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US' |
| 495 | , 'original', 'EN' , 'german' , 'DE' |
| 496 | , 'austrian', 'DE.AT', 'french' , 'FR' |
| 497 | , 'spanish', 'ES'); |
Fred Drake | e15956b | 2000-04-03 04:51:13 +0000 | [diff] [blame] | 498 | $isolanguage = $isolanguages{$default_language}; |
| 499 | $isolanguage = 'EN' unless $isolanguage; |
| 500 | $title = &purify($title,1); |
| 501 | eval("\$title = ". $default_title ) unless ($title); |
| 502 | |
| 503 | # allow user-modification of the <TITLE> tag; thanks Dan Young |
| 504 | if (defined &custom_TITLE_hook) { |
| 505 | $title = &custom_TITLE_hook($title, $toc_sec_title); |
| 506 | } |
| 507 | |
| 508 | if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included |
| 509 | $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n"; |
| 510 | } else { |
| 511 | $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//" |
| 512 | . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n"; |
| 513 | } |
| 514 | |
| 515 | $STYLESHEET = $FILE.".css" unless $STYLESHEET; |
| 516 | if (!$charset && $CHARSET) { $charset = $CHARSET; $charset =~ s/_/\-/go; } |
| 517 | |
| 518 | join('', ($DOCTYPE ? $DTDcomment : '' ) |
| 519 | ,"<html>\n<head>\n<title>", $title, "</title>\n" |
| 520 | , &meta_information($title) |
| 521 | , ($CHARSET && $HTML_VERSION ge "2.1" ? |
| 522 | "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">\n" |
| 523 | : "" ) |
| 524 | , ($BASE ? "<base href=\"$BASE\">\n" : "" ) |
| 525 | , "<link rel=\"STYLESHEET\" href=\"$STYLESHEET\">" |
| 526 | , $more_links_mark |
| 527 | , "\n</head>\n<body $body>\n"); |
| 528 | } |
| 529 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 530 | 1; # This must be the last line |