Fix #661.
[lilypond.git] / lilypond-texi2html.init
blob026d55dfb5e8298368f2ca126f9d8b8497deefa3
1 #!/usr/bin/env perl
3 ### texi2html customization script for Lilypond
4 ### Author: Reinhold Kainhofer <reinhold@kainhofer.com>, 2008.
5 ### Some code parts copied from texi2html and adapted. These functions
6 ### were written mainly by Patrice Dumas
7 ### License: GPLv2+
8 ###
9 ###
10 ### Features implemented here:
11 ### -) For split manuals, the main page is index.html.
12 ### -) All @unnumbered* sections are placed into the same file
13 ### (implemented by split_at_numbered_sections)
14 ### -) Use our custom CSS file, with IE-specific fixes in another CSS file,
15 ### impelmented by lilypond_css_lines
16 ### -) TOC (folded, with the current page highlighted) in an overflown <div>
17 ### is added to every page; implemented by:
18 ### lilypond_print_element_header -- building of the TOC
19 ### lilypond_toc_body -- generation of customized TOC output
20 ### lilypond_print_page_head -- start <div id="main">
21 ### print_lilypond_page_foot -- closing id=main, output of footer & TOC
22 ### -) External refs are formatted only as "Text of the node" (not as >>see
23 ### "NODE" section "SECTION" in "BOOK"<< like with default texi2html). Also,
24 ### the leading "(book-name)" is removed.
25 ### Implemented by overriding lilypond_external_ref
26 ### -) Navigation bars on top/bottom of the page and between sections are not
27 ### left-aligned, but use a combination of left/center/right aligned table
28 ### cells; For this, I heavily extend the texi2html code to allow for
29 ### differently aligned cells and for multi-line tables);
30 ### Implemented in lilypond_print_navigation
31 ### -) Different formatting than the default: example uses the same formatting
32 ### as quote.
33 ### -) Allow translated section titles: All section titles can be translated,
34 ### the original (English) title is associated with @translationof. This is
35 ### needed, because the file name / anchor is generated from the original
36 ### English title, since otherwise language-autoselection would break with
37 ### posted links.
38 ### Since it is then no longer possible to obtain the file name from the
39 ### section title, I keep a sectionname<=>filename/anchor around. This way,
40 ### xrefs from other manuals can simply load that map and retrieve the
41 ### correct file name for the link. Implemented in:
42 ### lilypond_unknown (handling of @translationof, in case
43 ### extract_texi_filenames.py messes up...)
44 ### lilypond_element_file_name (correct file name: use the map)
45 ### lilypond_element_target_name (correct anchor: use the map)
46 ### lilypond_init_map (read in the externally created map from disk)
47 ### lilypond_external_href (load the map for xrefs, use the correct
48 ### link target)
49 ### -) The HTML anchors for all sections are derived from the node name /
50 ### section title (pre-generated in the .xref-map file). Implemented by:
51 ### lilypond_element_target_name (adjust section anchors)
52 ### -) Use the standard footnote format "<sup>nr</sup> text" instead of the
53 ### ugly format of texi2html (<h3>(nr)</h3><p>text</p>). Implemented in
54 ### makeinfo_like_foot_line_and_ref
55 ### makeinfo_like_foot_lines
56 ### makeinfo_like_paragraph
57 ###
58 ###
59 ### Useful helper functions:
60 ### -) texinfo_file_name($node_name): returns a texinfo-compatible file name
61 ### for the given string $node_name (whitespace trimmed/replaced by -,
62 ### non-standard chars replaced by _xxxx (ascii char code) and forced to
63 ### start with a letter by prepending t_g if necessary)
66 package Texi2HTML::Config;
72 #############################################################################
73 ### SETTINGS FOR TEXI2HTML
74 #############################################################################
76 @Texi2HTML::Config::CSS_REFS = ("lilypond.css");
77 @Texi2HTML::Config::ALT_CSS_REFS = (
78 {FILENAME => "lilypond-mccarty.css", TITLE=>"Patrick McCarty's design"}
80 $Texi2HTML::Config::USE_ACCESSKEY = 1;
81 $Texi2HTML::Config::USE_LINKS = 1;
82 $Texi2HTML::Config::USE_REL_REV = 1;
83 $Texi2HTML::Config::SEPARATED_FOOTNOTES = 0; # Print footnotes on same page, not separated
84 $Texi2HTML::Config::element_file_name = \&lilypond_element_file_name;
85 $Texi2HTML::Config::element_target_name = \&lilypond_element_target_name;
86 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
87 $Texi2HTML::Config::print_page_foot = \&print_lilypond_page_foot;
88 $Texi2HTML::Config::print_navigation = \&lilypond_print_navigation;
89 $Texi2HTML::Config::external_ref = \&lilypond_external_ref;
90 $Texi2HTML::Config::external_href = \&lilypond_external_href;
91 $Texi2HTML::Config::toc_body = \&lilypond_toc_body;
92 $Texi2HTML::Config::css_lines = \&lilypond_css_lines;
93 $Texi2HTML::Config::unknown = \&lilypond_unknown;
94 $Texi2HTML::Config::print_page_head = \&lilypond_print_page_head;
95 # $Texi2HTML::Config::foot_line_and_ref = \&lilypond_foot_line_and_ref;
96 $Texi2HTML::Config::foot_line_and_ref = \&makeinfo_like_foot_line_and_ref;
97 $Texi2HTML::Config::foot_lines = \&makeinfo_like_foot_lines;
98 $Texi2HTML::Config::paragraph = \&makeinfo_like_paragraph;
102 # Examples should be formatted similar to quotes:
103 $Texi2HTML::Config::complex_format_map->{'example'} = {
104 'begin' => q{"<blockquote><pre class=\"example\">"},
105 'end' => q{"</pre></blockquote>\n"},
108 %Texi2HTML::config::misc_pages_targets = (
109 'Overview' => 'Overview',
110 'Contents' => 'Contents',
111 'About' => 'About'
115 my @section_to_filename;
120 #############################################################################
121 ### DEBUGGING
122 #############################################################################
124 use Data::Dumper;
125 $Data::Dumper::Maxdepth = 2;
127 sub print_element_info($)
129 my $element = shift;
130 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
131 print "Element: $element\n";
132 print Dumper($element);
139 #############################################################################
140 ### HELPER FUNCTIONS
141 #############################################################################
143 # Convert a given node name to its proper file name (normalization as explained
144 # in the texinfo manual:
145 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
146 sub texinfo_file_name($)
148 my $text = shift;
149 my $result = '';
150 # File name normalization by texinfo:
151 # 1/2: letters and numbers are left unchanged
152 # 3/4: multiple, leading and trailing whitespace is removed
153 $text = main::normalise_space($text);
154 # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
155 # chars are replaced by _xxxx (xxxx=ascii character code)
156 while ($text ne '') {
157 if ($text =~ s/^([A-Za-z0-9]+)//o) { # number or letter stay unchanged
158 $result .= $1;
159 } elsif ($text =~ s/^ //o) { # space -> '-'
160 $result .= '-';
161 } elsif ($text =~ s/^(.)//o) { # Otherwise use _xxxx (ascii char code)
162 my $ccode = ord($1);
163 if ( $ccode <= 0xFFFF ) {
164 $result .= sprintf("_%04x", $ccode);
165 } else {
166 $result .= sprintf("__%06x", $ccode);
170 # 7: if name does not begin with a letter, prepend 't_g' (so it starts with a letter)
171 if ($result !~ /^[a-zA-Z]/) {
172 $result = 't_g' . $result;
174 # DONE
175 return $result
179 # Load a file containing a nodename<=>filename map (tab-sepatared, i.e.
180 # NODENAME\tFILENAME\tANCHOR
181 # Returns a ref to a hash "Node title" => ["FilenameWithoutExt", "Anchor"]
182 sub load_map_file ($)
184 my $mapfile = shift;
185 my $node_map = ();
187 if (open(XREFFILE, $mapfile)) {
188 my $line;
189 while ( $line = <XREFFILE> ) {
190 # parse the tab-separated entries and insert them into the map:
191 chomp($line);
192 my @entries = split(/\t/, $line);
193 if (scalar (@entries) == 3) {
194 $node_map->{$entries[0]} = [$entries[1], $entries[2]];
195 } else {
196 print STDERR "Invalid entry in the node file $mapfile: $line\n";
199 close (XREFFILE);
200 } else {
201 print STDERR "WARNING: Unable to load the map file $mapfile\n";
203 return $node_map;
207 # Split the given path into dir and basename (with .texi removed). Used mainly
208 # to get the path/basename of the original texi input file
209 sub split_texi_filename ($)
211 my $docu = shift;
212 my $docu_dir, $docu_name;
213 if ($docu =~ /(.*\/)/) {
214 chop($docu_dir = $1);
215 $docu_name = $docu;
216 $docu_name =~ s/.*\///;
217 } else {
218 $docu_dir = '.';
219 $docu_name = $docu;
221 $docu_name =~ s/\.te?x(i|info)?$//;
222 return ($docu_dir, $docu_name);
229 #############################################################################
230 ### CSS HANDLING
231 #############################################################################
233 # Include our standard CSS file, not hard-coded CSS code directly in the HTML!
234 # For IE, conditionally include the lilypond-ie-fixes.css style sheet
235 sub lilypond_css_lines ($$)
237 my $import_lines = shift;
238 my $rule_lines = shift;
239 return if (defined($Texi2HTML::THISDOC{'CSS_LINES'}));
240 if (@$rule_lines or @$import_lines)
242 $Texi2HTML::THISDOC{'CSS_LINES'} = "<style type=\"text/css\">\n<!--\n";
243 $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$import_lines) . "\n" if (@$import_lines);
244 $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$rule_lines) . "\n" if (@$rule_lines);
245 $Texi2HTML::THISDOC{'CSS_LINES'} .= "-->\n</style>\n";
247 foreach my $ref (@CSS_REFS)
249 $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$ref\">\n";
251 foreach my $ref (@ALT_CSS_REFS)
253 $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"alternate stylesheet\" type=\"text/css\" title=\"$ref->{TITLE}\" href=\"$ref->{FILENAME}\">\n";
255 $Texi2HTML::THISDOC{'CSS_LINES'} .= "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
262 #############################################################################
263 ### SPLITTING BASED ON NUMBERED SECTIONS
264 #############################################################################
266 my $lastfilename;
267 my $docnr = 0;
268 my $node_to_filename_map = ();
271 # This function makes sure that files are only generated for numbered sections,
272 # but not for unnumbered ones. It is called after texi2html has done its own
273 # splitting and simply returns the filename for the node given as first argument
274 # Nodes with the same filename will be printed out to the same filename, so
275 # this really all we need. Also, make sure that the file names for sections
276 # are derived from the section title. We also might want to name the anchors
277 # according to node titles, which works by simply overriding the id element of
278 # the $element hash.
279 # If an external nodename<=>filename/anchor map file is found (loaded in
280 # lilypond_init_out, use the externally created values, otherwise use the
281 # same logic here.
282 sub lilypond_element_file_name($$$)
284 my $element = shift;
285 my $type = shift;
286 my $docu_name = shift;
287 my $docu_ext = $Texi2HTML::Config::EXTENSION;
289 my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
290 # the snippets page does not use nodes for the snippets, so in this case
291 # we'll have to use the section name!
292 if ($node_name eq '') {
293 $node_name = main::remove_texi($element->{'texi'});
296 # If we have an entry in the section<=>filename map, use that one, otherwise
297 # generate the filename/anchor here. In the latter case, external manuals
298 # will not be able to retrieve the file name for xrefs!!! Still, I already
299 # had that code, so I'll leave it in in case something goes wrong with the
300 # extract_texi_filenames.py script in the lilypond build process!
301 if (exists ($node_to_filename_map->{$node_name})) {
302 (my $filename, my $anchor) = @{$node_to_filename_map->{$node_name}};
303 $filename .= ".$docu_ext" if (defined($docu_ext));
305 # unnumbered sections (except those at top-level!) always go to the same
306 # file as the previous numbered section
307 if (not ($element->{number}) and not ($lastfilename eq '') and ($element->{level} > 1)) {
308 $filename = $lastfilename;
310 if (($filename eq $lastfilename)) {
311 $$element{doc_nr} = $docnr;
312 } else {
313 $docnr += 1;
314 $$element{doc_nr} = $docnr;
315 $lastfilename = $filename;
317 return $filename;
319 } elsif ($type eq "top" or $type eq "toc" or $type eq "doc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
320 return;
321 } else {
322 print STDERR "WARNING: Node '$node_name' was NOT found in the map\n"
323 unless ($node_name eq '') or ($element->{'tag'} eq 'unnumberedsec')
324 or ($node_name =~ /NOT REALLY USED/);
326 # Numbered sections will get a filename Node_title, unnumbered sections will use
327 # the file name of the previous numbered section:
328 if (($element->{number}) or ($lastfilename eq '') or ($element->{level} == 1)) {
329 # normalize to the same file name as texinfo
330 if ($element->{translationof}) {
331 $node_name = main::remove_texi($element->{translationof});
333 my $filename = texinfo_file_name($node_name);
334 $filename .= ".$docu_ext" if (defined($docu_ext));
335 $docnr += 1;
336 $$element{doc_nr} = $docnr;
337 $lastfilename = $filename;
338 return $filename;
339 } else {
340 $$element{doc_nr} = $docnr;
341 return $lastfilename;
345 return;
348 sub lilypond_element_target_name($$$)
350 my $element = shift;
351 my $target = shift;
352 my $id = shift;
353 # Target is based on node name (or sec name for secs without node attached)
354 my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
355 if ($node_name eq '') {
356 $node_name = main::remove_texi($element->{'texi'});
359 # If we have an entry in the section<=>filename map, use that one, otherwise
360 # generate the anchor here.
361 if (exists ($node_to_filename_map->{$node_name})) {
362 (my $filename, $target) = @{$node_to_filename_map->{$node_name}};
363 } else {
364 my $anchor = $node_name;
365 if ($element->{translationof}) {
366 $anchor = main::remove_texi($element->{translationof});
368 # normalize to the same file name as texinfo
369 $target = texinfo_file_name($anchor);
371 # TODO: Once texi2html correctly prints out the target and not the id for
372 # the sections, change this back to ($id, $target)
373 return ($target, $target);
377 ## Load the map file for the corrently processed texi file. We do this
378 # using a command init handler, since texi2html does not have any
379 # other hooks that are called after THISDOC is filled but before phase 2
380 # of the texi2html conversion.
381 sub lilypond_init_map ()
383 my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
384 my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
385 || main::locate_include_file ("${docu_name}.xref-map");
386 $node_to_filename_map = load_map_file ($map_filename);
388 push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map;
392 #############################################################################
393 ### CLEANER LINK TITLE FOR EXTERNAL REFS
394 #############################################################################
396 # The default formatting of external refs returns e.g.
397 # "(lilypond-internals)Timing_translator", so we remove all (...) from the
398 # file_and_node argument. Also, we want only a very simple format, so we don't
399 # even call the default handler!
400 sub lilypond_external_ref($$$$$$)
402 my $type = shift;
403 my $section = shift;
404 my $book = shift;
405 my $file_node = shift;
406 my $href = shift;
407 my $cross_ref = shift;
409 my $displaytext = '';
411 # 1) if we have a cross ref name, that's the text to be displayed:
412 # 2) For the top node, use the (printable) name of the manual, unless we
413 # have an explicit cross ref name
414 # 3) In all other cases use the section name
415 if ($cross_ref ne '') {
416 $displaytext = $cross_ref;
417 } elsif (($section eq '') or ($section eq 'Top')) {
418 $displaytext = $book;
419 } else {
420 $displaytext = $section;
423 $displaytext = &$anchor('', $href, $displaytext) if ($displaytext ne '');
424 return &$I('%{node_file_href}', { 'node_file_href' => $displaytext });
426 # Default: format as "see <a ..>NODE</a> section 'SECTION' in BOOK". We don't want this!
427 # return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref);
434 #############################################################################
435 ### HANDLING TRANSLATED SECTIONS: handle @translationof, secname<->filename
436 ### map stored on disk, xrefs in other manuals load that map
437 #############################################################################
440 # Try to make use of @translationof to generate files according to the original
441 # English section title...
442 sub lilypond_unknown($$$$$)
444 my $macro = shift;
445 my $line = shift;
446 my $pass = shift;
447 my $stack = shift;
448 my $state = shift;
450 # the @translationof macro provides the original English section title,
451 # which should be used for file/anchor naming, while the title will be
452 # translated to each language
453 # It is already used by extract_texi_filenames.py, so this should not be
454 # necessary here at all. Still, I'll leave the code in just in case the
455 # python script messed up ;-)
456 if ($pass == 1 and $macro eq "translationof") {
457 if (ref($state->{'element'}) eq 'HASH') {
458 $state->{'element'}->{'translationof'} = main::normalise_space($line);
460 return ('', true, undef, undef);
461 } else {
462 return t2h_default_unknown($macro, $line, $pass, $stack, $state);
469 my %translated_books = ();
470 # Construct a href to an external source of information.
471 # node is the node with texinfo @-commands
472 # node_id is the node transliterated and transformed as explained in the
473 # texinfo manual
474 # node_xhtml_id is the node transformed such that it is unique and can
475 # be used to make an html cross ref as explained in the texinfo manual
476 # file is the file in '(file)node'
477 sub lilypond_external_href($$$)
479 my $node = shift;
480 my $node_id = shift;
481 my $node_hxmlt_id = shift;
482 my $file = shift;
483 my $original_func = \&t2h_default_external_href;
485 # 1) Keep a hash of book->section_map
486 # 2) if not file in keys hash => try to load the map (assign empty map if
487 # non-existent => will load only once!)
488 # 3) if node in the section=>(file, anchor) map, replace node_id and
489 # node_xhtml_id by the map's values
490 # 4) call the t2h_default_external_href with these values (or the old ones if not found)
492 if (($node_id ne '') and defined($file) and ($node_id ne 'Top')) {
493 my $map_name = $file;
494 $map_name =~ s/-big-page//;
496 # Load the map if we haven't done so already
497 if (!exists($translated_books{$map_name})) {
498 my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
499 my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
500 || main::locate_include_file ("${map_name}.xref-map");
501 $translated_books{$map_name} = load_map_file ($map_filename);
504 # look up translation. use these values instead of the old filename/anchor
505 my $section_name_map = $translated_books{$map_name};
506 my $node_text = main::remove_texi($node);
507 if (defined($section_name_map->{$node_text})) {
508 ($node_id, $node_hxmlt_id) = @{$section_name_map->{$node_text}};
509 } else {
510 print STDERR "WARNING: Unable to find node '$node_text' in book $map_name.\n";
514 if (defined $file) {
515 return &$original_func($node, $node_id, $node_hxmlt_id, $file);
516 } else {
517 return &$original_func($node, $node_id, $node_hxmlt_id);
525 #############################################################################
526 ### CUSTOM TOC FOR EACH PAGE (in a frame on the left)
527 #############################################################################
529 my $page_toc_depth = 2;
530 my @default_toc = [];
532 # recursively generate the TOC entries for the element and its children (which
533 # are only shown up to maxlevel. All ancestors of the current element are also
534 # shown with their immediate children, irrespective of their level.
535 # Unnumbered entries are only printed out if they are at top-level or their
536 # parent element is an ancestor of the currently viewed node.
537 sub generate_ly_toc_entries($$$$)
539 my $element = shift;
540 my $element_path = shift;
541 my $maxlevel = shift;
542 my $always_show_unnumbered_children = shift;
543 # Skip undefined sections, plus all sections generated by index splitting
544 return() if (not defined($element) or exists($element->{'index_page'}));
545 my @result = ();
546 my $level = $element->{'toc_level'};
547 my $is_parent_of_current = $element->{'id'} && $element_path->{$element->{'id'}};
548 my $print_children = ( ($level < $maxlevel) or $is_parent_of_current );
549 my $ind = ' ' x $level;
550 my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : "";
552 my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}",$element->{'text'});
554 my $children = $element->{'section_childs'};
555 # Don't add unnumbered entries, unless they are at top-level or a parent of the current!
556 if (not ($element->{'number'} or $always_show_unnumbered_children)) {
557 return @result;
559 if ( $print_children and defined($children) and (ref($children) eq "ARRAY") ) {
560 push (@result, $entry);
561 my @child_result = ();
562 foreach (@$children) {
563 push (@child_result, generate_ly_toc_entries($_, $element_path, $maxlevel, $is_parent_of_current));
565 # if no child nodes were generated, e.g. for the index, where expanded pages
566 # are ignored, don't generate a list at all...
567 if (@child_result) {
568 push (@result, "\n$ind<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
569 push (@result, @child_result);
570 push (@result, "$ind</ul></li>\n");
572 } else {
573 push (@result, $entry . "</li>\n");
575 return @result;
579 # Print a customized TOC, containing only the first two levels plus the whole
580 # path to the current page
581 sub lilypond_generate_page_toc_body($)
583 my $element = shift;
584 my $current_element = $element;
585 my %parentelements;
586 $parentelements{$element->{'id'}} = 1;
587 # Find the path to the current element
588 while ( defined($current_element->{'sectionup'}) and
589 ($current_element->{'sectionup'} ne $current_element) )
591 $parentelements{$current_element->{'sectionup'}->{'id'}} = 1
592 if ($current_element->{'sectionup'}->{'id'} ne '');
593 $current_element = $current_element->{'sectionup'};
595 return () if not defined($current_element);
596 # Create the toc entries recursively
597 my @toc_entries = ("<div class=\"contents\">\n", "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
598 my $children = $current_element->{'section_childs'};
599 foreach ( @$children ) {
600 push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth, False));
602 push (@toc_entries, "</ul>\n");
603 push (@toc_entries, "</div>\n");
604 return @toc_entries;
607 sub lilypond_print_toc_div ($$)
609 my $fh = shift;
610 my $tocref = shift;
611 my @lines = @$tocref;
612 # use default TOC if no custom lines have been generated
613 @lines = @default_toc if (not @lines);
614 if (@lines) {
615 print $fh "\n\n<div id=\"tocframe\">\n";
616 print $fh '<h4> ' . $Texi2HTML::NAME{'Contents'} . "</h4>\n";
617 foreach my $line (@lines) {
618 print $fh $line;
620 print $fh "</div>\n\n";
624 # Create the custom TOC for this page (partially folded, current page is
625 # highlighted) and store it in a global variable. The TOC is written out after
626 # the html contents (but positioned correctly using CSS), so that browsers with
627 # css turned off still show the contents first.
628 our @this_page_toc = ();
629 sub lilypond_print_element_header
631 my $fh = shift;
632 my $first_in_page = shift;
633 my $previous_is_top = shift;
634 if ($first_in_page and not @this_page_toc) {
635 if (defined($Texi2HTML::THIS_ELEMENT)) {
636 # Create the TOC for this page
637 @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
640 return T2H_DEFAULT_print_element_header( $fh, $first_in_page, $previous_is_top);
643 # Generate the HTML output for the TOC
644 sub lilypond_toc_body($)
646 my $elements_list = shift;
647 # Generate a default TOC for pages without THIS_ELEMENT
648 @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
649 return T2H_GPL_toc_body($elements_list);
652 # Print out the TOC in a <div> at the beginning of the page
653 sub lilypond_print_page_head($)
655 my $fh = shift;
656 T2H_DEFAULT_print_page_head($fh);
657 print $fh "<div id=\"main\">\n";
660 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
661 # sidebar mimicking a TOC frame
662 sub print_lilypond_page_foot($)
664 my $fh = shift;
665 my $program_string = &$program_string();
666 # print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
667 print $fh "<!-- FOOTER -->\n\n";
668 print $fh "<!-- end div#main here -->\n</div>\n\n";
670 # Print the TOC frame and reset the TOC:
671 lilypond_print_toc_div ($fh, \@this_page_toc);
672 @this_page_toc = ();
674 # Close the page:
675 print $fh "</body>\n</html>\n";
682 #############################################################################
683 ### NICER / MORE FLEXIBLE NAVIGATION PANELS
684 #############################################################################
686 sub get_navigation_text
688 my $button = shift;
689 my $text = $NAVIGATION_TEXT{$button};
690 if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
691 $text = $text . $Texi2HTML::NODE{$button} . "&nbsp;";
692 } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
693 $text = "&nbsp;" . $Texi2HTML::NODE{$button} . $text;
694 } elsif ( $button eq 'Up' ) {
695 $text = "&nbsp;".$text.":&nbsp;" . $Texi2HTML::NODE{$button} . "&nbsp;";
697 return $text;
701 # Don't automatically create left-aligned table cells for every link, but
702 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
703 # button text. It's alignment as well as the colspan will be taken from the
704 # name of the button. Also, add 'newline' button text to create a new table
705 # row. The texts of the buttons are generated by get_navigation_text and
706 # will contain the name of the next/previous section/chapter.
707 sub lilypond_print_navigation
709 my $fh = shift;
710 my $buttons = shift;
711 my $vertical = shift;
712 my $spacing = 1;
713 # print $fh '<table cellpadding="', $spacing, '" cellspacing="', $spacing,
714 # "\" border=\"0\" class=\"nav_table\">\n";
715 print $fh "<table class=\"nav_table\">\n";
717 print $fh "<tr>" unless $vertical;
718 my $beginofline = 1;
719 foreach my $button (@$buttons)
721 print $fh qq{<tr valign="top" align="left">\n} if $vertical;
722 # Allow (left|right|center)-aligned-cell and newline as buttons!
723 if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
725 print $fh qq{</td>} unless $beginofline;
726 print $fh qq{<td valign="middle" align="$1" colspan="$2">};
727 $beginofline = 0;
729 elsif ( $button eq 'newline' )
731 print $fh qq{</td>} unless $beginofline;
732 print $fh qq{</tr>};
733 print $fh qq{<tr>};
734 $beginofline = 1;
737 elsif (ref($button) eq 'CODE')
739 &$button($fh, $vertical);
741 elsif (ref($button) eq 'SCALAR')
743 print $fh "$$button" if defined($$button);
745 elsif (ref($button) eq 'ARRAY')
747 my $text = $button->[1];
748 my $button_href = $button->[0];
749 # verify that $button_href is simple text and text is a reference
750 if (defined($button_href) and !ref($button_href)
751 and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
752 { # use given text
753 if ($Texi2HTML::HREF{$button_href})
755 my $anchor_attributes = '';
756 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
758 $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
760 if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
762 $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
764 print $fh "" .
765 &$anchor('',
766 $Texi2HTML::HREF{$button_href},
767 get_navigation_text($$text),
768 $anchor_attributes
771 else
773 print $fh get_navigation_text($$text);
777 elsif ($button eq ' ')
778 { # handle space button
779 print $fh
780 ($ICONS && $ACTIVE_ICONS{' '}) ?
781 &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
782 $NAVIGATION_TEXT{' '};
783 #next;
785 elsif ($Texi2HTML::HREF{$button})
786 { # button is active
787 my $btitle = $BUTTONS_GOTO{$button} ?
788 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
789 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
791 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
793 if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
795 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
797 if ($ICONS && $ACTIVE_ICONS{$button})
798 { # use icon
799 print $fh '' .
800 &$anchor('',
801 $Texi2HTML::HREF{$button},
802 &$button_icon_img($BUTTONS_NAME{$button},
803 $ACTIVE_ICONS{$button},
804 $Texi2HTML::SIMPLE_TEXT{$button}),
805 $btitle
808 else
809 { # use text
810 print $fh
811 '[' .
812 &$anchor('',
813 $Texi2HTML::HREF{$button},
814 get_navigation_text ($button),
815 $btitle
817 ']';
820 else
821 { # button is passive
822 print $fh
823 $ICONS && $PASSIVE_ICONS{$button} ?
824 &$button_icon_img($BUTTONS_NAME{$button},
825 $PASSIVE_ICONS{$button},
826 $Texi2HTML::SIMPLE_TEXT{$button}) :
828 "[" . get_navigation_text($button) . "]";
830 print $fh "</td>\n" if $vertical;
831 print $fh "</tr>\n" if $vertical;
833 print $fh "</td>" unless $beginofline;
834 print $fh "</tr>" unless $vertical;
835 print $fh "</table>\n";
839 @Texi2HTML::Config::SECTION_BUTTONS =
840 ('left-aligned-cell-1', 'FastBack',
841 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
842 'right-aligned-cell-1', 'FastForward',
843 'newline',
844 'left-aligned-cell-2', 'Back',
845 'center-aligned-cell-1', 'Up',
846 'right-aligned-cell-2', 'Forward'
849 # buttons for misc stuff
850 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
852 # buttons for chapter file footers
853 # (and headers but only if SECTION_NAVIGATION is false)
854 @Texi2HTML::Config::CHAPTER_BUTTONS =
855 ('left-aligned-cell-1', 'FastBack',
856 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
857 'right-aligned-cell-1', 'FastForward',
860 # buttons for section file footers
861 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
862 ('left-aligned-cell-1', 'FastBack',
863 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
864 'right-aligned-cell-1', 'FastForward',
865 'newline',
866 'left-aligned-cell-2', 'Back',
867 'center-aligned-cell-1', 'Up',
868 'right-aligned-cell-2', 'Forward'
871 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
872 ('left-aligned-cell-1', 'FastBack',
873 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
874 'right-aligned-cell-1', 'FastForward',
875 'newline',
876 'left-aligned-cell-2', 'Back',
877 'center-aligned-cell-1', 'Up',
878 'right-aligned-cell-2', 'Forward'
885 #############################################################################
886 ### FOOTNOTE FORMATTING
887 #############################################################################
889 # Format footnotes in a nicer way: Instead of printing the number in a separate
890 # (nr) heading line, use the standard way of prepending <sup>nr</sup> immediately
891 # before the fn text.
894 # The following code is copied from texi2html's examples/makeinfo.init and
895 # should be updated when texi2html makes some changes there!
897 my $makekinfo_like_footnote_absolute_number = 0;
899 sub makeinfo_like_foot_line_and_ref($$$$$$$$)
901 my $foot_num = shift;
902 my $relative_num = shift;
903 my $footid = shift;
904 my $docid = shift;
905 my $from_file = shift;
906 my $footnote_file = shift;
907 my $lines = shift;
908 my $state = shift;
910 $makekinfo_like_footnote_absolute_number++;
912 # this is a bit obscure, this allows to add an anchor only if formatted
913 # as part of the document.
914 $docid = '' if ($state->{'outside_document'} or $state->{'multiple_pass'});
916 if ($from_file eq $footnote_file)
918 $from_file = $footnote_file = '';
921 my $foot_anchor = "<sup>" . &$anchor($docid, "$footnote_file#$footid", $relative_num) . "</sup>";
922 $foot_anchor = &$anchor($docid, "$footnote_file#$footid", "($relative_num)") if ($state->{'preformatted'});
924 # unshift @$lines, "<li>";
925 # push @$lines, "</li>\n";
926 return ($lines, $foot_anchor);
929 sub makeinfo_like_foot_lines($)
931 my $lines = shift;
932 unshift @$lines, "<hr>\n<h4>$Texi2HTML::I18n::WORDS->{'Footnotes_Title'}</h4>\n";
933 #<ol type=\"1\">\n";
934 # push @$lines, "</ol>";
935 return $lines;
938 my %makekinfo_like_paragraph_in_footnote_nr;
940 sub makeinfo_like_paragraph ($$$$$$$$$$$$$)
942 my $text = shift;
943 my $align = shift;
944 my $indent = shift;
945 my $paragraph_command = shift;
946 my $paragraph_command_formatted = shift;
947 my $paragraph_number = shift;
948 my $format = shift;
949 my $item_nr = shift;
950 my $enumerate_style = shift;
951 my $number = shift;
952 my $command_stack_at_end = shift;
953 my $command_stack_at_begin = shift;
954 my $state = shift;
955 #print STDERR "format: $format\n" if (defined($format));
956 #print STDERR "paragraph @$command_stack_at_end; @$command_stack_at_begin\n";
957 $paragraph_command_formatted = '' if (!defined($paragraph_command_formatted) or
958 exists($special_list_commands{$format}->{$paragraph_command}));
959 return '' if ($text =~ /^\s*$/);
960 foreach my $style(t2h_collect_styles($command_stack_at_begin))
962 $text = t2h_begin_style($style, $text);
964 foreach my $style(t2h_collect_styles($command_stack_at_end))
966 $text = t2h_end_style($style, $text);
968 if (defined($paragraph_number) and defined($$paragraph_number))
970 $$paragraph_number++;
971 return $text if (($format eq 'itemize' or $format eq 'enumerate') and
972 ($$paragraph_number == 1));
974 my $open = '<p';
975 if ($align)
977 $open .= " align=\"$paragraph_style{$align}\"";
979 my $footnote_text = '';
980 if (defined($command_stack_at_begin->[0]) and $command_stack_at_begin->[0] eq 'footnote')
982 my $state = $Texi2HTML::THISDOC{'state'};
983 $makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number}++;
984 if ($makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number} <= 1)
986 $open.=' class="footnote"';
987 my $document_file = $state->{'footnote_document_file'};
988 if ($document_file eq $state->{'footnote_footnote_file'})
990 $document_file = '';
992 my $docid = $state->{'footnote_place_id'};
993 my $doc_state = $state->{'footnote_document_state'};
994 $docid = '' if ($doc_state->{'outside_document'} or $doc_state->{'multiple_pass'});
995 my $foot_label = &$anchor($state->{'footnote_footnote_id'},
996 $document_file . "#$state->{'footnote_place_id'}",
997 "$state->{'footnote_number_in_page'}");
998 $footnote_text = "<small>[${foot_label}]</small> ";
1001 return $open.'>'.$footnote_text.$text.'</p>';
1005 #############################################################################
1006 ### OTHER SETTINGS
1007 #############################################################################
1009 # For split pages, use index.html as start page!
1010 if ($Texi2HTML::Config::SPLIT eq 'section') {
1011 $Texi2HTML::Config::TOP_FILE = 'index.html';
1015 return 1;