]> git.donarmstrong.com Git - lilypond.git/blobdiff - lilypond-texi2html.init
Merge branch 'master' into dev/texi2html
[lilypond.git] / lilypond-texi2html.init
index 3ed3fcc6da2ff5af0479a283e61c9768ab354670..1d28c76cc55e02bfe54a51b046caadb93525af23 100644 (file)
@@ -12,8 +12,8 @@
 ###    (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 iframe is added
-###    to every page; implemented by:
+### -) TOC (folded, with the current page highlighted) in an overflown <div>
+###    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 <div id="main">
 ###    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 
+###    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 
+###           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 
+###           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 "<sup>nr</sup> text" instead of the
+###    ugly format of texi2html (<h3>(nr)</h3><p>text</p>). Implemented in
+###           lilypond_foot_line_and_ref
 ###
 ###
 ### Useful helper functions:
@@ -67,6 +73,7 @@ package Texi2HTML::Config;
 $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;
@@ -77,6 +84,7 @@ $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'} = {
@@ -84,6 +92,12 @@ $Texi2HTML::Config::complex_format_map->{'example'} = {
   'end' => q{"</pre></blockquote>\n"},
  };
 
+%Texi2HTML::config::misc_pages_targets = (
+   'Overview' => 'Overview',
+   'Contents' => 'Contents',
+   'About' => 'About'
+);
+
 
 my @section_to_filename;
 
@@ -236,6 +250,7 @@ my $lastfilename;
 my $docnr = 0;
 my $node_to_filename_map = ();
 
+
 # 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
@@ -245,7 +260,7 @@ my $node_to_filename_map = ();
 # according to node titles, which works by simply overriding the id element of
 # the $element hash.
 # If an external nodename<=>filename/anchor map file is found (loaded in
-# lilypond_init_out, use the externally created values, otherwise use the 
+# lilypond_init_out, use the externally created values, otherwise use the
 # same logic here.
 sub split_at_numbered_sections($$$)
 {
@@ -270,8 +285,16 @@ sub split_at_numbered_sections($$$)
     (my $filename, my $anchor) = @{$node_to_filename_map->{$node_name}};
     $filename .= ".$docu_ext" if (defined($docu_ext));
 
-    $element->{id} = $anchor;
-    if ($filename eq $lastfilename) {
+    # need to override both target (used as anchor in links to this section) and
+    # id (used in the <a name=..> tag for this section)!
+    $element->{'id'} = $element->{'target'} = $anchor;
+
+    # unnumbered sections (except those at top-level!) always go to the same
+    # file as the previous numbered section
+    if (not ($element->{number}) and not ($lastfilename eq '') and ($element->{level} > 1)) {
+      $filename = $lastfilename;
+    }
+    if (($filename eq $lastfilename)) {
       $$element{doc_nr} = $docnr;
     } else {
       $docnr += 1;
@@ -282,6 +305,9 @@ sub split_at_numbered_sections($$$)
 
   } elsif ($type eq "top" or $type eq "toc" or $type eq "doc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
     # TOC, footer, about etc. are called with undefined $element and $type == "toc"|"stoc"|"foot"|"about"
+    if ($type eq "top") {
+      $element->{'id'} = $element->{'target'} = "Top";
+    }
     return;
   } else {
     print STDERR "WARNING: Node '$node_name' was NOT found in the map\n"
@@ -292,7 +318,7 @@ sub split_at_numbered_sections($$$)
     # don't use texi2html's SECx.x default!
     my $sec_name = main::remove_texi($element->{'texi'});
     # if we have a node, use its name:
-    if ($element->{'node_ref'}->{'texi'} ne '') { 
+    if ($element->{'node_ref'}->{'texi'} ne '') {
       $sec_name = main::remove_texi($element->{'node_ref'}->{'texi'});
     }
     my $anchor = $sec_name;
@@ -301,7 +327,9 @@ sub split_at_numbered_sections($$$)
     }
     # normalize to the same file name as texinfo
     $anchor = texinfo_file_name($anchor);
-    $$element{id} = $anchor;
+    # need to override both target (used as anchor in links to this section) and
+    # id (used in the <a name=..> tag for this section)!
+    $element->{'id'} = $element->{'target'} = $anchor;
     # Numbered sections will get a filename Node_title, unnumbered sections will use
     # the file name of the previous numbered section:
     if (($element->{number}) or ($lastfilename eq '') or ($element->{level} == 1)) {
@@ -321,14 +349,15 @@ sub split_at_numbered_sections($$$)
 }
 
 
-## Load the map file for the corrently processed texi file. We do this 
-#  (mis-)using a command init handler, since texi2html does not have any 
+## Load the map file for the corrently processed texi file. We do this
+#  using a command init handler, since texi2html does not have any
 #  other hooks that are called after THISDOC is filled but before phase 2
 #  of the texi2html conversion.
 sub lilypond_init_map ()
 {
     my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
-    my $map_filename = "$docu_dir/${docu_name}.xref-map";
+    my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
+       || main::locate_include_file ("${docu_name}.xref-map");
     $node_to_filename_map = load_map_file ($map_filename);
 }
 push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map;
@@ -355,7 +384,7 @@ sub lilypond_external_ref($$$$$$)
   my $displaytext = '';
 
   # 1) if we have a cross ref name, that's the text to be displayed:
-  # 2) For the top node, use the (printable) name of the manual, unless we 
+  # 2) For the top node, use the (printable) name of the manual, unless we
   #    have an explicit cross ref name
   # 3) In all other cases use the section name
   if ($cross_ref ne '') {
@@ -429,9 +458,9 @@ sub lilypond_external_href($$$)
   my $original_func = \&t2h_default_external_href;
 
   # 1) Keep a hash of book->section_map
-  # 2) if not file in keys hash => try to load the map (assign empty map if 
+  # 2) if not file in keys hash => try to load the map (assign empty map if
   #    non-existent => will load only once!)
-  # 3) if node in the section=>(file, anchor) map, replace node_id and 
+  # 3) if node in the section=>(file, anchor) map, replace node_id and
   #    node_xhtml_id by the map's values
   # 4) call the t2h_default_external_href with these values (or the old ones if not found)
 
@@ -442,7 +471,8 @@ sub lilypond_external_href($$$)
     # Load the map if we haven't done so already
     if (!exists($translated_books{$map_name})) {
       my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
-      my $map_filename = "$docu_dir/${map_name}.xref-map";
+      my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
+         || main::locate_include_file ("${map_name}.xref-map");
       $translated_books{$map_name} = load_map_file ($map_filename);
     }
 
@@ -477,7 +507,7 @@ my @default_toc = [];
 # 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.
-# Unnumbered entries are only printed out if they are at top-level or their 
+# Unnumbered entries are only printed out if they are at top-level or their
 # parent element is an ancestor of the currently viewed node.
 sub generate_ly_toc_entries($$$$)
 {
@@ -827,6 +857,46 @@ sub lilypond_print_navigation
 
 
 
+#############################################################################
+###  FOOTNOTE FORMATTING
+#############################################################################
+
+# Format footnotes in a nicer way: Instead of printing the number in a separate
+# (nr) heading line, use the standard way of prepending <sup>nr</sup> immediately
+# before the fn text.
+sub lilypond_foot_line_and_ref($$$$$$$)
+{
+    my $number_in_doc = shift;
+    my $number_in_page = shift;
+    my $footnote_id = shift;
+    my $place_id = shift;
+    my $document_file = shift;
+    my $footnote_file = shift;
+    my $lines = shift;
+    my $state = shift;
+
+    if ($document_file eq $footnote_file)
+    {
+        $document_file = $footnote_file = '';
+    }
+    # FN number printed before the fn text:
+    my $tmptxt =  &$anchor($footnote_id, $document_file . "#$place_id",
+                   "<sup>$number_in_doc</sup>");
+    # unfortunately, the @$lines contain the already formatted footnote in the
+    # from <p>...</p>. This means that we have to modify this string and
+    # insert the FN number manually. The default (nr) on a separate line before
+    # the FN text is just plain ugly:
+    $lines->[0] =~ s/<p>/<p>$tmptxt /;
+    # this is a bit obscure, this allows to add an anchor only if formatted
+    # as part of the document.
+    $place_id = '' if ($state->{'outside_document'} or $state->{'multiple_pass'});
+    # return FN lines and text to be inserted in the running text (link to FN)
+    return ($lines, &$anchor($place_id,  $footnote_file . "#$footnote_id",
+           "<sup>$number_in_doc</sup>"));
+}
+
+
+
 #############################################################################
 ###  OTHER SETTINGS
 #############################################################################