]> git.donarmstrong.com Git - lilypond.git/blob - lilypond-texi2html.init
texi2html: We don't need to rewrite the node ids!
[lilypond.git] / lilypond-texi2html.init
1 #!/usr/bin/env perl
2
3 ### texi2html customization script for Lilypond
4 ### Author: Reinhold Kainhofer <reinhold@kainhofer.com>, 2008.
5 ###         Some code parts copied from texi2html and adapted.
6 ### License: GPLv2+
7 ###
8 ###
9 ### Features implemented here:
10 ### -) For split manuals, the main page is index.html.
11 ### -) All @unnumbered* sections are placed into the same file
12 ###    (implemented by split_at_numbered_sections)
13 ### -) Use our custom CSS file, with IE-specific fixes in another CSS file,
14 ###    impelmented by lilypond_css_lines
15 ### -) TOC (folded, with the current page highlighted) in an overflown <div>
16 ###    is added to every page; implemented by:
17 ###           lilypond_print_element_header -- building of the TOC
18 ###           lilypond_toc_body -- generation of customized TOC output
19 ###           lilypond_print_page_head -- start <div id="main">
20 ###           print_lilypond_page_foot -- closing id=main, output of footer & TOC
21 ### -) External refs are formatted only as "Text of the node" (not as >>see
22 ###    "NODE" section "SECTION" in "BOOK"<< like with default texi2html). Also,
23 ###    the leading "(book-name)" is removed.
24 ###    Implemented by overriding lilypond_external_ref
25 ### -) Navigation bars on top/bottom of the page and between sections are not
26 ###    left-aligned, but use a combination of left/center/right aligned table
27 ###    cells; For this, I heavily extend the texi2html code to allow for
28 ###    differently aligned cells and for multi-line tables);
29 ###    Implemented in lilypond_print_navigation
30 ### -) Different formatting than the default: example uses the same formatting
31 ###    as quote.
32 ### -) Allow translated section titles: All section titles can be translated,
33 ###    the original (English) title is associated with @translationof. This is
34 ###    needed, because the file name / anchor is generated from the original
35 ###    English title, since otherwise language-autoselection would break with
36 ###    posted links.
37 ###    Since it is then no longer possible to obtain the file name from the
38 ###    section title, I keep a sectionname<=>filename/anchor around. This way,
39 ###    xrefs from other manuals can simply load that map and retrieve the
40 ###    correct file name for the link. Implemented in:
41 ###           lilypond_unknown (handling of @translationof, in case
42 ###                             extract_texi_filenames.py messes up...)
43 ###           split_at_numbered_sections (correct file name: use the map)
44 ###           lilypond_init_map (read in the externally created map from disk)
45 ###           lilypond_external_href (load the map for xrefs, use the correct
46 ###                                   link target)
47 ### -) The HTML anchors for all sections are derived from the node name /
48 ###    section title (pre-generated in the .xref-map file). Implemented by:
49 ###           lilypond_node_file_name (adjust node anchors)
50 ###           split_at_numbered_sections (adjust section anchors)
51 ###
52 ###
53 ### Useful helper functions:
54 ### -) texinfo_file_name($node_name): returns a texinfo-compatible file name
55 ###    for the given string $node_name (whitespace trimmed/replaced by -,
56 ###    non-standard chars replaced by _xxxx (ascii char code) and forced to
57 ###    start with a letter by prepending t_g if necessary)
58
59
60 package Texi2HTML::Config;
61
62
63
64
65
66 #############################################################################
67 ###  SETTINGS FOR TEXI2HTML
68 #############################################################################
69
70 @Texi2HTML::Config::CSS_REFS      = ("lilypond.css");
71 $Texi2HTML::Config::USE_ACCESSKEY = 1;
72 $Texi2HTML::Config::USE_LINKS     = 1;
73 $Texi2HTML::Config::USE_REL_REV   = 1;
74 $Texi2HTML::Config::element_file_name    = \&split_at_numbered_sections;
75 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
76 $Texi2HTML::Config::print_page_foot      = \&print_lilypond_page_foot;
77 $Texi2HTML::Config::print_navigation     = \&lilypond_print_navigation;
78 $Texi2HTML::Config::external_ref         = \&lilypond_external_ref;
79 $Texi2HTML::Config::external_href        = \&lilypond_external_href;
80 $Texi2HTML::Config::toc_body             = \&lilypond_toc_body;
81 $Texi2HTML::Config::css_lines            = \&lilypond_css_lines;
82 $Texi2HTML::Config::unknown              = \&lilypond_unknown;
83 $Texi2HTML::Config::print_page_head      = \&lilypond_print_page_head;
84
85 # Examples should be formatted similar to quotes:
86 $Texi2HTML::Config::complex_format_map->{'example'} = {
87   'begin' => q{"<blockquote><pre class=\"example\">"},
88   'end' => q{"</pre></blockquote>\n"},
89  };
90
91
92 my @section_to_filename;
93
94
95
96
97 #############################################################################
98 ###  DEBUGGING
99 #############################################################################
100
101 use Data::Dumper;
102 $Data::Dumper::Maxdepth = 2;
103
104 sub print_element_info($)
105 {
106   my $element = shift;
107   print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
108   print "Element: $element\n";
109   print Dumper($element);
110 }
111
112
113
114
115
116 #############################################################################
117 ###  HELPER FUNCTIONS
118 #############################################################################
119
120 # Convert a given node name to its proper file name (normalization as explained
121 # in the texinfo manual:
122 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
123 sub texinfo_file_name($)
124 {
125   my $text = shift;
126   my $result = '';
127   # File name normalization by texinfo:
128   # 1/2: letters and numbers are left unchanged
129   # 3/4: multiple, leading and trailing whitespace is removed
130   $text = main::normalise_space($text);
131   # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
132   #      chars are replaced by _xxxx (xxxx=ascii character code)
133   while ($text ne '') {
134     if ($text =~ s/^([A-Za-z0-9]+)//o) { # number or letter stay unchanged
135       $result .= $1;
136     } elsif ($text =~ s/^ //o) { # space -> '-'
137       $result .= '-';
138     } elsif ($text =~ s/^(.)//o) { # Otherwise use _xxxx (ascii char code)
139       my $ccode = ord($1);
140       if ( $ccode <= 0xFFFF ) {
141         $result .= sprintf("_%04x", $ccode);
142       } else {
143         $result .= sprintf("__%06x", $ccode);
144       }
145     }
146   }
147   # 7: if name does not begin with a letter, prepend 't_g' (so it starts with a letter)
148   if ($result !~ /^[a-zA-Z]/) {
149     $result = 't_g' . $result;
150   }
151   # DONE
152   return $result
153 }
154
155
156 # Load a file containing a nodename<=>filename map (tab-sepatared, i.e.
157 # NODENAME\tFILENAME\tANCHOR
158 # Returns a ref to a hash "Node title" => ["FilenameWithoutExt", "Anchor"]
159 sub load_map_file ($)
160 {
161     my $mapfile = shift;
162     my $node_map = ();
163
164     if (open(XREFFILE, $mapfile)) {
165         my $line;
166         while ( $line = <XREFFILE> ) {
167             # parse the tab-separated entries and insert them into the map:
168             chomp($line);
169             my @entries = split(/\t/, $line);
170             if (scalar (@entries) == 3) {
171               $node_map->{$entries[0]} = [$entries[1], $entries[2]];
172             } else {
173               print STDERR "Invalid entry in the node file $mapfile: $line\n";
174             }
175         }
176         close (XREFFILE);
177     } else {
178         print STDERR "WARNING: Unable to load the map file $mapfile\n";
179     }
180     return $node_map;
181 }
182
183
184 # Split the given path into dir and basename (with .texi removed). Used mainly
185 # to get the path/basename of the original texi input file
186 sub split_texi_filename ($)
187 {
188   my $docu = shift;
189   my $docu_dir, $docu_name;
190   if ($docu =~ /(.*\/)/) {
191     chop($docu_dir = $1);
192     $docu_name = $docu;
193     $docu_name =~ s/.*\///;
194   } else {
195      $docu_dir = '.';
196      $docu_name = $docu;
197   }
198   $docu_name =~ s/\.te?x(i|info)?$//;
199   return ($docu_dir, $docu_name);
200 }
201
202
203
204
205
206 #############################################################################
207 ###  CSS HANDLING
208 #############################################################################
209
210 # Include our standard CSS file, not hard-coded CSS code directly in the HTML!
211 # For IE, conditionally include the lilypond-ie-fixes.css style sheet
212 sub lilypond_css_lines ($$)
213 {
214     my $import_lines = shift;
215     my $rule_lines = shift;
216     return if (defined($CSS_LINES));
217     if (@$rule_lines or @$import_lines)
218     {
219         $CSS_LINES = "<style type=\"text/css\">\n<!--\n";
220         $CSS_LINES .= join('',@$import_lines) . "\n" if (@$import_lines);
221         $CSS_LINES .= join('',@$rule_lines) . "\n" if (@$rule_lines);
222         $CSS_LINES .= "-->\n</style>\n";
223     }
224     foreach my $ref (@CSS_REFS)
225     {
226         $CSS_LINES .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$ref\">\n";
227     }
228     $CSS_LINES .= "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
229 }
230
231
232
233
234
235 #############################################################################
236 ###  SPLITTING BASED ON NUMBERED SECTIONS
237 #############################################################################
238
239 my $lastfilename;
240 my $docnr = 0;
241 my $node_to_filename_map = ();
242
243
244 # This function makes sure that files are only generated for numbered sections,
245 # but not for unnumbered ones. It is called after texi2html has done its own
246 # splitting and simply returns the filename for the node given as first argument
247 # Nodes with the same filename will be printed out to the same filename, so
248 # this really all we need. Also, make sure that the file names for sections
249 # are derived from the section title. We also might want to name the anchors
250 # according to node titles, which works by simply overriding the id element of
251 # the $element hash.
252 # If an external nodename<=>filename/anchor map file is found (loaded in
253 # lilypond_init_out, use the externally created values, otherwise use the
254 # same logic here.
255 sub split_at_numbered_sections($$$)
256 {
257   my $element = shift;
258   my $type = shift;
259   my $docu_name = shift;
260   my $docu_ext = $Texi2HTML::Config::EXTENSION;
261
262   my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
263   # the snippets page does not use nodes for the snippets, so in this case
264   # we'll have to use the section name!
265   if ($node_name eq '') {
266     $node_name = main::remove_texi($element->{'texi'});
267   }
268
269   # If we have an entry in the section<=>filename map, use that one, otherwise
270   # generate the filename/anchor here. In the latter case, external manuals
271   # will not be able to retrieve the file name for xrefs!!! Still, I already
272   # had that code, so I'll leave it in in case something goes wrong with the
273   # extract_texi_filenames.py script in the lilypond build process!
274   if (exists ($node_to_filename_map->{$node_name})) {
275     (my $filename, my $anchor) = @{$node_to_filename_map->{$node_name}};
276     $filename .= ".$docu_ext" if (defined($docu_ext));
277
278     $element->{'id'} = $anchor;
279 #     $element->{'node_ref'}->{'id'} = $anchor;
280     # unnumbered sections (except those at top-level!) always go to the same
281     # file as the previous numbered section
282     if (not ($element->{number}) and not ($lastfilename eq '') and ($element->{level} > 1)) {
283       $filename = $lastfilename;
284     }
285     if (($filename eq $lastfilename)) {
286       $$element{doc_nr} = $docnr;
287     } else {
288       $docnr += 1;
289       $$element{doc_nr} = $docnr;
290       $lastfilename = $filename;
291     }
292     return $filename;
293
294   } elsif ($type eq "top" or $type eq "toc" or $type eq "doc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
295     # TOC, footer, about etc. are called with undefined $element and $type == "toc"|"stoc"|"foot"|"about"
296     return;
297   } else {
298     print STDERR "WARNING: Node '$node_name' was NOT found in the map\n"
299         unless ($node_name eq '') or ($element->{'tag'} eq 'unnumberedsec')
300                or ($node_name =~ /NOT REALLY USED/);
301
302     # derive the name of the anchor (i.e. the part after # in the links!),
303     # don't use texi2html's SECx.x default!
304     my $sec_name = main::remove_texi($element->{'texi'});
305     # if we have a node, use its name:
306     if ($element->{'node_ref'}->{'texi'} ne '') {
307       $sec_name = main::remove_texi($element->{'node_ref'}->{'texi'});
308     }
309     my $anchor = $sec_name;
310     if ($element->{translationof}) {
311       $anchor = main::remove_texi($$element{translationof});
312     }
313     # normalize to the same file name as texinfo
314     $anchor = texinfo_file_name($anchor);
315     $element->{'id'} = $anchor;
316     $element->{'node_ref'}->{'id'} = $anchor;
317     # Numbered sections will get a filename Node_title, unnumbered sections will use
318     # the file name of the previous numbered section:
319     if (($element->{number}) or ($lastfilename eq '') or ($element->{level} == 1)) {
320       my $filename = $anchor;
321       $filename .= ".$docu_ext" if (defined($docu_ext));
322       $docnr += 1;
323       $$element{doc_nr} = $docnr;
324       $lastfilename = $filename;
325       return $filename;
326     } else {
327       $$element{doc_nr} = $docnr;
328       return $lastfilename;
329     }
330   }
331
332   return;
333 }
334
335
336 ## Load the map file for the corrently processed texi file. We do this
337 #  using a command init handler, since texi2html does not have any
338 #  other hooks that are called after THISDOC is filled but before phase 2
339 #  of the texi2html conversion.
340 sub lilypond_init_map ()
341 {
342     my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
343     my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
344         || main::locate_include_file ("${docu_name}.xref-map");
345     $node_to_filename_map = load_map_file ($map_filename);
346 }
347 push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map;
348
349
350
351 #############################################################################
352 ###  CLEANER LINK TITLE FOR EXTERNAL REFS
353 #############################################################################
354
355 # The default formatting of external refs returns e.g.
356 # "(lilypond-internals)Timing_translator", so we remove all (...) from the
357 # file_and_node argument. Also, we want only a very simple format, so we don't
358 # even call the default handler!
359 sub lilypond_external_ref($$$$$$)
360 {
361   my $type = shift;
362   my $section = shift;
363   my $book = shift;
364   my $file_node = shift;
365   my $href = shift;
366   my $cross_ref = shift;
367
368   my $displaytext = '';
369
370   # 1) if we have a cross ref name, that's the text to be displayed:
371   # 2) For the top node, use the (printable) name of the manual, unless we
372   #    have an explicit cross ref name
373   # 3) In all other cases use the section name
374   if ($cross_ref ne '') {
375     $displaytext = $cross_ref;
376   } elsif (($section eq '') or ($section eq 'Top')) {
377     $displaytext = $book;
378   } else {
379     $displaytext = $section;
380   }
381
382   $displaytext = &$anchor('', $href, $displaytext) if ($displaytext ne '');
383   return &$I('%{node_file_href}', { 'node_file_href' => $displaytext });
384
385 #  Default: format as "see <a ..>NODE</a> section 'SECTION' in BOOK". We don't want this!
386 #   return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref);
387 }
388
389
390
391
392
393 #############################################################################
394 ###  HANDLING TRANSLATED SECTIONS: handle @translationof, secname<->filename
395 ###                  map stored on disk, xrefs in other manuals load that map
396 #############################################################################
397
398
399 # Try to make use of @translationof to generate files according to the original
400 # English section title...
401 sub lilypond_unknown($$$$$)
402 {
403     my $macro = shift;
404     my $line = shift;
405     my $pass = shift;
406     my $stack = shift;
407     my $state = shift;
408
409     # the @translationof macro provides the original English section title,
410     # which should be used for file/anchor naming, while the title will be
411     # translated to each language
412     # It is already used by extract_texi_filenames.py, so this should not be
413     # necessary here at all. Still, I'll leave the code in just in case the
414     # python script messed up ;-)
415     if ($pass == 1 and $macro eq "translationof") {
416       if (ref($state->{'element'}) eq 'HASH') {
417         $state->{'element'}->{'translationof'} = main::normalise_space($line);
418       }
419       return ('', true, undef, undef);
420     } else {
421       return t2h_default_unknown($macro, $line, $pass, $stack, $state);
422     }
423 }
424
425
426
427
428 my %translated_books = ();
429 # Construct a href to an external source of information.
430 # node is the node with texinfo @-commands
431 # node_id is the node transliterated and transformed as explained in the
432 #         texinfo manual
433 # node_xhtml_id is the node transformed such that it is unique and can
434 #     be used to make an html cross ref as explained in the texinfo manual
435 # file is the file in '(file)node'
436 sub lilypond_external_href($$$)
437 {
438   my $node = shift;
439   my $node_id = shift;
440   my $node_hxmlt_id = shift;
441   my $file = shift;
442   my $original_func = \&t2h_default_external_href;
443
444   # 1) Keep a hash of book->section_map
445   # 2) if not file in keys hash => try to load the map (assign empty map if
446   #    non-existent => will load only once!)
447   # 3) if node in the section=>(file, anchor) map, replace node_id and
448   #    node_xhtml_id by the map's values
449   # 4) call the t2h_default_external_href with these values (or the old ones if not found)
450
451   if (($node_id ne '') and defined($file) and ($node_id ne 'Top')) {
452     my $map_name = $file;
453     $map_name =~ s/-big-page//;
454
455     # Load the map if we haven't done so already
456     if (!exists($translated_books{$map_name})) {
457       my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
458       my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
459           || main::locate_include_file ("${map_name}.xref-map");
460       $translated_books{$map_name} = load_map_file ($map_filename);
461     }
462
463     # look up translation. use these values instead of the old filename/anchor
464     my $section_name_map = $translated_books{$map_name};
465     my $node_text = main::remove_texi($node);
466     if (defined($section_name_map->{$node_text})) {
467       ($node_id, $node_hxmlt_id) = @{$section_name_map->{$node_text}};
468     } else {
469       print STDERR "WARNING: Unable to find node '$node_text' in book $map_name.\n";
470     }
471   }
472
473   if (defined $file) {
474     return &$original_func($node, $node_id, $node_hxmlt_id, $file);
475   } else {
476     return &$original_func($node, $node_id, $node_hxmlt_id);
477   }
478 }
479
480
481
482
483
484 #############################################################################
485 ###  CUSTOM TOC FOR EACH PAGE (in a frame on the left)
486 #############################################################################
487
488 my $page_toc_depth = 2;
489 my @default_toc = [];
490
491 # recursively generate the TOC entries for the element and its children (which
492 # are only shown up to maxlevel. All ancestors of the current element are also
493 # shown with their immediate children, irrespective of their level.
494 # Unnumbered entries are only printed out if they are at top-level or their
495 # parent element is an ancestor of the currently viewed node.
496 sub generate_ly_toc_entries($$$$)
497 {
498   my $element = shift;
499   my $element_path = shift;
500   my $maxlevel = shift;
501   my $always_show_unnumbered_children = shift;
502   # Skip undefined sections, plus all sections generated by index splitting
503   return() if (not defined($element) or exists($element->{'index_page'}));
504   my @result = ();
505   my $level = $element->{'toc_level'};
506   my $is_parent_of_current = $element->{'id'} && $element_path->{$element->{'id'}};
507   my $print_children = ( ($level < $maxlevel) or $is_parent_of_current );
508   my $ind = '  ' x $level;
509   my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : "";
510
511   my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'id'}",$element->{'text'});
512
513   my $children = $element->{'section_childs'};
514   # Don't add unnumbered entries, unless they are at top-level or a parent of the current!
515   if (not ($element->{'number'} or $always_show_unnumbered_children)) {
516     return @result;
517   }
518   if ( $print_children and defined($children) and (ref($children) eq "ARRAY") ) {
519     push (@result, $entry);
520     my @child_result = ();
521     foreach (@$children) {
522       push (@child_result, generate_ly_toc_entries($_, $element_path, $maxlevel, $is_parent_of_current));
523     }
524     # if no child nodes were generated, e.g. for the index, where expanded pages
525     # are ignored, don't generate a list at all...
526     if (@child_result) {
527       push (@result, "\n$ind<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
528       push (@result, @child_result);
529       push (@result, "$ind</ul></li>\n");
530     }
531   } else {
532     push (@result, $entry . "</li>\n");
533   }
534   return @result;
535 }
536
537
538 # Print a customized TOC, containing only the first two levels plus the whole
539 # path to the current page
540 sub lilypond_generate_page_toc_body($)
541 {
542     my $element = shift;
543     my $current_element = $element;
544     my %parentelements;
545     $parentelements{$element->{'id'}} = 1;
546     # Find the path to the current element
547     while ( defined($current_element->{'sectionup'}) and
548            ($current_element->{'sectionup'} ne $current_element) )
549     {
550       $parentelements{$current_element->{'sectionup'}->{'id'}} = 1
551               if ($current_element->{'sectionup'}->{'id'} ne '');
552       $current_element = $current_element->{'sectionup'};
553     }
554     return () if not defined($current_element);
555     # Create the toc entries recursively
556     my @toc_entries = ("<div class=\"contents\">\n", "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
557     my $children = $current_element->{'section_childs'};
558     foreach ( @$children ) {
559       push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth, False));
560     }
561     push (@toc_entries, "</ul>\n");
562     push (@toc_entries, "</div>\n");
563     return @toc_entries;
564 }
565
566 sub lilypond_print_toc_div ($$)
567 {
568   my $fh = shift;
569   my $tocref = shift;
570   my @lines = @$tocref;
571   # use default TOC if no custom lines have been generated
572   @lines = @default_toc if (not @lines);
573   if (@lines) {
574     print $fh "\n\n<div id=\"tocframe\">\n";
575     print $fh '<h4> ' . $Texi2HTML::NAME{'Contents'}  . "</h4>\n";
576     foreach my $line (@lines) {
577       print $fh $line;
578     }
579     print $fh "</div>\n\n";
580   }
581 }
582
583 # Create the custom TOC for this page (partially folded, current page is
584 # highlighted) and store it in a global variable. The TOC is written out after
585 # the html contents (but positioned correctly using CSS), so that browsers with
586 # css turned off still show the contents first.
587 our @this_page_toc = ();
588 sub lilypond_print_element_header
589 {
590   my $fh = shift;
591   my $first_in_page = shift;
592   my $previous_is_top = shift;
593   if ($first_in_page and not @this_page_toc) {
594     if (defined($Texi2HTML::THIS_ELEMENT)) {
595       # Create the TOC for this page
596       @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
597     }
598   }
599   return T2H_DEFAULT_print_element_header( $fh, $first_in_page, $previous_is_top);
600 }
601
602 # Generate the HTML output for the TOC
603 sub lilypond_toc_body($)
604 {
605     my $elements_list = shift;
606     # Generate a default TOC for pages without THIS_ELEMENT
607     @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
608     return T2H_GPL_toc_body($elements_list);
609 }
610
611 # Print out the TOC in a <div> at the beginning of the page
612 sub lilypond_print_page_head($)
613 {
614     my $fh = shift;
615     T2H_DEFAULT_print_page_head($fh);
616     print $fh "<div id=\"main\">\n";
617 }
618
619 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
620 # sidebar mimicking a TOC frame
621 sub print_lilypond_page_foot($)
622 {
623   my $fh = shift;
624   my $program_string = &$program_string();
625   print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
626   print $fh "<!-- FOOTER -->\n\n";
627   print $fh "<!-- end div#main here -->\n</div>\n\n";
628
629   # Print the TOC frame and reset the TOC:
630   lilypond_print_toc_div ($fh, \@this_page_toc);
631   @this_page_toc = ();
632
633   # Close the page:
634   print $fh "</body>\n</html>\n";
635 }
636
637
638
639
640
641 #############################################################################
642 ###  NICER / MORE FLEXIBLE NAVIGATION PANELS
643 #############################################################################
644
645 sub get_navigation_text
646 {
647   my $button = shift;
648   my $text = $NAVIGATION_TEXT{$button};
649   if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
650     $text = $text . $Texi2HTML::NODE{$button} . "&nbsp;";
651   } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
652     $text = "&nbsp;" . $Texi2HTML::NODE{$button} . $text;
653   } elsif ( $button eq 'Up' ) {
654     $text = "&nbsp;".$text.":&nbsp;" . $Texi2HTML::NODE{$button} . "&nbsp;";
655   }
656   return $text;
657 }
658
659
660 # Don't automatically create left-aligned table cells for every link, but
661 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
662 # button text. It's alignment as well as the colspan will be taken from the
663 # name of the button. Also, add 'newline' button text to create a new table
664 # row. The texts of the buttons are generated by get_navigation_text and
665 # will contain the name of the next/previous section/chapter.
666 sub lilypond_print_navigation
667 {
668     my $fh = shift;
669     my $buttons = shift;
670     my $vertical = shift;
671     my $spacing = 1;
672 #     print $fh '<table cellpadding="', $spacing, '" cellspacing="', $spacing,
673 #       "\" border=\"0\" class=\"nav_table\">\n";
674     print $fh "<table class=\"nav_table\">\n";
675
676     print $fh "<tr>" unless $vertical;
677     my $beginofline = 1;
678     foreach my $button (@$buttons)
679     {
680         print $fh qq{<tr valign="top" align="left">\n} if $vertical;
681         # Allow (left|right|center)-aligned-cell and newline as buttons!
682         if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
683         {
684           print $fh qq{</td>} unless $beginofline;
685           print $fh qq{<td valign="middle" align="$1" colspan="$2">};
686           $beginofline = 0;
687         }
688         elsif ( $button eq 'newline' )
689         {
690           print $fh qq{</td>} unless $beginofline;
691           print $fh qq{</tr>};
692           print $fh qq{<tr>};
693           $beginofline = 1;
694
695         }
696         elsif (ref($button) eq 'CODE')
697         {
698             &$button($fh, $vertical);
699         }
700         elsif (ref($button) eq 'SCALAR')
701         {
702             print $fh "$$button" if defined($$button);
703         }
704         elsif (ref($button) eq 'ARRAY')
705         {
706             my $text = $button->[1];
707             my $button_href = $button->[0];
708             # verify that $button_href is simple text and text is a reference
709             if (defined($button_href) and !ref($button_href)
710                and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
711             {             # use given text
712                 if ($Texi2HTML::HREF{$button_href})
713                 {
714                   my $anchor_attributes = '';
715                   if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
716                   {
717                       $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
718                   }
719                   if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
720                   {
721                       $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
722                   }
723                   print $fh "" .
724                         &$anchor('',
725                                     $Texi2HTML::HREF{$button_href},
726                                     get_navigation_text($$text),
727                                     $anchor_attributes
728                                    );
729                 }
730                 else
731                 {
732                   print $fh get_navigation_text($$text);
733                 }
734             }
735         }
736         elsif ($button eq ' ')
737         {                       # handle space button
738             print $fh
739                 ($ICONS && $ACTIVE_ICONS{' '}) ?
740                     &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
741                         $NAVIGATION_TEXT{' '};
742             #next;
743         }
744         elsif ($Texi2HTML::HREF{$button})
745         {                       # button is active
746             my $btitle = $BUTTONS_GOTO{$button} ?
747                 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
748             if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
749             {
750                 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
751             }
752             if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
753             {
754                 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
755             }
756             if ($ICONS && $ACTIVE_ICONS{$button})
757             {                   # use icon
758                 print $fh '' .
759                     &$anchor('',
760                         $Texi2HTML::HREF{$button},
761                         &$button_icon_img($BUTTONS_NAME{$button},
762                                    $ACTIVE_ICONS{$button},
763                                    $Texi2HTML::SIMPLE_TEXT{$button}),
764                         $btitle
765                       );
766             }
767             else
768             {                   # use text
769                 print $fh
770                     '[' .
771                         &$anchor('',
772                                     $Texi2HTML::HREF{$button},
773                                     get_navigation_text ($button),
774                                     $btitle
775                                    ) .
776                                        ']';
777             }
778         }
779         else
780         {                       # button is passive
781             print $fh
782                 $ICONS && $PASSIVE_ICONS{$button} ?
783                     &$button_icon_img($BUTTONS_NAME{$button},
784                                           $PASSIVE_ICONS{$button},
785                                           $Texi2HTML::SIMPLE_TEXT{$button}) :
786
787                                               "[" . get_navigation_text($button) . "]";
788         }
789         print $fh "</td>\n" if $vertical;
790         print $fh "</tr>\n" if $vertical;
791     }
792     print $fh "</td>" unless $beginofline;
793     print $fh "</tr>" unless $vertical;
794     print $fh "</table>\n";
795 }
796
797
798 @Texi2HTML::Config::SECTION_BUTTONS =
799     ('left-aligned-cell-1', 'FastBack',
800      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
801      'right-aligned-cell-1', 'FastForward',
802      'newline',
803      'left-aligned-cell-2', 'Back',
804      'center-aligned-cell-1', 'Up',
805      'right-aligned-cell-2', 'Forward'
806     );
807
808 # buttons for misc stuff
809 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
810
811 # buttons for chapter file footers
812 # (and headers but only if SECTION_NAVIGATION is false)
813 @Texi2HTML::Config::CHAPTER_BUTTONS =
814     ('left-aligned-cell-1', 'FastBack',
815      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
816      'right-aligned-cell-1', 'FastForward',
817     );
818
819 # buttons for section file footers
820 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
821     ('left-aligned-cell-1', 'FastBack',
822      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
823      'right-aligned-cell-1', 'FastForward',
824      'newline',
825      'left-aligned-cell-2', 'Back',
826      'center-aligned-cell-1', 'Up',
827      'right-aligned-cell-2', 'Forward'
828     );
829
830 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
831     ('left-aligned-cell-1', 'FastBack',
832      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
833      'right-aligned-cell-1', 'FastForward',
834      'newline',
835      'left-aligned-cell-2', 'Back',
836      'center-aligned-cell-1', 'Up',
837      'right-aligned-cell-2', 'Forward'
838     );
839
840
841
842
843
844 #############################################################################
845 ###  OTHER SETTINGS
846 #############################################################################
847
848 # For split pages, use index.html as start page!
849 if ($Texi2HTML::Config::SPLIT eq 'section') {
850   $Texi2HTML::Config::TOP_FILE = 'index.html';
851 }
852
853
854 return 1;