[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Fri, 12 Apr 2024 19:16:24 -0400 (EDT) |
branch: master
commit 29d60ef410e7e43b38320c46a0670e3deb35d2f7
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Apr 13 01:06:01 2024 +0200
* tp/Texinfo/Convert/Text.pm (convert_tree, convert): fix
implementations. Use XS for convert similarly as in output.
* tp/Makefile.tres, t/raw_text_converter.t: add test of raw text
converter functions not called elsewhere.
---
ChangeLog | 8 ++++++
tp/Makefile.tres | 1 +
tp/Texinfo/Convert/Text.pm | 38 ++++++++++++++++---------
tp/Texinfo/Convert/Utils.pm | 2 ++
tp/t/convert_to_text.t | 4 +--
tp/t/raw_text_converter.t | 69 +++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 106 insertions(+), 16 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9b334e126c..5cb6570e15 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-04-12 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/Text.pm (convert_tree, convert): fix
+ implementations. Use XS for convert similarly as in output.
+
+ * tp/Makefile.tres, t/raw_text_converter.t: add test of raw text
+ converter functions not called elsewhere.
+
2024-04-12 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Convert/HTML.pm (_html_set_pages_files),
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index 97ff55a34d..85424000f1 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -50,6 +50,7 @@ test_tap_files_generated_list = \
t/paragraph.t \
t/plaintext_tests.t \
t/protect_character_in_texinfo.t \
+ t/raw_text_converter.t \
t/reference_to_text_in_tree.t \
t/test_brace_count.t \
t/test_fill_gaps_in_sectioning.t \
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index a882e067d0..71973f7bcb 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -824,34 +824,44 @@ sub converter($;$)
return $converter;
}
-# This function is not called in anywhere in Texinfo code, it is implemented
-# to be in line with Texinfo::Convert::Converter documentation on functions
-# defined for a converter.
-# TODO set options with $self if defined?
+# This function is not called (except in a test testing the function),
+# it is implemented to be in line with Texinfo::Convert::Converter
+# documentation on functions defined for a converter.
+# We assume that $SELF is defined and a Texinfo::Convert::Text converter
+# that will supply the options.
sub convert_tree($$)
{
my $self = shift;
my $element = shift;
- my $options = {};
-
- return _convert($options, $element);
+ return _convert($self, $element);
}
-# This function is not called in anywhere in Texinfo code, it is implemented
-# to be in line with Texinfo::Convert::Converter documentation on functions
-# defined for a converter.
-# TODO set options with $self if defined?
+# This function is not called (except in a test testing the function),
+# it is implemented to be in line with Texinfo::Convert::Converter
+# documentation on functions defined for a converter.
+# We assume that $SELF is defined and a Texinfo::Convert::Text converter.
sub convert($$)
{
my $self = shift;
my $document = shift;
+ Texinfo::Common::set_output_encodings($self, $document);
+ # Cf comment in output() on using $self for options.
+ _initialize_options_encoding($self, $self);
+
my $root = $document->tree();
- my $options = {};
+ my $result;
+ # Interface with XS converter.
+ if ($XS_convert and defined($root->{'tree_document_descriptor'})
+ and $Texinfo::Convert::ConvertXS::XS_package) {
+ $result = _convert_tree_with_XS($self, $root);
+ } else {
+ $result = _convert($self, $root);
+ }
- return _convert($options, $root);
+ return $result;
}
# determine outfile and output to that file
@@ -967,7 +977,7 @@ sub output($$)
}
}
- # We use $self as text options, see the comment in converter.
+ # We use $self as text options, see the comment above.
my $result;
# Interface with XS converter.
diff --git a/tp/Texinfo/Convert/Utils.pm b/tp/Texinfo/Convert/Utils.pm
index cec41ca5d6..d9ed89d976 100644
--- a/tp/Texinfo/Convert/Utils.pm
+++ b/tp/Texinfo/Convert/Utils.pm
@@ -363,6 +363,8 @@ sub add_heading_number($$$;$)
$result = $text;
$result = $number.' '.$result if (defined($number));
if ($current->{'cmdname'} eq 'appendix'
+ # in case structuring code was not called could be undef
+ and defined($current->{'extra'}->{'section_level'})
and $current->{'extra'}->{'section_level'} == 1) {
$result = 'Appendix '.$result;
}
diff --git a/tp/t/convert_to_text.t b/tp/t/convert_to_text.t
index 58a66330ac..4bb2f19f6f 100644
--- a/tp/t/convert_to_text.t
+++ b/tp/t/convert_to_text.t
@@ -53,7 +53,7 @@ ok(1);
my $parser = Texinfo::Parser::parser();
-my $document = $parser->parse_texi_piece ('
+my $document = $parser->parse_texi_piece('
@documentlanguage fr
@node top
@@ -70,7 +70,7 @@ my $document = $parser->parse_texi_piece ('
my $tree = $document->tree();
#use Texinfo::DebugTree;
-#print STDERR Texinfo::DebugTree->convert_tree ($tree);
+#print STDERR Texinfo::DebugTree->convert_tree($tree);
# Setup sectioning commands numbers
my $sections_list
diff --git a/tp/t/raw_text_converter.t b/tp/t/raw_text_converter.t
new file mode 100644
index 0000000000..752035fc91
--- /dev/null
+++ b/tp/t/raw_text_converter.t
@@ -0,0 +1,69 @@
+use strict;
+
+use lib '.';
+use Texinfo::ModulePath (undef, undef, undef, 'updirs' => 2);
+
+use Test::More;
+
+BEGIN { plan tests => 4; }
+
+use Texinfo::Parser;
+use Texinfo::Convert::Text;
+
+ok(1);
+
+my $converter = Texinfo::Convert::Text->converter({'TEST' => 1,
+ 'ASCII_GLYPH' => 1,
+ 'ENABLE_ENCODING' => 1});
+
+my $texinfo_code = '@node top
+@top A top
+
+
+@node chap
+@chapter Chap
+
+@copyright{} @today{}.
+@AA{}.
+
+@node appendix
+@appendix Conclusion
+';
+
+my $parser = Texinfo::Parser::parser();
+
+my $document = $parser->parse_texi_text($texinfo_code);
+
+my $result_text = $converter->convert($document);
+
+# This also tests a situation where Texinfo::Structuring::sectioning_structure
+# is not called. There are therefore no sectioning commands numbers.
+is ($result_text, "A top
+*****
+
+
+Chap
+****
+
+(C) a sunny day.
+\x{00C5}.
+
+Conclusion
+**********
+", 'test convert');
+
+#print STDERR "$result_text";
+
+my $tree = $parser->parse_texi_line('@code{@bullet{} something} ``@^a---');
+
+my $result_line = $converter->convert_tree($tree);
+
+is ($result_line, "* something \"\x{00E2}--", 'test convert_tree');
+#print STDERR "RRR '$result_line'\n";
+
+Texinfo::Convert::Text::set_options_code($converter);
+my $result_code = $converter->convert_tree($tree);
+Texinfo::Convert::Text::reset_options_code($converter);
+
+is ($result_code, "* something ``\x{00E2}---",
+ 'test convert_tree in code context');