]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/lilypond-texi2html.init
Docs-it: initial translation
[lilypond.git] / Documentation / lilypond-texi2html.init
1 #!/usr/bin/env perl
2 # -*- coding: utf-8; -*-
3
4 ### texi2html customization script for LilyPond
5 ### Author: Reinhold Kainhofer <reinhold@kainhofer.com>, 2008.
6 ###         Some code parts copied from texi2html and adapted. These functions
7 ###         were written mainly by Patrice Dumas
8 ### License: GPLv2+
9 ###
10 ###
11 ### Features implemented here:
12 ### -) For split manuals, the main page is index.html.
13 ### -) All @unnumbered* sections are placed into the same file
14 ###    (implemented by split_at_numbered_sections)
15 ### -) Use our custom CSS file, with IE-specific fixes in another CSS file,
16 ###    impelmented by lilypond_css_lines
17 ### -) TOC (folded, with the current page highlighted) in an overflown <div>
18 ###    is added to every page; implemented by:
19 ###           lilypond_print_element_header -- building of the TOC
20 ###           lilypond_toc_body -- generation of customized TOC output
21 ###           lilypond_print_page_head -- start <div id="main">
22 ###           print_lilypond_page_foot -- closing id=main, output of footer & TOC
23 ### -) External refs are formatted only as "Text of the node" (not as >>see
24 ###    "NODE" section "SECTION" in "BOOK"<< like with default texi2html). Also,
25 ###    the leading "(book-name)" is removed.
26 ###    Implemented by overriding lilypond_external_ref
27 ### -) Navigation bars on top/bottom of the page and between sections are not
28 ###    left-aligned, but use a combination of left/center/right aligned table
29 ###    cells; For this, I heavily extend the texi2html code to allow for
30 ###    differently aligned cells and for multi-line tables);
31 ###    Implemented in lilypond_print_navigation
32 ### -) Different formatting than the default: example uses the same formatting
33 ###    as quote.
34 ### -) Allow translated section titles: All section titles can be translated,
35 ###    the original (English) title is associated with @translationof. This is
36 ###    needed, because the file name / anchor is generated from the original
37 ###    English title, since otherwise language-autoselection would break with
38 ###    posted links.
39 ###    Since it is then no longer possible to obtain the file name from the
40 ###    section title, I keep a sectionname<=>filename/anchor around. This way,
41 ###    xrefs from other manuals can simply load that map and retrieve the
42 ###    correct file name for the link. Implemented in:
43 ###           lilypond_unknown (handling of @translationof, in case
44 ###                             extract_texi_filenames.py messes up...)
45 ###           lilypond_element_file_name (correct file name: use the map)
46 ###           lilypond_element_target_name (correct anchor: use the map)
47 ###           lilypond_init_map (read in the externally created map from disk)
48 ###           lilypond_external_href (load the map for xrefs, use the correct
49 ###                                   link target)
50 ### -) The HTML anchors for all sections are derived from the node name /
51 ###    section title (pre-generated in the .xref-map file). Implemented by:
52 ###           lilypond_element_target_name (adjust section anchors)
53 ### -) Use the standard footnote format "<sup>nr</sup> text" instead of the
54 ###    ugly format of texi2html (<h3>(nr)</h3><p>text</p>). Implemented in
55 ###           makeinfo_like_foot_line_and_ref
56 ###           makeinfo_like_foot_lines
57 ###           makeinfo_like_paragraph
58 ###
59 ###
60 ### Useful helper functions:
61 ### -) texinfo_file_name($node_name): returns a texinfo-compatible file name
62 ###    for the given string $node_name (whitespace trimmed/replaced by -,
63 ###    non-standard chars replaced by _xxxx (ascii char code) and forced to
64 ###    start with a letter by prepending t_g if necessary)
65
66
67 package Texi2HTML::Config;
68
69 use utf8;
70 use Encode qw(decode);
71
72 #############################################################################
73 ### TRANSLATIONS
74 #############################################################################
75
76 my $LY_LANGUAGES = {};
77 $LY_LANGUAGES->{'fr'} = {
78     'Back to Documentation Index' => 'Retour à l\'accueil de la documentation',
79 };
80 $LY_LANGUAGES->{'es'} = {
81     'Back to Documentation Index' => 'Volver al índice de la documentación',
82 };
83 $LY_LANGUAGES->{'de'} = {
84     'Back to Documentation Index' => 'Zur Dokumentationsübersicht',
85 };
86 $LY_LANGUAGES->{'ja'} = {
87     'Back to Documentation Index' => 'ドキュメント インデックスに戻る',
88 };
89
90 $LY_LANGUAGES->{'hu'} = {
91     'Back to Documentation Index' => 'Vissza a dokumentációk jegyzékéhez',
92 };
93
94 $LY_LANGUAGES->{'it'} = {
95     'Back to Documentation Index' => 'Torna all\'indice della documentazione',
96 };
97
98 # FIXME: request the translations below then send them to texi2html/texinfo devs
99 $LANGUAGES->{'it'} = LANGUAGES->{'en'};
100 $LANGUAGES->{'hu'} = {
101                        '  The buttons in the navigation panels have the following meaning:' => '  A navigációs panelen levő gombok jelentése a következő:',
102                        '  where the @strong{ Example } assumes that the current position is at @strong{ Subsubsection One-Two-Three } of a document of the following structure:' => '  ahol a @strong{ Példa } feltételezi, hogy az aktuális pozíció az @strong{ 1-2-3 alalszakasz } egy olyan dokumentumban, melynek szerkezete a következő:',
103                        ' Up ' => ' Fel ',
104                        '(outside of any element)' => '(bármelyik elemen kívül)',
105                        '(outside of any node)' => '(bármelyik csomóponton kívül)',
106                        '@b{{quotation_arg}:} ' => '@b{{quotation_arg}:} ',
107                        '@cite{{book}}' => '@cite{{book}}',
108                        '@{No value for `{value}\'@}' => '@{Nincs értéke ennek: `{value}\'@}',
109                        'About' => 'Névjegy',
110                        'About (help)' => 'Névjegy (súgó)',
111                        'About This Document' => 'Erről a dokumentumról',
112                        'April' => 'április',
113                        'August' => 'augusztus',
114                        'Back' => 'Vissza',
115                        'Back section in previous file' => 'Előző fájl hátsó szakasza',
116                        'Beginning of this chapter or previous chapter' => 'Fejezet eleje vagy előző fejezet',
117                        'Button' => 'Gomb',
118                        'Contents' => 'Tartalom',
119                        'Cover (top) of document' => 'Dokumentum borítója',
120                        'Current' => 'Aktuális',
121                        'Current Position' => 'Aktuális pozíció',
122                        'Current section' => 'Aktuális szakasz',
123                        'December' => 'december',
124                        'FastBack' => 'Gyorsan vissza',
125                        'FastForward' => 'Gyorsan előre',
126                        'February' => 'február',
127                        'First' => 'Első',
128                        'First section in reading order' => 'Első szakasz az olvasási sorrendben',
129                        'Following' => 'Következő',
130                        'Following node' => 'Következő csomópont',
131                        'Footnotes' => 'Lábjegyzet',
132                        'Forward' => 'Előre',
133                        'Forward section in next file' => 'Következő fájl elülső szakasza',
134                        'From 1.2.3 go to' => '1.2.3-ból menj ide:',
135                        'Go to' => 'Menj ide:',
136                        'Index' => 'Tárgymutató',
137                        'Index Entry' => 'Tárgymutató-bejegyzés',
138                        'January' => 'január',
139                        'July' => 'július',
140                        'Jump to' => 'Ugorj ide:',
141                        'June' => 'június',
142                        'Last' => 'Utolsó',
143                        'Last section in reading order' => 'Utolsó szakasz az olvasási sorrendben',
144                        'March' => 'március',
145                        'May' => 'május',
146                        'Menu:' => 'Menü:',
147                        'Name' => 'Név',
148                        'Next' => 'Következő',
149                        'Next chapter' => 'Következő fejezet',
150                        'Next file' => 'Következő fájl',
151                        'Next node' => 'Következő csomópont',
152                        'Next section in reading order' => 'Következő szakasz az olvasási sorrendben',
153                        'Next section on same level' => 'Következő szakasz ugyanazon a szinten',
154                        'NextFile' => 'KövetkezőFájl',
155                        'Node following in node reading order' => 'Következő csomópont az olvasási sorrendben',
156                        'Node up' => 'Szülő csomópont',
157                        'NodeNext' => 'KövetkezőCsomópont',
158                        'NodePrev' => 'ElőzőCsomópont',
159                        'NodeUp' => 'SzülőCsomópont',
160                        'November' => 'november',
161                        'October' => 'október',
162                        'Overview' => 'Áttekintés',
163                        'Prev' => 'Előző',
164                        'PrevFile' => 'ElőzőFájl',
165                        'Previous' => 'Előző',
166                        'Previous file' => 'Előző fájl',
167                        'Previous node' => 'Előző csomópont',
168                        'Previous section in reading order' => 'Előző szakasz az olvasási sorrendben',
169                        'Previous section on same level' => 'Előző szakasz ugyanazon a szinten',
170                        'Section' => 'Szakasz',
171                        'Section One' => '1. szakasz',
172                        'See ' => 'Ld. ',
173                        'See @cite{{book}}' => 'Ld. @cite{{book}}',
174                        'See section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'Ld. ezt a szakaszt: `@asis{}`{section_name}\'@asis{}\' itt: @cite{{book}}',
175                        'See section `{section}\' in @cite{{book}}' => 'Ld. ezt a szakaszt: `{section}\' itt: @cite{{book}}',
176                        'See section {reference_name}' => 'Ld. ezt a szakaszt: {reference_name}',
177                        'See {node_file_href}' => 'Ld. {node_file_href}',
178                        'See {node_file_href} @cite{{book}}' => 'See {node_file_href} @cite{{book}}',
179                        'See {node_file_href} section `{section}\' in @cite{{book}}' => 'Ld. {node_file_href} ezt a szakaszt: `{section}\' itt: @cite{{book}}',
180                        'See {reference_name}' => 'Ld. {reference_name}',
181                        'See {ref}' => 'Ld. {ref}',
182                        'See {title_ref}' => 'Ld. {title_ref}',
183                        'September' => 'szeptember',
184                        'Short Table of Contents' => 'Rövid tartalomjegyzék',
185                        'Short table of contents' => 'Rövid tartalomjegyzék',
186                        'Subsection One-Four' => '1-4 alszakasz',
187                        'Subsection One-One' => '1-1 alszakasz',
188                        'Subsection One-Three' => '1-3 alszakasz',
189                        'Subsection One-Two' => '1-2 alszakasz',
190                        'Subsubsection One-Two-Four' => '1-2-4 alalszakasz',
191                        'Subsubsection One-Two-One' => '1-2-1 alalszakasz',
192                        'Subsubsection One-Two-Three' => '1-2-3 alalszakasz',
193                        'Subsubsection One-Two-Two' => '1-2-2 alalszakasz',
194                        'T2H_today' => '%s, %d %d',
195                        'Table of Contents' => 'Tartalomjegyzék',
196                        'Table of contents' => 'Tartalomjegyzék',
197                        'The node you are looking for is at {href}.' => 'A keresett csomópont itt található: {href}.',
198                        'This' => 'Ez a(z)',
199                        'This document was generated on @i{{date}} using @uref{{program_homepage}, @i{{program}}}.' => 'Ezt a dokumentumot @i{{date}} napon generálta a(z) @uref{{program_homepage}, @i{{program}}}.',
200                        'This document was generated using @uref{{program_homepage}, @emph{{program}}}.' => 'Ezt a dokumentumot a(z) @uref{{program_homepage}, @emph{{program}}} generálta.',
201                        'Top' => 'Tetejére',
202                        'Untitled Document' => 'Névtelen dokumentum',
203                        'Up' => 'Fel',
204                        'Up node' => 'Szülő csomópont',
205                        'Up section' => 'Szülő szakasz',
206                        'current' => 'aktuális',
207                        'on @emph{{date}}' => 'ekkor: @emph{{date}}',
208                        'section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'szakasz: `@asis{}`{section_name}\'@asis{}\' itt: @cite{{book}}',
209                        'section `{section}\' in @cite{{book}}' => 'szakasz: `{section}\' itt: @cite{{book}}',
210                        'see ' => 'ld. ',
211                        'see @cite{{book}}' => 'ld. @cite{{book}}',
212                        'see section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'ld. ezt a szakaszt: `@asis{}`{section_name}\'@asis{}\' itt: @cite{{book}}',
213                        'see section `{section}\' in @cite{{book}}' => 'ld. ezt a szakaszt: `{section}\' itt: @cite{{book}}',
214                        'see section {reference_name}' => 'ld. ezt a szakaszt: {reference_name}',
215                        'see {node_file_href}' => 'ld. {node_file_href}',
216                        'see {node_file_href} @cite{{book}}' => 'ld. {node_file_href} @cite{{book}}',
217                        'see {node_file_href} section `{section}\' in @cite{{book}}' => 'ld. {node_file_href} ezt a szakaszt: `{section}\' itt: @cite{{book}}',
218                        'see {reference_name}' => 'ld. {reference_name}',
219                        'see {ref}' => 'ld. {ref}',
220                        'see {title_ref}' => 'ld. {title_ref}',
221                        '{acronym_like} ({explanation})' => '{acronym_like} ({explanation})',
222                        '{name} of {class}' => '{name} típusa: {class}',
223                        '{name} on {class}' => '{name} ezen: {class}',
224                        '{node_file_href}' => '{node_file_href}',
225                        '{node_file_href} @cite{{book}}' => '{node_file_href} @cite{{book}}',
226                        '{node_file_href} section `{section}\' in @cite{{book}}' => '{node_file_href} szakasz: `{section}\' itt: @cite{{book}}',
227                        '{reference_name}' => '{reference_name}',
228                        '{ref}' => '{ref}',
229                        '{style} {number}' => '{style} {number}',
230                        '{style}: {caption_first_line}' => '{style}: {caption_first_line}',
231                        '{style}: {shortcaption_first_line}' => '{style}: {shortcaption_first_line}',
232                        '{title_ref}' => '{title_ref}'
233                      };
234
235 sub ly_get_string () {
236     my $lang = $Texi2HTML::THISDOC{current_lang};
237     my $string = shift;
238     if ($lang and $lang ne "en" and $LY_LANGUAGES->{$lang}->{$string}) {
239         return $LY_LANGUAGES->{$lang}->{$string};
240     } else {
241         return $string;
242     }
243 }
244
245
246 #############################################################################
247 ### FUNCTIONALITY FOR MAIN WEB PAGES
248 #############################################################################
249
250 my $web_manual = 0;
251 sub lilypond_init_web_manual ()
252 {
253   if (exists($main::value{'web_manual'}))
254   {
255       print STDERR "Initializing settings for web site\n";
256     $web_manual = 1;
257     web_settings();
258   }
259 }
260 push @Texi2HTML::Config::command_handler_process, \&lilypond_init_web_manual;
261
262 #############################################################################
263 ###  SETTINGS FOR TEXI2HTML
264 #############################################################################
265
266 # Validation fix for texi2html<=1.82
267 $Texi2HTML::Config::DOCTYPE = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
268
269 sub web_settings() {
270   if ($web_manual) {
271     @Texi2HTML::Config::CSS_REFS      = (
272       {FILENAME => "lilypond-web.css", TITLE => "Default style"}
273     );
274   } else {
275     @Texi2HTML::Config::CSS_REFS      = (
276       {FILENAME => "lilypond-mccarty.css", TITLE => "Patrick McCarty's design"}
277     );
278   }
279 }
280 @Texi2HTML::Config::ALT_CSS_REFS      = (
281     {FILENAME => "lilypond.css", TITLE => "Andrew Hawryluk's design" },
282     {FILENAME => "lilypond-blue.css", TITLE => "Kurt Kroon's blue design" },
283 );
284 $Texi2HTML::Config::USE_ACCESSKEY = 1;
285 $Texi2HTML::Config::USE_LINKS     = 1;
286 $Texi2HTML::Config::USE_REL_REV   = 1;
287 $Texi2HTML::Config::SPLIT_INDEX   = 0;
288 $Texi2HTML::Config::SEPARATED_FOOTNOTES = 0; # Print footnotes on same page, not separated
289
290 if ($Texi2HTML::Config::SPLIT eq 'section' or
291     $Texi2HTML::Config::SPLIT eq 'subsubsection') {
292   $Texi2HTML::Config::element_file_name    = \&lilypond_element_file_name;
293 }
294
295 $Texi2HTML::Config::element_target_name  = \&lilypond_element_target_name;
296 $default_print_element_header = $Texi2HTML::Config::print_element_header;
297 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
298 $Texi2HTML::Config::print_page_foot      = \&print_lilypond_page_foot;
299 $Texi2HTML::Config::print_navigation     = \&lilypond_print_navigation;
300 $Texi2HTML::Config::external_ref         = \&lilypond_external_ref;
301 $default_external_href = $Texi2HTML::Config::external_href;
302 $Texi2HTML::Config::external_href        = \&lilypond_external_href;
303 $default_toc_body = $Texi2HTML::Config::toc_body;
304 $Texi2HTML::Config::toc_body             = \&lilypond_toc_body;
305 $Texi2HTML::Config::css_lines            = \&lilypond_css_lines;
306 $default_unknown = $Texi2HTML::Config::unknown;
307 $Texi2HTML::Config::unknown              = \&lilypond_unknown;
308 $default_print_page_head = $Texi2HTML::Config::print_page_head;
309 $Texi2HTML::Config::print_page_head      = \&lilypond_print_page_head;
310 # $Texi2HTML::Config::foot_line_and_ref    = \&lilypond_foot_line_and_ref;
311 $Texi2HTML::Config::foot_line_and_ref  = \&makeinfo_like_foot_line_and_ref;
312 $Texi2HTML::Config::foot_lines         = \&makeinfo_like_foot_lines;
313 $Texi2HTML::Config::paragraph          = \&makeinfo_like_paragraph;
314
315
316
317 # Examples should be formatted similar to quotes:
318 $Texi2HTML::Config::complex_format_map->{'example'} = {
319   'begin' => q{"<blockquote>"},
320   'end' => q{"</blockquote>\n"},
321   'style' => 'code',
322  };
323
324 %Texi2HTML::config::misc_pages_targets = (
325    'Overview' => 'Overview',
326    'Contents' => 'Contents',
327    'About' => 'About'
328 );
329
330
331 my @section_to_filename;
332
333
334
335
336 #############################################################################
337 ###  DEBUGGING
338 #############################################################################
339
340 use Data::Dumper;
341 $Data::Dumper::Maxdepth = 2;
342
343 sub print_element_info($)
344 {
345   my $element = shift;
346   print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
347   print "Element: $element\n";
348   print Dumper($element);
349 }
350
351
352
353
354
355 #############################################################################
356 ###  HELPER FUNCTIONS
357 #############################################################################
358
359 # Convert a given node name to its proper file name (normalization as explained
360 # in the texinfo manual:
361 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
362 sub texinfo_file_name($)
363 {
364   my $text = shift;
365   my $result = '';
366   # File name normalization by texinfo:
367   # 1/2: letters and numbers are left unchanged
368   # 3/4: multiple, leading and trailing whitespace is removed
369   $text = main::normalise_space($text);
370   # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
371   #      chars are replaced by _xxxx (xxxx=ascii character code)
372   while ($text ne '') {
373     if ($text =~ s/^([A-Za-z0-9]+)//o) { # number or letter stay unchanged
374       $result .= $1;
375     } elsif ($text =~ s/^ //o) { # space -> '-'
376       $result .= '-';
377     } elsif ($text =~ s/^(.)//o) { # Otherwise use _xxxx (ascii char code)
378       my $ccode = ord($1);
379       if ( $ccode <= 0xFFFF ) {
380         $result .= sprintf("_%04x", $ccode);
381       } else {
382         $result .= sprintf("__%06x", $ccode);
383       }
384     }
385   }
386   # 7: if name does not begin with a letter, prepend 't_g' (so it starts with a letter)
387   if ($result !~ /^[a-zA-Z]/) {
388     $result = 't_g' . $result;
389   }
390   # DONE
391   return lc($result)
392 }
393
394 # Load a file containing a nodename<=>filename map (tab-sepatared, i.e.
395 # NODENAME\tFILENAME\tANCHOR
396 # Returns a ref to a hash "Node title" => ["FilenameWithoutExt", "Anchor"]
397 sub load_map_file ($)
398 {
399     my $mapfile = shift;
400     my $node_map = ();
401
402     # For some unknown reason, Perl on my system (5.10.0 on Fedora 12)
403     # refuses to open map files of translated documents with
404     # '<:encoding(utf8)', but decoding from UTF-8 line by line works. -jm
405     if (open(XREFFILE,'<', $mapfile)) {
406         my $line;
407         while ( $line = decode ('UTF-8', <XREFFILE>) ) {
408             # parse the tab-separated entries and insert them into the map:
409             chomp($line);
410             my @entries = split(/\t/, $line);
411             if (scalar (@entries) == 3) {
412               $node_map->{$entries[0]} = [$entries[1], $entries[2]];
413             } else {
414               print STDERR "Invalid entry in the node file $mapfile: $line\n";
415             }
416         }
417         # print STDERR %{$node_map};
418         close (XREFFILE);
419     } else {
420         print STDERR "WARNING: Unable to load the map file $mapfile\n";
421     }
422     return $node_map;
423 }
424
425
426 # Split the given path into dir and basename (with .texi removed). Used mainly
427 # to get the path/basename of the original texi input file
428 sub split_texi_filename ($)
429 {
430   my $docu = shift;
431   my ($docu_dir, $docu_name);
432   if ($docu =~ /(.*\/)/) {
433     chop($docu_dir = $1);
434     $docu_name = $docu;
435     $docu_name =~ s/.*\///;
436   } else {
437      $docu_dir = '.';
438      $docu_name = $docu;
439   }
440   $docu_name =~ s/\.te?x(i|info)?$//;
441   return ($docu_dir, $docu_name);
442 }
443
444
445
446
447
448 #############################################################################
449 ###  CSS HANDLING
450 #############################################################################
451
452 # Include our standard CSS file, not hard-coded CSS code directly in the HTML!
453 # For IE, conditionally include the lilypond-ie-fixes.css style sheet
454 sub lilypond_css_lines ($$)
455 {
456     my $import_lines = shift;
457     my $rule_lines = shift;
458     return if (defined($Texi2HTML::THISDOC{'CSS_LINES'}));
459     if (@$rule_lines or @$import_lines)
460     {
461         $Texi2HTML::THISDOC{'CSS_LINES'} = "<style type=\"text/css\">\n<!--\n";
462         $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$import_lines) . "\n" if (@$import_lines);
463         $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$rule_lines) . "\n" if (@$rule_lines);
464         $Texi2HTML::THISDOC{'CSS_LINES'} .= "-->\n</style>\n";
465     }
466     foreach my $ref (@CSS_REFS)
467     {
468         $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"stylesheet\" type=\"text/css\" title=\"$ref->{TITLE}\" href=\"$ref->{FILENAME}\">\n";
469     }
470     foreach my $ref (@Texi2HTML::Config::ALT_CSS_REFS)
471     {
472         $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"$ref->{FILENAME}\" title=\"$ref->{TITLE}\">\n";
473     }
474     # FIXME: the website doesn't use ie7-specific fixes; do the
475     # docs still need this?  -gp
476     $Texi2HTML::THISDOC{'CSS_LINES'} .= "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
477 }
478
479
480
481
482
483 #############################################################################
484 ###  SPLITTING BASED ON NUMBERED SECTIONS
485 #############################################################################
486
487 my $lastfilename;
488 my $docnr = 0;
489 my $node_to_filename_map = ();
490
491
492 # This function makes sure that files are only generated for numbered sections,
493 # but not for unnumbered ones. It is called after texi2html has done its own
494 # splitting and simply returns the filename for the node given as first argument
495 # Nodes with the same filename will be printed out to the same filename, so
496 # this really all we need. Also, make sure that the file names for sections
497 # are derived from the section title. We also might want to name the anchors
498 # according to node titles, which works by simply overriding the id element of
499 # the $element hash.
500 # If an external nodename<=>filename/anchor map file is found (loaded in
501 # the command handler, use the externally created values, otherwise use the
502 # same logic here.
503 sub lilypond_element_file_name($$$)
504 {
505   my $element = shift;
506   my $type = shift;
507   my $docu_name = shift;
508   my $docu_ext = $Texi2HTML::Config::EXTENSION;
509
510   my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
511   # the snippets page does not use nodes for the snippets, so in this case
512   # we'll have to use the section name!
513   if ($node_name eq '') {
514     $node_name = main::remove_texi($element->{'texi'});
515   }
516
517   # If we have an entry in the section<=>filename map, use that one, otherwise
518   # generate the filename/anchor here. In the latter case, external manuals
519   # will not be able to retrieve the file name for xrefs!!! Still, I already
520   # had that code, so I'll leave it in in case something goes wrong with the
521   # extract_texi_filenames.py script in the lilypond build process!
522   if (exists ($node_to_filename_map->{$node_name})) {
523     (my $filename, my $anchor) = @{$node_to_filename_map->{$node_name}};
524     $filename .= ".$docu_ext" if (defined($docu_ext));
525
526     # unnumbered sections (except those at top-level!) always go to the same
527     # file as the previous numbered section
528     if (not ($element->{number}) and not ($lastfilename eq '') and ($element->{level} > 1)) {
529       $filename = $lastfilename;
530     }
531     if (($filename eq $lastfilename)) {
532       $$element{doc_nr} = $docnr;
533     } else {
534       $docnr += 1;
535       $$element{doc_nr} = $docnr;
536       $lastfilename = $filename;
537     }
538     # print STDERR "File name: $filename\n";
539     return lc($filename);
540
541   } elsif ($type eq "top" or $type eq "toc" or $type eq "doc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
542     return;
543   } else {
544     print STDERR "WARNING: Node '$node_name' was NOT found in the map\n"
545         unless ($node_name eq '') or ($element->{'tag'} eq 'unnumberedsec')
546                or ($node_name =~ /NOT REALLY USED/);
547
548     # Numbered sections will get a filename Node_title, unnumbered sections will use
549     # the file name of the previous numbered section:
550     if (($element->{number}) or ($lastfilename eq '') or ($element->{level} == 1)) {
551       # normalize to the same file name as texinfo
552       if ($element->{translationof}) {
553         $node_name = main::remove_texi($element->{translationof});
554       }
555       my $filename = texinfo_file_name($node_name);
556       $filename .= ".$docu_ext" if (defined($docu_ext));
557       $docnr += 1;
558       $$element{doc_nr} = $docnr;
559       $lastfilename = $filename;
560       print STDERR "File name: $filename\n";
561       return lc($filename);
562     } else {
563       $$element{doc_nr} = $docnr;
564       print STDERR "File name: $filename\n";
565       return lc($filename);
566     }
567   }
568
569   return;
570 }
571
572 sub lilypond_element_target_name($$$)
573 {
574   my $element = shift;
575   my $target = shift;
576   my $id = shift;
577   # Target is based on node name (or sec name for secs without node attached)
578   my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
579   if ($node_name eq '') {
580     $node_name = main::remove_texi($element->{'texi'});
581   }
582
583   # If we have an entry in the section<=>filename map, use that one, otherwise
584   # generate the anchor here.
585   if (exists ($node_to_filename_map->{$node_name})) {
586     (my $filename, $target) = @{$node_to_filename_map->{$node_name}};
587   } else {
588     my $anchor = $node_name;
589     if ($element->{translationof}) {
590       $anchor = main::remove_texi($element->{translationof});
591     }
592     # normalize to the same file name as texinfo
593     $target = texinfo_file_name($anchor);
594   }
595   # TODO: Once texi2html correctly prints out the target and not the id for
596   #       the sections, change this back to ($id, $target)
597   $target = lc($target);
598   return ($target, $target);
599 }
600
601
602 ## Load the map file for the corrently processed texi file. We do this
603 #  using a command init handler, since texi2html does not have any
604 #  other hooks that are called after THISDOC is filled but before phase 2
605 #  of the texi2html conversion.
606 sub lilypond_init_map ()
607 {
608     my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
609     my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
610         || main::locate_include_file ("${docu_name}.xref-map");
611     print STDERR "Map filename is: $map_filename\nDocu name is $docu_name\n";
612     $node_to_filename_map = load_map_file ($map_filename);
613 }
614 push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map;
615
616
617
618 #############################################################################
619 ###  CLEANER LINK TITLE FOR EXTERNAL REFS
620 #############################################################################
621
622 # The default formatting of external refs returns e.g.
623 # "(lilypond-internals)Timing_translator", so we remove all (...) from the
624 # file_and_node argument. Also, we want only a very simple format, so we don't
625 # even call the default handler!
626 sub lilypond_external_ref($$$$$$)
627 {
628   my $type = shift;
629   my $section = shift;
630   my $book = shift;
631   my $file_node = shift;
632   my $href = lc(shift);
633   my $cross_ref = shift;
634
635   my $displaytext = '';
636
637   # 1) if we have a cross ref name, that's the text to be displayed:
638   # 2) For the top node, use the (printable) name of the manual, unless we
639   #    have an explicit cross ref name
640   # 3) In all other cases use the section name
641   if ($cross_ref ne '') {
642     $displaytext = $cross_ref;
643   } elsif (($section eq '') or ($section eq 'Top')) {
644     $displaytext = $book;
645   } else {
646     $displaytext = $section;
647   }
648
649   $displaytext = &$anchor('', $href, $displaytext) if ($displaytext ne '');
650   return &$I('%{node_file_href}', { 'node_file_href' => $displaytext });
651 }
652
653
654
655
656
657 #############################################################################
658 ###  HANDLING TRANSLATED SECTIONS: handle @translationof, secname<->filename
659 ###                  map stored on disk, xrefs in other manuals load that map
660 #############################################################################
661
662
663 # Try to make use of @translationof to generate files according to the original
664 # English section title...
665 sub lilypond_unknown($$$$$)
666 {
667     my $macro = shift;
668     my $line = shift;
669     my $pass = shift;
670     my $stack = shift;
671     my $state = shift;
672
673     # the @translationof macro provides the original English section title,
674     # which should be used for file/anchor naming, while the title will be
675     # translated to each language
676     # It is already used by extract_texi_filenames.py, so this should not be
677     # necessary here at all. Still, I'll leave the code in just in case the
678     # python script messed up ;-)
679     if ($pass == 1 and $macro eq "translationof") {
680       if (ref($state->{'element'}) eq 'HASH') {
681         $state->{'element'}->{'translationof'} = main::normalise_space($line);
682       }
683       return ('', 1, undef, undef);
684     } else {
685       return &$default_unknown($macro, $line, $pass, $stack, $state);
686     }
687 }
688
689
690
691
692 my %translated_books = ();
693 # Construct a href to an external source of information.
694 # node is the node with texinfo @-commands
695 # node_id is the node transliterated and transformed as explained in the
696 #         texinfo manual
697 # node_xhtml_id is the node transformed such that it is unique and can
698 #     be used to make an html cross ref as explained in the texinfo manual
699 # file is the file in '(file)node'
700 sub lilypond_external_href($$$)
701 {
702   my $node = shift;
703   my $node_id = shift;
704   my $node_hxmlt_id = shift;
705   my $file = shift;
706
707   # 1) Keep a hash of book->section_map
708   # 2) if not file in keys hash => try to load the map (assign empty map if
709   #    non-existent => will load only once!)
710   # 3) if node in the section=>(file, anchor) map, replace node_id and
711   #    node_xhtml_id by the map's values
712   # 4) call the default_external_href with these values (or the old ones if not found)
713
714   if (($node_id ne '') and defined($file) and ($node_id ne 'Top')) {
715     my $map_name = $file;
716     $map_name =~ s/-big-page//;
717
718     # Load the map if we haven't done so already
719     if (!exists($translated_books{$map_name})) {
720       my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
721       my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
722           || main::locate_include_file ("${map_name}.xref-map");
723       $translated_books{$map_name} = load_map_file ($map_filename);
724     }
725
726     # look up translation. use these values instead of the old filename/anchor
727     my $section_name_map = $translated_books{$map_name};
728     my $node_text = main::remove_texi($node);
729     if (defined($section_name_map->{$node_text})) {
730       ($node_id, $node_hxmlt_id) = @{$section_name_map->{$node_text}};
731     } else {
732       print STDERR "WARNING: Unable to find node '$node_text' in book $map_name.\n";
733     }
734   }
735
736   if (defined $file) {
737     return &$default_external_href($node, $node_id, $node_hxmlt_id, lc($file));
738   } else {
739     return &$default_external_href($node, $node_id, $node_hxmlt_id);
740   }
741 }
742
743
744
745
746
747 #############################################################################
748 ###  CUSTOM TOC FOR EACH PAGE (in a frame on the left)
749 #############################################################################
750
751 my $page_toc_depth = 2;
752 my @default_toc = [];
753
754 # Initialize the toc_depth to 1 if the command-line option -D=short_toc is given
755 sub lilypond_init_toc_depth ()
756 {
757   if (exists($main::value{'short_toc'}) and not exists($main::value{'bigpage'})) {
758     $page_toc_depth = 1;
759   }
760 }
761 # Set the TOC-depth (depending on a texinfo variable short_toc) in a 
762 # command-handler, so we have them available when creating the pages
763 push @Texi2HTML::Config::command_handler_process, \&lilypond_init_toc_depth;
764
765
766 # recursively generate the TOC entries for the element and its children (which
767 # are only shown up to maxlevel. All ancestors of the current element are also
768 # shown with their immediate children, irrespective of their level.
769 # Unnumbered entries are only printed out if they are at top-level or 2nd level 
770 # or their parent element is an ancestor of the currently viewed node.
771 # The conditions to call this method to print the entry for a child node is:
772 # -) the parent is an ancestor of the current page node
773 # -) the parent is a numbered element at top-level toplevel (i.e. show numbered 
774 #    and unnumbered 2nd-level children of numbered nodes)
775 # -) the child element is a numbered node below level maxlevel
776 sub generate_ly_toc_entries($$$)
777 {
778   my $element = shift;
779   my $element_path = shift;
780   if ($web_manual) {
781     my $maxlevel = 1;
782   } else {
783     my $maxlevel = shift;
784   }
785   # Skip undefined sections, plus all sections generated by index splitting
786   return() if (not defined($element) or exists($element->{'index_page'}));
787   my @result = ();
788   my $level = $element->{'toc_level'};
789   my $is_parent_of_current = $element->{'id'} && $element_path->{$element->{'id'}};
790   my $ind = '  ' x $level;
791   my $this_css_class;
792   if ($web_manual) {
793     $this_css_class = " class=\"";
794   } else {
795     $this_css_class = "";
796   }
797   $this_css_class .= $is_parent_of_current ? " toc_current" : "";
798 # HORRIBLE HACK
799   my @color_1 = (
800         "Learning", "Glossary", "Essay",
801         "Contact", "Tiny examples", "Bug reports"
802         );
803   my @color_2 = (
804         "Features", "Examples", "Freedom", "Background",
805         "Unix", "MacOS X", "Windows",
806         "Notation", "Usage", "Snippets",
807         "Help us", "Development", "Authors"
808         );
809   my @color_3 = (
810         "Productions", "Testimonials",
811         "Source", "Old downloads",
812         "FAQ", "Changes", "Extend", "Internals",
813         "Publications", "Old news"
814         );
815   my @color_4 = (
816         "Text input", "Alternate input",
817         "GPL",
818         "Translated", "All", "FDL"
819         );
820
821   my $addColor = " colorDefault";
822   foreach $color (@color_1) {
823     if ($element->{'text'} eq $color) {
824       $addColor = " color1";
825     }
826   }
827   foreach $color (@color_2) {
828     if ($element->{'text'} eq $color) {
829       $addColor = " color2";
830     }
831   }
832   foreach $color (@color_3) {
833     if ($element->{'text'} eq $color) {
834       $addColor = " color3";
835     }
836   }
837   foreach $color (@color_4) {
838     if ($element->{'text'} eq $color) {
839       $addColor = " color4";
840     }
841   }
842
843   $this_css_class .= $addColor . "\"";
844
845
846   my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}",$element->{'text'});
847
848   push (@result, $entry);
849   my $children = $element->{'section_childs'};
850   if (defined($children) and (ref($children) eq "ARRAY")) {
851     my $force_children = $is_parent_of_current or ($level == 1 and $element->{'number'});
852     my @child_result = ();
853     foreach my $c (@$children) {
854       my $is_numbered_child = defined ($c->{'number'});
855       my $below_maxlevel = $c->{'toc_level'} le $maxlevel;
856       if ($force_children or ($is_numbered_child and $below_maxlevel)) {
857         my @child_res = generate_ly_toc_entries($c, $element_path, $maxlevel);
858         push (@child_result, @child_res);
859       }
860     }
861     # if no child nodes were generated, e.g. for the index, where expanded pages
862     # are ignored, don't generate a list at all...
863     if (@child_result) {
864       push (@result, "\n$ind<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
865       if ($web_manual) {
866         push (@result, "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}","(main)"));
867       } else {
868         push (@result, @child_result);
869       }
870       push (@result, "$ind</ul>\n");
871     }
872   }
873   push (@result, "$ind</li>\n");
874   return @result;
875 }
876
877
878 # Print a customized TOC, containing only the first two levels plus the whole
879 # path to the current page
880 sub lilypond_generate_page_toc_body($)
881 {
882     my $element = shift;
883     my $current_element = $element;
884     my %parentelements;
885     $parentelements{$element->{'id'}} = 1;
886     # Find the path to the current element
887     while ( defined($current_element->{'sectionup'}) and
888            ($current_element->{'sectionup'} ne $current_element) )
889     {
890       $parentelements{$current_element->{'sectionup'}->{'id'}} = 1
891               if ($current_element->{'sectionup'}->{'id'} ne '');
892       $current_element = $current_element->{'sectionup'};
893       if ($web_manual) {
894         if (exists($main::value{'shallow_toc'})) {
895           last;
896         }
897       }
898     }
899     return () if not defined($current_element);
900     # Create the toc entries recursively
901     my @toc_entries = "";
902     if ($web_manual) {
903         push (@toc_entries, "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
904         # FIXME: add link to main page, really hackily.
905         if ($element->{'sectionup'}) {
906             # it's not the top element
907             push (@toc_entries, "<li><a href=\"index.html\">Main</a></li>\n");
908         } else {
909             push (@toc_entries, "<li class=\"toc_current\"><a href=\"index.html\">Main</a></li>\n");
910         }
911     } else {
912         push (@toc_entries, "<div class=\"contents\">\n");
913         push (@toc_entries, "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
914     }
915     my $children = $current_element->{'section_childs'};
916     foreach ( @$children ) {
917       push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth));
918     }
919     # search box
920     if ($web_manual) {
921         # WTF, perl needs 6 lines of magic to do: ' ' + open ('file-name').read ()?
922         local $/=undef;
923         my $name = "search-box.html";
924         open FILE, "$ENV{SRC_DIR}/$name" or open FILE, "$ENV{SRC_DIR}/../$name" or die  die "no such file: $name: $!";
925
926         my $string = <FILE>;
927         $string =  "<li>\n" . $string . "</li>\n";
928         push (@toc_entries, $string);
929         close FILE;
930     }
931     push (@toc_entries, "</ul>\n");
932     push (@toc_entries, "</div>\n");
933     return @toc_entries;
934 }
935
936 sub lilypond_print_toc_div ($$)
937 {
938   my $fh = shift;
939   my $tocref = shift;
940   my @lines = @$tocref;
941   # use default TOC if no custom lines have been generated
942   @lines = @default_toc if (not @lines);
943   if (@lines) {
944   
945     print $fh "\n\n<div id=\"tocframe\">\n";
946     
947     # Remove the leading "GNU LilyPond --- " from the manual title
948     my $topname = $Texi2HTML::NAME{'Top'};
949     $topname =~ s/^GNU LilyPond(:| &[mn]dash;) //;
950     
951     # construct the top-level Docs index (relative path and including language!)
952     my $lang = $Texi2HTML::THISDOC{current_lang};
953     if ($lang and $lang ne "en") {
954       $lang .= ".";
955     } else {
956       $lang = "";
957     }
958     my $reldir = "";
959     $reldir = "../" if ($Texi2HTML::Config::SPLIT eq 'section');
960     my $uplink = $reldir."web/manuals.${lang}html";
961
962     if ($web_manual) {
963     } else {
964       print $fh "<p class=\"toc_uplink\"><a href=\"$uplink\" 
965          title=\"Documentation Index\">&lt;&lt; " .
966          &ly_get_string ('Back to Documentation Index') .
967          "</a></p>\n";
968
969       print $fh '<h4 class="toc_header"> ' . &$anchor('',
970                                     $Texi2HTML::HREF{'Top'},
971                                     $topname,
972                                     'title="Start of the manual"'
973                                    ) . "</h4>\n";
974     }
975
976     foreach my $line (@lines) {
977       print $fh $line;
978     }
979     print $fh "</div>\n\n";
980   }
981 }
982
983 # Create the custom TOC for this page (partially folded, current page is
984 # highlighted) and store it in a global variable. The TOC is written out after
985 # the html contents (but positioned correctly using CSS), so that browsers with
986 # css turned off still show the contents first.
987 our @this_page_toc = ();
988 sub lilypond_print_element_header
989 {
990   my $first_in_page = shift;
991   my $previous_is_top = shift;
992   if ($first_in_page and not @this_page_toc) {
993     if (defined($Texi2HTML::THIS_ELEMENT)) {
994       # Create the TOC for this page
995       @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
996     }
997   }
998   return &$default_print_element_header( $first_in_page, $previous_is_top);
999 }
1000
1001 # Generate the HTML output for the TOC
1002 sub lilypond_toc_body($)
1003 {
1004     my $elements_list = shift;
1005     # Generate a default TOC for pages without THIS_ELEMENT
1006     @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
1007     return &$default_toc_body($elements_list);
1008 }
1009
1010 # Print out the TOC in a <div> at the beginning of the page
1011 sub lilypond_print_page_head($)
1012 {
1013     my $fh = shift;
1014     &$default_print_page_head($fh);
1015     print $fh "<div id=\"main\">\n";
1016 }
1017
1018 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
1019 # sidebar mimicking a TOC frame
1020 sub print_lilypond_page_foot($)
1021 {
1022   my $fh = shift;
1023   my $program_string = &$program_string();
1024 #   print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
1025   print $fh "<!-- FOOTER -->\n\n";
1026   print $fh "<!-- end div#main here -->\n</div>\n\n";
1027
1028   if ($web_manual) {
1029     # FIXME: This div and p#languages need to be in div#footer.
1030     #        Should we move this div to postprocess_html.py ?
1031     print $fh "<div id=\"verifier_texinfo\">\n";
1032     print $fh "<h3>Validation</h3>\n";
1033     print $fh "<p>Thanks to <a href=\"http://www.webdev.nl/\">webdev.nl</a>";
1034     print $fh " for hosting <code>lilypond.org</code>.\n";
1035     print $fh "<a href=\"http://validator.w3.org/check?uri=referer\">\n";
1036     print $fh "<img src=\"http://www.w3.org/Icons/valid-html401\"\n";
1037     print $fh "     alt=\"Valid HTML 4.01 Transitional\"\n";
1038     print $fh "     height=\"31\" width=\"88\"></a></p>\n";
1039     print $fh "</div>";
1040   }
1041
1042   # Print the TOC frame and reset the TOC:
1043   lilypond_print_toc_div ($fh, \@this_page_toc);
1044   @this_page_toc = ();
1045
1046   # Close the page:
1047   print $fh "</body>\n</html>\n";
1048 }
1049
1050
1051
1052
1053
1054 #############################################################################
1055 ###  NICER / MORE FLEXIBLE NAVIGATION PANELS
1056 #############################################################################
1057
1058 sub get_navigation_text
1059 {
1060   my $button = shift;
1061   my $text = $NAVIGATION_TEXT{$button};
1062   if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
1063     $text = $text . $Texi2HTML::NODE{$button} . "&nbsp;";
1064   } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
1065     $text = "&nbsp;" . $Texi2HTML::NODE{$button} . $text;
1066   } elsif ( $button eq 'Up' ) {
1067     $text = "&nbsp;".$text.":&nbsp;" . $Texi2HTML::NODE{$button} . "&nbsp;";
1068   }
1069   return $text;
1070 }
1071
1072
1073 # Don't automatically create left-aligned table cells for every link, but
1074 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
1075 # button text. It's alignment as well as the colspan will be taken from the
1076 # name of the button. Also, add 'newline' button text to create a new table
1077 # row. The texts of the buttons are generated by get_navigation_text and
1078 # will contain the name of the next/previous section/chapter.
1079 sub lilypond_print_navigation
1080 {
1081     my $buttons = shift;
1082     my $vertical = shift;
1083     my $spacing = 1;
1084     my $result = "<table class=\"nav_table\">\n";
1085
1086     $result .= "<tr>" unless $vertical;
1087     my $beginofline = 1;
1088     foreach my $button (@$buttons)
1089     {
1090         $result .= qq{<tr valign="top" align="left">\n} if $vertical;
1091         # Allow (left|right|center)-aligned-cell and newline as buttons!
1092         if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
1093         {
1094           $result .= qq{</td>} unless $beginofline;
1095           $result .= qq{<td valign="middle" align="$1" colspan="$2">};
1096           $beginofline = 0;
1097         }
1098         elsif ( $button eq 'newline' )
1099         {
1100           $result .= qq{</td>} unless $beginofline;
1101           $result .= qq{</tr>};
1102           $result .= qq{<tr>};
1103           $beginofline = 1;
1104
1105         }
1106         elsif (ref($button) eq 'CODE')
1107         {
1108             $result .= &$button($vertical);
1109         }
1110         elsif (ref($button) eq 'SCALAR')
1111         {
1112             $result .= "$$button" if defined($$button);
1113         }
1114         elsif (ref($button) eq 'ARRAY')
1115         {
1116             my $text = $button->[1];
1117             my $button_href = $button->[0];
1118             # verify that $button_href is simple text and text is a reference
1119             if (defined($button_href) and !ref($button_href) 
1120                and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
1121             {             # use given text
1122                 if ($Texi2HTML::HREF{$button_href})
1123                 {
1124                   my $anchor_attributes = '';
1125                   if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
1126                   {
1127                       $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
1128                   }
1129                   if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
1130                   {
1131                       $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
1132                   }
1133                   $result .=  "" .
1134                         &$anchor('',
1135                                     $Texi2HTML::HREF{$button_href},
1136                                     get_navigation_text($$text),
1137                                     $anchor_attributes
1138                                    );
1139                 }
1140                 else
1141                 {
1142                   $result .=  get_navigation_text($$text);
1143                 }
1144             }
1145         }
1146         elsif ($button eq ' ')
1147         {                       # handle space button
1148             $result .= 
1149                 ($ICONS && $ACTIVE_ICONS{' '}) ?
1150                     &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
1151                         $NAVIGATION_TEXT{' '};
1152             #next;
1153         }
1154         elsif ($Texi2HTML::HREF{$button})
1155         {                       # button is active
1156             my $btitle = $BUTTONS_GOTO{$button} ?
1157                 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
1158             if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
1159             {
1160                 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
1161             }
1162             if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
1163             {
1164                 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
1165             }
1166             if ($ICONS && $ACTIVE_ICONS{$button})
1167             {                   # use icon
1168                 $result .= '' .
1169                     &$anchor('',
1170                         $Texi2HTML::HREF{$button},
1171                         &$button_icon_img($BUTTONS_NAME{$button},
1172                                    $ACTIVE_ICONS{$button},
1173                                    $Texi2HTML::SIMPLE_TEXT{$button}),
1174                         $btitle
1175                       );
1176             }
1177             else
1178             {                   # use text
1179                 $result .= 
1180                     '[' .
1181                         &$anchor('',
1182                                     $Texi2HTML::HREF{$button},
1183                                     get_navigation_text($button),
1184                                     $btitle
1185                                    ) .
1186                                        ']';
1187             }
1188         }
1189         else
1190         {                       # button is passive
1191             $result .= 
1192                 $ICONS && $PASSIVE_ICONS{$button} ?
1193                     &$button_icon_img($BUTTONS_NAME{$button},
1194                                           $PASSIVE_ICONS{$button},
1195                                           $Texi2HTML::SIMPLE_TEXT{$button}) :
1196
1197                                               "[" . get_navigation_text($button) . "]";
1198         }
1199         $result .= "</td>\n" if $vertical;
1200         $result .= "</tr>\n" if $vertical;
1201     }
1202     $result .= "</td>" unless $beginofline;
1203     $result .= "</tr>" unless $vertical;
1204     $result .= "</table>\n";
1205     if ($web_manual) {
1206       return "\n";
1207     } else {
1208       return $result;
1209     }
1210 }
1211
1212
1213 @Texi2HTML::Config::SECTION_BUTTONS =
1214     ('left-aligned-cell-1', 'FastBack',
1215      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1216      'right-aligned-cell-1', 'FastForward',
1217      'newline',
1218      'left-aligned-cell-2', 'Back',
1219      'center-aligned-cell-1', 'Up',
1220      'right-aligned-cell-2', 'Forward'
1221     );
1222
1223 # buttons for misc stuff
1224 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
1225
1226 # buttons for chapter file footers
1227 # (and headers but only if SECTION_NAVIGATION is false)
1228 @Texi2HTML::Config::CHAPTER_BUTTONS =
1229     ('left-aligned-cell-1', 'FastBack',
1230      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1231      'right-aligned-cell-1', 'FastForward',
1232     );
1233
1234 # buttons for section file footers
1235 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
1236     ('left-aligned-cell-1', 'FastBack',
1237      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1238      'right-aligned-cell-1', 'FastForward',
1239      'newline',
1240      'left-aligned-cell-2', 'Back',
1241      'center-aligned-cell-1', 'Up',
1242      'right-aligned-cell-2', 'Forward'
1243     );
1244
1245 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
1246     ('left-aligned-cell-1', 'FastBack',
1247      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1248      'right-aligned-cell-1', 'FastForward',
1249      'newline',
1250      'left-aligned-cell-2', 'Back',
1251      'center-aligned-cell-1', 'Up',
1252      'right-aligned-cell-2', 'Forward'
1253     );
1254
1255
1256
1257
1258
1259 #############################################################################
1260 ###  FOOTNOTE FORMATTING
1261 #############################################################################
1262
1263 # Format footnotes in a nicer way: Instead of printing the number in a separate
1264 # (nr) heading line, use the standard way of prepending <sup>nr</sup> immediately
1265 # before the fn text.
1266
1267
1268 # The following code is copied from texi2html's examples/makeinfo.init and
1269 # should be updated when texi2html makes some changes there!
1270
1271 my $makekinfo_like_footnote_absolute_number = 0;
1272
1273 sub makeinfo_like_foot_line_and_ref($$$$$$$$)
1274 {
1275     my $foot_num = shift;
1276     my $relative_num = shift;
1277     my $footid = shift;
1278     my $docid = shift;
1279     my $from_file = shift;
1280     my $footnote_file = shift;
1281     my $lines = shift;
1282     my $state = shift;
1283
1284     $makekinfo_like_footnote_absolute_number++;
1285
1286     # this is a bit obscure, this allows to add an anchor only if formatted
1287     # as part of the document.
1288     $docid = '' if ($state->{'outside_document'} or $state->{'multiple_pass'});
1289
1290     if ($from_file eq $footnote_file)
1291     {
1292         $from_file = $footnote_file = '';
1293     }
1294
1295     my $foot_anchor = "<sup>" . &$anchor($docid, "$footnote_file#$footid", $relative_num) . "</sup>";
1296     $foot_anchor = &$anchor($docid, "$footnote_file#$footid", "($relative_num)") if ($state->{'preformatted'});
1297
1298 #    unshift @$lines, "<li>";
1299 #    push @$lines, "</li>\n";
1300     return ($lines, $foot_anchor);
1301 }
1302
1303 sub makeinfo_like_foot_lines($)
1304 {
1305     my $lines = shift;
1306     unshift @$lines, "<hr>\n<h4>$Texi2HTML::I18n::WORDS->{'Footnotes_Title'}</h4>\n";
1307 #<ol type=\"1\">\n";
1308 #    push @$lines, "</ol>";
1309     return $lines;
1310 }
1311
1312 my %makekinfo_like_paragraph_in_footnote_nr;
1313
1314 sub makeinfo_like_paragraph ($$$$$$$$$$$$$)
1315 {
1316     my $text = shift;
1317     my $align = shift;
1318     my $indent = shift;
1319     my $paragraph_command = shift;
1320     my $paragraph_command_formatted = shift;
1321     my $paragraph_number = shift;
1322     my $format = shift;
1323     my $item_nr = shift;
1324     my $enumerate_style = shift;
1325     my $number = shift;
1326     my $command_stack_at_end = shift;
1327     my $command_stack_at_begin = shift;
1328     my $state = shift;
1329 #print STDERR "format: $format\n" if (defined($format));
1330 #print STDERR "paragraph @$command_stack_at_end; @$command_stack_at_begin\n";
1331     $paragraph_command_formatted = '' if (!defined($paragraph_command_formatted) or
1332           exists($special_list_commands{$format}->{$paragraph_command}));
1333     return '' if ($text =~ /^\s*$/);
1334     foreach my $style(t2h_collect_styles($command_stack_at_begin))
1335     {
1336        $text = t2h_begin_style($style, $text);
1337     }
1338     foreach my $style(t2h_collect_styles($command_stack_at_end))
1339     {
1340        $text = t2h_end_style($style, $text);
1341     }
1342     if (defined($paragraph_number) and defined($$paragraph_number))
1343     {
1344          $$paragraph_number++;
1345          return $text  if (($format eq 'itemize' or $format eq 'enumerate') and
1346             ($$paragraph_number == 1));
1347     }
1348     my $open = '<p';
1349     if ($align)
1350     {
1351         $open .= " align=\"$paragraph_style{$align}\"";
1352     }
1353     my $footnote_text = '';
1354     if (defined($command_stack_at_begin->[0]) and $command_stack_at_begin->[0] eq 'footnote')
1355     {
1356         my $state = $Texi2HTML::THISDOC{'state'};
1357         $makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number}++;
1358         if ($makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number} <= 1)
1359         {
1360            $open.=' class="footnote"';
1361            my $document_file = $state->{'footnote_document_file'};
1362            if ($document_file eq $state->{'footnote_footnote_file'})
1363            {
1364                $document_file = '';
1365            }
1366            my $docid = $state->{'footnote_place_id'};
1367            my $doc_state = $state->{'footnote_document_state'};
1368            $docid = '' if ($doc_state->{'outside_document'} or $doc_state->{'multiple_pass'});
1369            my $foot_label = &$anchor($state->{'footnote_footnote_id'},
1370                  $document_file . "#$state->{'footnote_place_id'}",
1371                  "$state->{'footnote_number_in_page'}");
1372            $footnote_text = "<small>[${foot_label}]</small> ";
1373         }
1374     }
1375     return $open.'>'.$footnote_text.$text.'</p>';
1376 }
1377
1378
1379 #############################################################################
1380 ###  OTHER SETTINGS
1381 #############################################################################
1382
1383 # For split pages, use index.html as start page!
1384 if ($Texi2HTML::Config::SPLIT eq 'section') {
1385   $Texi2HTML::Config::TOP_FILE = 'index.html';
1386 }
1387 if ($web_node) {
1388 } else {
1389   push @Texi2HTML::Config::command_handler_process, \&lilypond_init_toc_depth;
1390 }
1391
1392
1393 return 1;