[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Thu, 18 Jan 2024 14:31:11 -0500 (EST) |
branch: master
commit 5f056d5c1840e981ff6f10506c74530cc220d915
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Jan 18 20:20:01 2024 +0100
* tp/Texinfo/Convert/Converter.pm (sort_element_counts): call
conversion_initialization and conversion_finalization.
* tp/Texinfo/Convert/TexinfoMarkup.pm (output, convert): give document
argument to conversion_initialization.
* tp/Texinfo/Convert/Converter.pm (conversion_initialization)
(converter), tp/Texinfo/Convert/DocBook.pm
(conversion_initialization), tp/Texinfo/Convert/HTML.pm
(conversion_initialization), tp/Texinfo/Convert/LaTeX.pm
(conversion_initialization), tp/Texinfo/Convert/Plaintext.pm
(conversion_initialization), tp/Texinfo/Convert/TexinfoMarkup.pm
(conversion_initialization), tp/t/test_utils.pl (convert_to_*),
tp/texi2any.pl: call set_document in conversion_initialization, do not
pass a document to converter initialization.
* tp/Texinfo/Convert/Text.pm (converter, output): get document in
output. Do not st global_information and global_commands_information
in converter state, they are only used in output().
* tp/t/convert_to_text.t: call set_document to set converter
document.
---
ChangeLog | 25 +++++++++++++++
tp/Texinfo/Convert/Converter.pm | 27 ++++++++--------
tp/Texinfo/Convert/DocBook.pm | 4 +++
tp/Texinfo/Convert/HTML.pm | 4 +++
tp/Texinfo/Convert/LaTeX.pm | 4 +++
tp/Texinfo/Convert/Plaintext.pm | 4 +++
tp/Texinfo/Convert/TexinfoMarkup.pm | 9 ++++--
tp/Texinfo/Convert/Text.pm | 62 ++++++++++++++++++-------------------
tp/t/convert_to_text.t | 3 +-
tp/t/test_utils.pl | 6 ----
tp/texi2any.pl | 2 --
11 files changed, 93 insertions(+), 57 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ddf644ee42..a7da42dd0b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2024-01-18 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/Converter.pm (sort_element_counts): call
+ conversion_initialization and conversion_finalization.
+
+ * tp/Texinfo/Convert/TexinfoMarkup.pm (output, convert): give document
+ argument to conversion_initialization.
+
+ * tp/Texinfo/Convert/Converter.pm (conversion_initialization)
+ (converter), tp/Texinfo/Convert/DocBook.pm
+ (conversion_initialization), tp/Texinfo/Convert/HTML.pm
+ (conversion_initialization), tp/Texinfo/Convert/LaTeX.pm
+ (conversion_initialization), tp/Texinfo/Convert/Plaintext.pm
+ (conversion_initialization), tp/Texinfo/Convert/TexinfoMarkup.pm
+ (conversion_initialization), tp/t/test_utils.pl (convert_to_*),
+ tp/texi2any.pl: call set_document in conversion_initialization, do not
+ pass a document to converter initialization.
+
+ * tp/Texinfo/Convert/Text.pm (converter, output): get document in
+ output. Do not st global_information and global_commands_information
+ in converter state, they are only used in output().
+
+ * tp/t/convert_to_text.t: call set_document to set converter
+ document.
+
2024-01-17 Gavin Smith <gavinsmith0123@gmail.com>
Find menu with hide-note-references=On
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index d9d0e458bc..25bb12bb0a 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -227,8 +227,12 @@ sub converter_initialize($)
sub conversion_initialization($;$)
{
- #my $converter = shift;
- #my $document = shift;
+ my $converter = shift;
+ my $document = shift;
+
+ if ($document) {
+ $converter->set_document($document);
+ }
}
sub conversion_finalization($)
@@ -297,9 +301,6 @@ sub converter($;$)
bless $converter, $class;
- # TODO set using set_document only
- my $document;
-
my %defaults = $converter->converter_defaults($conf);
foreach my $key (keys(%all_converters_defaults)) {
$defaults{$key} = $all_converters_defaults{$key}
@@ -314,10 +315,6 @@ sub converter($;$)
}
}
if (defined($conf)) {
- if ($conf->{'document'}) {
- $document = $conf->{'document'};
- delete $conf->{'document'};
- }
foreach my $key (keys(%$conf)) {
if (Texinfo::Common::valid_customization_option($key)) {
$converter->{'conf'}->{$key} = $conf->{$key};
@@ -363,10 +360,6 @@ sub converter($;$)
$converter->converter_initialize();
- if ($document) {
- set_document($converter, $document);
- }
-
return $converter;
}
@@ -739,6 +732,8 @@ sub write_or_return($$$)
my $STDIN_DOCU_NAME = 'stdin';
+# this requires a document, and is, in general, used in output(), therefore
+# a document need to be associated to the converter, not only a tree.
sub determine_files_and_directory($$)
{
my $self = shift;
@@ -1641,6 +1636,8 @@ sub sort_element_counts($$;$$)
my $use_sections = shift;
my $count_words = shift;
+ $converter->conversion_initialization($document);
+
my $tree = $document->tree();
my $output_units;
@@ -1667,9 +1664,10 @@ sub sort_element_counts($$;$$)
if ($output_unit->{'unit_command'}) {
my $command = $output_unit->{'unit_command'};
if ($command->{'args'}->[0]->{'contents'}) {
+ # convert contents to avoid outputting end of lines
$name = "\@$command->{'cmdname'} "
.Texinfo::Convert::Texinfo::convert_to_texinfo(
- {'contents' => $command->{'args'}->[0]->{'contents'}});
+ {'contents' => $command->{'args'}->[0]->{'contents'}});
}
}
$name = 'UNNAMED output unit' if (!defined($name));
@@ -1680,6 +1678,7 @@ sub sort_element_counts($$;$$)
$max_count = $count;
}
}
+ $converter->conversion_finalization();
my @sorted_name_counts_array = sort {$a->[0] <=> $b->[0]} @name_counts_array;
@sorted_name_counts_array = reverse(@sorted_name_counts_array);
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index e03ea66eeb..5871c161f2 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -297,6 +297,10 @@ sub conversion_initialization($;$)
my $self = shift;
my $document = shift;
+ if ($document) {
+ $self->set_document($document);
+ }
+
$self->{'document_context'} = [];
$self->_new_document_context();
$self->{'lang_stack'} = [];
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index fc5c25b8df..b0dee10f2c 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -11443,6 +11443,10 @@ sub conversion_initialization($;$)
my $self = shift;
my $document = shift;
+ if ($document) {
+ $self->set_document($document);
+ }
+
# duplicate such as not to modify the defaults
my $conf_default_no_arg_commands_formatting_normal
= Storable::dclone($default_no_arg_commands_formatting{'normal'});
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index 1f7fff233e..d39b6222f2 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -850,6 +850,10 @@ sub conversion_initialization($;$)
my $self = shift;
my $document = shift;
+ if ($document) {
+ $self->set_document($document);
+ }
+
%{$self->{'quotes_map'}} = %quotes_map;
# this condition means that there is no way to turn off
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index 557313376b..503728acfe 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -427,6 +427,10 @@ sub conversion_initialization($;$)
my $self = shift;
my $document = shift;
+ if ($document) {
+ $self->set_document($document);
+ }
+
$self->{'context'} = [];
$self->{'format_context'} = [];
$self->{'empty_lines_count'} = undef;
diff --git a/tp/Texinfo/Convert/TexinfoMarkup.pm
b/tp/Texinfo/Convert/TexinfoMarkup.pm
index 1d915bbbd2..b0a0ffd730 100644
--- a/tp/Texinfo/Convert/TexinfoMarkup.pm
+++ b/tp/Texinfo/Convert/TexinfoMarkup.pm
@@ -282,6 +282,11 @@ sub converter_initialize($)
sub conversion_initialization($;$)
{
my $self = shift;
+ my $document = shift;
+
+ if ($document) {
+ $self->set_document($document);
+ }
$self->{'document_context'} = [{'monospace' => [0]}];
}
@@ -292,7 +297,7 @@ sub output($$)
my $self = shift;
my $document = shift;
- $self->conversion_initialization();
+ $self->conversion_initialization($document);
my $root = $document->tree();
@@ -442,7 +447,7 @@ sub convert($$)
my $self = shift;
my $document = shift;
- $self->conversion_initialization();
+ $self->conversion_initialization($document);
my $root = $document->tree();
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index abd7898dc8..46a0ba9a18 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -871,14 +871,6 @@ sub converter($;$)
#print STDERR "CTe ".join("|", sort(keys(%{$conf})))."\n";
}
- if ($converter->{'document'}) {
- $converter->{'document_info'}
- = $converter->{'document'}->global_information();
- $converter->{'global_commands'}
- = $converter->{'document'}->global_commands_information();
- delete $converter->{'document'};
- }
-
my $expanded_formats = $converter->{'EXPANDED_FORMATS'};
if ($expanded_formats) {
$converter->{'expanded_formats'} = {};
@@ -887,22 +879,6 @@ sub converter($;$)
}
}
- Texinfo::Common::set_output_encodings($converter,
- $converter->{'document_info'})
- if ($converter->{'document_info'});
-
- # Text options and converter are of different nature.
- # It could have been possible to set up the options by calling
- # copy_options_for_convert_text on $self.
- # However, since the option keys are very similar between the converter
- # and text options and expanded_formats is already set in the converter,
- # we use the converter object as text options and we call
- # _initialize_options_encoding for the only option that is set up
- # based on other customization options.
- # Also, we need a blessed reference as get_conf can be called on the options,
- # using the converter brings that too.
- _initialize_options_encoding($converter, $converter);
-
return $converter;
}
@@ -943,12 +919,34 @@ sub output($$)
my $self = shift;
my $document = shift;
+ my $document_info;
+ my $global_commands;
+ if ($document) {
+ $document_info = $document->global_information();
+ $global_commands = $document->global_commands_information();
+ }
+
+ Texinfo::Common::set_output_encodings($self, $document_info)
+ if ($document_info);
+
+ # Text options and converter are of different nature.
+ # It could have been possible to set up the options by calling
+ # copy_options_for_convert_text on $self.
+ # However, since the option keys are very similar between the converter
+ # and text options and expanded_formats is already set in the converter,
+ # we use the converter object as text options and we call
+ # _initialize_options_encoding for the only option that is set up
+ # based on other customization options.
+ # Also, we need a blessed reference as get_conf can be called on the options,
+ # using the converter brings that too.
+ _initialize_options_encoding($self, $self);
+
my $root = $document->tree();
#print STDERR "OUTPUT\n";
my $input_basename;
- if (defined($self->{'document_info'}->{'input_file_name'})) {
- my $input_file_name = $self->{'document_info'}->{'input_file_name'};
+ if ($document_info and defined($document_info->{'input_file_name'})) {
+ my $input_file_name = $document_info->{'input_file_name'};
my $encoding = $self->{'COMMAND_LINE_ENCODING'};
if (defined($encoding)) {
$input_file_name = decode($encoding, $input_file_name);
@@ -964,12 +962,12 @@ sub output($$)
my $setfilename;
$setfilename
- = $self->{'global_commands'}->{'setfilename'}->{'extra'}->{'text_arg'}
- if ($self->{'global_commands'}
- and $self->{'global_commands'}->{'setfilename'}
- and $self->{'global_commands'}->{'setfilename'}->{'extra'}
- and defined($self->{'global_commands'}->{'setfilename'}
- ->{'extra'}->{'text_arg'}));
+ = $global_commands->{'setfilename'}->{'extra'}->{'text_arg'}
+ if ($global_commands
+ and $global_commands->{'setfilename'}
+ and $global_commands->{'setfilename'}->{'extra'}
+ and defined($global_commands->{'setfilename'}
+ ->{'extra'}->{'text_arg'}));
my $outfile;
if (!defined($self->{'OUTFILE'})) {
if (defined($setfilename)) {
diff --git a/tp/t/convert_to_text.t b/tp/t/convert_to_text.t
index 63b425b1e3..2e01ec5c6e 100644
--- a/tp/t/convert_to_text.t
+++ b/tp/t/convert_to_text.t
@@ -85,7 +85,8 @@ $tree = Texinfo::Document::rebuild_tree($tree);
# a converter only used for translation in text conversion, not
# to convert anything.
-my $converter = Texinfo::Convert::HTML->converter({'document' => $document});
+my $converter = Texinfo::Convert::HTML->converter();
+$converter->set_document($document);
# note that parse_texi_piece is used, so there is no preamble
$converter->set_global_document_commands('preamble_or_first',
['documentlanguage']);
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 8d805129a9..14a68c5123 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -532,7 +532,6 @@ sub convert_to_plaintext($$$$$$;$)
my $converter =
Texinfo::Convert::Plaintext->converter({'DEBUG' => $self->{'DEBUG'},
- 'document' => $document,
'converted_format' => 'plaintext',
%$converter_options });
my $result;
@@ -580,7 +579,6 @@ sub convert_to_info($$$$$;$)
my $converter =
Texinfo::Convert::Info->converter ({'DEBUG' => $self->{'DEBUG'},
- 'document' => $document,
'converted_format' => 'info',
%$converter_options });
my $result = $converter->output($document);
@@ -614,7 +612,6 @@ sub convert_to_html($$$$$$;$)
and !defined($converter_options->{'SPLIT'}));
my $converter =
Texinfo::Convert::HTML->converter ({'DEBUG' => $self->{'DEBUG'},
- 'document' => $document,
'converted_format' => 'html',
%$converter_options });
my $result;
@@ -650,7 +647,6 @@ sub convert_to_xml($$$$$$;$)
my $converter =
Texinfo::Convert::TexinfoXML->converter ({'DEBUG' => $self->{'DEBUG'},
- 'document' => $document,
'converted_format' => 'texinfoxml',
%$converter_options });
@@ -688,7 +684,6 @@ sub convert_to_docbook($$$$$$;$)
my $converter =
Texinfo::Convert::DocBook->converter ({'DEBUG' => $self->{'DEBUG'},
- 'document' => $document,
'converted_format' => 'docbook',
%$converter_options });
my $result;
@@ -745,7 +740,6 @@ sub convert_to_latex($$$$$$;$)
my $converter =
Texinfo::Convert::LaTeX->converter ({'DEBUG' => $self->{'DEBUG'},
- 'document' => $document,
'converted_format' => 'latex',
%$converter_options });
my $result;
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 4ea5e3fc8f..b4dd04872d 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1691,7 +1691,6 @@ while(@input_files) {
# It could be possible to pass some information if it allows
# for instance to have some consistent information for Structuring
# and Converters.
- $converter_options->{'document'} = $document;
$converter_options->{'output_format'} = $format;
$converter_options->{'converted_format'} = $converted_format;
$converter_options->{'language_config_dirs'} = \@language_config_dirs;
@@ -1790,7 +1789,6 @@ while(@input_files) {
%$file_cmdline_options,
};
- $sort_element_converter_options->{'document'} = $document;
# This is not clear that this is correct. On the one hand it could
# be more consistent with the formatting to have nothing here or a
# format corresponding to Texinfo::Convert::TextContent. On the other