4 package Texi2HTML::Config;
8 my $page_toc_depth = 2;
12 $Data::Dumper::Maxdepth = 2;
14 sub print_element_info($)
17 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
18 print "Element: $element\n";
19 print Dumper($element);
23 # Convert a given node name to its proper file name (normalization as explained
24 # in the texinfo manual:
25 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
26 sub texinfo_file_name($)
29 # File name normalization by texinfo:
30 # 1/2: letters and numbers are left unchanged
31 # 3/4: multiple, leading and trailing whitespace is removed
32 $str = main::normalise_space($str);
33 # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
34 # chars are replaced by _xxxx (xxxx=ascii character code)
35 my @chars = split(//, $str);
37 foreach my $char (@chars) {
38 if ( $char eq ' ' ) { # space -> '-'
40 } elsif ( ('0' le $char and $char le '9' ) or
41 ('A' le $char and $char le 'Z' ) or
42 ('a' le $char and $char le 'z' ) ) { # number or letter
45 my $ccode = ord($char);
47 if ( ord($char)<= 0xFFFF ) {
48 $addstr = sprintf("_%4x", $ccode);
50 $addstr = sprintf("__%6x", $ccode);
52 # padding is done by spaces, replace by '0'
57 # 7: if name begins with number, prepend 't_g' (so it starts with a letter)
58 if ($str =~ /^[0-9]/) {
67 # This function makes sure that files are only generated for numbered sections,
68 # but not for unnumbered ones. It is called after texi2html has done its own
69 # splitting and simply returns the filename for the node given as first argument
70 # Nodes with the same filename will be printed out to the same filename, so
71 # this really all we need. Also, make sure that the file names for sections
72 # are derived from the section title. We also might want to name the anchors
73 # according to node titles, which works by simply overriding the id element of
75 sub split_at_numbered_sections($$$)
79 my $docu_name = shift;
80 my $docu_ext = $Texi2HTML::Config::EXTENSION;
82 # if ($$element{number} eq "1.1") {
83 # print_element_info ($element);
86 # TOC, footer, about etc. are called with undefined $element and $type == "toc"|"stoc"|"foot"|"about"
87 if ($type eq "toc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
90 # derive the name of the anchor (i.e. the part after # in the links!),
91 # don't use texi2html's SECx.x default!
92 my $anchor = main::remove_texi($$element{texi});
93 if ($$element{translationof}) {
94 $anchor = main::remove_texi($$element{translationof});
96 # normalize to the same file name as texinfo
97 $anchor = texinfo_file_name($anchor);
98 $$element{id} = $anchor;
99 # Numbered sections will get a filename Section_1.1.2, unnumbered sections will use
100 # the file name of the previous numbered section:
101 if ($$element{number}) {
102 my $filename = $anchor;
103 $filename .= ".$docu_ext" if (defined($docu_ext));
105 $$element{doc_nr} = $docnr;
106 $lastfilename = $filename;
109 $$element{doc_nr} = $docnr;
110 return $lastfilename;
118 # The default formatting of external refs returns e.g.
119 # "(lilypond-internals)Timing_translator", while we simply want "Timing_translator".
120 # Solution: Remove all (...) from the file_and_node argument before calling
121 # the default handler!
122 sub lilypond_external_ref($$$$$$)
127 my $file_node = shift;
129 my $cross_ref = shift;
131 $file_node =~ s/\(.*\)//;
132 return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref);
136 # recursively generate the TOC entries for the element and its children (which
137 # are only shown up to maxlevel. All ancestors of the current element are also
138 # shown with their immediate children, irrespective of their level.
139 sub generate_ly_toc_entries($$$)
142 my $element_path = shift;
143 my $maxlevel = shift;
144 # Skip undefined sections, plus all sections generated by index splitting
145 return() if (not defined($element) or exists($element->{'index_page'}));
147 my $level = $element->{'toc_level'};
148 my $is_parent_of_current = $element_path->{$element->{'number'}};
149 my $print_children = ( ($level < $maxlevel) or $is_parent_of_current );
150 my $ind = ' ' x $level;
151 my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : "";
153 my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'id'}",$element->{'text'});
155 my $children = $element->{'section_childs'};
156 if ( $print_children and defined($children) and (ref($children) eq "ARRAY") ) {
157 push (@result, $entry);
158 my @child_result = ();
159 foreach (@$children) {
160 push (@child_result, generate_ly_toc_entries($_, $element_path, $maxlevel));
162 # if no child nodes were generated, e.g. for the index, where expanded pages
163 # are ignored, don't generate a list at all...
165 push (@result, "$ind<ul$NO_BULLET_LIST_ATTRIBUTE>");
166 push (@result, @child_result);
167 push (@result, "$ind</ul></li>\n");
170 push (@result, $entry . "</li>\n");
176 # Print a customized TOC, containing only the first two levels plus the whole
177 # path to the current page
178 sub lilypond_generate_page_toc_body($)
181 my $current_element = $element;
183 $parentelements{$element->{'number'}} = 1;
184 # Find the path to the current element
185 while ( defined($current_element->{'sectionup'}) and
186 ($current_element->{'sectionup'} ne $current_element) )
188 $parentelements{$current_element->{'sectionup'}->{'number'}} = 1
189 if ($current_element->{'sectionup'}->{'number'} ne '');
190 $current_element = $current_element->{'sectionup'};
192 return () if not defined($current_element);
193 # Create the toc entries recursively
194 my @toc_entries = ("<div class=\"contents\">", "<ul$NO_BULLET_LIST_ATTRIBUTE>");
195 my $children = $current_element->{'section_childs'};
196 foreach ( @$children ) {
197 push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth));
199 push (@toc_entries, "</ul>");
200 push (@toc_entries, "</div>");
204 my @this_page_toc = ();
206 sub lilypond_print_element_header
209 my $first_in_page = shift;
210 my $previous_is_top = shift;
211 if ($first_in_page and not @this_page_toc) {
212 if (defined($Texi2HTML::THIS_ELEMENT)) {
213 # Create the TOC for this page
214 @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
217 return T2H_DEFAULT_print_element_header( $fh, $first_in_page, $previous_is_top);
220 sub lilypond_toc_body($)
222 my $elements_list = shift;
223 # Generate a default TOC for pages without THIS_ELEMENT
224 @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
225 return T2H_GPL_toc_body($elements_list);
237 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
238 # sidebar mimicking a TOC frame
239 sub print_lilypond_page_foot($)
242 my @lines = @this_page_toc;
243 # use default TOC if no custom lines have been generated
244 @lines = @default_toc if (not @lines);
246 print $fh "<div id=\"tocframe\">";
247 print $fh '<h4> ' . $Texi2HTML::NAME{'Contents'} . "</h4>\n";
248 foreach my $line (@lines) {
254 T2H_DEFAULT_print_page_foot($fh);
262 sub get_navigation_text
265 my $text = $NAVIGATION_TEXT{$button};
266 if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
267 $text = $text . $Texi2HTML::NODE{$button} . " ";
268 } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
269 $text = " " . $Texi2HTML::NODE{$button} . $text;
270 } elsif ( $button eq 'Up' ) {
271 $text = " ".$text.": " . $Texi2HTML::NODE{$button} . " ";
277 # Don't automatically create left-aligned table cells for every link, but
278 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
279 # button text. It's alignment as well as the colspan will be taken from the
280 # name of the button. Also, add 'newline' button text to create a new table
281 # row. The texts of the buttons are generated by get_navigation_text and
282 # will contain the name of the next/previous section/chapter.
283 sub lilypond_print_navigation
287 my $vertical = shift;
289 # print $fh '<table cellpadding="', $spacing, '" cellspacing="', $spacing,
290 # "\" border=\"0\" class=\"nav_table\">\n";
291 print $fh "<table class=\"nav_table\">\n";
293 print $fh "<tr>" unless $vertical;
295 foreach my $button (@$buttons)
297 print $fh qq{<tr valign="top" align="left">\n} if $vertical;
298 # Allow (left|right|center)-aligned-cell and newline as buttons!
299 if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
301 print $fh qq{</td>} unless $beginofline;
302 print $fh qq{<td valign="middle" align="$1" colspan="$2">};
305 elsif ( $button eq 'newline' )
307 print $fh qq{</td>} unless $beginofline;
313 elsif (ref($button) eq 'CODE')
315 &$button($fh, $vertical);
317 elsif (ref($button) eq 'SCALAR')
319 print $fh "$$button" if defined($$button);
321 elsif (ref($button) eq 'ARRAY')
323 my $text = $button->[1];
324 my $button_href = $button->[0];
325 # verify that $button_href is simple text and text is a reference
326 if (defined($button_href) and !ref($button_href)
327 and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
329 if ($Texi2HTML::HREF{$button_href})
331 my $anchor_attributes = '';
332 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
334 $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
336 if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
338 $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
342 $Texi2HTML::HREF{$button_href},
343 get_navigation_text($$text),
349 print $fh get_navigation_text($$text);
353 elsif ($button eq ' ')
354 { # handle space button
356 ($ICONS && $ACTIVE_ICONS{' '}) ?
357 &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
358 $NAVIGATION_TEXT{' '};
361 elsif ($Texi2HTML::HREF{$button})
363 my $btitle = $BUTTONS_GOTO{$button} ?
364 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
365 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
367 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
369 if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
371 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
373 if ($ICONS && $ACTIVE_ICONS{$button})
377 $Texi2HTML::HREF{$button},
378 &$button_icon_img($BUTTONS_NAME{$button},
379 $ACTIVE_ICONS{$button},
380 $Texi2HTML::SIMPLE_TEXT{$button}),
389 $Texi2HTML::HREF{$button},
390 get_navigation_text ($button),
397 { # button is passive
399 $ICONS && $PASSIVE_ICONS{$button} ?
400 &$button_icon_img($BUTTONS_NAME{$button},
401 $PASSIVE_ICONS{$button},
402 $Texi2HTML::SIMPLE_TEXT{$button}) :
404 "[" . get_navigation_text($button) . "]";
406 print $fh "</td>\n" if $vertical;
407 print $fh "</tr>\n" if $vertical;
409 print $fh "</td>" unless $beginofline;
410 print $fh "</tr>" unless $vertical;
411 print $fh "</table>\n";
415 @Texi2HTML::Config::SECTION_BUTTONS =
416 ('left-aligned-cell-1', 'FastBack',
417 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
418 'right-aligned-cell-1', 'FastForward',
420 'left-aligned-cell-2', 'Back',
421 'center-aligned-cell-1', 'Up',
422 'right-aligned-cell-2', 'Forward'
425 # buttons for misc stuff
426 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
428 # buttons for chapter file footers
429 # (and headers but only if SECTION_NAVIGATION is false)
430 @Texi2HTML::Config::CHAPTER_BUTTONS =
431 ('left-aligned-cell-1', 'FastBack',
432 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
433 'right-aligned-cell-1', 'FastForward',
436 # buttons for section file footers
437 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
438 ('left-aligned-cell-1', 'FastBack',
439 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
440 'right-aligned-cell-1', 'FastForward',
442 'left-aligned-cell-2', 'Back',
443 'center-aligned-cell-1', 'Up',
444 'right-aligned-cell-2', 'Forward'
447 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
448 ('left-aligned-cell-1', 'FastBack',
449 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
450 'right-aligned-cell-1', 'FastForward',
452 'left-aligned-cell-2', 'Back',
453 'center-aligned-cell-1', 'Up',
454 'right-aligned-cell-2', 'Forward'
457 # $Texi2HTML::Config::SPLIT = 'section';
458 @Texi2HTML::Config::CSS_REFS = ("lilypond.css");
459 $Texi2HTML::Config::USE_ACCESSKEY = 1;
460 $Texi2HTML::Config::USE_LINKS = 1;
461 $Texi2HTML::Config::USE_REL_REV = 1;
462 $Texi2HTML::Config::element_file_name = \&split_at_numbered_sections;
463 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
464 $Texi2HTML::Config::print_page_foot = \&print_lilypond_page_foot;
465 $Texi2HTML::Config::print_navigation = \&lilypond_print_navigation;
466 $Texi2HTML::Config::external_ref = \&lilypond_external_ref;
467 $Texi2HTML::Config::toc_body = \&lilypond_toc_body;
470 # For split pages, use index(.lang).html as start page!
471 if ($Texi2HTML::Config::SPLIT == 'section') {
472 # my $lng = $Texi2HTML::THISDOC{'current_lang'};
473 # if ($lng and ($lng ne "en")) {
474 # $Texi2HTML::Config::TOP_FILE = 'index.'.$lng.'.html';
476 $Texi2HTML::Config::TOP_FILE = 'index.html';
480 # if ($Texi2HTML::THISDOC{'current_lang'}) {
481 # $Texi2HTML::Config::EXTENSION = $Texi2HTML::THISDOC{'current_lang'} . "." .
482 # $docu_ext = $Texi2HTML::Config::EXTENSION;;
487 # Try to make use of @translationof to generate files according to the original
488 # English section title...
489 sub lilypond_unknown($$$$$)
497 # the @translationof macro provides the original English section title,
498 # which should be used for file/anchor naming, while the title will be
499 # translated to each language
500 if ($pass == 1 and $macro eq "translationof") {
501 if (ref($state->{'element'})=='HASH') {
502 $state->{'element'}->{'translationof'} = main::normalise_space($line);
504 return ('', true, undef, undef);
506 return t2h_default_unknown($macro, $line, $pass, $stack, $state);
509 $Texi2HTML::Config::unknown = \&lilypond_unknown;