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 = $$element{texi};
54 $anchor =~ tr/\ ?:'/-/d;
55 $$element{id} = $anchor;
56 # Numbered sections will get a filename Section_1.1.2, unnumbered sections will use
57 # the file name of the previous numbered section:
58 if ($$element{number}) {
59 my $filename = $anchor;
60 $filename .= ".$docu_ext" if (defined($docu_ext));
62 $$element{doc_nr} = $docnr;
63 $lastfilename = $filename;
66 $$element{doc_nr} = $docnr;
75 # The default formatting of external refs returns e.g.
76 # "(lilypond-internals)Timing_translator", while we simply want "Timing_translator".
77 # Solution: Remove all (...) from the file_and_node argument before calling
78 # the default handler!
79 sub lilypond_external_ref($$$$$$)
84 my $file_node = shift;
86 my $cross_ref = shift;
88 $file_node =~ s/\(.*\)//;
89 return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref);
93 # recursively generate the TOC entries for the element and its children (which
94 # are only shown up to maxlevel. All ancestors of the current element are also
95 # shown with their immediate children, irrespective of their level.
96 sub generate_ly_toc_entries($$$)
99 my $element_path = shift;
100 my $maxlevel = shift;
101 # Skip undefined sections, plus all sections generated by index splitting
102 return() if (not defined($element) or exists($element->{'index_page'}));
104 my $level = $element->{'toc_level'};
105 my $is_parent_of_current = $element_path->{$element->{'number'}};
106 my $print_children = ( ($level < $maxlevel) or $is_parent_of_current );
107 my $ind = ' ' x $level;
108 my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : "";
110 my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'id'}",$element->{'text'});
112 my $children = $element->{'section_childs'};
113 if ( $print_children and defined($children) and (ref($children) eq "ARRAY") ) {
114 push (@result, $entry);
115 my @child_result = ();
116 foreach (@$children) {
117 push (@child_result, generate_ly_toc_entries($_, $element_path, $maxlevel));
119 # if no child nodes were generated, e.g. for the index, where expanded pages
120 # are ignored, don't generate a list at all...
122 push (@result, "$ind<ul$NO_BULLET_LIST_ATTRIBUTE>");
123 push (@result, @child_result);
124 push (@result, "$ind</ul></li>\n");
127 push (@result, $entry . "</li>\n");
133 # Print a customized TOC, containing only the first two levels plus the whole
134 # path to the current page
135 sub lilypond_generate_page_toc_body($)
138 my $current_element = $element;
140 $parentelements{$element->{'number'}} = 1;
141 # Find the path to the current element
142 while ( defined($current_element->{'sectionup'}) and
143 ($current_element->{'sectionup'} ne $current_element) )
145 $parentelements{$current_element->{'sectionup'}->{'number'}} = 1
146 if ($current_element->{'sectionup'}->{'number'} ne '');
147 $current_element = $current_element->{'sectionup'};
149 return () if not defined($current_element);
150 # Create the toc entries recursively
151 my @toc_entries = ("<div class=\"contents\">", "<ul$NO_BULLET_LIST_ATTRIBUTE>");
152 my $children = $current_element->{'section_childs'};
153 foreach ( @$children ) {
154 push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth));
156 push (@toc_entries, "</ul>");
157 push (@toc_entries, "</div>");
161 my @this_page_toc = ();
163 sub lilypond_print_element_header
166 my $first_in_page = shift;
167 my $previous_is_top = shift;
168 if ($first_in_page and not @this_page_toc) {
169 if (defined($Texi2HTML::THIS_ELEMENT)) {
170 # Create the TOC for this page
171 @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
174 return T2H_DEFAULT_print_element_header( $fh, $first_in_page, $previous_is_top);
186 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
187 # sidebar mimicking a TOC frame
188 sub print_lilypond_page_foot($)
191 # my @lines = @{$Texi2HTML::OVERVIEW};
192 # my $lines = $Texi2HTML::TOC_LINES;
193 my @lines = @this_page_toc;
195 print "We have no toc lines, generate generic ones for main::element_top::\n";
196 # print Dumper( $main::element_top );
197 # print Dumper( $main::section_top );
198 # print Dumper( $main::node_top );
199 # @lines = lilypond_generate_page_toc_body( $main::element_top );
200 # @lines = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
201 @lines = @$Texi2HTML::TOC_LINES;
204 print $fh "<div id=\"tocframe\">";
205 print $fh '<h4> ' . $Texi2HTML::NAME{'Contents'} . "</h4>\n";
206 foreach my $line (@lines) {
212 T2H_DEFAULT_print_page_foot($fh);
221 sub get_navigation_text
224 my $text = $NAVIGATION_TEXT{$button};
225 if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
226 $text = $text . $Texi2HTML::NODE{$button} . " ";
227 } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
228 $text = " " . $Texi2HTML::NODE{$button} . $text;
229 } elsif ( $button eq 'Up' ) {
230 $text = " Up: " . $Texi2HTML::NODE{$button} . " ";
236 # Don't automatically create left-aligned table cells for every link, but
237 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
238 # button text. It's alignment as well as the colspan will be taken from the
239 # name of the button. Also, add 'newline' button text to create a new table
240 # row. The texts of the buttons are generated by get_navigation_text and
241 # will contain the name of the next/previous section/chapter.
242 sub lilypond_print_navigation
246 my $vertical = shift;
248 # print $fh '<table cellpadding="', $spacing, '" cellspacing="', $spacing,
249 # "\" border=\"0\" class=\"nav_table\">\n";
250 print $fh "<table class=\"nav_table\">\n";
252 print $fh "<tr>" unless $vertical;
254 foreach my $button (@$buttons)
256 print $fh qq{<tr valign="top" align="left">\n} if $vertical;
257 # Allow (left|right|center)-aligned-cell and newline as buttons!
258 if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
260 print $fh qq{</td>} unless $beginofline;
261 print $fh qq{<td valign="middle" align="$1" colspan="$2">};
264 elsif ( $button eq 'newline' )
266 print $fh qq{</td>} unless $beginofline;
272 elsif (ref($button) eq 'CODE')
274 &$button($fh, $vertical);
276 elsif (ref($button) eq 'SCALAR')
278 print $fh "$$button" if defined($$button);
280 elsif (ref($button) eq 'ARRAY')
282 my $text = $button->[1];
283 my $button_href = $button->[0];
284 # verify that $button_href is simple text and text is a reference
285 if (defined($button_href) and !ref($button_href)
286 and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
288 if ($Texi2HTML::HREF{$button_href})
292 $Texi2HTML::HREF{$button_href},
303 elsif ($button eq ' ')
304 { # handle space button
306 ($ICONS && $ACTIVE_ICONS{' '}) ?
307 &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
308 $NAVIGATION_TEXT{' '};
311 elsif ($Texi2HTML::HREF{$button})
313 my $btitle = $BUTTONS_GOTO{$button} ?
314 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
315 if ($ICONS && $ACTIVE_ICONS{$button})
319 $Texi2HTML::HREF{$button},
320 &$button_icon_img($BUTTONS_NAME{$button},
321 $ACTIVE_ICONS{$button},
322 $Texi2HTML::SIMPLE_TEXT{$button}),
331 $Texi2HTML::HREF{$button},
332 get_navigation_text($button),
339 { # button is passive
341 $ICONS && $PASSIVE_ICONS{$button} ?
342 &$button_icon_img($BUTTONS_NAME{$button},
343 $PASSIVE_ICONS{$button},
344 $Texi2HTML::SIMPLE_TEXT{$button}) :
346 "[" . get_navigation_text($button) . "]";
348 print $fh "</td>\n" if $vertical;
349 print $fh "</tr>\n" if $vertical;
351 print $fh "</td>" unless $beginofline;
352 print $fh "</tr>" unless $vertical;
353 print $fh "</table>\n";
357 @Texi2HTML::Config::SECTION_BUTTONS =
358 ('left-aligned-cell-1', 'FastBack',
359 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
360 'right-aligned-cell-1', 'FastForward',
362 'left-aligned-cell-2', 'Back',
363 'center-aligned-cell-1', 'Up',
364 'right-aligned-cell-2', 'Forward'
367 # buttons for misc stuff
368 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
370 # buttons for chapter file footers
371 # (and headers but only if SECTION_NAVIGATION is false)
372 @Texi2HTML::Config::CHAPTER_BUTTONS =
373 ('left-aligned-cell-1', 'FastBack',
374 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
375 'right-aligned-cell-1', 'FastForward',
378 # buttons for section file footers
379 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
380 ('left-aligned-cell-1', 'FastBack',
381 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
382 'right-aligned-cell-1', 'FastForward',
384 'left-aligned-cell-2', 'Back',
385 'center-aligned-cell-1', 'Up',
386 'right-aligned-cell-2', 'Forward'
389 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
390 ('left-aligned-cell-1', 'FastBack',
391 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
392 'right-aligned-cell-1', 'FastForward',
394 'left-aligned-cell-2', 'Back',
395 'center-aligned-cell-1', 'Up',
396 'right-aligned-cell-2', 'Forward'
399 # $Texi2HTML::Config::SPLIT = 'section';
400 $Texi2HTML::Config::PREFIX = 'lilypond';
401 # $Texi2HTML::Config::FRAMES = 1;
402 @Texi2HTML::Config::CSS_REFS = ("lilypond.css");
403 $Texi2HTML::Config::element_file_name = \&split_at_numbered_sections;
404 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
405 $Texi2HTML::Config::print_page_foot = \&print_lilypond_page_foot;
406 $Texi2HTML::Config::print_navigation = \&lilypond_print_navigation;
407 $Texi2HTML::Config::external_ref = \&lilypond_external_ref;