4 package Texi2HTML::Config;
8 my $page_toc_depth = 2;
11 $Data::Dumper::Maxdepth = 2;
13 sub print_element_info($)
16 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
17 print "Element: $element\n";
18 print Dumper($element);
22 # This function makes sure that files are only generated for numbered sections,
23 # but not for unnumbered ones. It is called after texi2html has done its own
24 # splitting and simply returns the filename for the node given as first argument
25 # Nodes with the same filename will be printed out to the same filename, so
26 # this really all we need. Also, make sure that the file names for sections
27 # are derived from the section title. We also might want to name the anchors
28 # according to node titles, which works by simply overriding the id element of
30 sub split_at_numbered_sections($$$)
34 my $docu_name = shift;
35 my $docu_ext = $Texi2HTML::Config::EXTENSION;
36 if ( $Texi2HTML::THISDOC{'current_lang'} ) {
37 $docu_ext = $Texi2HTML::THISDOC{'current_lang'} . "." . $docu_ext;
40 # if ($$element{number} eq "1.1") {
41 # print_element_info ($element);
44 # TOC, footer, about etc. are called with undefined $element and $type == "toc"|"stoc"|"foot"|"about"
45 if ($type eq "toc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
46 my $filename = "lilypond_$type";
47 $filename .= ".$docu_ext" if (defined($docu_ext));
48 # print "Standard file of type $type\n";
51 # derive the name of the anchor (i.e. the part after # in the links!),
52 # don't use texi2html's SECx.x default!
53 my $anchor = main::remove_texi($$element{texi});
54 my $trof = $$element{translationof};
56 print "We have a translationof: $trof\n";
57 print Dumper($element);
60 $anchor =~ tr/\ ?:'/-/d;
61 $$element{id} = $anchor;
62 # Numbered sections will get a filename Section_1.1.2, unnumbered sections will use
63 # the file name of the previous numbered section:
64 if ($$element{number}) {
65 my $filename = $anchor;
66 $filename .= ".$docu_ext" if (defined($docu_ext));
68 $$element{doc_nr} = $docnr;
69 $lastfilename = $filename;
72 $$element{doc_nr} = $docnr;
81 # Print a link in a menu. Since we split at sections, but still want access keys,
82 # we have to duplicate this function here :-((((
83 sub lilypond_menu_link($$$$$$)
91 if (($entry eq '') or $NODE_NAME_IN_MENU or $state->{'preformatted'})
93 $name .= ':' if ($name ne '');
94 $entry = "$MENU_SYMBOL$name$node";
98 $accesskey = "accesskey=\"$menu_entry_index\"" if ($USE_ACCESSKEY and ($menu_entry_index < 10));
99 $entry = &$anchor ('', $href, $entry, $accesskey) if (defined($href));
100 return $entry if ($SIMPLE_MENU);
101 if ($state->{'preformatted'})
103 return '<tr><td>' . main::do_preformatted($entry . $ending, $state);
105 return "<tr><td align=\"left\" valign=\"top\">$entry</td><td> </td>";
109 # The default formatting of external refs returns e.g.
110 # "(lilypond-internals)Timing_translator", while we simply want "Timing_translator".
111 # Solution: Remove all (...) from the file_and_node argument before calling
112 # the default handler!
113 sub lilypond_external_ref($$$$$$)
118 my $file_node = shift;
120 my $cross_ref = shift;
122 $file_node =~ s/\(.*\)//;
123 return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref);
127 # recursively generate the TOC entries for the element and its children (which
128 # are only shown up to maxlevel. All ancestors of the current element are also
129 # shown with their immediate children, irrespective of their level.
130 sub generate_ly_toc_entries($$$)
133 my $element_path = shift;
134 my $maxlevel = shift;
135 # Skip undefined sections, plus all sections generated by index splitting
136 return() if (not defined($element) or exists($element->{'index_page'}));
138 my $level = $element->{'toc_level'};
139 my $is_parent_of_current = $element_path->{$element->{'number'}};
140 my $print_children = ( ($level < $maxlevel) or $is_parent_of_current );
141 my $ind = ' ' x $level;
142 my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : "";
144 my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'id'}",$element->{'text'});
146 my $children = $element->{'section_childs'};
147 if ( $print_children and defined($children) and (ref($children) eq "ARRAY") ) {
148 push (@result, $entry);
149 my @child_result = ();
150 foreach (@$children) {
151 push (@child_result, generate_ly_toc_entries($_, $element_path, $maxlevel));
153 # if no child nodes were generated, e.g. for the index, where expanded pages
154 # are ignored, don't generate a list at all...
156 push (@result, "$ind<ul$NO_BULLET_LIST_ATTRIBUTE>");
157 push (@result, @child_result);
158 push (@result, "$ind</ul></li>\n");
161 push (@result, $entry . "</li>\n");
167 # Print a customized TOC, containing only the first two levels plus the whole
168 # path to the current page
169 sub lilypond_generate_page_toc_body($)
172 my $current_element = $element;
174 $parentelements{$element->{'number'}} = 1;
175 # Find the path to the current element
176 while ( defined($current_element->{'sectionup'}) and
177 ($current_element->{'sectionup'} ne $current_element) )
179 $parentelements{$current_element->{'sectionup'}->{'number'}} = 1
180 if ($current_element->{'sectionup'}->{'number'} ne '');
181 $current_element = $current_element->{'sectionup'};
183 return () if not defined($current_element);
184 # Create the toc entries recursively
185 my @toc_entries = ("<div class=\"contents\">", "<ul$NO_BULLET_LIST_ATTRIBUTE>");
186 my $children = $current_element->{'section_childs'};
187 foreach ( @$children ) {
188 push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth));
190 push (@toc_entries, "</ul>");
191 push (@toc_entries, "</div>");
195 my @this_page_toc = ();
197 sub lilypond_print_element_header
200 my $first_in_page = shift;
201 my $previous_is_top = shift;
202 if ($first_in_page and not @this_page_toc) {
203 if (defined($Texi2HTML::THIS_ELEMENT)) {
204 # Create the TOC for this page
205 @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
208 return T2H_DEFAULT_print_element_header( $fh, $first_in_page, $previous_is_top);
220 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
221 # sidebar mimicking a TOC frame
222 sub print_lilypond_page_foot($)
225 # my @lines = @{$Texi2HTML::OVERVIEW};
226 # my $lines = $Texi2HTML::TOC_LINES;
227 my @lines = @this_page_toc;
229 print "We have no toc lines, generate generic ones for main::element_top::\n";
230 # print Dumper( $main::element_top );
231 # print Dumper( $main::section_top );
232 # print Dumper( $main::node_top );
233 # @lines = lilypond_generate_page_toc_body( $main::element_top );
234 # @lines = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
235 @lines = @$Texi2HTML::TOC_LINES;
238 print $fh "<div id=\"tocframe\">";
239 print $fh '<h4> ' . $Texi2HTML::NAME{'Contents'} . "</h4>\n";
240 foreach my $line (@lines) {
246 T2H_DEFAULT_print_page_foot($fh);
255 sub get_navigation_text
258 my $text = $NAVIGATION_TEXT{$button};
259 if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
260 $text = $text . $Texi2HTML::NODE{$button} . " ";
261 } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
262 $text = " " . $Texi2HTML::NODE{$button} . $text;
263 } elsif ( $button eq 'Up' ) {
264 $text = " Up: " . $Texi2HTML::NODE{$button} . " ";
270 # Don't automatically create left-aligned table cells for every link, but
271 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
272 # button text. It's alignment as well as the colspan will be taken from the
273 # name of the button. Also, add 'newline' button text to create a new table
274 # row. The texts of the buttons are generated by get_navigation_text and
275 # will contain the name of the next/previous section/chapter.
276 sub lilypond_print_navigation
280 my $vertical = shift;
282 # print $fh '<table cellpadding="', $spacing, '" cellspacing="', $spacing,
283 # "\" border=\"0\" class=\"nav_table\">\n";
284 print $fh "<table class=\"nav_table\">\n";
286 print $fh "<tr>" unless $vertical;
288 foreach my $button (@$buttons)
290 print $fh qq{<tr valign="top" align="left">\n} if $vertical;
291 # Allow (left|right|center)-aligned-cell and newline as buttons!
292 if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
294 print $fh qq{</td>} unless $beginofline;
295 print $fh qq{<td valign="middle" align="$1" colspan="$2">};
298 elsif ( $button eq 'newline' )
300 print $fh qq{</td>} unless $beginofline;
306 elsif (ref($button) eq 'CODE')
308 &$button($fh, $vertical);
310 elsif (ref($button) eq 'SCALAR')
312 print $fh "$$button" if defined($$button);
314 elsif (ref($button) eq 'ARRAY')
316 my $text = $button->[1];
317 my $button_href = $button->[0];
318 # verify that $button_href is simple text and text is a reference
319 if (defined($button_href) and !ref($button_href)
320 and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
322 if ($Texi2HTML::HREF{$button_href})
324 my $anchor_attributes = '';
325 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
327 $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
329 if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
331 $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
335 $Texi2HTML::HREF{$button_href},
347 elsif ($button eq ' ')
348 { # handle space button
350 ($ICONS && $ACTIVE_ICONS{' '}) ?
351 &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
352 $NAVIGATION_TEXT{' '};
355 elsif ($Texi2HTML::HREF{$button})
357 my $btitle = $BUTTONS_GOTO{$button} ?
358 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
359 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
361 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
363 if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
365 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
367 if ($ICONS && $ACTIVE_ICONS{$button})
371 $Texi2HTML::HREF{$button},
372 &$button_icon_img($BUTTONS_NAME{$button},
373 $ACTIVE_ICONS{$button},
374 $Texi2HTML::SIMPLE_TEXT{$button}),
383 $Texi2HTML::HREF{$button},
384 $NAVIGATION_TEXT{$button},
391 { # button is passive
393 $ICONS && $PASSIVE_ICONS{$button} ?
394 &$button_icon_img($BUTTONS_NAME{$button},
395 $PASSIVE_ICONS{$button},
396 $Texi2HTML::SIMPLE_TEXT{$button}) :
398 "[" . $NAVIGATION_TEXT{$button} . "]";
400 print $fh "</td>\n" if $vertical;
401 print $fh "</tr>\n" if $vertical;
403 print $fh "</td>" unless $beginofline;
404 print $fh "</tr>" unless $vertical;
405 print $fh "</table>\n";
409 @Texi2HTML::Config::SECTION_BUTTONS =
410 ('left-aligned-cell-1', 'FastBack',
411 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
412 'right-aligned-cell-1', 'FastForward',
414 'left-aligned-cell-2', 'Back',
415 'center-aligned-cell-1', 'Up',
416 'right-aligned-cell-2', 'Forward'
419 # buttons for misc stuff
420 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
422 # buttons for chapter file footers
423 # (and headers but only if SECTION_NAVIGATION is false)
424 @Texi2HTML::Config::CHAPTER_BUTTONS =
425 ('left-aligned-cell-1', 'FastBack',
426 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
427 'right-aligned-cell-1', 'FastForward',
430 # buttons for section file footers
431 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
432 ('left-aligned-cell-1', 'FastBack',
433 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
434 'right-aligned-cell-1', 'FastForward',
436 'left-aligned-cell-2', 'Back',
437 'center-aligned-cell-1', 'Up',
438 'right-aligned-cell-2', 'Forward'
441 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
442 ('left-aligned-cell-1', 'FastBack',
443 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
444 'right-aligned-cell-1', 'FastForward',
446 'left-aligned-cell-2', 'Back',
447 'center-aligned-cell-1', 'Up',
448 'right-aligned-cell-2', 'Forward'
451 # $Texi2HTML::Config::SPLIT = 'section';
452 @Texi2HTML::Config::CSS_REFS = ("lilypond.css");
453 $Texi2HTML::Config::USE_ACCESSKEY = 1;
454 $Texi2HTML::Config::USE_LINKS = 1;
455 $Texi2HTML::Config::USE_REL_REV = 1;
456 $Texi2HTML::Config::element_file_name = \&split_at_numbered_sections;
457 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
458 $Texi2HTML::Config::print_page_foot = \&print_lilypond_page_foot;
459 $Texi2HTML::Config::print_navigation = \&lilypond_print_navigation;
460 $Texi2HTML::Config::external_ref = \&lilypond_external_ref;
461 $Texi2HTML::Config::menu_link = \&lilypond_menu_link;
464 # For split pages, use index(.lang).html as start page!
465 if ($Texi2HTML::Config::SPLIT == 'section') {
466 my $lng = $Texi2HTML::THISDOC{'current_lang'};
467 if ($lng and ($lng ne "en")) {
468 $Texi2HTML::Config::TOP_FILE = 'index.'.$lng.'.html';
470 $Texi2HTML::Config::TOP_FILE = 'index.html';
476 # Try to make use of @translationof to generate files according to the original
477 # English section title...
478 sub lilypond_unknown($$$$$)
486 if ($pass == 1 and $macro eq "translationof") {
487 if (ref($state->{'element'})=='HASH') {
488 $state->{'element'}->{'translationof'} = $line;
490 print "UNKNOWN: macro:$macro, line:$line, pass:$pass, stack:$stack, state:$state\n";
491 print Dumper($stack);
492 print Dumper($state);
494 if ($pass == 2 and $macro eq "translationof") {
495 # if (ref($state->{'element'})=='HASH') {
496 # # $state->{'element'}->{'translationonf'} = $line;
498 print "UNKNOWN: macro:$macro, line:$line, pass:$pass, stack:$stack, state:$state\n";
499 print Dumper($stack);
500 print Dumper($state);
501 return ($line, 0, undef, undef);
503 return t2h_default_unknown($macro, $line, $pass, $stack, $state);
506 $Texi2HTML::Config::unknown = \&lilypond_unknown;