texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: Add contrib/init_examples directory for texi2any


From: Patrice Dumas
Subject: branch master updated: Add contrib/init_examples directory for texi2any initialization files
Date: Wed, 30 Oct 2024 13:14:53 -0400

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new ece6019eb5 Add contrib/init_examples directory for texi2any 
initialization files
ece6019eb5 is described below

commit ece6019eb5f43a1de61353923bfb6d2527ed9377
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Oct 30 18:14:38 2024 +0100

    Add contrib/init_examples directory for texi2any initialization files
---
 ChangeLog                                    |  4 ++
 contrib/init_examples/README                 | 11 ++++
 contrib/init_examples/emacs_texi2any_init.pm | 90 ++++++++++++++++++++++++++
 contrib/init_examples/file_names_simple.pm   | 39 ++++++++++++
 contrib/init_examples/maxima_file_names.pm   | 94 ++++++++++++++++++++++++++++
 5 files changed, 238 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 6963d4633e..1a1ca72d24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2024-10-30  Patrice Dumas  <pertusus@free.fr>
+
+       Add contrib/init_examples directory for texi2any initialization files
+
 2024-10-29  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/call_html_perl_function.c
diff --git a/contrib/init_examples/README b/contrib/init_examples/README
new file mode 100644
index 0000000000..dabd655e94
--- /dev/null
+++ b/contrib/init_examples/README
@@ -0,0 +1,11 @@
+contrib/init_examples/README
+
+  Copyright 2024 Free Software Foundation, Inc.
+
+  Copying and distribution of this file, with or without modification,
+  are permitted in any medium without royalty provided the copyright
+  notice and this notice are preserved.
+
+This directory contains initialization files for texi2any/makeinfo
+that are not officially supported, but were correct at the time they were
+added.
diff --git a/contrib/init_examples/emacs_texi2any_init.pm 
b/contrib/init_examples/emacs_texi2any_init.pm
new file mode 100644
index 0000000000..f19b54d731
--- /dev/null
+++ b/contrib/init_examples/emacs_texi2any_init.pm
@@ -0,0 +1,90 @@
+# Copyright 2024 Free Software Foundation, Inc.
+# 
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+
+# This is an example init file that could replace the elisp code used
+# in Emacs to postprocess Texinfo manuals.  If and when this could be
+# used in Emacs is not clear, in particular because the elisp code handles
+# compatibility for older GNU Texinfo releases.  There is a discussion here:
+#  https://lists.gnu.org/archive/html/help-texinfo/2024-03/msg00009.html
+
+use strict;
+
+
+texinfo_set_from_init_file('TOP_BUTTONS', undef);
+
+texinfo_set_from_init_file('EXTRA_HEAD',
+'<link rev="made" href="mailto:bug-gnu-emacs@gnu.org";>
+<link rel="icon" type="image/png" href="/graphics/gnu-head-mini.png">
+<meta name="ICBM" content="42.256233,-71.006581">
+<meta name="DC.title" content="gnu.org">
+');
+
+# NOTE it is likely that the div added in the following code is not
+# useful, see
+#   https://lists.gnu.org/archive/html/help-texinfo/2024-03/msg00031.html
+
+# The following adds a <div>.  This is only done for the Top element
+# if split.  The opening div is at the same place, right after body open
+# if split and non-split.  The div is closed at the end of the document
+# if non-split and at the end of the top element before the table of
+# contents if split.
+
+# used if split
+sub _emacs_texinfo_html_customization_convert_heading_command($$$$$)
+{
+  my $self = shift;
+  my $cmdname = shift;
+  my $element = shift;
+  my $args = shift;
+  my $content = shift;
+
+  # div opening is before the Top node, after body open
+  if ($cmdname eq 'node' and $element->{'extra'}
+      and $element->{'extra'}->{'normalized'} eq 'Top') {
+    my $result = &{$self->default_command_conversion($cmdname)}($self,
+                     $cmdname, $element, $args, $content);
+    return '<div id="content" class="inner">'."\n".$result;
+  # div closing is at the end of the top element, before the after_top
+  # contents
+  } elsif ($cmdname eq 'top') {
+    return &{$self->default_command_conversion($cmdname)}($self,
+                     $cmdname, $element, $args, $content . "</div>\n");
+  }
+
+  # call the default formatting function for other nodes
+  return &{$self->default_command_conversion($cmdname)}($self,
+                     $cmdname, $element, $args, $content);
+}
+
+if (defined(texinfo_get_conf('SPLIT')) and texinfo_get_conf('SPLIT') eq '') {
+  # if non-split, the div is closed at the end of the document
+  texinfo_set_from_init_file('AFTER_BODY_OPEN',
+     '<div id="content" class="inner">'."\n");
+  texinfo_set_from_init_file('PRE_BODY_CLOSE', "</div>\n");
+} else {
+  foreach my $cmdname ('top', 'node') {
+    texinfo_register_command_formatting($cmdname,
+      \&_emacs_texinfo_html_customization_convert_heading_command);
+  }
+}
+
+sub _emacs_texinfo_html_customization_format_css_lines($;$)
+{
+  my $self = shift;
+  my $filename = shift;
+
+  return '<style type="text/css">
+@import url(\'/software/emacs/manual.css\');
+</style>
+';
+}
+
+texinfo_register_formatting_function('format_css_lines',
+     \&_emacs_texinfo_html_customization_format_css_lines);
+
+
+1;
diff --git a/contrib/init_examples/file_names_simple.pm 
b/contrib/init_examples/file_names_simple.pm
new file mode 100644
index 0000000000..5a11dc6f73
--- /dev/null
+++ b/contrib/init_examples/file_names_simple.pm
@@ -0,0 +1,39 @@
+# Copyright 2022-2024 Free Software Foundation, Inc.
+# 
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+
+# Make the output file names consist of the base name followed by a number,
+# like my_manual_nnn.html
+
+use strict;
+
+# REMARK: if more than one manual is processed, $file_nr should be reset,
+# using a handler
+
+my $file_nr = -1;
+
+sub _texinfo_filename_simple($$$$)
+{
+  my $converter = shift;
+  my $output_unit = shift;
+  my $filename = shift;
+  my $filepath = shift;
+
+  return ($filename, $filepath) if (defined($filepath));
+
+  my $prefix = $converter->get_info('document_name');
+  if ($converter->unit_is_top_output_unit($output_unit)) {
+    return (undef, undef);
+  } else {
+    $file_nr++;
+    return ($prefix.'_'.$file_nr.'.'.$converter->get_conf('EXTENSION'), undef);
+  }
+}
+
+texinfo_register_file_id_setting_function('unit_file_name',
+                                          \&_texinfo_filename_simple);
+
+1;
diff --git a/contrib/init_examples/maxima_file_names.pm 
b/contrib/init_examples/maxima_file_names.pm
new file mode 100644
index 0000000000..c105b8cf21
--- /dev/null
+++ b/contrib/init_examples/maxima_file_names.pm
@@ -0,0 +1,94 @@
+# Copyright 2022-2024 Free Software Foundation, Inc.
+# 
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+
+# Make the output file names consist of the base name followed by a number,
+# maxima_nnn.html or maxima_toc.html for the table of contents.
+# In addition the appendices or indices don't get a number.
+
+# See
+#  https://lists.gnu.org/archive/html/help-texinfo/2022-08/msg00000.html
+
+use strict;
+
+# ./texi2any.pl --split=chapter --no-node-files --html --force -e 10000 
--init-file contrib/init_examples/maxima_file_names.pm 
--set-customization-variable HTML_MATH=mathjax maxima_init.texi
+
+# REMARK: if more than one manual is processed, $file_nr, 
%reference_file_name_file_nr
+# and $after_appendix_printindex should be reset, using a handler
+
+my $file_nr = -1;
+
+my %reference_file_name_file_nr = ();
+
+my $after_appendix_printindex = 0;
+
+sub _filename_simple_except_indices($$$$)
+{
+  my $converter = shift;
+  my $output_unit = shift;
+  my $filename = shift;
+  my $filepath = shift;
+
+  return ($filename, $filepath) if (defined($filepath));
+
+  my $prefix = $converter->get_info('document_name');
+  # If we're not splitting, just return the name.  Note that it should
+  # not happen, as in that case the $filepath should be set and the previous
+  # condition should also hold.
+  if (!$converter->get_conf('SPLIT')) {
+    return ($prefix.'.'.$converter->get_conf('EXTENSION'),
+            undef);
+  }
+  if ($converter->unit_is_top_output_unit($output_unit)) {
+    # The table of contents file should be named this.
+    return ("maxima_toc.html", undef);
+  } else {
+    if ($after_appendix_printindex) {
+      return ($filename, undef);
+    } else {
+      # FIXME would be more efficient to set it up in a handler (probably 
'init')
+      # once for all
+      my $printindex_unit = $converter->global_direction_unit('Index');
+      if (defined($printindex_unit) and $printindex_unit eq $output_unit) {
+        $after_appendix_printindex = 1;
+        return ($filename, undef);
+      }
+      if ($output_unit->{'unit_command'}) {
+        my $associated_command_element = $output_unit->{'unit_command'};
+        my $sectioning_command;
+        if ($associated_command_element->{'cmdname'} eq 'node') {
+          if ($associated_command_element->{'extra'}
+              and 
$associated_command_element->{'extra'}->{'associated_section'}) {
+            $sectioning_command
+              = 
$associated_command_element->{'extra'}->{'associated_section'}->{'cmdname'};
+          }
+        } else {
+          $sectioning_command = $associated_command_element->{'cmdname'};
+        }
+        if (defined($sectioning_command) and $sectioning_command =~ 
/appendix/) {
+          $after_appendix_printindex = 1;
+          return ($filename, undef);
+        }
+      }
+    }
+    if (defined($reference_file_name_file_nr{$filename})) {
+      $file_nr = $reference_file_name_file_nr{$filename};
+    } else {
+      $file_nr++;
+      $reference_file_name_file_nr{$filename} = $file_nr;
+    }
+    if ($file_nr == 0) {
+      return ($prefix.'.'.$converter->get_conf('EXTENSION'), undef);
+    } else {
+      return ($prefix.'_'.$file_nr.'.'.$converter->get_conf('EXTENSION'), 
undef);
+    }
+  }
+}
+
+texinfo_register_file_id_setting_function('unit_file_name',
+                                        \&_filename_simple_except_indices);
+
+1;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]