#!/usr/bin/env perl # { package Texi2HTML::Config; my $lastfilename; my $docnr = 0; my $page_toc_depth = 2; my @default_toc = []; use Data::Dumper; $Data::Dumper::Maxdepth = 2; sub print_element_info($) { my $element = shift; print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; print "Element: $element\n"; print Dumper($element); } # Convert a given node name to its proper file name (normalization as explained # in the texinfo manual: # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html sub texinfo_file_name($) { my $str = shift; # File name normalization by texinfo: # 1/2: letters and numbers are left unchanged # 3/4: multiple, leading and trailing whitespace is removed $str = main::normalise_space($str); # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit # chars are replaced by _xxxx (xxxx=ascii character code) my @chars = split(//, $str); my $str = ''; foreach my $char (@chars) { if ( $char eq ' ' ) { # space -> '-' $str .= '-'; } elsif ( ('0' le $char and $char le '9' ) or ('A' le $char and $char le 'Z' ) or ('a' le $char and $char le 'z' ) ) { # number or letter $str .= $char; } else { my $ccode = ord($char); my $addstr; if ( ord($char)<= 0xFFFF ) { $addstr = sprintf("_%4x", $ccode); } else { $addstr = sprintf("__%6x", $ccode); } # padding is done by spaces, replace by '0' $addstr =~ s/\ /0/g; $str .= $addstr; } } # 7: if name begins with number, prepend 't_g' (so it starts with a letter) if ($str =~ /^[0-9]/) { $str = 't_g' . $str; } # DONE return $str } # This function makes sure that files are only generated for numbered sections, # but not for unnumbered ones. It is called after texi2html has done its own # splitting and simply returns the filename for the node given as first argument # Nodes with the same filename will be printed out to the same filename, so # this really all we need. Also, make sure that the file names for sections # are derived from the section title. We also might want to name the anchors # according to node titles, which works by simply overriding the id element of # the $element hash. sub split_at_numbered_sections($$$) { my $element = shift; my $type = shift; my $docu_name = shift; my $docu_ext = $Texi2HTML::Config::EXTENSION; # if ($$element{number} eq "1.1") { # print_element_info ($element); # } # TOC, footer, about etc. are called with undefined $element and $type == "toc"|"stoc"|"foot"|"about" if ($type eq "toc" or $type eq "stoc" or $type eq "foot" or $type eq "about") { return; } else { # derive the name of the anchor (i.e. the part after # in the links!), # don't use texi2html's SECx.x default! my $anchor = main::remove_texi($$element{texi}); if ($$element{translationof}) { $anchor = main::remove_texi($$element{translationof}); } # normalize to the same file name as texinfo $anchor = texinfo_file_name($anchor); $$element{id} = $anchor; # Numbered sections will get a filename Section_1.1.2, unnumbered sections will use # the file name of the previous numbered section: if ($$element{number}) { my $filename = $anchor; $filename .= ".$docu_ext" if (defined($docu_ext)); $docnr += 1; $$element{doc_nr} = $docnr; $lastfilename = $filename; return $filename; } else { $$element{doc_nr} = $docnr; return $lastfilename; } } return; } # The default formatting of external refs returns e.g. # "(lilypond-internals)Timing_translator", while we simply want "Timing_translator". # Solution: Remove all (...) from the file_and_node argument before calling # the default handler! sub lilypond_external_ref($$$$$$) { my $type = shift; my $section = shift; my $book = shift; my $file_node = shift; my $href = shift; my $cross_ref = shift; $file_node =~ s/\(.*\)//; return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref); } # recursively generate the TOC entries for the element and its children (which # are only shown up to maxlevel. All ancestors of the current element are also # shown with their immediate children, irrespective of their level. sub generate_ly_toc_entries($$$) { my $element = shift; my $element_path = shift; my $maxlevel = shift; # Skip undefined sections, plus all sections generated by index splitting return() if (not defined($element) or exists($element->{'index_page'})); my @result = (); my $level = $element->{'toc_level'}; my $is_parent_of_current = $element_path->{$element->{'number'}}; my $print_children = ( ($level < $maxlevel) or $is_parent_of_current ); my $ind = ' ' x $level; my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : ""; my $entry = "$ind
$program_string
$PRE_BODY_CLOSE