texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sun, 21 Jan 2024 13:35:31 -0500 (EST)

branch: master
commit c1f77b132dfcb96ac5dd3174946e6d33f3e356e3
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Jan 20 23:20:16 2024 +0100

    * tp/Texinfo/Convert/DocBook.pm (_output_beginning, output)
    (_output_end), tp/Texinfo/Convert/TexinfoMarkup.pm (_output_beginning)
    (output, _output_end): add _output_beginning to prepare output
    appearing before tree conversion, and _output_end for output after
    tree conversion.
---
 ChangeLog                           |   8 +++
 tp/Texinfo/Convert/DocBook.pm       | 108 ++++++++++++++++++++++--------------
 tp/Texinfo/Convert/LaTeX.pm         |   2 +-
 tp/Texinfo/Convert/TexinfoMarkup.pm |  49 +++++++++++-----
 4 files changed, 109 insertions(+), 58 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c0fbbb5a74..e9e1f34c95 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,14 @@
        an empty line to the output.  Call _add_newline_if_needed to
        output the newline and increment the count of empty lines.
 
+2024-01-20  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/DocBook.pm (_output_beginning, output)
+       (_output_end), tp/Texinfo/Convert/TexinfoMarkup.pm (_output_beginning)
+       (output, _output_end): add _output_beginning to prepare output
+       appearing before tree conversion, and _output_end for output after
+       tree conversion.
+
 2024-01-20  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/DocBook.pm (_convert): do not ignore especially
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index 338ac982d8..caa2111677 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -348,46 +348,11 @@ sub convert_tree($$)
 # is used in the lang attribute, but if there is no @documentlanguag,
 # the lang_stack will start with an empty string, not with $DEFAULT_LANG.
 my $DEFAULT_LANG = 'en';
-sub output($$)
+sub _output_beginning($;$$)
 {
   my $self = shift;
-  my $document = shift;
-
-  $self->conversion_initialization($document);
-
-  my $root = $document->tree();
-
-  my ($output_file, $destination_directory, $output_filename)
-    = $self->determine_files_and_directory($self->{'output_format'});
-
-  my ($encoded_destination_directory, $dir_encoding)
-    = $self->encoded_output_file_name($destination_directory);
-  my $succeeded
-    = $self->create_destination_directory($encoded_destination_directory,
-                                          $destination_directory);
-  unless ($succeeded) {
-    $self->conversion_finalization();
-    return undef;
-  }
-
-  my $fh;
-  my $encoded_output_file;
-  if (! $output_file eq '') {
-    my $path_encoding;
-    ($encoded_output_file, $path_encoding)
-      = $self->encoded_output_file_name($output_file);
-    my $error_message;
-    ($fh, $error_message) = Texinfo::Common::output_files_open_out(
-                              $self->output_files_information(), $self,
-                              $encoded_output_file);
-    if (!$fh) {
-      $self->converter_document_error(
-           sprintf(__("could not open %s for writing: %s"),
-                                    $output_file, $error_message));
-      $self->conversion_finalization();
-      return undef;
-    }
-  }
+  my $output_file = shift;
+  my $output_filename = shift;
 
   my $encoding = '';
   if ($self->get_conf('OUTPUT_ENCODING_NAME')
@@ -410,7 +375,7 @@ sub output($$)
   } else {
     push @{$self->{'lang_stack'}}, '';
   }
-  my $header =  "<?xml version=\"1.0\"${encoding}?>".'
+  my $result =  "<?xml version=\"1.0\"${encoding}?>".'
 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" 
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"; [
   <!ENTITY tex "TeX">
   <!ENTITY latex "LaTeX">
@@ -536,17 +501,74 @@ sub output($$)
 
   # we duplicate title info, as it is explicitly said in the DocBook manual
   # that it can be duplicated if exactly the same
-  $header .= $title_info;
+  $result .= $title_info;
 
   if ($document_info ne '') {
     # FIXME DocBook 5 bookinfo->info
-    $header .= "<bookinfo>$document_info</bookinfo>\n";
+    $result .= "<bookinfo>$document_info</bookinfo>\n";
+  }
+
+  return $result;
+}
+
+sub _output_end($)
+{
+  my $self = shift;
+  return "</book>\n";
+}
+
+sub output($$)
+{
+  my $self = shift;
+  my $document = shift;
+
+  $self->conversion_initialization($document);
+
+  my $root = $document->tree();
+
+  my ($output_file, $destination_directory, $output_filename)
+    = $self->determine_files_and_directory($self->{'output_format'});
+
+  my ($encoded_destination_directory, $dir_encoding)
+    = $self->encoded_output_file_name($destination_directory);
+  my $succeeded
+    = $self->create_destination_directory($encoded_destination_directory,
+                                          $destination_directory);
+  unless ($succeeded) {
+    $self->conversion_finalization();
+    return undef;
   }
 
+  my $fh;
+  my $encoded_output_file;
+  if (! $output_file eq '') {
+    my $path_encoding;
+    ($encoded_output_file, $path_encoding)
+      = $self->encoded_output_file_name($output_file);
+    my $error_message;
+    ($fh, $error_message) = Texinfo::Common::output_files_open_out(
+                              $self->output_files_information(), $self,
+                              $encoded_output_file);
+    if (!$fh) {
+      $self->converter_document_error(
+           sprintf(__("could not open %s for writing: %s"),
+                                    $output_file, $error_message));
+      $self->conversion_finalization();
+      return undef;
+    }
+  }
+
+  my $output_beginning
+    = $self->_output_beginning($output_file, $output_filename);
+
   my $result = '';
-  $result .= $self->write_or_return($header, $fh);
+  $result .= $self->write_or_return($output_beginning, $fh);
   $result .= $self->write_or_return($self->convert_tree($root), $fh);
-  $result .= $self->write_or_return("</book>\n", $fh);
+
+  my $output_end = $self->_output_end();
+
+  $result .= $self->write_or_return($output_end, $fh);
+
   if ($fh and $output_file ne '-') {
     Texinfo::Common::output_files_register_closed(
                   $self->output_files_information(), $encoded_output_file);
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index a2ace096d6..2171d0891c 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -1768,7 +1768,7 @@ sub _latex_begin_output($)
 
   #my $header = "\n";
   my $header = "";
-  # Special treatment for setchapternewpage, we want to avid
+  # Special treatment for setchapternewpage, we want to avoid
   # a useless headings set just below
   $header .= "% set default for \@setchapternewpage\n";
   my $heading_set;
diff --git a/tp/Texinfo/Convert/TexinfoMarkup.pm 
b/tp/Texinfo/Convert/TexinfoMarkup.pm
index 55ded79ad7..26bc0a5abb 100644
--- a/tp/Texinfo/Convert/TexinfoMarkup.pm
+++ b/tp/Texinfo/Convert/TexinfoMarkup.pm
@@ -291,6 +291,32 @@ sub conversion_initialization($;$)
   $self->{'document_context'} = [{'monospace' => [0]}];
 }
 
+sub _output_beginning($;$$)
+{
+  my $self = shift;
+  my $output_file = shift;
+  my $output_filename = shift;
+
+
+  my $result = $self->txi_markup_header();
+  $result .= $self->txi_markup_open_element('texinfo')."\n";
+  if ($output_file ne '') {
+    my $filename_element = $self->txi_markup_open_element('filename',
+                                                  [['file', $output_filename]])
+             .$self->txi_markup_close_element('filename')."\n";
+    $result .= $filename_element;
+  }
+  return $result;
+}
+
+sub _output_end($)
+{
+  my $self = shift;
+
+  # FIXME add txi_markup_footer() to format a footer for the file?
+  return $self->txi_markup_close_element('texinfo')."\n";
+}
+
 # Main output function for the Texinfo language markup output files.
 sub output($$)
 {
@@ -329,22 +355,17 @@ sub output($$)
     }
   }
 
+  my $output_beginning
+    = $self->_output_beginning($output_file, $output_filename);
+
   my $result = '';
-  $result .= $self->write_or_return($self->txi_markup_header(), $fh);
-  $result
-    .= $self->write_or_return($self->txi_markup_open_element('texinfo')."\n",
-                              $fh);
-  if ($output_file ne '') {
-    my $filename_element = $self->txi_markup_open_element('filename',
-                                                  [['file', $output_filename]])
-             .$self->txi_markup_close_element('filename')."\n";
-    $result .= $self->write_or_return($filename_element, $fh);
-  }
+  $result .= $self->write_or_return($output_beginning, $fh);
   $result .= $self->write_or_return($self->convert_tree($root), $fh);
-  $result
-    .= $self->write_or_return($self->txi_markup_close_element('texinfo')."\n",
-                              $fh);
-  # FIXME add txi_markup_footer() to format a footer for the file?
+
+  my $output_end = $self->_output_end();
+
+  $result .= $self->write_or_return($output_end, $fh);
+
   if ($fh and $output_file ne '-') {
     Texinfo::Common::output_files_register_closed(
                   $self->output_files_information(), $encoded_output_file);



reply via email to

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