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