[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Convert/TexinfoXML.pm (_convert): av
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Convert/TexinfoXML.pm (_convert): avoid using $result if the @-command has no contents. Make braces commands formatting code cleaner and easier to understand. Put content at end of line of @item @*table commands at the end of line, after closing the item element. |
Date: |
Sat, 11 Sep 2021 04:18:49 -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 2deb80e * tp/Texinfo/Convert/TexinfoXML.pm (_convert): avoid using
$result if the @-command has no contents. Make braces commands formatting code
cleaner and easier to understand. Put content at end of line of @item @*table
commands at the end of line, after closing the item element.
2deb80e is described below
commit 2deb80e42397d344151154e0620253c6a1363544
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Sep 11 10:18:40 2021 +0200
* tp/Texinfo/Convert/TexinfoXML.pm (_convert): avoid using $result
if the @-command has no contents. Make braces commands formatting
code cleaner and easier to understand.
Put content at end of line of @item @*table commands at the end
of line, after closing the item element.
---
ChangeLog | 8 +++
tp/Texinfo/Convert/TexinfoXML.pm | 132 ++++++++++++++++++++++-----------------
tp/Texinfo/ParserNonXS.pm | 5 +-
tp/t/results/coverage/table.pl | 2 +-
4 files changed, 88 insertions(+), 59 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4ebdf75..5cab753 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-09-11 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/TexinfoXML.pm (_convert): avoid using $result
+ if the @-command has no contents. Make braces commands formatting
+ code cleaner and easier to understand.
+ Put content at end of line of @item @*table commands at the end
+ of line, after closing the item element.
+
2021-09-10 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Convert/TexinfoXML.pm (_end_line_spaces)
diff --git a/tp/Texinfo/Convert/TexinfoXML.pm b/tp/Texinfo/Convert/TexinfoXML.pm
index a3da960..5eeaca4 100644
--- a/tp/Texinfo/Convert/TexinfoXML.pm
+++ b/tp/Texinfo/Convert/TexinfoXML.pm
@@ -354,14 +354,6 @@ my $inline_command = 'inlinefmtifelse';
$commands_args_elements{$inline_command} = ["${inline_command}format",
"${inline_command}contentif", "${inline_command}contentelse"];
-my %commands_elements;
-foreach my $command (keys(%Texinfo::Common::brace_commands)) {
- $commands_elements{$command} = [$command];
- if ($commands_args_elements{$command}) {
- push @{$commands_elements{$command}}, @{$commands_args_elements{$command}};
- }
-}
-
my %defcommand_name_type = (
'deffn' => 'function',
'defvr' => 'variable',
@@ -721,7 +713,6 @@ sub _convert($$;$)
}
return '' if ($element->{'type'} and $ignored_types{$element->{'type'}});
- my $result = '';
if (defined($element->{'text'})) {
if ($self->{'document_context'}->[-1]->{'raw'}) {
# ignore the newline at the end of the @xml line, and the last in xml
@@ -732,10 +723,12 @@ sub _convert($$;$)
return $element->{'text'};
}
}
- $result = $self->format_text($element);
- return $result;
+ return $self->format_text($element);
}
+
my @close_format_elements;
+ # for @-commands with contents, to accumulate conversion results
+ my $result = '';
if ($element->{'cmdname'}) {
if (defined($no_arg_commands_formatting{$element->{'cmdname'}})) {
if ($element->{'cmdname'} eq 'click'
@@ -754,10 +747,11 @@ sub _convert($$;$)
return $self->convert_accents($element, \&_accent);
} else {
my $attributes = [];
+ my $arg;
if (!$element->{'args'}) {
- $result = '';
+ $arg = '';
} else {
- $result = $self->_convert($element->{'args'}->[0]);
+ $arg = $self->_convert($element->{'args'}->[0]);
if ($element->{'extra'} and $element->{'extra'}->{'spaces'}) {
push @$attributes, ('spaces', $element->{'extra'}->{'spaces'});
}
@@ -765,7 +759,7 @@ sub _convert($$;$)
push @$attributes, ('bracketed', 'off');
}
}
- return $self->_accent($result, $element, undef, $attributes);
+ return $self->_accent($arg, $element, undef, $attributes);
}
} elsif ($element->{'cmdname'} eq 'item' or $element->{'cmdname'} eq
'itemx'
or $element->{'cmdname'} eq 'headitem' or $element->{'cmdname'}
eq 'tab') {
@@ -795,11 +789,13 @@ sub _convert($$;$)
$attribute
=
[$self->_infoenclose_attribute($table_command->{'extra'}->{'command_as_argument'})];
}
- $result .= $self->open_element($element->{'cmdname'},
[_leading_spaces($element)]);
+ my $line_item_result = $self->open_element($element->{'cmdname'},
+
[_leading_spaces($element)]);
if ($format_item_command) {
- $result .= $self->open_element('itemformat', ['command',
$format_item_command, @$attribute]);
+ $line_item_result .= $self->open_element('itemformat',
+ ['command', $format_item_command,
@$attribute]);
}
- $result .= $self->_index_entry($element);
+ $line_item_result .= $self->_index_entry($element);
my $in_code;
$in_code = 1
if ($format_item_command
@@ -819,14 +815,16 @@ sub _convert($$;$)
if (defined($in_monospace_not_normal));
my ($arg, $end_line) = $self->_convert_argument_and_end_line($element);
- $result .= $arg . $end_line;
+
pop @{$self->{'document_context'}->[-1]->{'monospace'}}
if (defined($in_monospace_not_normal));
- chomp ($result);
+
+ $line_item_result .= $arg;
if ($format_item_command) {
- $result .= $self->close_element('itemformat');
+ $line_item_result .= $self->close_element('itemformat');
}
- $result .= $self->close_element($element->{'cmdname'})."\n";
+ $line_item_result .=
$self->close_element($element->{'cmdname'}).$end_line;
+ return $line_item_result;
} else {
unless (($element->{'cmdname'} eq 'item'
or $element->{'cmdname'} eq 'headitem'
@@ -1103,16 +1101,15 @@ sub _convert($$;$)
$in_monospace_not_normal
if (defined($in_monospace_not_normal));
my $arg = $self->_convert($element->{'args'}->[0]);
- $result .= $self->open_element('infoenclose', ['command',
$element->{'cmdname'},
-
$self->_infoenclose_attribute($element)])
- .$arg.$self->close_element('infoenclose');
pop @{$self->{'document_context'}->[-1]->{'monospace'}}
if (defined($in_monospace_not_normal));
+ my $command_result = $self->open_element('infoenclose', ['command',
$element->{'cmdname'},
+
$self->_infoenclose_attribute($element)])
+ .$arg.$self->close_element('infoenclose');
+ return $command_result;
} elsif ($element->{'args'}
and
exists($Texinfo::Common::brace_commands{$element->{'cmdname'}})) {
- if ($Texinfo::Common::context_brace_commands{$element->{'cmdname'}}) {
- push @{$self->{'document_context'}}, {'monospace' => [0]};
- }
+
if ($Texinfo::Common::inline_format_commands{$element->{'cmdname'}}
and $element->{'extra'} and $element->{'extra'}->{'format'}
and
$self->{'expanded_formats_hash'}->{$element->{'extra'}->{'format'}}) {
@@ -1120,22 +1117,20 @@ sub _convert($$;$)
push @{$self->{'document_context'}}, {'monospace' => [0]};
$self->{'document_context'}->[-1]->{'raw'} = 1;
}
+ my $command_result = '';
if (scalar (@{$element->{'args'}}) == 2
and defined($element->{'args'}->[-1])
and @{$element->{'args'}->[-1]->{'contents'}}) {
- $result .= $self->_convert({'contents'
+ $command_result = $self->_convert({'contents'
=> $element->{'args'}->[-1]->{'contents'}});
}
if ($element->{'cmdname'} eq 'inlineraw') {
pop @{$self->{'document_context'}};
}
- return $result;
- }
- my @format_elements = @{$commands_elements{$element->{'cmdname'}}};
- my $command;
- if (scalar(@format_elements) > 1) {
- $command = shift @format_elements;
+ return $command_result;
}
+
+
# this is used for commands without args, or associated to the
# first argument
my $attribute = [];
@@ -1150,9 +1145,34 @@ sub _convert($$;$)
}
push @$attribute, ('name', $anchor_name);
}
+
+ my @format_elements;
+ my $main_cmdname;
+ if ($commands_args_elements{$element->{'cmdname'}}) {
+ # command with arguments, format the arguments using their specific
+ # elements
+ @format_elements = @{$commands_args_elements{$element->{'cmdname'}}};
+ $main_cmdname = $element->{'cmdname'};
+ } else {
+ # command with only one argument, the command itself is used as
+ # element for the first argument
+ @format_elements = ($element->{'cmdname'});
+ # leading spaces are directly associated to the @-command for @-command
+ # in context_brace_commands
+ push @$attribute, _leading_spaces_before_argument($element);
+ }
+
+ if ($Texinfo::Common::context_brace_commands{$element->{'cmdname'}}) {
+ push @{$self->{'document_context'}}, {'monospace' => [0]};
+ }
+ my $args_or_one_arg_cmd = '';
my $arg_index = 0;
foreach my $format_element (@format_elements) {
if (defined($element->{'args'}->[$arg_index])) {
+ # Leading spaces are gathered here except for context_brace_commands
+ # (gathered just above).
+ push @$attribute,
+ _leading_spaces_before_argument($element->{'args'}->[$arg_index]);
my $in_monospace_not_normal;
if (defined($default_args_code_style{$element->{'cmdname'}})
and
$default_args_code_style{$element->{'cmdname'}}->[$arg_index]) {
@@ -1164,31 +1184,33 @@ sub _convert($$;$)
$in_monospace_not_normal
if (defined($in_monospace_not_normal));
my $arg = $self->_convert($element->{'args'}->[$arg_index]);
+ pop @{$self->{'document_context'}->[-1]->{'monospace'}}
+ if (defined($in_monospace_not_normal));
+
if ($element->{'args'}->[$arg_index]->{'extra'}
and
$element->{'args'}->[$arg_index]->{'extra'}->{'spaces_after_argument'}) {
$arg .= $element->{'args'}->[$arg_index]
->{'extra'}->{'spaces_after_argument'};
}
- if (!$Texinfo::Common::context_brace_commands{$element->{'cmdname'}}
- and $element->{'cmdname'} ne 'verb') {
- push @$attribute,
-
_leading_spaces_before_argument($element->{'args'}->[$arg_index]);
- }
- if (!defined($command) or $arg ne '' or scalar(@$attribute) > 0) {
- # ${attribute} is only set for @verb
- push @$attribute, _leading_spaces_before_argument($element)
- if (!defined($command));
- $result .= $self->open_element($format_element, $attribute).$arg
+
+ if (!defined($main_cmdname) or $arg ne '' or scalar(@$attribute) >
0) {
+ $args_or_one_arg_cmd .=
+ $self->open_element($format_element, $attribute).$arg
.$self->close_element($format_element);
}
$attribute = [];
- pop @{$self->{'document_context'}->[-1]->{'monospace'}}
- if (defined($in_monospace_not_normal));
} else {
last;
}
$arg_index++;
}
+ if ($Texinfo::Common::context_brace_commands{$element->{'cmdname'}}) {
+ pop @{$self->{'document_context'}};
+ }
+ if (not defined($main_cmdname)) {
+ # one argument @-command
+ return $args_or_one_arg_cmd;
+ }
# This is for the main command
$attribute = [];
if ($element->{'cmdname'} eq 'image') {
@@ -1239,14 +1261,13 @@ sub _convert($$;$)
}
}
}
- if (defined($command)) {
- push @$attribute, _leading_spaces_before_argument($element);
- $result = $self->open_element($command, $attribute).$result
- .$self->close_element($command);
- }
- if ($Texinfo::Common::context_brace_commands{$element->{'cmdname'}}) {
- pop @{$self->{'document_context'}};
- }
+ # this never happens as there is no @-commands with more than one
+ # argument that is also a context_brace_commands. Leading spaces
+ # after the command brace opening are only associated with command
+ # if a context_brace_commands, therefore they are with the first
argument.
+ push @$attribute, _leading_spaces_before_argument($element);
+ return $self->open_element($main_cmdname,
$attribute).$args_or_one_arg_cmd
+ .$self->close_element($main_cmdname);
} elsif (exists($Texinfo::Common::block_commands{$element->{'cmdname'}})) {
if ($self->{'context_block_commands'}->{$element->{'cmdname'}}) {
push @{$self->{'document_context'}}, {'monospace' => [0]};
@@ -1667,9 +1688,6 @@ sub _convert($$;$)
and $element->{'parent'}->{'extra'}->{'unit_command'}
and $element->{'parent'}->{'extra'}->{'unit_command'} eq
$element)))
and $self->get_conf('USE_NODES')) {
- #if ($element->{'type'} and $element->{'type'} eq 'unit') {
- # $element = $element->{'extra'}->{'unit_command'};
- #}
$result .= $self->close_element('node');
if ($self->{'pending_bye'}) {
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 8acada1..90ea802 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -6869,8 +6869,11 @@ arguments.
=item spaces_before_argument
-For @-commands with opening brace followed by spaces held in a
+For @-commands with opening brace or comma followed by spaces held in a
C<empty_spaces_before_argument> element, a reference to those spaces.
+For context brace commands, I<spaces_before_argument> is associated
+with the @-command element, for other brace commands it is associated
+with each argument elements.
=item spaces
diff --git a/tp/t/results/coverage/table.pl b/tp/t/results/coverage/table.pl
index bb123bc..f5cf942 100644
--- a/tp/t/results/coverage/table.pl
+++ b/tp/t/results/coverage/table.pl
@@ -724,7 +724,7 @@ $result_converted{'xml'}->{'table'} = '
</beforefirstitem><tableentry><tableterm><item spaces=" "><itemformat
command="samp"><indexterm index="vr" number="1">vtable item</indexterm>vtable
item</itemformat></item>
<!-- c after item -->
<kindex index="ky" spaces=" "><indexterm index="ky"
number="1">key</indexterm></kindex>
-<itemx spaces=" "><itemformat command="samp"><indexterm index="vr"
number="2">itemx vtable</indexterm>itemx vtable <!-- comment comment in itemx
line --></itemformat></itemx>
+<itemx spaces=" "><itemformat command="samp"><indexterm index="vr"
number="2">itemx vtable</indexterm>itemx vtable </itemformat></itemx><!--
comment comment in itemx line -->
</tableterm><tableitem>
</tableitem></tableentry></vtable>
';
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Convert/TexinfoXML.pm (_convert): avoid using $result if the @-command has no contents. Make braces commands formatting code cleaner and easier to understand. Put content at end of line of @item @*table commands at the end of line, after closing the item element.,
Patrice Dumas <=