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