]> git.donarmstrong.com Git - lilypond.git/blob - lilypond-texi2html.init
texi2html: Show 2nd-level entries in TOC only if numbered or parent of current
[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 $result
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} or $lastfilename == '') {
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   my $always_show_unnumbered_children = shift;
567   # Skip undefined sections, plus all sections generated by index splitting
568   return() if (not defined($element) or exists($element->{'index_page'}));
569   my @result = ();
570   my $level = $element->{'toc_level'};
571   my $is_parent_of_current = $element->{'number'} && $element_path->{$element->{'number'}};
572   my $print_children = ( ($level < $maxlevel) or $is_parent_of_current );
573   my $ind = '  ' x $level;
574   my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : "";
575
576   my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'id'}",$element->{'text'});
577
578   my $children = $element->{'section_childs'};
579   # Don't add unnumbered entries, unless they are at top-level or a parent of the current!
580   if (not ($element->{'number'} or $always_show_unnumbered_children)) {
581     return @result;
582   }
583   if ( $print_children and defined($children) and (ref($children) eq "ARRAY") ) {
584     push (@result, $entry);
585     my @child_result = ();
586     foreach (@$children) {
587       push (@child_result, generate_ly_toc_entries($_, $element_path, $maxlevel, $is_parent_of_current));
588     }
589     # if no child nodes were generated, e.g. for the index, where expanded pages
590     # are ignored, don't generate a list at all...
591     if (@child_result) {
592       push (@result, "$ind<ul$NO_BULLET_LIST_ATTRIBUTE>");
593       push (@result, @child_result);
594       push (@result, "$ind</ul></li>\n");
595     }
596   } else {
597     push (@result, $entry . "</li>\n");
598   }
599   return @result;
600 }
601
602
603 # Print a customized TOC, containing only the first two levels plus the whole
604 # path to the current page
605 sub lilypond_generate_page_toc_body($)
606 {
607     my $element = shift;
608     my $current_element = $element;
609     my %parentelements;
610     $parentelements{$element->{'number'}} = 1;
611     # Find the path to the current element
612     while ( defined($current_element->{'sectionup'}) and
613            ($current_element->{'sectionup'} ne $current_element) )
614     {
615       $parentelements{$current_element->{'sectionup'}->{'number'}} = 1
616               if ($current_element->{'sectionup'}->{'number'} ne '');
617       $current_element = $current_element->{'sectionup'};
618     }
619     return () if not defined($current_element);
620     # Create the toc entries recursively
621     my @toc_entries = ("<div class=\"contents\">", "<ul$NO_BULLET_LIST_ATTRIBUTE>");
622     my $children = $current_element->{'section_childs'};
623     foreach ( @$children ) {
624       push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth, False));
625     }
626     push (@toc_entries, "</ul>");
627     push (@toc_entries, "</div>");
628     return @toc_entries;
629 }
630
631
632 # Create the custom TOC for this page (partially folded, current page is
633 # highlighted) and store it in a global variable. The TOC is written out after
634 # the html contents (but positioned correctly using CSS), so that browsers with
635 # css turned off still show the contents first.
636 my @this_page_toc = ();
637 sub lilypond_print_element_header
638 {
639   my $fh = shift;
640   my $first_in_page = shift;
641   my $previous_is_top = shift;
642   if ($first_in_page and not @this_page_toc) {
643     if (defined($Texi2HTML::THIS_ELEMENT)) {
644       # Create the TOC for this page
645       @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
646     }
647   }
648   return T2H_DEFAULT_print_element_header( $fh, $first_in_page, $previous_is_top);
649 }
650
651 # Generate the HTML output for the TOC
652 sub lilypond_toc_body($)
653 {
654     my $elements_list = shift;
655     # Generate a default TOC for pages without THIS_ELEMENT
656     @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
657     return T2H_GPL_toc_body($elements_list);
658 }
659
660
661 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
662 # sidebar mimicking a TOC frame
663 sub print_lilypond_page_foot($)
664 {
665   my $fh = shift;
666   my $program_string = &$program_string();
667   print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
668
669   # Print the TOC frame:
670   my @lines = @this_page_toc;
671   # use default TOC if no custom lines have been generated
672   @lines = @default_toc if (not @lines);
673   if (@lines) {
674     print $fh "\n\n<div id=\"tocframe\">";
675     print $fh '<h4> ' . $Texi2HTML::NAME{'Contents'}  . "</h4>\n";
676     foreach my $line (@lines) {
677       print $fh $line;
678     }
679     print $fh "</div>";
680     @this_page_toc = ();
681   }
682
683   # Close the page:
684   print $fh "</body>\n</html>\n";
685 }
686
687
688
689
690
691 #############################################################################
692 ###  NICER / MORE FLEXIBLE NAVIGATION PANELS
693 #############################################################################
694
695 sub get_navigation_text
696 {
697   my $button = shift;
698   my $text = $NAVIGATION_TEXT{$button};
699   if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
700     $text = $text . $Texi2HTML::NODE{$button} . "&nbsp;";
701   } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
702     $text = "&nbsp;" . $Texi2HTML::NODE{$button} . $text;
703   } elsif ( $button eq 'Up' ) {
704     $text = "&nbsp;".$text.":&nbsp;" . $Texi2HTML::NODE{$button} . "&nbsp;";
705   }
706   return $text;
707 }
708
709
710 # Don't automatically create left-aligned table cells for every link, but
711 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
712 # button text. It's alignment as well as the colspan will be taken from the
713 # name of the button. Also, add 'newline' button text to create a new table
714 # row. The texts of the buttons are generated by get_navigation_text and
715 # will contain the name of the next/previous section/chapter.
716 sub lilypond_print_navigation
717 {
718     my $fh = shift;
719     my $buttons = shift;
720     my $vertical = shift;
721     my $spacing = 1;
722 #     print $fh '<table cellpadding="', $spacing, '" cellspacing="', $spacing,
723 #       "\" border=\"0\" class=\"nav_table\">\n";
724     print $fh "<table class=\"nav_table\">\n";
725
726     print $fh "<tr>" unless $vertical;
727     my $beginofline = 1;
728     foreach my $button (@$buttons)
729     {
730         print $fh qq{<tr valign="top" align="left">\n} if $vertical;
731         # Allow (left|right|center)-aligned-cell and newline as buttons!
732         if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
733         {
734           print $fh qq{</td>} unless $beginofline;
735           print $fh qq{<td valign="middle" align="$1" colspan="$2">};
736           $beginofline = 0;
737         }
738         elsif ( $button eq 'newline' )
739         {
740           print $fh qq{</td>} unless $beginofline;
741           print $fh qq{</tr>};
742           print $fh qq{<tr>};
743           $beginofline = 1;
744
745         }
746         elsif (ref($button) eq 'CODE')
747         {
748             &$button($fh, $vertical);
749         }
750         elsif (ref($button) eq 'SCALAR')
751         {
752             print $fh "$$button" if defined($$button);
753         }
754         elsif (ref($button) eq 'ARRAY')
755         {
756             my $text = $button->[1];
757             my $button_href = $button->[0];
758             # verify that $button_href is simple text and text is a reference
759             if (defined($button_href) and !ref($button_href)
760                and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
761             {             # use given text
762                 if ($Texi2HTML::HREF{$button_href})
763                 {
764                   my $anchor_attributes = '';
765                   if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
766                   {
767                       $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
768                   }
769                   if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
770                   {
771                       $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
772                   }
773                   print $fh "" .
774                         &$anchor('',
775                                     $Texi2HTML::HREF{$button_href},
776                                     get_navigation_text($$text),
777                                     $anchor_attributes
778                                    );
779                 }
780                 else
781                 {
782                   print $fh get_navigation_text($$text);
783                 }
784             }
785         }
786         elsif ($button eq ' ')
787         {                       # handle space button
788             print $fh
789                 ($ICONS && $ACTIVE_ICONS{' '}) ?
790                     &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
791                         $NAVIGATION_TEXT{' '};
792             #next;
793         }
794         elsif ($Texi2HTML::HREF{$button})
795         {                       # button is active
796             my $btitle = $BUTTONS_GOTO{$button} ?
797                 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
798             if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
799             {
800                 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
801             }
802             if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
803             {
804                 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
805             }
806             if ($ICONS && $ACTIVE_ICONS{$button})
807             {                   # use icon
808                 print $fh '' .
809                     &$anchor('',
810                         $Texi2HTML::HREF{$button},
811                         &$button_icon_img($BUTTONS_NAME{$button},
812                                    $ACTIVE_ICONS{$button},
813                                    $Texi2HTML::SIMPLE_TEXT{$button}),
814                         $btitle
815                       );
816             }
817             else
818             {                   # use text
819                 print $fh
820                     '[' .
821                         &$anchor('',
822                                     $Texi2HTML::HREF{$button},
823                                     get_navigation_text ($button),
824                                     $btitle
825                                    ) .
826                                        ']';
827             }
828         }
829         else
830         {                       # button is passive
831             print $fh
832                 $ICONS && $PASSIVE_ICONS{$button} ?
833                     &$button_icon_img($BUTTONS_NAME{$button},
834                                           $PASSIVE_ICONS{$button},
835                                           $Texi2HTML::SIMPLE_TEXT{$button}) :
836
837                                               "[" . get_navigation_text($button) . "]";
838         }
839         print $fh "</td>\n" if $vertical;
840         print $fh "</tr>\n" if $vertical;
841     }
842     print $fh "</td>" unless $beginofline;
843     print $fh "</tr>" unless $vertical;
844     print $fh "</table>\n";
845 }
846
847
848 @Texi2HTML::Config::SECTION_BUTTONS =
849     ('left-aligned-cell-1', 'FastBack',
850      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
851      'right-aligned-cell-1', 'FastForward',
852      'newline',
853      'left-aligned-cell-2', 'Back',
854      'center-aligned-cell-1', 'Up',
855      'right-aligned-cell-2', 'Forward'
856     );
857
858 # buttons for misc stuff
859 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
860
861 # buttons for chapter file footers
862 # (and headers but only if SECTION_NAVIGATION is false)
863 @Texi2HTML::Config::CHAPTER_BUTTONS =
864     ('left-aligned-cell-1', 'FastBack',
865      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
866      'right-aligned-cell-1', 'FastForward',
867     );
868
869 # buttons for section file footers
870 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
871     ('left-aligned-cell-1', 'FastBack',
872      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
873      'right-aligned-cell-1', 'FastForward',
874      'newline',
875      'left-aligned-cell-2', 'Back',
876      'center-aligned-cell-1', 'Up',
877      'right-aligned-cell-2', 'Forward'
878     );
879
880 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
881     ('left-aligned-cell-1', 'FastBack',
882      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
883      'right-aligned-cell-1', 'FastForward',
884      'newline',
885      'left-aligned-cell-2', 'Back',
886      'center-aligned-cell-1', 'Up',
887      'right-aligned-cell-2', 'Forward'
888     );
889
890
891
892
893
894 #############################################################################
895 ###  OTHER SETTINGS
896 #############################################################################
897
898 # For split pages, use index.html as start page!
899 if ($Texi2HTML::Config::SPLIT == 'section') {
900   $Texi2HTML::Config::TOP_FILE = 'index.html';
901 }
902
903
904 return 1;