[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp MANIFEST TODO Texinfo/Structuring.pm...
From: |
Patrice Dumas |
Subject: |
texinfo/tp MANIFEST TODO Texinfo/Structuring.pm... |
Date: |
Wed, 01 Feb 2012 00:41:11 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 12/02/01 00:41:11
Modified files:
tp : MANIFEST TODO
tp/Texinfo : Structuring.pm
Added files:
tp/t : test_fill_gaps_in_sectioning.t
Log message:
Add a function that adds empty @unnumbered* to fill gaps in sectioning,
to
be used, for example, when converting from a format that can handle
gaps in sectioning.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/MANIFEST?cvsroot=texinfo&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/TODO?cvsroot=texinfo&r1=1.258&r2=1.259
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.110&r2=1.111
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/test_fill_gaps_in_sectioning.t?cvsroot=texinfo&rev=1.1
Patches:
Index: MANIFEST
===================================================================
RCS file: /sources/texinfo/texinfo/tp/MANIFEST,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- MANIFEST 29 Jan 2012 22:16:07 -0000 1.28
+++ MANIFEST 1 Feb 2012 00:41:09 -0000 1.29
@@ -1128,6 +1128,7 @@
t/results/xtable/text_between_item_itemx.pl
t/results/xtable/title_and_itemx_before_item.pl
t/test_count.t
+t/test_fill_gaps_in_sectioning.t
t/test_sort.t
t/test_tree_copy.t
t/test_utils.pl
Index: TODO
===================================================================
RCS file: /sources/texinfo/texinfo/tp/TODO,v
retrieving revision 1.258
retrieving revision 1.259
diff -u -b -r1.258 -r1.259
--- TODO 29 Jan 2012 22:16:07 -0000 1.258
+++ TODO 1 Feb 2012 00:41:10 -0000 1.259
@@ -7,6 +7,12 @@
Document TEXTCONTENT_COMMENT.
+pod2texi: remove ( ) that makes a node an external node. remove :: in node
+to avoid confusing @ref in info.
+
+New command to modify/transform a texinfo manual, for now to fix
+a tree by adding empty unnumbered commands.
+
Bugs
====
Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -b -r1.110 -r1.111
--- Texinfo/Structuring.pm 26 Jan 2012 00:17:31 -0000 1.110
+++ Texinfo/Structuring.pm 1 Feb 2012 00:41:10 -0000 1.111
@@ -148,9 +148,28 @@
$unnumbered_commands{'centerchap'} = 1;
$unnumbered_commands{'part'} = 1;
-my $min_level = $command_structuring_level{'top'};
+my $min_level = $command_structuring_level{'chapter'};
my $max_level = $command_structuring_level{'subsubsection'};
+sub _section_level ($)
+{
+ my $section = shift;
+ my $level = $command_structuring_level{$section->{'cmdname'}};
+ # correct level according to raise/lowersections
+ if ($section->{'extra'} and $section->{'extra'}->{'sections_level'}) {
+ $level -= $section->{'extra'}->{'sections_level'};
+ if ($level < $min_level) {
+ if ($command_structuring_level{$section->{'cmdname'}} < $min_level) {
+ $level = $command_structuring_level{$section->{'cmdname'}};
+ } else {
+ $level = $min_level;
+ }
+ } elsif ($level > $max_level) {
+ $level = $max_level;
+ }
+ }
+ return $level;
+}
# sets:
# 'level'
# 'number'
@@ -199,16 +218,7 @@
$section_top = $content;
}
}
- my $level = $command_structuring_level{$content->{'cmdname'}};
- # correct level according to raise/lowersections
- if ($content->{'extra'} and $content->{'extra'}->{'sections_level'}) {
- $level -= $content->{'extra'}->{'sections_level'};
- if ($level < $min_level) {
- $level = $min_level;
- } elsif ($level > $max_level) {
- $level = $max_level;
- }
- }
+ my $level = _section_level($content);
$content->{'level'} = $level;
if ($previous_section) {
@@ -348,6 +358,111 @@
return $sec_root;
}
+
+# Add raise/lowersections to be back at the normal level
+sub _correct_level ($$;$)
+{
+ my $section = shift;
+ my $parent = shift;
+ my $modifier = shift;
+ $modifier = 1 if (!defined($modifier));
+
+ my @result;
+ if ($section->{'extra'} and $section->{'extra'}->{'sections_level'}) {
+ my $level_to_remove = $modifier * $section->{'extra'}->{'sections_level'};
+ my $command;
+ if ($level_to_remove < 0) {
+ $command = 'raisesection';
+ } else {
+ $command = 'lowersection';
+ }
+ my $remaining_level = abs($level_to_remove);
+ while ($remaining_level) {
+ push @result, {'cmdname' => $command,
+ 'parent' => $parent};
+ push @result, {'type' => 'empty_line', 'text' => "\n",
+ 'parent' => $parent};
+ $remaining_level--;
+ }
+ }
+ return @result;
+}
+
+sub fill_gaps_in_sectioning($)
+{
+ my $root = shift;
+ if (!$root->{'type'} or $root->{'type'} ne 'document_root'
+ or !$root->{'contents'}) {
+ return undef;
+ }
+ my @sections_list;
+ foreach my $content (@{$root->{'contents'}}) {
+ if ($content->{'cmdname'} and $content->{'cmdname'} ne 'node'
+ and $content->{'cmdname'} ne 'bye') {
+ push @sections_list, $content;
+ }
+ }
+
+ return undef if (!scalar(@sections_list));
+
+ my @contents;
+ my $previous_section;
+ foreach my $content(@{$root->{'contents'}}) {
+ push @contents, $content;
+ if (address@hidden or $sections_list[0] ne $content) {
+ next;
+ }
+ my $current_section = shift @sections_list;
+ my $current_section_level = _section_level($current_section);
+ my $next_section = $sections_list[0];
+
+ if (defined($next_section)) {
+ my $next_section_level = _section_level($next_section);
+ if ($next_section_level - $current_section_level > 1) {
+ my @correct_level_offset_commands = _correct_level($next_section,
+ $contents[-1]);
+ if (@correct_level_offset_commands) {
+ push @{$contents[-1]->{'contents'}}, @correct_level_offset_commands;
+ }
+ while ($next_section_level - $current_section_level > 1) {
+ $current_section_level++;
+ my $new_section = {'cmdname' =>
+
$Texinfo::Common::level_to_structuring_command{'unnumbered'}->[$current_section_level],
+ 'contents' => [],
+ 'parent' => $root,
+ };
+ $new_section->{'args'} = [{'type' => 'misc_line_arg',
+ 'parent' => $new_section}];
+ $new_section->{'args'}->[0]->{'contents'} = [
+ {'type' => 'empty_spaces_after_command',
+ 'text' => " ",
+ 'extra' => {'command' => $new_section},
+ 'parent' => $new_section->{'args'}->[0]
+ },
+ {'cmdname' => 'asis',
+ 'parent' => $new_section->{'args'}->[0]
+ },
+ {'type' => 'spaces_at_end',
+ 'text' => "\n",
+ 'parent' => $new_section->{'args'}->[0]
+ }];
+ $new_section->{'args'}->[0]->{'contents'}->[1]->{'args'}
+ = [{'type' => 'brace_command_arg',
+ 'contents' => [],
+ 'parent' => $new_section->{'args'}->[0]->{'contents'}->[1]}];
+ push @contents, $new_section;
+ }
+ my @set_level_offset_commands = _correct_level($next_section,
+ $contents[-1], -1);
+ if (@set_level_offset_commands) {
+ push @{$contents[-1]->{'contents'}}, @set_level_offset_commands;
+ }
+ }
+ }
+ }
+ return address@hidden;
+}
+
my @node_directions = ('next', 'prev', 'up');
# No translation of those special Info keywords.
my %direction_texts = (
Index: t/test_fill_gaps_in_sectioning.t
===================================================================
RCS file: t/test_fill_gaps_in_sectioning.t
diff -N t/test_fill_gaps_in_sectioning.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/test_fill_gaps_in_sectioning.t 1 Feb 2012 00:41:10 -0000 1.1
@@ -0,0 +1,95 @@
+use strict;
+
+use Test::More;
+BEGIN { plan tests => 8 };
+
+use lib 'maintain/lib/Unicode-EastAsianWidth/lib/';
+use lib 'maintain/lib/libintl-perl/lib/';
+use lib 'maintain/lib/Text-Unidecode/lib/';
+use Texinfo::Structuring;
+use Texinfo::Parser qw(parse_texi_text);
+use Texinfo::Convert::Texinfo;
+
+ok(1, "modules loading");
+
+my $tree = parse_texi_text(undef, '@raisesections
address@hidden truc
+');
+
+my $section = $tree->{'contents'}->[1];
+my @correct_level_offset_commands
+ = Texinfo::Structuring::_correct_level($section, $tree->{'contents'}->[0]);
+
+# 2 because there is also an empty line
+ok (scalar(@correct_level_offset_commands) == 2,"one lowersection");
+ok ($correct_level_offset_commands[0]->{'cmdname'} eq 'lowersection' ,
+ "command is lowersection");
+
+$tree = parse_texi_text(undef, '@lowersections
address@hidden
address@hidden truc
+');
+$section = $tree->{'contents'}->[1];
address@hidden
+ = Texinfo::Structuring::_correct_level($section, $tree->{'contents'}->[0],
-1);
+ok (scalar(@correct_level_offset_commands) == 4,"two lowersection");
+ok ($correct_level_offset_commands[0]->{'cmdname'} eq 'lowersection' ,
+ "command is lowersection");
+
+sub test_correction($$$)
+{
+ my $in = shift;
+ my $out = shift;
+ my $name = shift;
+ my $tree = parse_texi_text(undef, $in);
+ my $corrected_content = Texinfo::Structuring::fill_gaps_in_sectioning($tree);
+ $tree->{'contents'} = $corrected_content;
+ {
+ local $Data::Dumper::Purity = 1;
+ #local $Data::Dumper::Maxdepth = 2;
+ local $Data::Dumper::Indent = 1;
+ #print STDERR Data::Dumper->Dump([$tree]);
+ #print STDERR Data::Dumper->Dump([$corrected_content]);
+ }
+ my $texi_result = Texinfo::Convert::Texinfo::convert({'contents' =>
$corrected_content});
+ if (!defined($out)) {
+ print STDERR " --> $name:\n$texi_result";
+ } else {
+ is ($texi_result, $out, $name);
+ }
+}
+test_correction('@chapter chap
address@hidden sub
+','@chapter chap
address@hidden @asis{}
address@hidden sub
+', 'simple completed tree');
+
+my $raisesections_lowersection_no_correction_text = '@raisesections
address@hidden sec
address@hidden
address@hidden
address@hidden chap
+';
+test_correction($raisesections_lowersection_no_correction_text,
+ $raisesections_lowersection_no_correction_text,
+ 'raisesections and lowersection, no correction');
+
+test_correction('@raisesections
address@hidden sec
address@hidden
address@hidden
address@hidden
address@hidden chap
+', '@raisesections
address@hidden sec
address@hidden
address@hidden
address@hidden
address@hidden
address@hidden
address@hidden @asis{}
address@hidden
address@hidden
address@hidden chap
+', 'raisesections lowersection with correction');
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp MANIFEST TODO Texinfo/Structuring.pm...,
Patrice Dumas <=