#!/usr/bin/env perl
### texi2html customization script for Lilypond
### Author: Reinhold Kainhofer , 2008.
### Some code parts copied from texi2html and adapted.
### License: GPLv2+
###
###
### Features implemented here:
### -) For split manuals, the main page is index.html.
### -) All @unnumbered* sections are placed into the same file
### (implemented by split_at_numbered_sections)
### -) Use our custom CSS file, with IE-specific fixes in another CSS file,
### impelmented by lilypond_css_lines
### -) TOC (folded, with the current page highlighted) in an overflown
### is added to every page; implemented by:
### lilypond_print_element_header -- building of the TOC
### lilypond_toc_body -- generation of customized TOC output
### lilypond_print_page_head -- start
### print_lilypond_page_foot -- closing id=main, output of footer & TOC
### -) External refs are formatted only as "Text of the node" (not as >>see
### "NODE" section "SECTION" in "BOOK"<< like with default texi2html). Also,
### the leading "(book-name)" is removed.
### Implemented by overriding lilypond_external_ref
### -) Navigation bars on top/bottom of the page and between sections are not
### left-aligned, but use a combination of left/center/right aligned table
### cells; For this, I heavily extend the texi2html code to allow for
### differently aligned cells and for multi-line tables);
### Implemented in lilypond_print_navigation
### -) Different formatting than the default: example uses the same formatting
### as quote.
### -) Allow translated section titles: All section titles can be translated,
### the original (English) title is associated with @translationof. This is
### needed, because the file name / anchor is generated from the original
### English title, since otherwise language-autoselection would break with
### posted links.
### Since it is then no longer possible to obtain the file name from the
### section title, I keep a sectionname<=>filename/anchor around. This way,
### xrefs from other manuals can simply load that map and retrieve the
### correct file name for the link. Implemented in:
### lilypond_unknown (handling of @translationof, in case
### extract_texi_filenames.py messes up...)
### split_at_numbered_sections (correct file name: use the map)
### lilypond_init_map (read in the externally created map from disk)
### lilypond_external_href (load the map for xrefs, use the correct
### link target)
### -) The HTML anchors for all sections are derived from the node name /
### section title (pre-generated in the .xref-map file). Implemented by:
### split_at_numbered_sections (adjust section anchors)
### -) Use the standard footnote format "nr text" instead of the
### ugly format of texi2html (
(nr)
text
). Implemented in
### lilypond_foot_line_and_ref
###
###
### Useful helper functions:
### -) texinfo_file_name($node_name): returns a texinfo-compatible file name
### for the given string $node_name (whitespace trimmed/replaced by -,
### non-standard chars replaced by _xxxx (ascii char code) and forced to
### start with a letter by prepending t_g if necessary)
package Texi2HTML::Config;
#############################################################################
### SETTINGS FOR TEXI2HTML
#############################################################################
@Texi2HTML::Config::CSS_REFS = ("lilypond.css");
$Texi2HTML::Config::USE_ACCESSKEY = 1;
$Texi2HTML::Config::USE_LINKS = 1;
$Texi2HTML::Config::USE_REL_REV = 1;
$Texi2HTML::Config::SEPARATED_FOOTNOTES = 0; # Print footnotes on same page, not separated
$Texi2HTML::Config::element_file_name = \&split_at_numbered_sections;
$Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
$Texi2HTML::Config::print_page_foot = \&print_lilypond_page_foot;
$Texi2HTML::Config::print_navigation = \&lilypond_print_navigation;
$Texi2HTML::Config::external_ref = \&lilypond_external_ref;
$Texi2HTML::Config::external_href = \&lilypond_external_href;
$Texi2HTML::Config::toc_body = \&lilypond_toc_body;
$Texi2HTML::Config::css_lines = \&lilypond_css_lines;
$Texi2HTML::Config::unknown = \&lilypond_unknown;
$Texi2HTML::Config::print_page_head = \&lilypond_print_page_head;
$Texi2HTML::Config::foot_line_and_ref = \&lilypond_foot_line_and_ref;
# Examples should be formatted similar to quotes:
$Texi2HTML::Config::complex_format_map->{'example'} = {
'begin' => q{"
" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'id'}",$element->{'text'});
my $children = $element->{'section_childs'};
# Don't add unnumbered entries, unless they are at top-level or a parent of the current!
if (not ($element->{'number'} or $always_show_unnumbered_children)) {
return @result;
}
if ( $print_children and defined($children) and (ref($children) eq "ARRAY") ) {
push (@result, $entry);
my @child_result = ();
foreach (@$children) {
push (@child_result, generate_ly_toc_entries($_, $element_path, $maxlevel, $is_parent_of_current));
}
# if no child nodes were generated, e.g. for the index, where expanded pages
# are ignored, don't generate a list at all...
if (@child_result) {
push (@result, "\n$ind
\n");
}
} else {
push (@result, $entry . "\n");
}
return @result;
}
# Print a customized TOC, containing only the first two levels plus the whole
# path to the current page
sub lilypond_generate_page_toc_body($)
{
my $element = shift;
my $current_element = $element;
my %parentelements;
$parentelements{$element->{'id'}} = 1;
# Find the path to the current element
while ( defined($current_element->{'sectionup'}) and
($current_element->{'sectionup'} ne $current_element) )
{
$parentelements{$current_element->{'sectionup'}->{'id'}} = 1
if ($current_element->{'sectionup'}->{'id'} ne '');
$current_element = $current_element->{'sectionup'};
}
return () if not defined($current_element);
# Create the toc entries recursively
my @toc_entries = ("
\n");
return @toc_entries;
}
sub lilypond_print_toc_div ($$)
{
my $fh = shift;
my $tocref = shift;
my @lines = @$tocref;
# use default TOC if no custom lines have been generated
@lines = @default_toc if (not @lines);
if (@lines) {
print $fh "\n\n
\n\n";
}
}
# Create the custom TOC for this page (partially folded, current page is
# highlighted) and store it in a global variable. The TOC is written out after
# the html contents (but positioned correctly using CSS), so that browsers with
# css turned off still show the contents first.
our @this_page_toc = ();
sub lilypond_print_element_header
{
my $fh = shift;
my $first_in_page = shift;
my $previous_is_top = shift;
if ($first_in_page and not @this_page_toc) {
if (defined($Texi2HTML::THIS_ELEMENT)) {
# Create the TOC for this page
@this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
}
}
return T2H_DEFAULT_print_element_header( $fh, $first_in_page, $previous_is_top);
}
# Generate the HTML output for the TOC
sub lilypond_toc_body($)
{
my $elements_list = shift;
# Generate a default TOC for pages without THIS_ELEMENT
@default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
return T2H_GPL_toc_body($elements_list);
}
# Print out the TOC in a
at the beginning of the page
sub lilypond_print_page_head($)
{
my $fh = shift;
T2H_DEFAULT_print_page_head($fh);
print $fh "
\n";
}
# Print out the TOC in a
at the end of th page, which will be formatted as a
# sidebar mimicking a TOC frame
sub print_lilypond_page_foot($)
{
my $fh = shift;
my $program_string = &$program_string();
print $fh "
$program_string $PRE_BODY_CLOSE
\n";
print $fh "\n\n";
print $fh "\n
\n\n";
# Print the TOC frame and reset the TOC:
lilypond_print_toc_div ($fh, \@this_page_toc);
@this_page_toc = ();
# Close the page:
print $fh "