3 package Texi2HTML::Config;
7 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 # Convert a given node name to its proper file name (normalization as explained
23 # in the texinfo manual:
24 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
25 sub texinfo_file_name($)
28 # File name normalization by texinfo:
29 # 1/2: letters and numbers are left unchanged
30 # 3/4: multiple, leading and trailing whitespace is removed
31 $str = main::normalise_space($str);
32 # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
33 # chars are replaced by _xxxx (xxxx=ascii character code)
34 my @chars = split(//, $str);
36 foreach my $char (@chars) {
37 if ( $char eq ' ' ) { # space -> '-'
39 } elsif ( ('0' le $char and $char le '9' ) or
40 ('A' le $char and $char le 'Z' ) or
41 ('a' le $char and $char le 'z' ) ) { # number or letter
44 my $ccode = ord($char);
46 if ( ord($char)<= 0xFFFF ) {
47 $addstr = sprintf("_%4x", $ccode);
49 $addstr = sprintf("__%6x", $ccode);
51 # padding is done by spaces, replace by '0'
56 # 7: if name begins with number, prepend 't_g' (so it starts with a letter)
57 if ($str =~ /^[0-9]/) {
66 # This function makes sure that files are only generated for numbered sections,
67 # but not for unnumbered ones. It is called after texi2html has done its own
68 # splitting and simply returns the filename for the node given as first argument
69 # Nodes with the same filename will be printed out to the same filename, so
70 # this really all we need. Also, make sure that the file names for sections
71 # are derived from the section title. We also might want to name the anchors
72 # according to node titles, which works by simply overriding the id element of
74 sub split_at_numbered_sections($$$)
78 my $docu_name = shift;
79 my $docu_ext = $Texi2HTML::Config::EXTENSION;
81 # TOC, footer, about etc. are called with undefined $element and $type == "toc"|"stoc"|"foot"|"about"
82 if ($type eq "toc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
85 # derive the name of the anchor (i.e. the part after # in the links!),
86 # don't use texi2html's SECx.x default!
87 my $anchor = main::remove_texi($$element{texi});
88 if ($$element{translationof}) {
89 $anchor = main::remove_texi($$element{translationof});
91 # normalize to the same file name as texinfo
92 $anchor = texinfo_file_name($anchor);
93 $$element{id} = $anchor;
94 # Numbered sections will get a filename Section_1.1.2, unnumbered sections will use
95 # the file name of the previous numbered section:
96 if ($$element{number}) {
97 my $filename = $anchor;
98 $filename .= ".$docu_ext" if (defined($docu_ext));
100 $$element{doc_nr} = $docnr;
101 $lastfilename = $filename;
104 $$element{doc_nr} = $docnr;
105 return $lastfilename;
113 # The default formatting of external refs returns e.g.
114 # "(lilypond-internals)Timing_translator", while we simply want "Timing_translator".
115 # Solution: Remove all (...) from the file_and_node argument before calling
116 # the default handler!
117 sub lilypond_external_ref($$$$$$)
122 my $file_node = shift;
124 my $cross_ref = shift;
126 $file_node =~ s/\(.*\)//;
127 return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref);
131 # recursively generate the TOC entries for the element and its children (which
132 # are only shown up to maxlevel. All ancestors of the current element are also
133 # shown with their immediate children, irrespective of their level.
134 sub generate_ly_toc_entries($$$)
137 my $element_path = shift;
138 my $maxlevel = shift;
139 # Skip undefined sections, plus all sections generated by index splitting
140 return() if (not defined($element) or exists($element->{'index_page'}));
142 my $level = $element->{'toc_level'};
143 my $is_parent_of_current = $element_path->{$element->{'number'}};
144 my $print_children = ( ($level < $maxlevel) or $is_parent_of_current );
145 my $ind = ' ' x $level;
146 my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : "";
148 my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'id'}",$element->{'text'});
150 my $children = $element->{'section_childs'};
151 if ( $print_children and defined($children) and (ref($children) eq "ARRAY") ) {
152 push (@result, $entry);
153 my @child_result = ();
154 foreach (@$children) {
155 push (@child_result, generate_ly_toc_entries($_, $element_path, $maxlevel));
157 # if no child nodes were generated, e.g. for the index, where expanded pages
158 # are ignored, don't generate a list at all...
160 push (@result, "$ind<ul$NO_BULLET_LIST_ATTRIBUTE>");
161 push (@result, @child_result);
162 push (@result, "$ind</ul></li>\n");
165 push (@result, $entry . "</li>\n");
171 # Print a customized TOC, containing only the first two levels plus the whole
172 # path to the current page
173 sub lilypond_generate_page_toc_body($)
176 my $current_element = $element;
178 $parentelements{$element->{'number'}} = 1;
179 # Find the path to the current element
180 while ( defined($current_element->{'sectionup'}) and
181 ($current_element->{'sectionup'} ne $current_element) )
183 $parentelements{$current_element->{'sectionup'}->{'number'}} = 1
184 if ($current_element->{'sectionup'}->{'number'} ne '');
185 $current_element = $current_element->{'sectionup'};
187 return () if not defined($current_element);
188 # Create the toc entries recursively
189 my @toc_entries = ("<div class=\"contents\">", "<ul$NO_BULLET_LIST_ATTRIBUTE>");
190 my $children = $current_element->{'section_childs'};
191 foreach ( @$children ) {
192 push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth));
194 push (@toc_entries, "</ul>");
195 push (@toc_entries, "</div>");
199 my @this_page_toc = ();
201 sub lilypond_print_element_header
204 my $first_in_page = shift;
205 my $previous_is_top = shift;
206 if ($first_in_page and not @this_page_toc) {
207 if (defined($Texi2HTML::THIS_ELEMENT)) {
208 # Create the TOC for this page
209 @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
212 return T2H_DEFAULT_print_element_header( $fh, $first_in_page, $previous_is_top);
215 sub lilypond_toc_body($)
217 my $elements_list = shift;
218 # Generate a default TOC for pages without THIS_ELEMENT
219 @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
220 return T2H_GPL_toc_body($elements_list);
224 sub lilypond_css_lines ($$)
226 my $import_lines = shift;
227 my $rule_lines = shift;
228 return if (defined($CSS_LINES));
229 # return if (!@$rule_lines and !@$import_lines and (! keys(%css_map)));
230 if (@$rule_lines or @$import_lines)
232 $CSS_LINES = "<style type=\"text/css\">\n<!--\n";
233 $CSS_LINES .= join('',@$import_lines) . "\n" if (@$import_lines);
234 $CSS_LINES .= join('',@$rule_lines) . "\n" if (@$rule_lines);
235 $CSS_LINES .= "-->\n</style>\n";
237 foreach my $ref (@CSS_REFS)
239 $CSS_LINES .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$ref\">\n";
241 $CSS_LINES .= "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
250 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
251 # sidebar mimicking a TOC frame
252 sub print_lilypond_page_foot($)
255 my $program_string = &$program_string();
256 print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
258 # Print the TOC frame:
259 my @lines = @this_page_toc;
260 # use default TOC if no custom lines have been generated
261 @lines = @default_toc if (not @lines);
263 print $fh "\n\n<div id=\"tocframe\">";
264 print $fh '<h4> ' . $Texi2HTML::NAME{'Contents'} . "</h4>\n";
265 foreach my $line (@lines) {
273 print $fh "</body>\n</html>\n";
281 sub get_navigation_text
284 my $text = $NAVIGATION_TEXT{$button};
285 if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
286 $text = $text . $Texi2HTML::NODE{$button} . " ";
287 } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
288 $text = " " . $Texi2HTML::NODE{$button} . $text;
289 } elsif ( $button eq 'Up' ) {
290 $text = " ".$text.": " . $Texi2HTML::NODE{$button} . " ";
296 # Don't automatically create left-aligned table cells for every link, but
297 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
298 # button text. It's alignment as well as the colspan will be taken from the
299 # name of the button. Also, add 'newline' button text to create a new table
300 # row. The texts of the buttons are generated by get_navigation_text and
301 # will contain the name of the next/previous section/chapter.
302 sub lilypond_print_navigation
306 my $vertical = shift;
308 # print $fh '<table cellpadding="', $spacing, '" cellspacing="', $spacing,
309 # "\" border=\"0\" class=\"nav_table\">\n";
310 print $fh "<table class=\"nav_table\">\n";
312 print $fh "<tr>" unless $vertical;
314 foreach my $button (@$buttons)
316 print $fh qq{<tr valign="top" align="left">\n} if $vertical;
317 # Allow (left|right|center)-aligned-cell and newline as buttons!
318 if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
320 print $fh qq{</td>} unless $beginofline;
321 print $fh qq{<td valign="middle" align="$1" colspan="$2">};
324 elsif ( $button eq 'newline' )
326 print $fh qq{</td>} unless $beginofline;
332 elsif (ref($button) eq 'CODE')
334 &$button($fh, $vertical);
336 elsif (ref($button) eq 'SCALAR')
338 print $fh "$$button" if defined($$button);
340 elsif (ref($button) eq 'ARRAY')
342 my $text = $button->[1];
343 my $button_href = $button->[0];
344 # verify that $button_href is simple text and text is a reference
345 if (defined($button_href) and !ref($button_href)
346 and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
348 if ($Texi2HTML::HREF{$button_href})
350 my $anchor_attributes = '';
351 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
353 $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
355 if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
357 $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
361 $Texi2HTML::HREF{$button_href},
362 get_navigation_text($$text),
368 print $fh get_navigation_text($$text);
372 elsif ($button eq ' ')
373 { # handle space button
375 ($ICONS && $ACTIVE_ICONS{' '}) ?
376 &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
377 $NAVIGATION_TEXT{' '};
380 elsif ($Texi2HTML::HREF{$button})
382 my $btitle = $BUTTONS_GOTO{$button} ?
383 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
384 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
386 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
388 if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
390 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
392 if ($ICONS && $ACTIVE_ICONS{$button})
396 $Texi2HTML::HREF{$button},
397 &$button_icon_img($BUTTONS_NAME{$button},
398 $ACTIVE_ICONS{$button},
399 $Texi2HTML::SIMPLE_TEXT{$button}),
408 $Texi2HTML::HREF{$button},
409 get_navigation_text ($button),
416 { # button is passive
418 $ICONS && $PASSIVE_ICONS{$button} ?
419 &$button_icon_img($BUTTONS_NAME{$button},
420 $PASSIVE_ICONS{$button},
421 $Texi2HTML::SIMPLE_TEXT{$button}) :
423 "[" . get_navigation_text($button) . "]";
425 print $fh "</td>\n" if $vertical;
426 print $fh "</tr>\n" if $vertical;
428 print $fh "</td>" unless $beginofline;
429 print $fh "</tr>" unless $vertical;
430 print $fh "</table>\n";
434 @Texi2HTML::Config::SECTION_BUTTONS =
435 ('left-aligned-cell-1', 'FastBack',
436 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
437 'right-aligned-cell-1', 'FastForward',
439 'left-aligned-cell-2', 'Back',
440 'center-aligned-cell-1', 'Up',
441 'right-aligned-cell-2', 'Forward'
444 # buttons for misc stuff
445 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
447 # buttons for chapter file footers
448 # (and headers but only if SECTION_NAVIGATION is false)
449 @Texi2HTML::Config::CHAPTER_BUTTONS =
450 ('left-aligned-cell-1', 'FastBack',
451 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
452 'right-aligned-cell-1', 'FastForward',
455 # buttons for section file footers
456 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
457 ('left-aligned-cell-1', 'FastBack',
458 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
459 'right-aligned-cell-1', 'FastForward',
461 'left-aligned-cell-2', 'Back',
462 'center-aligned-cell-1', 'Up',
463 'right-aligned-cell-2', 'Forward'
466 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
467 ('left-aligned-cell-1', 'FastBack',
468 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
469 'right-aligned-cell-1', 'FastForward',
471 'left-aligned-cell-2', 'Back',
472 'center-aligned-cell-1', 'Up',
473 'right-aligned-cell-2', 'Forward'
476 # $Texi2HTML::Config::SPLIT = 'section';
477 @Texi2HTML::Config::CSS_REFS = ("lilypond.css");
478 $Texi2HTML::Config::USE_ACCESSKEY = 1;
479 $Texi2HTML::Config::USE_LINKS = 1;
480 $Texi2HTML::Config::USE_REL_REV = 1;
481 $Texi2HTML::Config::element_file_name = \&split_at_numbered_sections;
482 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
483 $Texi2HTML::Config::print_page_foot = \&print_lilypond_page_foot;
484 $Texi2HTML::Config::print_navigation = \&lilypond_print_navigation;
485 $Texi2HTML::Config::external_ref = \&lilypond_external_ref;
486 $Texi2HTML::Config::toc_body = \&lilypond_toc_body;
487 $Texi2HTML::Config::css_lines = \&lilypond_css_lines;
490 # For split pages, use index(.lang).html as start page!
491 if ($Texi2HTML::Config::SPLIT == 'section') {
492 # my $lng = $Texi2HTML::THISDOC{'current_lang'};
493 # if ($lng and ($lng ne "en")) {
494 # $Texi2HTML::Config::TOP_FILE = 'index.'.$lng.'.html';
496 $Texi2HTML::Config::TOP_FILE = 'index.html';
500 # if ($Texi2HTML::THISDOC{'current_lang'}) {
501 # $Texi2HTML::Config::EXTENSION = $Texi2HTML::THISDOC{'current_lang'} . "." .
502 # $docu_ext = $Texi2HTML::Config::EXTENSION;;
507 # Try to make use of @translationof to generate files according to the original
508 # English section title...
509 sub lilypond_unknown($$$$$)
517 # the @translationof macro provides the original English section title,
518 # which should be used for file/anchor naming, while the title will be
519 # translated to each language
520 if ($pass == 1 and $macro eq "translationof") {
521 if (ref($state->{'element'})=='HASH') {
522 $state->{'element'}->{'translationof'} = main::normalise_space($line);
524 return ('', true, undef, undef);
526 return t2h_default_unknown($macro, $line, $pass, $stack, $state);
529 $Texi2HTML::Config::unknown = \&lilypond_unknown;