[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp/Texinfo/Convert Plaintext.pm
From: |
Patrice Dumas |
Subject: |
texinfo/tp/Texinfo/Convert Plaintext.pm |
Date: |
Sat, 20 Nov 2010 16:44:30 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/11/20 16:44:30
Modified files:
tp/Texinfo/Convert: Plaintext.pm
Log message:
Handle better preformatted and indented block commands.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.4&r2=1.5
Patches:
Index: Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- Plaintext.pm 20 Nov 2010 11:53:40 -0000 1.4
+++ Plaintext.pm 20 Nov 2010 16:44:30 -0000 1.5
@@ -82,6 +82,7 @@
my %block_commands = %Texinfo::Common::block_commands;
my %menu_commands = %Texinfo::Common::menu_commands;
my %root_commands = %Texinfo::Common::root_commands;
+my %preformatted_commands = %Texinfo::Common::preformatted_commands;
foreach my $def_command (keys(%def_commands)) {
$kept_misc_commands{$def_command} = 1 if ($misc_commands{$def_command});
@@ -99,6 +100,27 @@
$ignored_commands{$ignored_brace_commands} = 1;
}
+my %item_indent_format_length = ('enumerate' => 2,
+ 'itemize' => 3,
+ 'table' => 0,
+ 'vtable' => 0,
+ 'ftable' => 0,
+ );
+
+my $indent_length = 5;
+
+my %indented_commands;
+foreach my $indented_command (keys (%item_indent_format_length),
+ keys (%preformatted_commands), 'quotation', 'smallquotation',
+ keys(%def_commands)) {
+ $indented_commands{$indented_command} = 1
+ if exists($block_commands{$indented_command});
+}
+
+foreach my $non_indented('format', 'smallformat') {
+ delete $indented_commands{$non_indented};
+}
+
# commands that leads to advancing the paragraph number. This is mostly
#used to determine the first line, in fact.
my %advance_paragraph_count_commands;
@@ -233,7 +255,9 @@
};
$converter->{'context'} = ['_Root_context'];
$converter->{'containers'} = [];
- $converter->{'format_context'} = [{'paragraph_count' => 0}];
+ $converter->{'format_context'} = [{'cmdname' => '_top_format',
+ 'paragraph_count' => 0,
+ 'indent_level' => 0}];
return $converter;
}
@@ -371,6 +395,7 @@
# and with paragraphs.
# preformatted
+
sub convert($$);
sub convert($$)
@@ -383,7 +408,8 @@
$container_context = $self->{'containers'}->[-1];
}
if ($self->{'debug'}) {
- print STDERR "ROOT (@{$self->{'context'}})";
+ print STDERR "ROOT (@{$self->{'context'}}|@{$self->{'format_context'}})";
+ print STDERR " format_context:
$self->{'format_context'}->[-1]->{'cmdname'},
$self->{'format_context'}->[-1]->{'paragraph_count'},
$self->{'format_context'}->[-1]->{'indent_level'}\n";
print STDERR " cmd: $root->{'cmdname'}," if ($root->{'cmdname'});
print STDERR " type: $root->{'type'}" if ($root->{'type'});
print STDERR "\n";
@@ -391,7 +417,7 @@
#print STDERR " Special def_command: $root->{'extra'}->{'def_command'}\n"
# if (defined($root->{'extra'}) and $root->{'extra'}->{'def_command'});
if ($container_context) {
- print STDERR "
Container:($container_context->{'code'},$container_context->{'upper_case'},$container_context->{'preformatted'})";
+ print STDERR "
Container:($container_context->{'code'},$container_context->{'upper_case'},$container_context->{'preformatted'})
";
$container_context->{'container'}->dump();
}
}
@@ -444,6 +470,7 @@
warn "BUG: ignored text not empty `$root->{'text'}'\n";
}
}
+ my $preformatted;
if ($root->{'cmdname'}) {
my $unknown_command;
my $command = $root->{'cmdname'};
@@ -536,6 +563,19 @@
# cartouche
# flushleft and flushright -> keep track of result and add space
# at the end. do something specific here or at the end?
+
+ if ($indented_commands{$root->{'cmdname'}}) {
+ push @{$self->{'format_context'}}, {'cmdname' => $root->{'cmdname'},
+ 'paragraph_count' => 0,
+ 'indent_level' =>
+ $self->{'format_context'}->[-1]->{'indent_level'} + 1 };
+ }
+ if ($preformatted_commands{$root->{'cmdname'}} or
$menu_commands{$root->{'cmdname'}}) {
+ push @{$self->{'context'}}, 'preformatted';
+ $preformatted = Texinfo::Convert::UnFilled->new({
+ 'indent_length' =>
$indent_length*$self->{'format_context'}->[-1]->{'indent_level'} });
+ push @{$self->{'containers'}}, {'container' => $preformatted};
+ }
if ($root->{'cmdname'} eq 'quotation'
or $root->{'cmdname'} eq 'smallquotation') {
if ($root->{'extra'} and
$root->{'extra'}->{'block_command_line_contents'}) {
@@ -713,6 +753,13 @@
$result .= $paragraph->end();
pop @{$self->{'containers'}};
}
+ if ($preformatted) {
+ $result .= $preformatted->end();
+ pop @{$self->{'containers'}};
+ pop @{$self->{'context'}};
+ }
+ pop @{$self->{'format_context'}}
+ if ($indented_commands{$root->{'cmdname'}});
return $result;
}
- texinfo/tp/Texinfo/Convert Plaintext.pm,
Patrice Dumas <=