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