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