2 # -*- coding: utf-8; -*-
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
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
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
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
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
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)
67 package Texi2HTML::Config;
70 use Encode qw(decode);
72 #############################################################################
74 #############################################################################
76 my $LY_LANGUAGES = {};
77 $LY_LANGUAGES->{'fr'} = {
78 'Back to Documentation Index' => 'Retour à l\'accueil de la documentation',
80 $LY_LANGUAGES->{'es'} = {
81 'Back to Documentation Index' => 'Volver al índice de la documentación',
83 $LY_LANGUAGES->{'de'} = {
84 'Back to Documentation Index' => 'Zur Dokumentationsübersicht',
86 $LY_LANGUAGES->{'ja'} = {
87 'Back to Documentation Index' => 'ドキュメント インデックスに戻る',
90 $LY_LANGUAGES->{'hu'} = {
91 'Back to Documentation Index' => 'Vissza a dokumentációk jegyzékéhez',
94 # FIXME: request translation and send it to texi2html/texinfo devs
95 $LANGUAGES->{'hu'} = $LANGUAGES->{'en'};
97 sub ly_get_string () {
98 my $lang = $Texi2HTML::THISDOC{current_lang};
100 if ($lang and $lang ne "en" and $LY_LANGUAGES->{$lang}->{$string}) {
101 return $LY_LANGUAGES->{$lang}->{$string};
108 #############################################################################
109 ### FUNCTIONALITY FOR MAIN WEB PAGES
110 #############################################################################
113 sub lilypond_init_web_manual ()
115 if (exists($main::value{'web_manual'}))
117 print STDERR "Initializing settings for web site\n";
122 push @Texi2HTML::Config::command_handler_process, \&lilypond_init_web_manual;
124 #############################################################################
125 ### SETTINGS FOR TEXI2HTML
126 #############################################################################
128 # Validation fix for texi2html<=1.82
129 $Texi2HTML::Config::DOCTYPE = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
133 @Texi2HTML::Config::CSS_REFS = (
134 {FILENAME => "lilypond-web.css", TITLE => "Default style"}
137 @Texi2HTML::Config::CSS_REFS = (
138 {FILENAME => "lilypond-mccarty.css", TITLE => "Patrick McCarty's design"}
142 @Texi2HTML::Config::ALT_CSS_REFS = (
143 {FILENAME => "lilypond.css", TITLE => "Andrew Hawryluk's design" },
144 {FILENAME => "lilypond-blue.css", TITLE => "Kurt Kroon's blue design" },
146 $Texi2HTML::Config::USE_ACCESSKEY = 1;
147 $Texi2HTML::Config::USE_LINKS = 1;
148 $Texi2HTML::Config::USE_REL_REV = 1;
149 $Texi2HTML::Config::SPLIT_INDEX = 0;
150 $Texi2HTML::Config::SEPARATED_FOOTNOTES = 0; # Print footnotes on same page, not separated
152 if ($Texi2HTML::Config::SPLIT eq 'section' or
153 $Texi2HTML::Config::SPLIT eq 'subsubsection') {
154 $Texi2HTML::Config::element_file_name = \&lilypond_element_file_name;
157 $Texi2HTML::Config::element_target_name = \&lilypond_element_target_name;
158 $default_print_element_header = $Texi2HTML::Config::print_element_header;
159 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
160 $Texi2HTML::Config::print_page_foot = \&print_lilypond_page_foot;
161 $Texi2HTML::Config::print_navigation = \&lilypond_print_navigation;
162 $Texi2HTML::Config::external_ref = \&lilypond_external_ref;
163 $default_external_href = $Texi2HTML::Config::external_href;
164 $Texi2HTML::Config::external_href = \&lilypond_external_href;
165 $default_toc_body = $Texi2HTML::Config::toc_body;
166 $Texi2HTML::Config::toc_body = \&lilypond_toc_body;
167 $Texi2HTML::Config::css_lines = \&lilypond_css_lines;
168 $default_unknown = $Texi2HTML::Config::unknown;
169 $Texi2HTML::Config::unknown = \&lilypond_unknown;
170 $default_print_page_head = $Texi2HTML::Config::print_page_head;
171 $Texi2HTML::Config::print_page_head = \&lilypond_print_page_head;
172 # $Texi2HTML::Config::foot_line_and_ref = \&lilypond_foot_line_and_ref;
173 $Texi2HTML::Config::foot_line_and_ref = \&makeinfo_like_foot_line_and_ref;
174 $Texi2HTML::Config::foot_lines = \&makeinfo_like_foot_lines;
175 $Texi2HTML::Config::paragraph = \&makeinfo_like_paragraph;
179 # Examples should be formatted similar to quotes:
180 $Texi2HTML::Config::complex_format_map->{'example'} = {
181 'begin' => q{"<blockquote>"},
182 'end' => q{"</blockquote>\n"},
186 %Texi2HTML::config::misc_pages_targets = (
187 'Overview' => 'Overview',
188 'Contents' => 'Contents',
193 my @section_to_filename;
198 #############################################################################
200 #############################################################################
203 $Data::Dumper::Maxdepth = 2;
205 sub print_element_info($)
208 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
209 print "Element: $element\n";
210 print Dumper($element);
217 #############################################################################
219 #############################################################################
221 # Convert a given node name to its proper file name (normalization as explained
222 # in the texinfo manual:
223 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
224 sub texinfo_file_name($)
228 # File name normalization by texinfo:
229 # 1/2: letters and numbers are left unchanged
230 # 3/4: multiple, leading and trailing whitespace is removed
231 $text = main::normalise_space($text);
232 # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
233 # chars are replaced by _xxxx (xxxx=ascii character code)
234 while ($text ne '') {
235 if ($text =~ s/^([A-Za-z0-9]+)//o) { # number or letter stay unchanged
237 } elsif ($text =~ s/^ //o) { # space -> '-'
239 } elsif ($text =~ s/^(.)//o) { # Otherwise use _xxxx (ascii char code)
241 if ( $ccode <= 0xFFFF ) {
242 $result .= sprintf("_%04x", $ccode);
244 $result .= sprintf("__%06x", $ccode);
248 # 7: if name does not begin with a letter, prepend 't_g' (so it starts with a letter)
249 if ($result !~ /^[a-zA-Z]/) {
250 $result = 't_g' . $result;
256 # Load a file containing a nodename<=>filename map (tab-sepatared, i.e.
257 # NODENAME\tFILENAME\tANCHOR
258 # Returns a ref to a hash "Node title" => ["FilenameWithoutExt", "Anchor"]
259 sub load_map_file ($)
264 # For some unknown reason, Perl on my system (5.10.0 on Fedora 12)
265 # refuses to open map files of translated documents with '<:encoding'
266 if (open(XREFFILE,'<', $mapfile)) {
268 while ( $line = decode ('UTF-8', <XREFFILE>) ) {
269 # parse the tab-separated entries and insert them into the map:
271 my @entries = split(/\t/, $line);
272 if (scalar (@entries) == 3) {
273 $node_map->{$entries[0]} = [$entries[1], $entries[2]];
275 print STDERR "Invalid entry in the node file $mapfile: $line\n";
278 # print STDERR %{$node_map};
281 print STDERR "WARNING: Unable to load the map file $mapfile\n";
287 # Split the given path into dir and basename (with .texi removed). Used mainly
288 # to get the path/basename of the original texi input file
289 sub split_texi_filename ($)
292 my ($docu_dir, $docu_name);
293 if ($docu =~ /(.*\/)/) {
294 chop($docu_dir = $1);
296 $docu_name =~ s/.*\///;
301 $docu_name =~ s/\.te?x(i|info)?$//;
302 return ($docu_dir, $docu_name);
309 #############################################################################
311 #############################################################################
313 # Include our standard CSS file, not hard-coded CSS code directly in the HTML!
314 # For IE, conditionally include the lilypond-ie-fixes.css style sheet
315 sub lilypond_css_lines ($$)
317 my $import_lines = shift;
318 my $rule_lines = shift;
319 return if (defined($Texi2HTML::THISDOC{'CSS_LINES'}));
320 if (@$rule_lines or @$import_lines)
322 $Texi2HTML::THISDOC{'CSS_LINES'} = "<style type=\"text/css\">\n<!--\n";
323 $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$import_lines) . "\n" if (@$import_lines);
324 $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$rule_lines) . "\n" if (@$rule_lines);
325 $Texi2HTML::THISDOC{'CSS_LINES'} .= "-->\n</style>\n";
327 foreach my $ref (@CSS_REFS)
329 $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"stylesheet\" type=\"text/css\" title=\"$ref->{TITLE}\" href=\"$ref->{FILENAME}\">\n";
331 foreach my $ref (@Texi2HTML::Config::ALT_CSS_REFS)
333 $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"$ref->{FILENAME}\" title=\"$ref->{TITLE}\">\n";
335 # FIXME: the website doesn't use ie7-specific fixes; do the
336 # docs still need this? -gp
337 $Texi2HTML::THISDOC{'CSS_LINES'} .= "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
344 #############################################################################
345 ### SPLITTING BASED ON NUMBERED SECTIONS
346 #############################################################################
350 my $node_to_filename_map = ();
353 # This function makes sure that files are only generated for numbered sections,
354 # but not for unnumbered ones. It is called after texi2html has done its own
355 # splitting and simply returns the filename for the node given as first argument
356 # Nodes with the same filename will be printed out to the same filename, so
357 # this really all we need. Also, make sure that the file names for sections
358 # are derived from the section title. We also might want to name the anchors
359 # according to node titles, which works by simply overriding the id element of
361 # If an external nodename<=>filename/anchor map file is found (loaded in
362 # the command handler, use the externally created values, otherwise use the
364 sub lilypond_element_file_name($$$)
368 my $docu_name = shift;
369 my $docu_ext = $Texi2HTML::Config::EXTENSION;
371 my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
372 # the snippets page does not use nodes for the snippets, so in this case
373 # we'll have to use the section name!
374 if ($node_name eq '') {
375 $node_name = main::remove_texi($element->{'texi'});
378 # If we have an entry in the section<=>filename map, use that one, otherwise
379 # generate the filename/anchor here. In the latter case, external manuals
380 # will not be able to retrieve the file name for xrefs!!! Still, I already
381 # had that code, so I'll leave it in in case something goes wrong with the
382 # extract_texi_filenames.py script in the lilypond build process!
383 if (exists ($node_to_filename_map->{$node_name})) {
384 (my $filename, my $anchor) = @{$node_to_filename_map->{$node_name}};
385 $filename .= ".$docu_ext" if (defined($docu_ext));
387 # unnumbered sections (except those at top-level!) always go to the same
388 # file as the previous numbered section
389 if (not ($element->{number}) and not ($lastfilename eq '') and ($element->{level} > 1)) {
390 $filename = $lastfilename;
392 if (($filename eq $lastfilename)) {
393 $$element{doc_nr} = $docnr;
396 $$element{doc_nr} = $docnr;
397 $lastfilename = $filename;
399 # print STDERR "File name: $filename\n";
400 return lc($filename);
402 } elsif ($type eq "top" or $type eq "toc" or $type eq "doc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
405 print STDERR "WARNING: Node '$node_name' was NOT found in the map\n"
406 unless ($node_name eq '') or ($element->{'tag'} eq 'unnumberedsec')
407 or ($node_name =~ /NOT REALLY USED/);
409 # Numbered sections will get a filename Node_title, unnumbered sections will use
410 # the file name of the previous numbered section:
411 if (($element->{number}) or ($lastfilename eq '') or ($element->{level} == 1)) {
412 # normalize to the same file name as texinfo
413 if ($element->{translationof}) {
414 $node_name = main::remove_texi($element->{translationof});
416 my $filename = texinfo_file_name($node_name);
417 $filename .= ".$docu_ext" if (defined($docu_ext));
419 $$element{doc_nr} = $docnr;
420 $lastfilename = $filename;
421 print STDERR "File name: $filename\n";
422 return lc($filename);
424 $$element{doc_nr} = $docnr;
425 print STDERR "File name: $filename\n";
426 return lc($filename);
433 sub lilypond_element_target_name($$$)
438 # Target is based on node name (or sec name for secs without node attached)
439 my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
440 if ($node_name eq '') {
441 $node_name = main::remove_texi($element->{'texi'});
444 # If we have an entry in the section<=>filename map, use that one, otherwise
445 # generate the anchor here.
446 if (exists ($node_to_filename_map->{$node_name})) {
447 (my $filename, $target) = @{$node_to_filename_map->{$node_name}};
449 my $anchor = $node_name;
450 if ($element->{translationof}) {
451 $anchor = main::remove_texi($element->{translationof});
453 # normalize to the same file name as texinfo
454 $target = texinfo_file_name($anchor);
456 # TODO: Once texi2html correctly prints out the target and not the id for
457 # the sections, change this back to ($id, $target)
458 $target = lc($target);
459 return ($target, $target);
463 ## Load the map file for the corrently processed texi file. We do this
464 # using a command init handler, since texi2html does not have any
465 # other hooks that are called after THISDOC is filled but before phase 2
466 # of the texi2html conversion.
467 sub lilypond_init_map ()
469 my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
470 my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
471 || main::locate_include_file ("${docu_name}.xref-map");
472 print STDERR "Map filename is: $map_filename\nDocu name is $docu_name\n";
473 $node_to_filename_map = load_map_file ($map_filename);
475 push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map;
479 #############################################################################
480 ### CLEANER LINK TITLE FOR EXTERNAL REFS
481 #############################################################################
483 # The default formatting of external refs returns e.g.
484 # "(lilypond-internals)Timing_translator", so we remove all (...) from the
485 # file_and_node argument. Also, we want only a very simple format, so we don't
486 # even call the default handler!
487 sub lilypond_external_ref($$$$$$)
492 my $file_node = shift;
493 my $href = lc(shift);
494 my $cross_ref = shift;
496 my $displaytext = '';
498 # 1) if we have a cross ref name, that's the text to be displayed:
499 # 2) For the top node, use the (printable) name of the manual, unless we
500 # have an explicit cross ref name
501 # 3) In all other cases use the section name
502 if ($cross_ref ne '') {
503 $displaytext = $cross_ref;
504 } elsif (($section eq '') or ($section eq 'Top')) {
505 $displaytext = $book;
507 $displaytext = $section;
510 $displaytext = &$anchor('', $href, $displaytext) if ($displaytext ne '');
511 return &$I('%{node_file_href}', { 'node_file_href' => $displaytext });
518 #############################################################################
519 ### HANDLING TRANSLATED SECTIONS: handle @translationof, secname<->filename
520 ### map stored on disk, xrefs in other manuals load that map
521 #############################################################################
524 # Try to make use of @translationof to generate files according to the original
525 # English section title...
526 sub lilypond_unknown($$$$$)
534 # the @translationof macro provides the original English section title,
535 # which should be used for file/anchor naming, while the title will be
536 # translated to each language
537 # It is already used by extract_texi_filenames.py, so this should not be
538 # necessary here at all. Still, I'll leave the code in just in case the
539 # python script messed up ;-)
540 if ($pass == 1 and $macro eq "translationof") {
541 if (ref($state->{'element'}) eq 'HASH') {
542 $state->{'element'}->{'translationof'} = main::normalise_space($line);
544 return ('', 1, undef, undef);
546 return &$default_unknown($macro, $line, $pass, $stack, $state);
553 my %translated_books = ();
554 # Construct a href to an external source of information.
555 # node is the node with texinfo @-commands
556 # node_id is the node transliterated and transformed as explained in the
558 # node_xhtml_id is the node transformed such that it is unique and can
559 # be used to make an html cross ref as explained in the texinfo manual
560 # file is the file in '(file)node'
561 sub lilypond_external_href($$$)
565 my $node_hxmlt_id = shift;
568 # 1) Keep a hash of book->section_map
569 # 2) if not file in keys hash => try to load the map (assign empty map if
570 # non-existent => will load only once!)
571 # 3) if node in the section=>(file, anchor) map, replace node_id and
572 # node_xhtml_id by the map's values
573 # 4) call the default_external_href with these values (or the old ones if not found)
575 if (($node_id ne '') and defined($file) and ($node_id ne 'Top')) {
576 my $map_name = $file;
577 $map_name =~ s/-big-page//;
579 # Load the map if we haven't done so already
580 if (!exists($translated_books{$map_name})) {
581 my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
582 my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
583 || main::locate_include_file ("${map_name}.xref-map");
584 $translated_books{$map_name} = load_map_file ($map_filename);
587 # look up translation. use these values instead of the old filename/anchor
588 my $section_name_map = $translated_books{$map_name};
589 my $node_text = main::remove_texi($node);
590 if (defined($section_name_map->{$node_text})) {
591 ($node_id, $node_hxmlt_id) = @{$section_name_map->{$node_text}};
593 print STDERR "WARNING: Unable to find node '$node_text' in book $map_name.\n";
598 return &$default_external_href($node, $node_id, $node_hxmlt_id, lc($file));
600 return &$default_external_href($node, $node_id, $node_hxmlt_id);
608 #############################################################################
609 ### CUSTOM TOC FOR EACH PAGE (in a frame on the left)
610 #############################################################################
612 my $page_toc_depth = 2;
613 my @default_toc = [];
615 # Initialize the toc_depth to 1 if the command-line option -D=short_toc is given
616 sub lilypond_init_toc_depth ()
618 if (exists($main::value{'short_toc'}) and not exists($main::value{'bigpage'})) {
622 # Set the TOC-depth (depending on a texinfo variable short_toc) in a
623 # command-handler, so we have them available when creating the pages
624 push @Texi2HTML::Config::command_handler_process, \&lilypond_init_toc_depth;
627 # recursively generate the TOC entries for the element and its children (which
628 # are only shown up to maxlevel. All ancestors of the current element are also
629 # shown with their immediate children, irrespective of their level.
630 # Unnumbered entries are only printed out if they are at top-level or 2nd level
631 # or their parent element is an ancestor of the currently viewed node.
632 # The conditions to call this method to print the entry for a child node is:
633 # -) the parent is an ancestor of the current page node
634 # -) the parent is a numbered element at top-level toplevel (i.e. show numbered
635 # and unnumbered 2nd-level children of numbered nodes)
636 # -) the child element is a numbered node below level maxlevel
637 sub generate_ly_toc_entries($$$)
640 my $element_path = shift;
644 my $maxlevel = shift;
646 # Skip undefined sections, plus all sections generated by index splitting
647 return() if (not defined($element) or exists($element->{'index_page'}));
649 my $level = $element->{'toc_level'};
650 my $is_parent_of_current = $element->{'id'} && $element_path->{$element->{'id'}};
651 my $ind = ' ' x $level;
654 $this_css_class = " class=\"";
656 $this_css_class = "";
658 $this_css_class .= $is_parent_of_current ? " toc_current" : "";
661 "Learning", "Glossary", "Essay",
662 "Contact", "Tiny examples", "Bug reports"
665 "Features", "Examples", "Freedom", "Background",
666 "Unix", "MacOS X", "Windows",
667 "Notation", "Usage", "Snippets",
668 "Help us", "Development", "Authors"
671 "Productions", "Testimonials",
672 "Source", "Old downloads",
673 "FAQ", "Changes", "Extend", "Internals",
674 "Publications", "Old news"
677 "Text input", "Alternate input",
679 "Translated", "All", "FDL"
682 my $addColor = " colorDefault";
683 foreach $color (@color_1) {
684 if ($element->{'text'} eq $color) {
685 $addColor = " color1";
688 foreach $color (@color_2) {
689 if ($element->{'text'} eq $color) {
690 $addColor = " color2";
693 foreach $color (@color_3) {
694 if ($element->{'text'} eq $color) {
695 $addColor = " color3";
698 foreach $color (@color_4) {
699 if ($element->{'text'} eq $color) {
700 $addColor = " color4";
704 $this_css_class .= $addColor . "\"";
707 my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}",$element->{'text'});
709 push (@result, $entry);
710 my $children = $element->{'section_childs'};
711 if (defined($children) and (ref($children) eq "ARRAY")) {
712 my $force_children = $is_parent_of_current or ($level == 1 and $element->{'number'});
713 my @child_result = ();
714 foreach my $c (@$children) {
715 my $is_numbered_child = defined ($c->{'number'});
716 my $below_maxlevel = $c->{'toc_level'} le $maxlevel;
717 if ($force_children or ($is_numbered_child and $below_maxlevel)) {
718 my @child_res = generate_ly_toc_entries($c, $element_path, $maxlevel);
719 push (@child_result, @child_res);
722 # if no child nodes were generated, e.g. for the index, where expanded pages
723 # are ignored, don't generate a list at all...
725 push (@result, "\n$ind<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
727 push (@result, "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}","(main)"));
729 push (@result, @child_result);
731 push (@result, "$ind</ul>\n");
734 push (@result, "$ind</li>\n");
739 # Print a customized TOC, containing only the first two levels plus the whole
740 # path to the current page
741 sub lilypond_generate_page_toc_body($)
744 my $current_element = $element;
746 $parentelements{$element->{'id'}} = 1;
747 # Find the path to the current element
748 while ( defined($current_element->{'sectionup'}) and
749 ($current_element->{'sectionup'} ne $current_element) )
751 $parentelements{$current_element->{'sectionup'}->{'id'}} = 1
752 if ($current_element->{'sectionup'}->{'id'} ne '');
753 $current_element = $current_element->{'sectionup'};
755 if (exists($main::value{'shallow_toc'})) {
760 return () if not defined($current_element);
761 # Create the toc entries recursively
762 my @toc_entries = "";
764 push (@toc_entries, "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
765 # FIXME: add link to main page, really hackily.
766 if ($element->{'sectionup'}) {
767 # it's not the top element
768 push (@toc_entries, "<li><a href=\"index.html\">Main</a></li>\n");
770 push (@toc_entries, "<li class=\"toc_current\"><a href=\"index.html\">Main</a></li>\n");
773 push (@toc_entries, "<div class=\"contents\">\n");
774 push (@toc_entries, "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
776 my $children = $current_element->{'section_childs'};
777 foreach ( @$children ) {
778 push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth));
782 # WTF, perl needs 6 lines of magic to do: ' ' + open ('file-name').read ()?
784 my $name = "search-box.html";
785 open FILE, "$ENV{SRC_DIR}/$name" or open FILE, "$ENV{SRC_DIR}/../$name" or die die "no such file: $name: $!";
788 $string = "<li>\n" . $string . "</li>\n";
789 push (@toc_entries, $string);
792 push (@toc_entries, "</ul>\n");
793 push (@toc_entries, "</div>\n");
797 sub lilypond_print_toc_div ($$)
801 my @lines = @$tocref;
802 # use default TOC if no custom lines have been generated
803 @lines = @default_toc if (not @lines);
806 print $fh "\n\n<div id=\"tocframe\">\n";
808 # Remove the leading "GNU LilyPond --- " from the manual title
809 my $topname = $Texi2HTML::NAME{'Top'};
810 $topname =~ s/^GNU LilyPond(:| &[mn]dash;) //;
812 # construct the top-level Docs index (relative path and including language!)
813 my $lang = $Texi2HTML::THISDOC{current_lang};
814 if ($lang and $lang ne "en") {
820 $reldir = "../" if ($Texi2HTML::Config::SPLIT eq 'section');
821 my $uplink = $reldir."web/manuals.${lang}html";
825 print $fh "<p class=\"toc_uplink\"><a href=\"$uplink\"
826 title=\"Documentation Index\"><< " .
827 &ly_get_string ('Back to Documentation Index') .
830 print $fh '<h4 class="toc_header"> ' . &$anchor('',
831 $Texi2HTML::HREF{'Top'},
833 'title="Start of the manual"'
837 foreach my $line (@lines) {
840 print $fh "</div>\n\n";
844 # Create the custom TOC for this page (partially folded, current page is
845 # highlighted) and store it in a global variable. The TOC is written out after
846 # the html contents (but positioned correctly using CSS), so that browsers with
847 # css turned off still show the contents first.
848 our @this_page_toc = ();
849 sub lilypond_print_element_header
851 my $first_in_page = shift;
852 my $previous_is_top = shift;
853 if ($first_in_page and not @this_page_toc) {
854 if (defined($Texi2HTML::THIS_ELEMENT)) {
855 # Create the TOC for this page
856 @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
859 return &$default_print_element_header( $first_in_page, $previous_is_top);
862 # Generate the HTML output for the TOC
863 sub lilypond_toc_body($)
865 my $elements_list = shift;
866 # Generate a default TOC for pages without THIS_ELEMENT
867 @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
868 return &$default_toc_body($elements_list);
871 # Print out the TOC in a <div> at the beginning of the page
872 sub lilypond_print_page_head($)
875 &$default_print_page_head($fh);
876 print $fh "<div id=\"main\">\n";
879 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
880 # sidebar mimicking a TOC frame
881 sub print_lilypond_page_foot($)
884 my $program_string = &$program_string();
885 # print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
886 print $fh "<!-- FOOTER -->\n\n";
887 print $fh "<!-- end div#main here -->\n</div>\n\n";
890 # FIXME: This div and p#languages need to be in div#footer.
891 # Should we move this div to postprocess_html.py ?
892 print $fh "<div id=\"verifier_texinfo\">\n";
893 print $fh "<h3>Validation</h3>\n";
894 print $fh "<p>Thanks to <a href=\"http://www.webdev.nl/\">webdev.nl</a>";
895 print $fh " for hosting <code>lilypond.org</code>.\n";
896 print $fh "<a href=\"http://validator.w3.org/check?uri=referer\">\n";
897 print $fh "<img src=\"http://www.w3.org/Icons/valid-html401\"\n";
898 print $fh " alt=\"Valid HTML 4.01 Transitional\"\n";
899 print $fh " height=\"31\" width=\"88\"></a></p>\n";
903 # Print the TOC frame and reset the TOC:
904 lilypond_print_toc_div ($fh, \@this_page_toc);
908 print $fh "</body>\n</html>\n";
915 #############################################################################
916 ### NICER / MORE FLEXIBLE NAVIGATION PANELS
917 #############################################################################
919 sub get_navigation_text
922 my $text = $NAVIGATION_TEXT{$button};
923 if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
924 $text = $text . $Texi2HTML::NODE{$button} . " ";
925 } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
926 $text = " " . $Texi2HTML::NODE{$button} . $text;
927 } elsif ( $button eq 'Up' ) {
928 $text = " ".$text.": " . $Texi2HTML::NODE{$button} . " ";
934 # Don't automatically create left-aligned table cells for every link, but
935 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
936 # button text. It's alignment as well as the colspan will be taken from the
937 # name of the button. Also, add 'newline' button text to create a new table
938 # row. The texts of the buttons are generated by get_navigation_text and
939 # will contain the name of the next/previous section/chapter.
940 sub lilypond_print_navigation
943 my $vertical = shift;
945 my $result = "<table class=\"nav_table\">\n";
947 $result .= "<tr>" unless $vertical;
949 foreach my $button (@$buttons)
951 $result .= qq{<tr valign="top" align="left">\n} if $vertical;
952 # Allow (left|right|center)-aligned-cell and newline as buttons!
953 if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
955 $result .= qq{</td>} unless $beginofline;
956 $result .= qq{<td valign="middle" align="$1" colspan="$2">};
959 elsif ( $button eq 'newline' )
961 $result .= qq{</td>} unless $beginofline;
962 $result .= qq{</tr>};
967 elsif (ref($button) eq 'CODE')
969 $result .= &$button($vertical);
971 elsif (ref($button) eq 'SCALAR')
973 $result .= "$$button" if defined($$button);
975 elsif (ref($button) eq 'ARRAY')
977 my $text = $button->[1];
978 my $button_href = $button->[0];
979 # verify that $button_href is simple text and text is a reference
980 if (defined($button_href) and !ref($button_href)
981 and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
983 if ($Texi2HTML::HREF{$button_href})
985 my $anchor_attributes = '';
986 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
988 $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
990 if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
992 $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
996 $Texi2HTML::HREF{$button_href},
997 get_navigation_text($$text),
1003 $result .= get_navigation_text($$text);
1007 elsif ($button eq ' ')
1008 { # handle space button
1010 ($ICONS && $ACTIVE_ICONS{' '}) ?
1011 &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
1012 $NAVIGATION_TEXT{' '};
1015 elsif ($Texi2HTML::HREF{$button})
1016 { # button is active
1017 my $btitle = $BUTTONS_GOTO{$button} ?
1018 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
1019 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
1021 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
1023 if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
1025 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
1027 if ($ICONS && $ACTIVE_ICONS{$button})
1031 $Texi2HTML::HREF{$button},
1032 &$button_icon_img($BUTTONS_NAME{$button},
1033 $ACTIVE_ICONS{$button},
1034 $Texi2HTML::SIMPLE_TEXT{$button}),
1043 $Texi2HTML::HREF{$button},
1044 get_navigation_text($button),
1051 { # button is passive
1053 $ICONS && $PASSIVE_ICONS{$button} ?
1054 &$button_icon_img($BUTTONS_NAME{$button},
1055 $PASSIVE_ICONS{$button},
1056 $Texi2HTML::SIMPLE_TEXT{$button}) :
1058 "[" . get_navigation_text($button) . "]";
1060 $result .= "</td>\n" if $vertical;
1061 $result .= "</tr>\n" if $vertical;
1063 $result .= "</td>" unless $beginofline;
1064 $result .= "</tr>" unless $vertical;
1065 $result .= "</table>\n";
1074 @Texi2HTML::Config::SECTION_BUTTONS =
1075 ('left-aligned-cell-1', 'FastBack',
1076 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1077 'right-aligned-cell-1', 'FastForward',
1079 'left-aligned-cell-2', 'Back',
1080 'center-aligned-cell-1', 'Up',
1081 'right-aligned-cell-2', 'Forward'
1084 # buttons for misc stuff
1085 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
1087 # buttons for chapter file footers
1088 # (and headers but only if SECTION_NAVIGATION is false)
1089 @Texi2HTML::Config::CHAPTER_BUTTONS =
1090 ('left-aligned-cell-1', 'FastBack',
1091 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1092 'right-aligned-cell-1', 'FastForward',
1095 # buttons for section file footers
1096 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
1097 ('left-aligned-cell-1', 'FastBack',
1098 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1099 'right-aligned-cell-1', 'FastForward',
1101 'left-aligned-cell-2', 'Back',
1102 'center-aligned-cell-1', 'Up',
1103 'right-aligned-cell-2', 'Forward'
1106 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
1107 ('left-aligned-cell-1', 'FastBack',
1108 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1109 'right-aligned-cell-1', 'FastForward',
1111 'left-aligned-cell-2', 'Back',
1112 'center-aligned-cell-1', 'Up',
1113 'right-aligned-cell-2', 'Forward'
1120 #############################################################################
1121 ### FOOTNOTE FORMATTING
1122 #############################################################################
1124 # Format footnotes in a nicer way: Instead of printing the number in a separate
1125 # (nr) heading line, use the standard way of prepending <sup>nr</sup> immediately
1126 # before the fn text.
1129 # The following code is copied from texi2html's examples/makeinfo.init and
1130 # should be updated when texi2html makes some changes there!
1132 my $makekinfo_like_footnote_absolute_number = 0;
1134 sub makeinfo_like_foot_line_and_ref($$$$$$$$)
1136 my $foot_num = shift;
1137 my $relative_num = shift;
1140 my $from_file = shift;
1141 my $footnote_file = shift;
1145 $makekinfo_like_footnote_absolute_number++;
1147 # this is a bit obscure, this allows to add an anchor only if formatted
1148 # as part of the document.
1149 $docid = '' if ($state->{'outside_document'} or $state->{'multiple_pass'});
1151 if ($from_file eq $footnote_file)
1153 $from_file = $footnote_file = '';
1156 my $foot_anchor = "<sup>" . &$anchor($docid, "$footnote_file#$footid", $relative_num) . "</sup>";
1157 $foot_anchor = &$anchor($docid, "$footnote_file#$footid", "($relative_num)") if ($state->{'preformatted'});
1159 # unshift @$lines, "<li>";
1160 # push @$lines, "</li>\n";
1161 return ($lines, $foot_anchor);
1164 sub makeinfo_like_foot_lines($)
1167 unshift @$lines, "<hr>\n<h4>$Texi2HTML::I18n::WORDS->{'Footnotes_Title'}</h4>\n";
1168 #<ol type=\"1\">\n";
1169 # push @$lines, "</ol>";
1173 my %makekinfo_like_paragraph_in_footnote_nr;
1175 sub makeinfo_like_paragraph ($$$$$$$$$$$$$)
1180 my $paragraph_command = shift;
1181 my $paragraph_command_formatted = shift;
1182 my $paragraph_number = shift;
1184 my $item_nr = shift;
1185 my $enumerate_style = shift;
1187 my $command_stack_at_end = shift;
1188 my $command_stack_at_begin = shift;
1190 #print STDERR "format: $format\n" if (defined($format));
1191 #print STDERR "paragraph @$command_stack_at_end; @$command_stack_at_begin\n";
1192 $paragraph_command_formatted = '' if (!defined($paragraph_command_formatted) or
1193 exists($special_list_commands{$format}->{$paragraph_command}));
1194 return '' if ($text =~ /^\s*$/);
1195 foreach my $style(t2h_collect_styles($command_stack_at_begin))
1197 $text = t2h_begin_style($style, $text);
1199 foreach my $style(t2h_collect_styles($command_stack_at_end))
1201 $text = t2h_end_style($style, $text);
1203 if (defined($paragraph_number) and defined($$paragraph_number))
1205 $$paragraph_number++;
1206 return $text if (($format eq 'itemize' or $format eq 'enumerate') and
1207 ($$paragraph_number == 1));
1212 $open .= " align=\"$paragraph_style{$align}\"";
1214 my $footnote_text = '';
1215 if (defined($command_stack_at_begin->[0]) and $command_stack_at_begin->[0] eq 'footnote')
1217 my $state = $Texi2HTML::THISDOC{'state'};
1218 $makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number}++;
1219 if ($makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number} <= 1)
1221 $open.=' class="footnote"';
1222 my $document_file = $state->{'footnote_document_file'};
1223 if ($document_file eq $state->{'footnote_footnote_file'})
1225 $document_file = '';
1227 my $docid = $state->{'footnote_place_id'};
1228 my $doc_state = $state->{'footnote_document_state'};
1229 $docid = '' if ($doc_state->{'outside_document'} or $doc_state->{'multiple_pass'});
1230 my $foot_label = &$anchor($state->{'footnote_footnote_id'},
1231 $document_file . "#$state->{'footnote_place_id'}",
1232 "$state->{'footnote_number_in_page'}");
1233 $footnote_text = "<small>[${foot_label}]</small> ";
1236 return $open.'>'.$footnote_text.$text.'</p>';
1240 #############################################################################
1242 #############################################################################
1244 # For split pages, use index.html as start page!
1245 if ($Texi2HTML::Config::SPLIT eq 'section') {
1246 $Texi2HTML::Config::TOP_FILE = 'index.html';
1250 push @Texi2HTML::Config::command_handler_process, \&lilypond_init_toc_depth;