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