[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp Texinfo/Common.pm Texinfo/Structurin...
From: |
Patrice Dumas |
Subject: |
texinfo/tp Texinfo/Common.pm Texinfo/Structurin... |
Date: |
Sun, 04 Mar 2012 23:22:25 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 12/03/04 23:22:25
Modified files:
tp/Texinfo : Common.pm Structuring.pm
tp/t : automatic_nodes.t
Added files:
tp/t : reference_to_text_in_tree.t
Log message:
Change @*ref to one of their arguments in tree when generating nodes
from sectioning commands.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.138&r2=1.139
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.125&r2=1.126
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/automatic_nodes.t?cvsroot=texinfo&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/reference_to_text_in_tree.t?cvsroot=texinfo&rev=1.1
Patches:
Index: Texinfo/Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -b -r1.138 -r1.139
--- Texinfo/Common.pm 29 Feb 2012 21:48:10 -0000 1.138
+++ Texinfo/Common.pm 4 Mar 2012 23:22:24 -0000 1.139
@@ -1645,8 +1645,8 @@
if ($tree->{'args'}) {
my @args = @{$tree->{'args'}};
for (my $i = 0; $i <= $#args; $i++) {
- modify_tree($self, $args[$i], $operation, $argument);
my @new_args = &$operation($self, 'arg', $args[$i], $argument);
+ modify_tree($self, $args[$i], $operation, $argument);
# this puts the new args at the place of the old arg using the
# offset from the end of the array
splice (@{$tree->{'args'}}, $i - $#args -1, 1, @new_args);
@@ -1658,8 +1658,8 @@
if ($tree->{'contents'}) {
my @contents = @{$tree->{'contents'}};
for (my $i = 0; $i <= $#contents; $i++) {
- modify_tree($self, $contents[$i], $operation, $argument);
my @new_contents = &$operation($self, 'content', $contents[$i],
$argument);
+ modify_tree($self, $contents[$i], $operation, $argument);
# this puts the new contents at the place of the old content using the
# offset from the end of the array
splice (@{$tree->{'contents'}}, $i - $#contents -1, 1, @new_contents);
Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -b -r1.125 -r1.126
--- Texinfo/Structuring.pm 29 Feb 2012 21:48:10 -0000 1.125
+++ Texinfo/Structuring.pm 4 Mar 2012 23:22:24 -0000 1.126
@@ -1250,6 +1250,49 @@
}
}
+sub _reference_to_text($$$)
+{
+ my $self = shift;
+ my $type = shift;
+ my $current = shift;
+
+ if ($current->{'cmdname'} and
+ $Texinfo::Common::ref_commands{$current->{'cmdname'}}
+ and $current->{'extra'}
+ and $current->{'extra'}->{'brace_command_contents'}) {
+ my @args_try_order;
+ if ($current->{'cmdname'} eq 'inforef') {
+ @args_try_order = (0, 1, 2);
+ } else {
+ @args_try_order = (0, 1, 2, 4, 3);
+ }
+ foreach my $index (@args_try_order) {
+ if (defined($current->{'args'}->[$index])
+ and
defined($current->{'extra'}->{'brace_command_contents'}->[$index])) {
+ # This a double checking that there is some content.
+ # Not sure that it is useful.
+ my $text =
Texinfo::Convert::Text::convert($current->{'args'}->[$index]);
+ if (defined($text) and $text =~ /\S/) {
+ my $result = {'contents' =>
+ $current->{'extra'}->{'brace_command_contents'}->[$index],
+ 'parent' => $current->{'parent'}};
+ return ($result);
+ }
+ }
+ }
+ return {'text' => '', 'parent' => $current->{'parent'}};
+ } else {
+ return ($current);
+ }
+}
+
+sub reference_to_text_in_tree($$)
+{
+ my $self = shift;
+ my $tree = shift;
+ return Texinfo::Common::modify_tree($self, $tree, \&_reference_to_text);
+}
+
# prepare a new node and register it
sub _new_node($$)
{
@@ -1259,6 +1302,7 @@
$node_tree = Texinfo::Common::protect_comma_in_tree($node_tree);
$node_tree->{'contents'}
= Texinfo::Common::protect_first_parenthesis($node_tree->{'contents'});
+ $node_tree = reference_to_text_in_tree($self, $node_tree);
return undef if (!$node_tree->{'contents'}
or !scalar(@{$node_tree->{'contents'}}));
Index: t/automatic_nodes.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/automatic_nodes.t,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- t/automatic_nodes.t 26 Feb 2012 15:44:31 -0000 1.6
+++ t/automatic_nodes.t 4 Mar 2012 23:22:24 -0000 1.7
@@ -1,7 +1,7 @@
use strict;
use Test::More;
-BEGIN { plan tests => 18 };
+BEGIN { plan tests => 21 };
use lib 'maintain/lib/Unicode-EastAsianWidth/lib/';
use lib 'maintain/lib/libintl-perl/lib/';
@@ -48,6 +48,11 @@
test_new_node ('(in paren(too aaa', '_0028in-paren_0028too-aaa',
'@node @asis{(}in paren(too aaa
', 'with parenthesis');
+test_new_node ('changed @ref{ @code{node}} and (@pxref{ ,, , @samp{file}})',
+'changed-node-and-_0028file_0029',
+'@node changed @code{node} and (@samp{file})
+',
+'ref in new node');
my $parser = Texinfo::Parser::parser();
my $tree = $parser->parse_texi_text('@node a node
Index: t/reference_to_text_in_tree.t
===================================================================
RCS file: t/reference_to_text_in_tree.t
diff -N t/reference_to_text_in_tree.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/reference_to_text_in_tree.t 4 Mar 2012 23:22:24 -0000 1.1
@@ -0,0 +1,36 @@
+use strict;
+
+use Test::More;
+BEGIN { plan tests => 2 };
+
+use lib 'maintain/lib/Unicode-EastAsianWidth/lib/';
+use lib 'maintain/lib/libintl-perl/lib/';
+use lib 'maintain/lib/Text-Unidecode/lib/';
+use Texinfo::Parser qw(parse_texi_text);
+use Texinfo::Structuring;
+use Texinfo::Convert::Texinfo;
+
+ok(1);
+
+sub run_test($$$)
+{
+ my $in = shift;
+ my $out = shift;
+ my $name = shift;
+
+ my $parser = Texinfo::Parser::parser();
+ my $tree = parse_texi_text($parser, $in);
+
+ my $corrected_tree
+ = Texinfo::Structuring::reference_to_text_in_tree($parser, $tree);
+ my $texi_result = Texinfo::Convert::Texinfo::convert($corrected_tree);
+
+ if (!defined($out)) {
+ print STDERR " --> $name:\n$texi_result";
+ } else {
+ is ($texi_result, $out, $name);
+ }
+}
+
+run_test('AA @ref{a, b, c, d, e} (@pxref{,,, @code{trc}})',
+'AA a (@code{trc})', 'simple test');
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp Texinfo/Common.pm Texinfo/Structurin...,
Patrice Dumas <=