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;
114 # The default formatting of external refs returns e.g.
115 # "(lilypond-internals)Timing_translator", so we remove all (...) from the
116 # file_and_node argument. Also, we want only a very simple format, so we don't
117 # even call the default handler!
118 sub lilypond_external_ref($$$$$$)
123 my $file_node = shift;
125 my $cross_ref = shift;
127 $file_node =~ s/\(.*\)//;
128 $file_node = &$anchor('', $href, $file_node) if ($file_node ne '');
129 return &$I('%{node_file_href}', { 'node_file_href' => $file_node });
131 # Default: format as "see <a ..>NODE</a> section 'SECTION' in BOOK"
132 # return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref);
138 # recursively generate the TOC entries for the element and its children (which
139 # are only shown up to maxlevel. All ancestors of the current element are also
140 # shown with their immediate children, irrespective of their level.
141 sub generate_ly_toc_entries($$$)
144 my $element_path = shift;
145 my $maxlevel = shift;
146 # Skip undefined sections, plus all sections generated by index splitting
147 return() if (not defined($element) or exists($element->{'index_page'}));
149 my $level = $element->{'toc_level'};
150 my $is_parent_of_current = $element_path->{$element->{'number'}};
151 my $print_children = ( ($level < $maxlevel) or $is_parent_of_current );
152 my $ind = ' ' x $level;
153 my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : "";
155 my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'id'}",$element->{'text'});
157 my $children = $element->{'section_childs'};
158 if ( $print_children and defined($children) and (ref($children) eq "ARRAY") ) {
159 push (@result, $entry);
160 my @child_result = ();
161 foreach (@$children) {
162 push (@child_result, generate_ly_toc_entries($_, $element_path, $maxlevel));
164 # if no child nodes were generated, e.g. for the index, where expanded pages
165 # are ignored, don't generate a list at all...
167 push (@result, "$ind<ul$NO_BULLET_LIST_ATTRIBUTE>");
168 push (@result, @child_result);
169 push (@result, "$ind</ul></li>\n");
172 push (@result, $entry . "</li>\n");
178 # Print a customized TOC, containing only the first two levels plus the whole
179 # path to the current page
180 sub lilypond_generate_page_toc_body($)
183 my $current_element = $element;
185 $parentelements{$element->{'number'}} = 1;
186 # Find the path to the current element
187 while ( defined($current_element->{'sectionup'}) and
188 ($current_element->{'sectionup'} ne $current_element) )
190 $parentelements{$current_element->{'sectionup'}->{'number'}} = 1
191 if ($current_element->{'sectionup'}->{'number'} ne '');
192 $current_element = $current_element->{'sectionup'};
194 return () if not defined($current_element);
195 # Create the toc entries recursively
196 my @toc_entries = ("<div class=\"contents\">", "<ul$NO_BULLET_LIST_ATTRIBUTE>");
197 my $children = $current_element->{'section_childs'};
198 foreach ( @$children ) {
199 push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth));
201 push (@toc_entries, "</ul>");
202 push (@toc_entries, "</div>");
206 my @this_page_toc = ();
208 sub lilypond_print_element_header
211 my $first_in_page = shift;
212 my $previous_is_top = shift;
213 if ($first_in_page and not @this_page_toc) {
214 if (defined($Texi2HTML::THIS_ELEMENT)) {
215 # Create the TOC for this page
216 @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
219 return T2H_DEFAULT_print_element_header( $fh, $first_in_page, $previous_is_top);
222 sub lilypond_toc_body($)
224 my $elements_list = shift;
225 # Generate a default TOC for pages without THIS_ELEMENT
226 @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
227 return T2H_GPL_toc_body($elements_list);
231 sub lilypond_css_lines ($$)
233 my $import_lines = shift;
234 my $rule_lines = shift;
235 return if (defined($CSS_LINES));
236 # return if (!@$rule_lines and !@$import_lines and (! keys(%css_map)));
237 if (@$rule_lines or @$import_lines)
239 $CSS_LINES = "<style type=\"text/css\">\n<!--\n";
240 $CSS_LINES .= join('',@$import_lines) . "\n" if (@$import_lines);
241 $CSS_LINES .= join('',@$rule_lines) . "\n" if (@$rule_lines);
242 $CSS_LINES .= "-->\n</style>\n";
244 foreach my $ref (@CSS_REFS)
246 $CSS_LINES .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$ref\">\n";
248 $CSS_LINES .= "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
257 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
258 # sidebar mimicking a TOC frame
259 sub print_lilypond_page_foot($)
262 my $program_string = &$program_string();
263 print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
265 # Print the TOC frame:
266 my @lines = @this_page_toc;
267 # use default TOC if no custom lines have been generated
268 @lines = @default_toc if (not @lines);
270 print $fh "\n\n<div id=\"tocframe\">";
271 print $fh '<h4> ' . $Texi2HTML::NAME{'Contents'} . "</h4>\n";
272 foreach my $line (@lines) {
280 print $fh "</body>\n</html>\n";
288 sub get_navigation_text
291 my $text = $NAVIGATION_TEXT{$button};
292 if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
293 $text = $text . $Texi2HTML::NODE{$button} . " ";
294 } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
295 $text = " " . $Texi2HTML::NODE{$button} . $text;
296 } elsif ( $button eq 'Up' ) {
297 $text = " ".$text.": " . $Texi2HTML::NODE{$button} . " ";
303 # Don't automatically create left-aligned table cells for every link, but
304 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
305 # button text. It's alignment as well as the colspan will be taken from the
306 # name of the button. Also, add 'newline' button text to create a new table
307 # row. The texts of the buttons are generated by get_navigation_text and
308 # will contain the name of the next/previous section/chapter.
309 sub lilypond_print_navigation
313 my $vertical = shift;
315 # print $fh '<table cellpadding="', $spacing, '" cellspacing="', $spacing,
316 # "\" border=\"0\" class=\"nav_table\">\n";
317 print $fh "<table class=\"nav_table\">\n";
319 print $fh "<tr>" unless $vertical;
321 foreach my $button (@$buttons)
323 print $fh qq{<tr valign="top" align="left">\n} if $vertical;
324 # Allow (left|right|center)-aligned-cell and newline as buttons!
325 if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
327 print $fh qq{</td>} unless $beginofline;
328 print $fh qq{<td valign="middle" align="$1" colspan="$2">};
331 elsif ( $button eq 'newline' )
333 print $fh qq{</td>} unless $beginofline;
339 elsif (ref($button) eq 'CODE')
341 &$button($fh, $vertical);
343 elsif (ref($button) eq 'SCALAR')
345 print $fh "$$button" if defined($$button);
347 elsif (ref($button) eq 'ARRAY')
349 my $text = $button->[1];
350 my $button_href = $button->[0];
351 # verify that $button_href is simple text and text is a reference
352 if (defined($button_href) and !ref($button_href)
353 and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
355 if ($Texi2HTML::HREF{$button_href})
357 my $anchor_attributes = '';
358 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
360 $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
362 if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
364 $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
368 $Texi2HTML::HREF{$button_href},
369 get_navigation_text($$text),
375 print $fh get_navigation_text($$text);
379 elsif ($button eq ' ')
380 { # handle space button
382 ($ICONS && $ACTIVE_ICONS{' '}) ?
383 &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
384 $NAVIGATION_TEXT{' '};
387 elsif ($Texi2HTML::HREF{$button})
389 my $btitle = $BUTTONS_GOTO{$button} ?
390 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
391 if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
393 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
395 if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
397 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
399 if ($ICONS && $ACTIVE_ICONS{$button})
403 $Texi2HTML::HREF{$button},
404 &$button_icon_img($BUTTONS_NAME{$button},
405 $ACTIVE_ICONS{$button},
406 $Texi2HTML::SIMPLE_TEXT{$button}),
415 $Texi2HTML::HREF{$button},
416 get_navigation_text ($button),
423 { # button is passive
425 $ICONS && $PASSIVE_ICONS{$button} ?
426 &$button_icon_img($BUTTONS_NAME{$button},
427 $PASSIVE_ICONS{$button},
428 $Texi2HTML::SIMPLE_TEXT{$button}) :
430 "[" . get_navigation_text($button) . "]";
432 print $fh "</td>\n" if $vertical;
433 print $fh "</tr>\n" if $vertical;
435 print $fh "</td>" unless $beginofline;
436 print $fh "</tr>" unless $vertical;
437 print $fh "</table>\n";
441 @Texi2HTML::Config::SECTION_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 # buttons for misc stuff
452 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
454 # buttons for chapter file footers
455 # (and headers but only if SECTION_NAVIGATION is false)
456 @Texi2HTML::Config::CHAPTER_BUTTONS =
457 ('left-aligned-cell-1', 'FastBack',
458 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
459 'right-aligned-cell-1', 'FastForward',
462 # buttons for section file footers
463 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
464 ('left-aligned-cell-1', 'FastBack',
465 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
466 'right-aligned-cell-1', 'FastForward',
468 'left-aligned-cell-2', 'Back',
469 'center-aligned-cell-1', 'Up',
470 'right-aligned-cell-2', 'Forward'
473 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
474 ('left-aligned-cell-1', 'FastBack',
475 'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
476 'right-aligned-cell-1', 'FastForward',
478 'left-aligned-cell-2', 'Back',
479 'center-aligned-cell-1', 'Up',
480 'right-aligned-cell-2', 'Forward'
483 # $Texi2HTML::Config::SPLIT = 'section';
484 @Texi2HTML::Config::CSS_REFS = ("lilypond.css");
485 $Texi2HTML::Config::USE_ACCESSKEY = 1;
486 $Texi2HTML::Config::USE_LINKS = 1;
487 $Texi2HTML::Config::USE_REL_REV = 1;
488 $Texi2HTML::Config::element_file_name = \&split_at_numbered_sections;
489 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
490 $Texi2HTML::Config::print_page_foot = \&print_lilypond_page_foot;
491 $Texi2HTML::Config::print_navigation = \&lilypond_print_navigation;
492 $Texi2HTML::Config::external_ref = \&lilypond_external_ref;
493 $Texi2HTML::Config::toc_body = \&lilypond_toc_body;
494 $Texi2HTML::Config::css_lines = \&lilypond_css_lines;
497 # For split pages, use index(.lang).html as start page!
498 if ($Texi2HTML::Config::SPLIT == 'section') {
499 # my $lng = $Texi2HTML::THISDOC{'current_lang'};
500 # if ($lng and ($lng ne "en")) {
501 # $Texi2HTML::Config::TOP_FILE = 'index.'.$lng.'.html';
503 $Texi2HTML::Config::TOP_FILE = 'index.html';
507 # if ($Texi2HTML::THISDOC{'current_lang'}) {
508 # $Texi2HTML::Config::EXTENSION = $Texi2HTML::THISDOC{'current_lang'} . "." .
509 # $docu_ext = $Texi2HTML::Config::EXTENSION;;
514 # Try to make use of @translationof to generate files according to the original
515 # English section title...
516 sub lilypond_unknown($$$$$)
524 # the @translationof macro provides the original English section title,
525 # which should be used for file/anchor naming, while the title will be
526 # translated to each language
527 if ($pass == 1 and $macro eq "translationof") {
528 if (ref($state->{'element'})=='HASH') {
529 $state->{'element'}->{'translationof'} = main::normalise_space($line);
531 return ('', true, undef, undef);
533 return t2h_default_unknown($macro, $line, $pass, $stack, $state);
536 $Texi2HTML::Config::unknown = \&lilypond_unknown;