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