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