[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sat, 25 Nov 2023 18:22:01 -0500 (EST) |
branch: master
commit baa7795553d1025bf638d1c7570f8e592e75753e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Nov 25 23:36:23 2023 +0100
* tp/Texinfo/Convert/HTML.pm (count_elements_in_filename)
(_convert_special_unit_type): do not pass an undefined file name to
count_elements_in_filename.
* tp/Texinfo/Convert/Converter.pm (float_type_number): simplify code.
* tp/Texinfo/Convert/HTML.pm (command_tree): remove code never run.
Simplify code.
* tp/Texinfo/Convert/HTML.pm (command_text): reorganize code. Handle
string_nonumber similarly to text_nonumber. Introduce more
intermediate variables, change variables names.
---
ChangeLog | 15 +++++++
tp/Texinfo/Convert/Converter.pm | 17 +++-----
tp/Texinfo/Convert/HTML.pm | 97 +++++++++++++++++++++++------------------
3 files changed, 76 insertions(+), 53 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d71299909a..98aa88cb94 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2023-11-25 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/HTML.pm (count_elements_in_filename)
+ (_convert_special_unit_type): do not pass an undefined file name to
+ count_elements_in_filename.
+
+ * tp/Texinfo/Convert/Converter.pm (float_type_number): simplify code.
+
+ * tp/Texinfo/Convert/HTML.pm (command_tree): remove code never run.
+ Simplify code.
+
+ * tp/Texinfo/Convert/HTML.pm (command_text): reorganize code. Handle
+ string_nonumber similarly to text_nonumber. Introduce more
+ intermediate variables, change variables names.
+
2023-11-25 Patrice Dumas <pertusus@free.fr>
* tp/Makefile.tres, tp/t/03coverage_braces.t
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 2867a8bddc..98c58fe97a 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -1268,24 +1268,21 @@ sub float_type_number($$)
if ($float->{'extra'}->{'float_type'} ne '') {
$type_element = $float->{'args'}->[0];
}
+ my $float_number = $float->{'extra'}->{'float_number'};
my $tree;
if ($type_element) {
- if (defined($float->{'extra'})
- and defined($float->{'extra'}->{'float_number'})) {
+ if (defined($float_number)) {
$tree = $self->gdt("{float_type} {float_number}",
- {'float_type' => $type_element,
- 'float_number'
- => {'text' => $float->{'extra'}->{'float_number'}}});
+ {'float_type' => $type_element,
+ 'float_number' => {'text' => $float_number}});
} else {
$tree = $self->gdt("{float_type}",
- {'float_type' => $type_element});
+ {'float_type' => $type_element});
}
- } elsif (defined($float->{'extra'})
- and defined($float->{'extra'}->{'float_number'})) {
+ } elsif (defined($float_number)) {
$tree = $self->gdt("{float_number}",
- {'float_number'
- => {'text' => $float->{'extra'}->{'float_number'}}});
+ {'float_number' => {'text' => $float_number}});
}
return $tree;
}
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 5b1b42164c..6eb76f1843 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -660,6 +660,10 @@ sub count_elements_in_filename($$$)
my $spec = shift;
my $filename = shift;
+ if (!defined($filename)) {
+ confess("count_elements_in_filename: filename undef");
+ }
+
if ($spec eq 'total') {
if (defined($self->{'elements_in_file_count'}->{$filename})) {
return $self->{'elements_in_file_count'}->{$filename};
@@ -1094,18 +1098,13 @@ sub command_tree($$;$)
}
if ($command->{'extra'} and $command->{'extra'}->{'manual_content'}) {
- my $node_content = {};
- $node_content = $command->{'extra'}->{'node_content'}
- if (defined($command->{'extra'}->{'node_content'}));
- my $tree;
- if ($command->{'extra'}->{'manual_content'}) {
- $tree = {'type' => '_code',
+ my $node_content = $command->{'extra'}->{'node_content'};
+ my $tree = {'type' => '_code',
'contents' => [{'text' => '('},
$command->{'extra'}->{'manual_content'},
- {'text' => ')'}, $node_content]};
- } else {
- $tree = {'type' => '_code',
- 'contents' => [$node_content]};
+ {'text' => ')'}]};
+ if ($node_content) {
+ push @{$tree->{'contents'}}, $node_content;
}
return $tree;
}
@@ -1133,24 +1132,25 @@ sub command_tree($$;$)
or !$command->{'args'}->[0]->{'contents'}
or !scalar(@{$command->{'args'}->[0]->{'contents'}})) {
} else {
- if ($command->{'extra'}
- and defined($command->{'extra'}->{'section_number'})
+ my $section_number;
+ $section_number = $command->{'extra'}->{'section_number'}
+ if ($command->{'extra'}
+ and defined($command->{'extra'}->{'section_number'}));
+ if ($section_number
and ($self->get_conf('NUMBER_SECTIONS')
or !defined($self->get_conf('NUMBER_SECTIONS')))) {
+ my $substituted_strings
+ = {'number' => {'text' => $section_number},
+ 'section_title' => $command->{'args'}->[0]};
+
if ($command->{'cmdname'} eq 'appendix'
and $command->{'extra'}->{'section_level'} == 1) {
$tree = $self->gdt('Appendix {number} {section_title}',
- {'number' => {'text' => $command->{'extra'}
- ->{'section_number'}},
- 'section_title'
- => $command->{'args'}->[0]});
+ $substituted_strings);
} else {
# TRANSLATORS: numbered section title
$tree = $self->gdt('{number} {section_title}',
- {'number' => {'text' => $command->{'extra'}
- ->{'section_number'}},
- 'section_title'
- => $command->{'args'}->[0]});
+ $substituted_strings);
}
} else {
$tree = $command->{'args'}->[0];
@@ -1172,9 +1172,7 @@ sub command_tree($$;$)
# Return text to be used for a hyperlink to $COMMAND.
# $TYPE refers to the type of value returned from this function:
# 'text' - return text
-# 'tree' - return a tree
-# 'tree_nonumber' - return tree representing text without a chapter number
-# being included.
+# 'text_nonumber' - return text, without the section/chapter number
# 'string' - return simpler text that can be used in element attributes
sub command_text($$;$)
{
@@ -1206,35 +1204,47 @@ sub command_text($$;$)
if (defined($target->{$type})) {
return $target->{$type};
}
+ my $command_tree = $self->command_tree($command);
+ return '' if (!defined($command_tree));
+
my $explanation;
- if ($command->{'type'}
- and $command->{'type'} eq 'special_unit_element') {
- my $special_unit_variety
+ my $context_name;
+
+ if (defined($command->{'cmdname'})) {
+ my $cmdname = $command->{'cmdname'};
+ $context_name = $cmdname;
+ $explanation = "command_text:$type \@$cmdname";
+ } else {
+ $context_name = $command->{'type'};
+ if ($command->{'type'} eq 'special_unit_element') {
+ my $special_unit_variety
= $command->{'associated_unit'}->{'special_unit_variety'};
- $explanation = "command_text $special_unit_variety";
- } elsif ($command->{'cmdname'}) {
- $explanation = "command_text:$type \@$command->{'cmdname'}";
+ $explanation = "command_text $special_unit_variety";
+ }
}
- my $tree = $self->command_tree($command);
- return '' if (!defined($tree));
-
- my $context_name = $command->{'cmdname'};
- $context_name = $command->{'type'} if (!defined($context_name));
$self->_new_document_context($context_name, $explanation);
- if ($type eq 'string') {
- $tree = {'type' => '_string',
- 'contents' => [$tree]};
+ my $selected_tree;
+
+ if ($type =~ /^(.*)_nonumber$/
+ and defined($target->{'tree_nonumber'})) {
+ $selected_tree = $target->{'tree_nonumber'};
+ } else {
+ $selected_tree = $command_tree;
}
- if ($type =~ /^(.*)_nonumber$/) {
- $tree = $target->{'tree_nonumber'}
- if (defined($target->{'tree_nonumber'}));
+ my $tree_root;
+ if ($type eq 'string') {
+ $tree_root = {'type' => '_string',
+ 'contents' => [$selected_tree]};
+ } else {
+ $tree_root = $selected_tree;
}
+
$self->{'ignore_notice'}++;
push @{$self->{'referred_command_stack'}}, $command;
- $target->{$type} = $self->_convert($tree, $explanation);
+ $target->{$type} = $self->_convert($tree_root, $explanation);
pop @{$self->{'referred_command_stack'}};
$self->{'ignore_notice'}--;
@@ -7439,8 +7449,9 @@ sub _convert_special_unit_type($$$$)
$result .= ">\n";
if ($self->get_conf('HEADERS')
# first in page
- or $self->count_elements_in_filename('current',
- $output_unit->{'unit_filename'}) == 1) {
+ or (defined($output_unit->{'unit_filename'})
+ and $self->count_elements_in_filename('current',
+ $output_unit->{'unit_filename'}) == 1)) {
$result .= &{$self->formatting_function('format_navigation_header')}($self,
$self->get_conf('MISC_BUTTONS'), undef, $unit_command);
}
- Prev by Date:
master updated (265bf1c4d0 -> d3ad6d6ca5)
- Next by Date:
branch master updated: * tp/Texinfo/XS/main/debug.c (print_associate_info_debug), tp/Texinfo/XS/main/extra.c (lookup_extra_integer), tp/Texinfo/XS/main/manipulate_tree.c (increase_ref_counter) (get_copy_ref), tp/Texinfo/XS/main/tree_types.h (KEY_PAIR), tp/Texinfo/XS/main/utils.c (section_level), tp/Texinfo/XS/parsetexi/handle_commands.c (handle_other_command) (handle_line_command): use int for the integer field in KEY_PAIR values union. Update declarations and remove casts.
- Previous by thread:
[no subject]
- Next by thread:
branch master updated: * tp/Texinfo/XS/main/debug.c (print_associate_info_debug), tp/Texinfo/XS/main/extra.c (lookup_extra_integer), tp/Texinfo/XS/main/manipulate_tree.c (increase_ref_counter) (get_copy_ref), tp/Texinfo/XS/main/tree_types.h (KEY_PAIR), tp/Texinfo/XS/main/utils.c (section_level), tp/Texinfo/XS/parsetexi/handle_commands.c (handle_other_command) (handle_line_command): use int for the integer field in KEY_PAIR values union. Update declarations and remove casts.
- Index(es):