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;
69 #############################################################################
71 #############################################################################
74 my $LY_LANGUAGES = {};
75 $LY_LANGUAGES->{'fr'} = {
76 'Back to Documentation Index' => 'Retour à l\'accueil de la documentation',
78 $LY_LANGUAGES->{'es'} = {
79 'Back to Documentation Index' => 'Volver al índice de la documentación',
81 $LY_LANGUAGES->{'de'} = {
82 'Back to Documentation Index' => 'Zur Dokumentationsübersicht',
86 sub ly_get_string () {
87 my $lang = $Texi2HTML::THISDOC{current_lang};
89 if ($lang and $lang ne "en" and $LY_LANGUAGES->{$lang}->{$string}) {
90 return $LY_LANGUAGES->{$lang}->{$string};
97 #############################################################################
98 ### SETTINGS FOR TEXI2HTML
99 #############################################################################
101 @Texi2HTML::Config::CSS_REFS = (
102 {FILENAME => "lilypond-mccarty.css", TITLE => "Patrick McCarty's design"}
104 @Texi2HTML::Config::ALT_CSS_REFS = (
105 {FILENAME => "lilypond.css", TITLE => "Andrew Hawryluk's design" },
106 {FILENAME => "lilypond-blue.css", TITLE => "Kurt Kroon's blue design" },
108 $Texi2HTML::Config::USE_ACCESSKEY = 1;
109 $Texi2HTML::Config::USE_LINKS = 1;
110 $Texi2HTML::Config::USE_REL_REV = 1;
111 $Texi2HTML::Config::SPLIT_INDEX = 0;
112 $Texi2HTML::Config::SEPARATED_FOOTNOTES = 0; # Print footnotes on same page, not separated
113 if ($Texi2HTML::Config::SPLIT eq 'section') {
114 $Texi2HTML::Config::element_file_name = \&lilypond_element_file_name;
116 $Texi2HTML::Config::element_target_name = \&lilypond_element_target_name;
117 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
118 $Texi2HTML::Config::print_page_foot = \&print_lilypond_page_foot;
119 $Texi2HTML::Config::print_navigation = \&lilypond_print_navigation;
120 $Texi2HTML::Config::external_ref = \&lilypond_external_ref;
121 $Texi2HTML::Config::external_href = \&lilypond_external_href;
122 $Texi2HTML::Config::toc_body = \&lilypond_toc_body;
123 $Texi2HTML::Config::css_lines = \&lilypond_css_lines;
124 $Texi2HTML::Config::unknown = \&lilypond_unknown;
125 $Texi2HTML::Config::print_page_head = \&lilypond_print_page_head;
126 # $Texi2HTML::Config::foot_line_and_ref = \&lilypond_foot_line_and_ref;
127 $Texi2HTML::Config::foot_line_and_ref = \&makeinfo_like_foot_line_and_ref;
128 $Texi2HTML::Config::foot_lines = \&makeinfo_like_foot_lines;
129 $Texi2HTML::Config::paragraph = \&makeinfo_like_paragraph;
133 # Examples should be formatted similar to quotes:
134 $Texi2HTML::Config::complex_format_map->{'example'} = {
135 'begin' => q{"<blockquote><pre class=\"example\">"},
136 'end' => q{"</pre></blockquote>\n"},
140 %Texi2HTML::config::misc_pages_targets = (
141 'Overview' => 'Overview',
142 'Contents' => 'Contents',
147 my @section_to_filename;
152 #############################################################################
154 #############################################################################
157 $Data::Dumper::Maxdepth = 2;
159 sub print_element_info($)
162 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
163 print "Element: $element\n";
164 print Dumper($element);
171 #############################################################################
173 #############################################################################
175 # Convert a given node name to its proper file name (normalization as explained
176 # in the texinfo manual:
177 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
178 sub texinfo_file_name($)
182 # File name normalization by texinfo:
183 # 1/2: letters and numbers are left unchanged
184 # 3/4: multiple, leading and trailing whitespace is removed
185 $text = main::normalise_space($text);
186 # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
187 # chars are replaced by _xxxx (xxxx=ascii character code)
188 while ($text ne '') {
189 if ($text =~ s/^([A-Za-z0-9]+)//o) { # number or letter stay unchanged
191 } elsif ($text =~ s/^ //o) { # space -> '-'
193 } elsif ($text =~ s/^(.)//o) { # Otherwise use _xxxx (ascii char code)
195 if ( $ccode <= 0xFFFF ) {
196 $result .= sprintf("_%04x", $ccode);
198 $result .= sprintf("__%06x", $ccode);
202 # 7: if name does not begin with a letter, prepend 't_g' (so it starts with a letter)
203 if ($result !~ /^[a-zA-Z]/) {
204 $result = 't_g' . $result;
211 # Load a file containing a nodename<=>filename map (tab-sepatared, i.e.
212 # NODENAME\tFILENAME\tANCHOR
213 # Returns a ref to a hash "Node title" => ["FilenameWithoutExt", "Anchor"]
214 sub load_map_file ($)
219 if (open(XREFFILE, $mapfile)) {
221 while ( $line = <XREFFILE> ) {
222 # parse the tab-separated entries and insert them into the map:
224 my @entries = split(/\t/, $line);
225 if (scalar (@entries) == 3) {
226 $node_map->{$entries[0]} = [$entries[1], $entries[2]];
228 print STDERR "Invalid entry in the node file $mapfile: $line\n";
233 print STDERR "WARNING: Unable to load the map file $mapfile\n";
239 # Split the given path into dir and basename (with .texi removed). Used mainly
240 # to get the path/basename of the original texi input file
241 sub split_texi_filename ($)
244 my ($docu_dir, $docu_name);
245 if ($docu =~ /(.*\/)/) {
246 chop($docu_dir = $1);
248 $docu_name =~ s/.*\///;
253 $docu_name =~ s/\.te?x(i|info)?$//;
254 return ($docu_dir, $docu_name);
261 #############################################################################
263 #############################################################################
265 # Include our standard CSS file, not hard-coded CSS code directly in the HTML!
266 # For IE, conditionally include the lilypond-ie-fixes.css style sheet
267 sub lilypond_css_lines ($$)
269 my $import_lines = shift;
270 my $rule_lines = shift;
271 return if (defined($Texi2HTML::THISDOC{'CSS_LINES'}));
272 if (@$rule_lines or @$import_lines)
274 $Texi2HTML::THISDOC{'CSS_LINES'} = "<style type=\"text/css\">\n<!--\n";
275 $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$import_lines) . "\n" if (@$import_lines);
276 $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$rule_lines) . "\n" if (@$rule_lines);
277 $Texi2HTML::THISDOC{'CSS_LINES'} .= "-->\n</style>\n";
279 foreach my $ref (@CSS_REFS)
281 $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"stylesheet\" type=\"text/css\" title=\"$ref->{TITLE}\" href=\"$ref->{FILENAME}\">\n";
283 foreach my $ref (@Texi2HTML::Config::ALT_CSS_REFS)
285 $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"$ref->{FILENAME}\" title=\"$ref->{TITLE}\">\n";
287 $Texi2HTML::THISDOC{'CSS_LINES'} .= "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
294 #############################################################################
295 ### SPLITTING BASED ON NUMBERED SECTIONS
296 #############################################################################
300 my $node_to_filename_map = ();
303 # This function makes sure that files are only generated for numbered sections,
304 # but not for unnumbered ones. It is called after texi2html has done its own
305 # splitting and simply returns the filename for the node given as first argument
306 # Nodes with the same filename will be printed out to the same filename, so
307 # this really all we need. Also, make sure that the file names for sections
308 # are derived from the section title. We also might want to name the anchors
309 # according to node titles, which works by simply overriding the id element of
311 # If an external nodename<=>filename/anchor map file is found (loaded in
312 # the command handler, use the externally created values, otherwise use the
314 sub lilypond_element_file_name($$$)
318 my $docu_name = shift;
319 my $docu_ext = $Texi2HTML::Config::EXTENSION;
321 my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
322 # the snippets page does not use nodes for the snippets, so in this case
323 # we'll have to use the section name!
324 if ($node_name eq '') {
325 $node_name = main::remove_texi($element->{'texi'});
328 # If we have an entry in the section<=>filename map, use that one, otherwise
329 # generate the filename/anchor here. In the latter case, external manuals
330 # will not be able to retrieve the file name for xrefs!!! Still, I already
331 # had that code, so I'll leave it in in case something goes wrong with the
332 # extract_texi_filenames.py script in the lilypond build process!
333 if (exists ($node_to_filename_map->{$node_name})) {
334 (my $filename, my $anchor) = @{$node_to_filename_map->{$node_name}};
335 $filename .= ".$docu_ext" if (defined($docu_ext));
337 # unnumbered sections (except those at top-level!) always go to the same
338 # file as the previous numbered section
339 if (not ($element->{number}) and not ($lastfilename eq '') and ($element->{level} > 1)) {
340 $filename = $lastfilename;
342 if (($filename eq $lastfilename)) {
343 $$element{doc_nr} = $docnr;
346 $$element{doc_nr} = $docnr;
347 $lastfilename = $filename;
351 } elsif ($type eq "top" or $type eq "toc" or $type eq "doc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
354 print STDERR "WARNING: Node '$node_name' was NOT found in the map\n"
355 unless ($node_name eq '') or ($element->{'tag'} eq 'unnumberedsec')
356 or ($node_name =~ /NOT REALLY USED/);
358 # Numbered sections will get a filename Node_title, unnumbered sections will use
359 # the file name of the previous numbered section:
360 if (($element->{number}) or ($lastfilename eq '') or ($element->{level} == 1)) {
361 # normalize to the same file name as texinfo
362 if ($element->{translationof}) {
363 $node_name = main::remove_texi($element->{translationof});
365 my $filename = texinfo_file_name($node_name);
366 $filename .= ".$docu_ext" if (defined($docu_ext));
368 $$element{doc_nr} = $docnr;
369 $lastfilename = $filename;
372 $$element{doc_nr} = $docnr;
373 return $lastfilename;
380 sub lilypond_element_target_name($$$)
385 # Target is based on node name (or sec name for secs without node attached)
386 my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
387 if ($node_name eq '') {
388 $node_name = main::remove_texi($element->{'texi'});
391 # If we have an entry in the section<=>filename map, use that one, otherwise
392 # generate the anchor here.
393 if (exists ($node_to_filename_map->{$node_name})) {
394 (my $filename, $target) = @{$node_to_filename_map->{$node_name}};
396 my $anchor = $node_name;
397 if ($element->{translationof}) {
398 $anchor = main::remove_texi($element->{translationof});
400 # normalize to the same file name as texinfo
401 $target = texinfo_file_name($anchor);
403 # TODO: Once texi2html correctly prints out the target and not the id for
404 # the sections, change this back to ($id, $target)
405 return ($target, $target);
409 ## Load the map file for the corrently processed texi file. We do this
410 # using a command init handler, since texi2html does not have any
411 # other hooks that are called after THISDOC is filled but before phase 2
412 # of the texi2html conversion.
413 sub lilypond_init_map ()
415 my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
416 my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
417 || main::locate_include_file ("${docu_name}.xref-map");
418 $node_to_filename_map = load_map_file ($map_filename);
420 push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map;
424 #############################################################################
425 ### CLEANER LINK TITLE FOR EXTERNAL REFS
426 #############################################################################
428 # The default formatting of external refs returns e.g.
429 # "(lilypond-internals)Timing_translator", so we remove all (...) from the
430 # file_and_node argument. Also, we want only a very simple format, so we don't
431 # even call the default handler!
432 sub lilypond_external_ref($$$$$$)
437 my $file_node = shift;
439 my $cross_ref = shift;
441 my $displaytext = '';
443 # 1) if we have a cross ref name, that's the text to be displayed:
444 # 2) For the top node, use the (printable) name of the manual, unless we
445 # have an explicit cross ref name
446 # 3) In all other cases use the section name
447 if ($cross_ref ne '') {
448 $displaytext = $cross_ref;
449 } elsif (($section eq '') or ($section eq 'Top')) {
450 $displaytext = $book;
452 $displaytext = $section;
455 $displaytext = &$anchor('', $href, $displaytext) if ($displaytext ne '');
456 return &$I('%{node_file_href}', { 'node_file_href' => $displaytext });
458 # Default: format as "see <a ..>NODE</a> section 'SECTION' in BOOK". We don't want this!
459 # return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref);
466 #############################################################################
467 ### HANDLING TRANSLATED SECTIONS: handle @translationof, secname<->filename
468 ### map stored on disk, xrefs in other manuals load that map
469 #############################################################################
472 # Try to make use of @translationof to generate files according to the original
473 # English section title...
474 sub lilypond_unknown($$$$$)
482 # the @translationof macro provides the original English section title,
483 # which should be used for file/anchor naming, while the title will be
484 # translated to each language
485 # It is already used by extract_texi_filenames.py, so this should not be
486 # necessary here at all. Still, I'll leave the code in just in case the
487 # python script messed up ;-)
488 if ($pass == 1 and $macro eq "translationof") {
489 if (ref($state->{'element'}) eq 'HASH') {
490 $state->{'element'}->{'translationof'} = main::normalise_space($line);
492 return ('', 1, undef, undef);
494 return t2h_default_unknown($macro, $line, $pass, $stack, $state);
501 my %translated_books = ();
502 # Construct a href to an external source of information.
503 # node is the node with texinfo @-commands
504 # node_id is the node transliterated and transformed as explained in the
506 # node_xhtml_id is the node transformed such that it is unique and can
507 # be used to make an html cross ref as explained in the texinfo manual
508 # file is the file in '(file)node'
509 sub lilypond_external_href($$$)
513 my $node_hxmlt_id = shift;
515 my $original_func = \&t2h_default_external_href;
517 # 1) Keep a hash of book->section_map
518 # 2) if not file in keys hash => try to load the map (assign empty map if
519 # non-existent => will load only once!)
520 # 3) if node in the section=>(file, anchor) map, replace node_id and
521 # node_xhtml_id by the map's values
522 # 4) call the t2h_default_external_href with these values (or the old ones if not found)
524 if (($node_id ne '') and defined($file) and ($node_id ne 'Top')) {
525 my $map_name = $file;
526 $map_name =~ s/-big-page//;
528 # Load the map if we haven't done so already
529 if (!exists($translated_books{$map_name})) {
530 my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
531 my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
532 || main::locate_include_file ("${map_name}.xref-map");
533 $translated_books{$map_name} = load_map_file ($map_filename);
536 # look up translation. use these values instead of the old filename/anchor
537 my $section_name_map = $translated_books{$map_name};
538 my $node_text = main::remove_texi($node);
539 if (defined($section_name_map->{$node_text})) {
540 ($node_id, $node_hxmlt_id) = @{$section_name_map->{$node_text}};
542 print STDERR "WARNING: Unable to find node '$node_text' in book $map_name.\n";
547 return &$original_func($node, $node_id, $node_hxmlt_id, $file);
549 return &$original_func($node, $node_id, $node_hxmlt_id);
557 #############################################################################
558 ### CUSTOM TOC FOR EACH PAGE (in a frame on the left)
559 #############################################################################
561 my $page_toc_depth = 2;
562 my @default_toc = [];
565 # Initialize the toc_depth to 1 if the command-line option -D=short_toc is given
566 sub lilypond_init_toc_depth ()
568 if (exists($main::value{'short_toc'}) and not exists($main::value{'bigpage'})) {
572 # Set the TOC-depth (depending on a texinfo variable short_toc) in a
573 # command-handler, so we have them available when creating the pages
574 push @Texi2HTML::Config::command_handler_process, \&lilypond_init_toc_depth;
577 # recursively generate the TOC entries for the element and its children (which
578 # are only shown up to maxlevel. All ancestors of the current element are also
579 # shown with their immediate children, irrespective of their level.
580 # Unnumbered entries are only printed out if they are at top-level or 2nd level
581 # or their parent element is an ancestor of the currently viewed node.
582 # The conditions to call this method to print the entry for a child node is:
583 # -) the parent is an ancestor of the current page node
584 # -) the parent is a numbered element at top-level toplevel (i.e. show numbered
585 # and unnumbered 2nd-level children of numbered nodes)
586 # -) the child element is a numbered node below level maxlevel
587 sub generate_ly_toc_entries($$$)
590 my $element_path = shift;
591 my $maxlevel = shift;
592 # Skip undefined sections, plus all sections generated by index splitting
593 return() if (not defined($element) or exists($element->{'index_page'}));
595 my $level = $element->{'toc_level'};
596 my $is_parent_of_current = $element->{'id'} && $element_path->{$element->{'id'}};
597 my $ind = ' ' x $level;
598 my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : "";
600 my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}",$element->{'text'});
602 push (@result, $entry);
603 my $children = $element->{'section_childs'};
604 if (defined($children) and (ref($children) eq "ARRAY")) {
605 my $force_children = $is_parent_of_current or ($level == 1 and $element->{'number'});
606 my @child_result = ();
607 foreach my $c (@$children) {
608 my $is_numbered_child = defined ($c->{'number'});
609 my $below_maxlevel = $c->{'toc_level'} le $maxlevel;
610 if ($force_children or ($is_numbered_child and $below_maxlevel)) {
611 my @child_res = generate_ly_toc_entries($c, $element_path, $maxlevel);
612 push (@child_result, @child_res);
615 # if no child nodes were generated, e.g. for the index, where expanded pages
616 # are ignored, don't generate a list at all...
618 push (@result, "\n$ind<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
619 push (@result, @child_result);
620 push (@result, "$ind</ul>\n");
623 push (@result, "$ind</li>\n");
628 # Print a customized TOC, containing only the first two levels plus the whole
629 # path to the current page
630 sub lilypond_generate_page_toc_body($)
633 my $current_element = $element;
635 $parentelements{$element->{'id'}} = 1;
636 # Find the path to the current element
637 while ( defined($current_element->{'sectionup'}) and
638 ($current_element->{'sectionup'} ne $current_element) )
640 $parentelements{$current_element->{'sectionup'}->{'id'}} = 1
641 if ($current_element->{'sectionup'}->{'id'} ne '');
642 $current_element = $current_element->{'sectionup'};
644 return () if not defined($current_element);
645 # Create the toc entries recursively
646 my @toc_entries = ("<div class=\"contents\">\n", "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
647 my $children = $current_element->{'section_childs'};
648 foreach ( @$children ) {
649 push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth));
651 push (@toc_entries, "</ul>\n");
652 push (@toc_entries, "</div>\n");
656 sub lilypond_print_toc_div ($$)
660 my @lines = @$tocref;
661 # use default TOC if no custom lines have been generated
662 @lines = @default_toc if (not @lines);
665 print $fh "\n\n<div id=\"tocframe\">\n";
667 # Remove the leading "GNU LilyPond --- " from the manual title
668 my $topname = $Texi2HTML::NAME{'Top'};
669 $topname =~ s/^GNU LilyPond(:| &[mn]dash;) //;
671 # construct the top-level Docs index (relative path and including language!)
672 my $lang = $Texi2HTML::THISDOC{current_lang};
673 if ($lang and $lang ne "en") {
679 $reldir = "../" if ($Texi2HTML::Config::SPLIT eq 'section');
680 my $uplink = $reldir."index.${lang}html";
682 print $fh "<p class=\"toc_uplink\"><a href=\"$uplink\"
683 title=\"Documentation Index\"><< " .
684 &ly_get_string ('Back to Documentation Index') .
687 print $fh '<h4 class="toc_header"> ' . &$anchor('',
688 $Texi2HTML::HREF{'Top'},
690 'title="Start of the manual"'
692 foreach my $line (@lines) {
695 print $fh "</div>\n\n";
699 # Create the custom TOC for this page (partially folded, current page is
700 # highlighted) and store it in a global variable. The TOC is written out after
701 # the html contents (but positioned correctly using CSS), so that browsers with
702 # css turned off still show the contents first.
703 our @this_page_toc = ();
704 sub lilypond_print_element_header
706 my $first_in_page = shift;
707 my $previous_is_top = shift;
708 if ($first_in_page and not @this_page_toc) {
709 if (defined($Texi2HTML::THIS_ELEMENT)) {
710 # Create the TOC for this page
711 @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
714 return T2H_DEFAULT_print_element_header( $first_in_page, $previous_is_top);
717 # Generate the HTML output for the TOC
718 sub lilypond_toc_body($)
720 my $elements_list = shift;
721 # Generate a default TOC for pages without THIS_ELEMENT
722 @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
723 return T2H_GPL_toc_body($elements_list);
726 # Print out the TOC in a <div> at the beginning of the page
727 sub lilypond_print_page_head($)
730 T2H_DEFAULT_print_page_head($fh);
731 print $fh "<div id=\"main\">\n";
734 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
735 # sidebar mimicking a TOC frame
736 sub print_lilypond_page_foot($)
739 my $program_string = &$program_string();
740 # print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
741 print $fh "<!-- FOOTER -->\n\n";
742 print $fh "<!-- end div#main here -->\n</div>\n\n";
744 # Print the TOC frame and reset the TOC:
745 lilypond_print_toc_div ($fh, \@this_page_toc);
749 print $fh "</body>\n</html>\n";
756 #############################################################################
757 ### NICER / MORE FLEXIBLE NAVIGATION PANELS
758 #############################################################################
760 sub get_navigation_text
763 my $text = $NAVIGATION_TEXT{$button};
764 if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
765 $text = $text . $Texi2HTML::NODE{$button} . " ";
766 } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
767 $text = " " . $Texi2HTML::NODE{$button} . $text;
768 } elsif ( $button eq 'Up' ) {
769 $text = " ".$text.": " . $Texi2HTML::NODE{$button} . " ";
775 # Don't automatically create left-aligned table cells for every link, but
776 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
777 # button text. It's alignment as well as the colspan will be taken from the
778 # name of the button. Also, add 'newline' button text to create a new table
779 # row. The texts of the buttons are generated by get_navigation_text and
780 # will contain the name of the next/previous section/chapter.
781 sub lilypond_print_navigation
784 my $vertical = shift;
786 my $result = "<table class=\"nav_table\">\n";
788 $result .= "<tr>" unless $vertical;
790 foreach my $button (@$buttons)
792 $result .= qq{<tr valign="top" align="left">\n} if $vertical;
793 # Allow (left|right|center)-aligned-cell and newline as buttons!
794 if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
796 $result .= qq{</td>} unless $beginofline;
797 $result .= qq{<td valign="middle" align="$1" colspan="$2">};
800 elsif ( $button eq 'newline' )
802 $result .= qq{</td>} unless $beginofline;
803 $result .= qq{</tr>};
808 elsif (ref($button) eq 'CODE')
810 $result .= &$button($vertical);
812 elsif (ref($button) eq 'SCALAR')
814 $result .= "$$button" if defined($$button);
816 elsif (ref($button) eq 'ARRAY')
818 my $text = $button->[1];
819 my $button_href = $button->[0];
820 # verify that $button_href is simple text and text is a reference
821 if (defined($button_href) and !ref($button_href)
822 and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
824 if ($Texi2HTML::HREF{$button_href})
826 my $anchor_attributes = '';
827 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
829 $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
831 if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
833 $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
837 $Texi2HTML::HREF{$button_href},
838 get_navigation_text($$text),
844 $result .= get_navigation_text($$text);
848 elsif ($button eq ' ')
849 { # handle space button
851 ($ICONS && $ACTIVE_ICONS{' '}) ?
852 &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
853 $NAVIGATION_TEXT{' '};
856 elsif ($Texi2HTML::HREF{$button})
858 my $btitle = $BUTTONS_GOTO{$button} ?
859 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
860 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
862 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
864 if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
866 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
868 if ($ICONS && $ACTIVE_ICONS{$button})
872 $Texi2HTML::HREF{$button},
873 &$button_icon_img($BUTTONS_NAME{$button},
874 $ACTIVE_ICONS{$button},
875 $Texi2HTML::SIMPLE_TEXT{$button}),
884 $Texi2HTML::HREF{$button},
885 get_navigation_text($button),
892 { # button is passive
894 $ICONS && $PASSIVE_ICONS{$button} ?
895 &$button_icon_img($BUTTONS_NAME{$button},
896 $PASSIVE_ICONS{$button},
897 $Texi2HTML::SIMPLE_TEXT{$button}) :
899 "[" . get_navigation_text($button) . "]";
901 $result .= "</td>\n" if $vertical;
902 $result .= "</tr>\n" if $vertical;
904 $result .= "</td>" unless $beginofline;
905 $result .= "</tr>" unless $vertical;
906 $result .= "</table>\n";
911 @Texi2HTML::Config::SECTION_BUTTONS =
912 ('left-aligned-cell-1', 'FastBack',
913 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
914 'right-aligned-cell-1', 'FastForward',
916 'left-aligned-cell-2', 'Back',
917 'center-aligned-cell-1', 'Up',
918 'right-aligned-cell-2', 'Forward'
921 # buttons for misc stuff
922 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
924 # buttons for chapter file footers
925 # (and headers but only if SECTION_NAVIGATION is false)
926 @Texi2HTML::Config::CHAPTER_BUTTONS =
927 ('left-aligned-cell-1', 'FastBack',
928 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
929 'right-aligned-cell-1', 'FastForward',
932 # buttons for section file footers
933 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
934 ('left-aligned-cell-1', 'FastBack',
935 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
936 'right-aligned-cell-1', 'FastForward',
938 'left-aligned-cell-2', 'Back',
939 'center-aligned-cell-1', 'Up',
940 'right-aligned-cell-2', 'Forward'
943 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
944 ('left-aligned-cell-1', 'FastBack',
945 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
946 'right-aligned-cell-1', 'FastForward',
948 'left-aligned-cell-2', 'Back',
949 'center-aligned-cell-1', 'Up',
950 'right-aligned-cell-2', 'Forward'
957 #############################################################################
958 ### FOOTNOTE FORMATTING
959 #############################################################################
961 # Format footnotes in a nicer way: Instead of printing the number in a separate
962 # (nr) heading line, use the standard way of prepending <sup>nr</sup> immediately
963 # before the fn text.
966 # The following code is copied from texi2html's examples/makeinfo.init and
967 # should be updated when texi2html makes some changes there!
969 my $makekinfo_like_footnote_absolute_number = 0;
971 sub makeinfo_like_foot_line_and_ref($$$$$$$$)
973 my $foot_num = shift;
974 my $relative_num = shift;
977 my $from_file = shift;
978 my $footnote_file = shift;
982 $makekinfo_like_footnote_absolute_number++;
984 # this is a bit obscure, this allows to add an anchor only if formatted
985 # as part of the document.
986 $docid = '' if ($state->{'outside_document'} or $state->{'multiple_pass'});
988 if ($from_file eq $footnote_file)
990 $from_file = $footnote_file = '';
993 my $foot_anchor = "<sup>" . &$anchor($docid, "$footnote_file#$footid", $relative_num) . "</sup>";
994 $foot_anchor = &$anchor($docid, "$footnote_file#$footid", "($relative_num)") if ($state->{'preformatted'});
996 # unshift @$lines, "<li>";
997 # push @$lines, "</li>\n";
998 return ($lines, $foot_anchor);
1001 sub makeinfo_like_foot_lines($)
1004 unshift @$lines, "<hr>\n<h4>$Texi2HTML::I18n::WORDS->{'Footnotes_Title'}</h4>\n";
1005 #<ol type=\"1\">\n";
1006 # push @$lines, "</ol>";
1010 my %makekinfo_like_paragraph_in_footnote_nr;
1012 sub makeinfo_like_paragraph ($$$$$$$$$$$$$)
1017 my $paragraph_command = shift;
1018 my $paragraph_command_formatted = shift;
1019 my $paragraph_number = shift;
1021 my $item_nr = shift;
1022 my $enumerate_style = shift;
1024 my $command_stack_at_end = shift;
1025 my $command_stack_at_begin = shift;
1027 #print STDERR "format: $format\n" if (defined($format));
1028 #print STDERR "paragraph @$command_stack_at_end; @$command_stack_at_begin\n";
1029 $paragraph_command_formatted = '' if (!defined($paragraph_command_formatted) or
1030 exists($special_list_commands{$format}->{$paragraph_command}));
1031 return '' if ($text =~ /^\s*$/);
1032 foreach my $style(t2h_collect_styles($command_stack_at_begin))
1034 $text = t2h_begin_style($style, $text);
1036 foreach my $style(t2h_collect_styles($command_stack_at_end))
1038 $text = t2h_end_style($style, $text);
1040 if (defined($paragraph_number) and defined($$paragraph_number))
1042 $$paragraph_number++;
1043 return $text if (($format eq 'itemize' or $format eq 'enumerate') and
1044 ($$paragraph_number == 1));
1049 $open .= " align=\"$paragraph_style{$align}\"";
1051 my $footnote_text = '';
1052 if (defined($command_stack_at_begin->[0]) and $command_stack_at_begin->[0] eq 'footnote')
1054 my $state = $Texi2HTML::THISDOC{'state'};
1055 $makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number}++;
1056 if ($makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number} <= 1)
1058 $open.=' class="footnote"';
1059 my $document_file = $state->{'footnote_document_file'};
1060 if ($document_file eq $state->{'footnote_footnote_file'})
1062 $document_file = '';
1064 my $docid = $state->{'footnote_place_id'};
1065 my $doc_state = $state->{'footnote_document_state'};
1066 $docid = '' if ($doc_state->{'outside_document'} or $doc_state->{'multiple_pass'});
1067 my $foot_label = &$anchor($state->{'footnote_footnote_id'},
1068 $document_file . "#$state->{'footnote_place_id'}",
1069 "$state->{'footnote_number_in_page'}");
1070 $footnote_text = "<small>[${foot_label}]</small> ";
1073 return $open.'>'.$footnote_text.$text.'</p>';
1077 #############################################################################
1079 #############################################################################
1081 # For split pages, use index.html as start page!
1082 if ($Texi2HTML::Config::SPLIT eq 'section') {
1083 $Texi2HTML::Config::TOP_FILE = 'index.html';