From 469754de2c595b6dbf269f04b1a59f5705e3045f Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Fri, 27 Nov 2009 19:52:20 +0100 Subject: [PATCH] Docs: merge the two Texi2HTML init files Formatting for the web site is enabled through "-D web_manual"Texinfo command line option. Cherry-picked, squashed together by John from commits in dev/gperciva branch: 86dd84e0ed4248e931ce6998ac94de4bd9969809 89ba33490b1dd18b69a4fcb98fea70b69841aece 8dd8d653cb43bc6b86ac014b022f9834695b24f5 f1ecf05f6b816e7f2e890a01c1f862f99f2092e9 e3fbdebeac091b8be5d1d4b186f3cdaf9aa50fdb In addition to this merging, John made a few subsequent changes: - use --split=subsubsection for the website, which makes extract_texi_filenames.py generate a correct map; - reorder Texi2HTML command line arguments to make sure the init file catches the ones which are necessary; - splitted HTML docs: downcase all filenames (manuals and web site), and sections anchors (which fix the duplicate anchors issues that makes Opera barf); - fix translated docs map files loading. --- Documentation/lilypond-texi2html.init | 208 ++++++++++++++++++++++---- make/doc-i18n-root-rules.make | 4 +- make/doc-i18n-root-vars.make | 6 +- stepmake/stepmake/texinfo-vars.make | 4 +- 4 files changed, 189 insertions(+), 33 deletions(-) diff --git a/Documentation/lilypond-texi2html.init b/Documentation/lilypond-texi2html.init index 90a10d0234..539ee044a1 100644 --- a/Documentation/lilypond-texi2html.init +++ b/Documentation/lilypond-texi2html.init @@ -66,11 +66,13 @@ package Texi2HTML::Config; +use utf8; +use Encode qw(decode); + ############################################################################# ### TRANSLATIONS ############################################################################# -use utf8; my $LY_LANGUAGES = {}; $LY_LANGUAGES->{'fr'} = { 'Back to Documentation Index' => 'Retour à l\'accueil de la documentation', @@ -89,6 +91,9 @@ $LY_LANGUAGES->{'hu'} = { 'Back to Documentation Index' => 'Vissza a dokumentációk jegyzékéhez', }; +# FIXME: request translation and send it to texi2html/texinfo devs +$LANGUAGES->{'hu'} = $LANGUAGES->{'en'}; + sub ly_get_string () { my $lang = $Texi2HTML::THISDOC{current_lang}; my $string = shift; @@ -100,29 +105,55 @@ sub ly_get_string () { } +############################################################################# +### FUNCTIONALITY FOR MAIN WEB PAGES +############################################################################# + +my $web_manual = 0; +sub lilypond_init_web_manual () +{ + if (exists($main::value{'web_manual'})) + { + print STDERR "Initializing settings for web site\n"; + $web_manual = 1; + web_settings(); + } +} +push @Texi2HTML::Config::command_handler_process, \&lilypond_init_web_manual; + ############################################################################# ### SETTINGS FOR TEXI2HTML ############################################################################# -@Texi2HTML::Config::CSS_REFS = ( - {FILENAME => "lilypond-mccarty.css", TITLE => "Patrick McCarty's design"} -); +# Validation fix for texi2html<=1.82 +$Texi2HTML::Config::DOCTYPE = ''; + +sub web_settings() { + if ($web_manual) { + @Texi2HTML::Config::CSS_REFS = ( + {FILENAME => "lilypond-web.css", TITLE => "Default style"} + ); + } else { + @Texi2HTML::Config::CSS_REFS = ( + {FILENAME => "lilypond-mccarty.css", TITLE => "Patrick McCarty's design"} + ); + } +} @Texi2HTML::Config::ALT_CSS_REFS = ( {FILENAME => "lilypond.css", TITLE => "Andrew Hawryluk's design" }, {FILENAME => "lilypond-blue.css", TITLE => "Kurt Kroon's blue design" }, ); -# no bgcolor and link colors in tag -# in texi2html >=1.83, override $Texi2HTML::Config::html_default_bodytext instead -$Texi2HTML::Config::BODYTEXT = ""; -$Texi2HTML::Config::DOCTYPE = ''; $Texi2HTML::Config::USE_ACCESSKEY = 1; $Texi2HTML::Config::USE_LINKS = 1; $Texi2HTML::Config::USE_REL_REV = 1; $Texi2HTML::Config::SPLIT_INDEX = 0; $Texi2HTML::Config::SEPARATED_FOOTNOTES = 0; # Print footnotes on same page, not separated -if ($Texi2HTML::Config::SPLIT eq 'section') { + +if ($Texi2HTML::Config::SPLIT eq 'section' or + $Texi2HTML::Config::SPLIT eq 'subsubsection') { $Texi2HTML::Config::element_file_name = \&lilypond_element_file_name; } + $Texi2HTML::Config::element_target_name = \&lilypond_element_target_name; $default_print_element_header = $Texi2HTML::Config::print_element_header; $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header; @@ -219,10 +250,9 @@ sub texinfo_file_name($) $result = 't_g' . $result; } # DONE - return $result + return lc($result) } - # Load a file containing a nodename<=>filename map (tab-sepatared, i.e. # NODENAME\tFILENAME\tANCHOR # Returns a ref to a hash "Node title" => ["FilenameWithoutExt", "Anchor"] @@ -231,9 +261,11 @@ sub load_map_file ($) my $mapfile = shift; my $node_map = (); - if (open(XREFFILE,'<:encoding(utf8)', $mapfile)) { + # For some unknown reason, Perl on my system (5.10.0 on Fedora 12) + # refuses to open map files of translated documents with '<:encoding' + if (open(XREFFILE,'<', $mapfile)) { my $line; - while ( $line = ) { + while ( $line = decode ('UTF-8', ) ) { # parse the tab-separated entries and insert them into the map: chomp($line); my @entries = split(/\t/, $line); @@ -243,6 +275,7 @@ sub load_map_file ($) print STDERR "Invalid entry in the node file $mapfile: $line\n"; } } + # print STDERR %{$node_map}; close (XREFFILE); } else { print STDERR "WARNING: Unable to load the map file $mapfile\n"; @@ -299,6 +332,8 @@ sub lilypond_css_lines ($$) { $Texi2HTML::THISDOC{'CSS_LINES'} .= "{FILENAME}\" title=\"$ref->{TITLE}\">\n"; } + # FIXME: the website doesn't use ie7-specific fixes; do the + # docs still need this? -gp $Texi2HTML::THISDOC{'CSS_LINES'} .= "\n"; } @@ -361,7 +396,8 @@ sub lilypond_element_file_name($$$) $$element{doc_nr} = $docnr; $lastfilename = $filename; } - return $filename; + # print STDERR "File name: $filename\n"; + return lc($filename); } elsif ($type eq "top" or $type eq "toc" or $type eq "doc" or $type eq "stoc" or $type eq "foot" or $type eq "about") { return; @@ -382,10 +418,12 @@ sub lilypond_element_file_name($$$) $docnr += 1; $$element{doc_nr} = $docnr; $lastfilename = $filename; - return $filename; + print STDERR "File name: $filename\n"; + return lc($filename); } else { $$element{doc_nr} = $docnr; - return $lastfilename; + print STDERR "File name: $filename\n"; + return lc($filename); } } @@ -417,6 +455,7 @@ sub lilypond_element_target_name($$$) } # TODO: Once texi2html correctly prints out the target and not the id for # the sections, change this back to ($id, $target) + $target = lc($target); return ($target, $target); } @@ -430,6 +469,7 @@ sub lilypond_init_map () my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'}); my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map") || main::locate_include_file ("${docu_name}.xref-map"); + print STDERR "Map filename is: $map_filename\nDocu name is $docu_name\n"; $node_to_filename_map = load_map_file ($map_filename); } push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map; @@ -450,7 +490,7 @@ sub lilypond_external_ref($$$$$$) my $section = shift; my $book = shift; my $file_node = shift; - my $href = shift; + my $href = lc(shift); my $cross_ref = shift; my $displaytext = ''; @@ -555,7 +595,7 @@ sub lilypond_external_href($$$) } if (defined $file) { - return &$default_external_href($node, $node_id, $node_hxmlt_id, $file); + return &$default_external_href($node, $node_id, $node_hxmlt_id, lc($file)); } else { return &$default_external_href($node, $node_id, $node_hxmlt_id); } @@ -572,7 +612,6 @@ sub lilypond_external_href($$$) my $page_toc_depth = 2; my @default_toc = []; - # Initialize the toc_depth to 1 if the command-line option -D=short_toc is given sub lilypond_init_toc_depth () { @@ -599,14 +638,71 @@ sub generate_ly_toc_entries($$$) { my $element = shift; my $element_path = shift; - my $maxlevel = shift; + if ($web_manual) { + my $maxlevel = 1; + } else { + 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->{'id'} && $element_path->{$element->{'id'}}; my $ind = ' ' x $level; - my $this_css_class = $is_parent_of_current ? " class=\"toc_current\"" : ""; + my $this_css_class; + if ($web_manual) { + $this_css_class = " class=\""; + } else { + $this_css_class = ""; + } + $this_css_class .= $is_parent_of_current ? " toc_current" : ""; +# HORRIBLE HACK + my @color_1 = ( + "Learning", "Glossary", "Essay", + "Contact", "Tiny examples", "Bug reports" + ); + my @color_2 = ( + "Features", "Examples", "Freedom", "Background", + "Unix", "MacOS X", "Windows", + "Notation", "Usage", "Snippets", + "Help us", "Development", "Authors" + ); + my @color_3 = ( + "Productions", "Testimonials", + "Source", "Old downloads", + "FAQ", "Changes", "Extend", "Internals", + "Publications", "Old news" + ); + my @color_4 = ( + "Text input", "Alternate input", + "GPL", + "Translated", "All", "FDL" + ); + + my $addColor = " colorDefault"; + foreach $color (@color_1) { + if ($element->{'text'} eq $color) { + $addColor = " color1"; + } + } + foreach $color (@color_2) { + if ($element->{'text'} eq $color) { + $addColor = " color2"; + } + } + foreach $color (@color_3) { + if ($element->{'text'} eq $color) { + $addColor = " color3"; + } + } + foreach $color (@color_4) { + if ($element->{'text'} eq $color) { + $addColor = " color4"; + } + } + + $this_css_class .= $addColor . "\""; + my $entry = "$ind" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}",$element->{'text'}); @@ -627,7 +723,11 @@ sub generate_ly_toc_entries($$$) # are ignored, don't generate a list at all... if (@child_result) { push (@result, "\n$ind\n"); - push (@result, @child_result); + if ($web_manual) { + push (@result, "$ind" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}","(main)")); + } else { + push (@result, @child_result); + } push (@result, "$ind\n"); } } @@ -651,14 +751,44 @@ sub lilypond_generate_page_toc_body($) $parentelements{$current_element->{'sectionup'}->{'id'}} = 1 if ($current_element->{'sectionup'}->{'id'} ne ''); $current_element = $current_element->{'sectionup'}; + if ($web_manual) { + if (exists($main::value{'shallow_toc'})) { + last; + } + } } return () if not defined($current_element); # Create the toc entries recursively - my @toc_entries = ("
\n", "\n"); + my @toc_entries = ""; + if ($web_manual) { + push (@toc_entries, "\n"); + # FIXME: add link to main page, really hackily. + if ($element->{'sectionup'}) { + # it's not the top element + push (@toc_entries, "
  • Main
  • \n"); + } else { + push (@toc_entries, "
  • Main
  • \n"); + } + } else { + push (@toc_entries, "
    \n"); + push (@toc_entries, "\n"); + } my $children = $current_element->{'section_childs'}; foreach ( @$children ) { push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth)); } + # search box + if ($web_manual) { + # WTF, perl needs 6 lines of magic to do: ' ' + open ('file-name').read ()? + local $/=undef; + my $name = "search-box.html"; + open FILE, "$ENV{SRC_DIR}/$name" or open FILE, "$ENV{SRC_DIR}/../$name" or die die "no such file: $name: $!"; + + my $string = ; + $string = "
  • \n" . $string . "
  • \n"; + push (@toc_entries, $string); + close FILE; + } push (@toc_entries, "\n"); push (@toc_entries, "
    \n"); return @toc_entries; @@ -690,16 +820,20 @@ sub lilypond_print_toc_div ($$) $reldir = "../" if ($Texi2HTML::Config::SPLIT eq 'section'); my $uplink = $reldir."web/manuals.${lang}html"; - print $fh "

    << " . &ly_get_string ('Back to Documentation Index') . "

    \n"; - print $fh '

    ' . &$anchor('', + print $fh '

    ' . &$anchor('', $Texi2HTML::HREF{'Top'}, $topname, 'title="Start of the manual"' ) . "

    \n"; + } + foreach my $line (@lines) { print $fh $line; } @@ -752,6 +886,20 @@ sub print_lilypond_page_foot($) print $fh "\n\n"; print $fh "\n
    \n\n"; + if ($web_manual) { + # FIXME: This div and p#languages need to be in div#footer. + # Should we move this div to postprocess_html.py ? + print $fh "
    \n"; + print $fh "

    Validation

    \n"; + print $fh "

    Thanks to webdev.nl"; + print $fh " for hosting lilypond.org.\n"; + print $fh "\n"; + print $fh "\"Valid

    \n"; + print $fh "
    "; + } + # Print the TOC frame and reset the TOC: lilypond_print_toc_div ($fh, \@this_page_toc); @this_page_toc = (); @@ -915,7 +1063,11 @@ sub lilypond_print_navigation $result .= "" unless $beginofline; $result .= "" unless $vertical; $result .= "\n"; - return $result; + if ($web_manual) { + return "\n"; + } else { + return $result; + } } @@ -1093,6 +1245,10 @@ sub makeinfo_like_paragraph ($$$$$$$$$$$$$) if ($Texi2HTML::Config::SPLIT eq 'section') { $Texi2HTML::Config::TOP_FILE = 'index.html'; } +if ($web_node) { +} else { + push @Texi2HTML::Config::command_handler_process, \&lilypond_init_toc_depth; +} return 1; diff --git a/make/doc-i18n-root-rules.make b/make/doc-i18n-root-rules.make index 0a368ef12b..ce9c7fa53c 100644 --- a/make/doc-i18n-root-rules.make +++ b/make/doc-i18n-root-rules.make @@ -4,11 +4,11 @@ $(outdir)/%.texi: $(src-dir)/%.texi $(top-build-dir)/Documentation/$(outdir)/%/index.$(ISOLANG).html: $(outdir)/%.texi $(XREF_MAPS_DIR)/%.$(ISOLANG).xref-map $(TRANSLATION_LILY_IMAGES) mkdir -p $(dir $@) mkdir -p $(outdir)/$* - $(TEXI2HTML) $(TEXI2HTML_FLAGS) $(TEXI2HTML_SPLIT) --output=$(outdir)/$* $< + $(TEXI2HTML) $(TEXI2HTML_SPLIT) $(TEXI2HTML_FLAGS) --output=$(outdir)/$* $< find $(outdir)/$* -name '*.html' | xargs grep -L --label="" 'UNTRANSLATED NODE: IGNORE ME' | sed 's!$(outdir)/!!g' | xargs $(buildscript-dir)/mass-link --prepend-suffix .$(ISOLANG) hard $(outdir) $(top-build-dir)/Documentation/$(outdir) $(top-build-dir)/Documentation/$(outdir)/%-big-page.$(ISOLANG).html: $(outdir)/%.texi $(XREF_MAPS_DIR)/%.$(ISOLANG).xref-map $(TRANSLATION_LILY_IMAGES) - $(TEXI2HTML) $(TEXI2HTML_FLAGS) -D bigpage --output=$@ $< + $(TEXI2HTML) -D bigpage $(TEXI2HTML_FLAGS) --output=$@ $< $(top-build-dir)/Documentation/$(outdir)/%.$(ISOLANG).html: $(outdir)/%.texi $(XREF_MAPS_DIR)/%.$(ISOLANG).xref-map $(outdir)/version.itexi $(TEXI2HTML) $(TEXI2HTML_FLAGS) --output=$@ $< diff --git a/make/doc-i18n-root-vars.make b/make/doc-i18n-root-vars.make index fed399b8ae..9171461c38 100644 --- a/make/doc-i18n-root-vars.make +++ b/make/doc-i18n-root-vars.make @@ -53,11 +53,11 @@ TEXI2HTML_LANG = --lang=$(ISOLANG) endif DOC_TEXI2HTML_INIT = --init-file=$(top-src-dir)/Documentation/lilypond-texi2html.init -WEB_TEXI2HTML_INIT =--init-file=$(top-src-dir)/Documentation/web-texi2html.init +WEB_TEXI2HTML_INIT =-D web_manual --init-file=$(top-src-dir)/Documentation/lilypond-texi2html.init TEXI2HTML_INIT = $(DOC_TEXI2HTML_INIT) DOC_TEXI2HTML_SPLIT = --prefix=index --split=section -WEB_TEXI2HTML_SPLIT = --prefix=index --split=node --node-files +WEB_TEXI2HTML_SPLIT = --prefix=index --split=subsubsection --node-files TEXI2HTML_SPLIT = $(DOC_TEXI2HTML_SPLIT) $(top-build-dir)/Documentation/$(outdir)/web/index.$(ISOLANG).html:\ @@ -66,7 +66,7 @@ $(top-build-dir)/Documentation/$(outdir)/web/index.$(ISOLANG).html:\ TEXI2HTML_SPLIT := $(WEB_TEXI2HTML_SPLIT) TEXI2HTML_INCLUDES += --I=. --I=$(src-dir) --I=$(outdir) $(DOCUMENTATION_INCLUDES) --I=$(XREF_MAPS_DIR) -TEXI2HTML_FLAGS += $(TEXI2HTML_INCLUDES) $(TEXI2HTML_INIT) $(TEXI2HTML_LANG) +TEXI2HTML_FLAGS += $(TEXI2HTML_INCLUDES) $(TEXI2HTML_LANG) $(TEXI2HTML_INIT) TEXI2HTML = SRC_DIR=$(src-dir) PERL_UNICODE=SD $(TEXI2HTML_PROGRAM) ########### diff --git a/stepmake/stepmake/texinfo-vars.make b/stepmake/stepmake/texinfo-vars.make index 8bc4b7fe5f..7011b48d82 100644 --- a/stepmake/stepmake/texinfo-vars.make +++ b/stepmake/stepmake/texinfo-vars.make @@ -28,11 +28,11 @@ TEXI2HTML_LANG = --lang=$(ISOLANG) endif DOC_TEXI2HTML_INIT = --init-file=$(top-src-dir)/Documentation/lilypond-texi2html.init -WEB_TEXI2HTML_INIT =--init-file=$(top-src-dir)/Documentation/web-texi2html.init +WEB_TEXI2HTML_INIT =-D web_manual --init-file=$(top-src-dir)/Documentation/lilypond-texi2html.init TEXI2HTML_INIT = $(DOC_TEXI2HTML_INIT) DOC_TEXI2HTML_SPLIT = --prefix=index --split=section -WEB_TEXI2HTML_SPLIT = --prefix=index --split=section +WEB_TEXI2HTML_SPLIT = --prefix=index --split=subsubsection TEXI2HTML_SPLIT = $(DOC_TEXI2HTML_SPLIT) TEXI2HTML_INCLUDES += --I=$(src-dir) --I=$(outdir) $(DOCUMENTATION_INCLUDES) --I=$(XREF_MAPS_DIR) -- 2.39.2