[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[5551] * tp/Texinfo/Common.pm(is_content_empty),
From: |
Patrice Dumas |
Subject: |
[5551] * tp/Texinfo/Common.pm(is_content_empty), |
Date: |
Sat, 10 May 2014 23:50:26 +0000 |
Revision: 5551
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5551
Author: pertusus
Date: 2014-05-10 23:50:25 +0000 (Sat, 10 May 2014)
Log Message:
-----------
* tp/Texinfo/Common.pm(is_content_empty),
tp/t/test_is_content_empty.t: check if a tree item contains non empty
content.
Modified Paths:
--------------
trunk/ChangeLog
trunk/tp/Texinfo/Common.pm
trunk/tp/Texinfo/Convert/DocBook.pm
trunk/tp/Texinfo/Convert/Text.pm
trunk/tp/t/test_fill_gaps_in_sectioning.t
Added Paths:
-----------
trunk/tp/t/test_is_content_empty.t
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2014-05-10 23:42:26 UTC (rev 5550)
+++ trunk/ChangeLog 2014-05-10 23:50:25 UTC (rev 5551)
@@ -3,6 +3,9 @@
* tp/t/test_utils.pl(test): use SKIP and not TODO, as TODO is
assumed to fail, while there is an unknown output since different
perl verions treat NEL differently.
+ * tp/Texinfo/Common.pm(is_content_empty),
+ tp/t/test_is_content_empty.t: check if a tree item contains non empty
+ content.
2014-05-10 Gavin Smith <address@hidden>
Modified: trunk/tp/Texinfo/Common.pm
===================================================================
--- trunk/tp/Texinfo/Common.pm 2014-05-10 23:42:26 UTC (rev 5550)
+++ trunk/tp/Texinfo/Common.pm 2014-05-10 23:50:25 UTC (rev 5551)
@@ -672,6 +672,14 @@
$in_heading_commands{$in_heading_command} = 1;
}
+# brace command that is not replaced with text.
+my %unformatted_brace_commands;
+foreach my $unformatted_brace_command ('anchor', 'shortcaption',
+ 'caption', 'hyphenation', 'errormsg') {
+ $unformatted_brace_commands{$unformatted_brace_command} = 1;
+}
+
+
# commands delimiting blocks, with an @end.
# Value is either the number of arguments on the line separated by
# commas or the type of command, 'raw', 'def' or 'multitable'.
@@ -867,6 +875,12 @@
'quote-arg' => N__('arguments are quoted by default'),
);
+my %unformatted_block_commands;
+foreach my $unformatted_block_command ('ignore', 'macro', 'rmacro') {
+ $unformatted_block_commands{$unformatted_block_command} = 1;
+}
+
+
# commands that should only appear at the root level and contain up to
# the next root command. @node and sectioning commands.
our %root_commands;
@@ -937,6 +951,18 @@
$sectioning_commands{$sectioning_command} = 1;
}
+# misc commands that may be formatted as text.
+# index commands may be too, but index command may be added with
+# @def*index so they are not added here.
+my %formatted_misc_commands;
+foreach my $formatted_misc_command ('insertcopying', 'contents',
+ 'shortcontents', 'summarycontents', 'center', 'printindex',
+ 'listoffloats', 'shorttitlepage', 'settitle',
+ 'author', 'subtitle', 'title', 'sp', 'exdent', 'headitem', 'item',
+ 'itemx', 'tab', 'node', keys(%sectioning_commands)) {
+ $formatted_misc_commands{$formatted_misc_command} = 1;
+}
+
$root_commands{'node'} = 1;
our %all_commands;
@@ -1126,9 +1152,11 @@
{'type' => 'raw', 'text' => $_ };
}
if (!close (VERBINCLUDE)) {
- $self->document_warn(sprintf($self->__(
+ if ($self) {
+ $self->document_warn(sprintf($self->__(
"error on closing address@hidden file %s: %s"),
$file, $!));
+ }
}
}
} elsif ($self) {
@@ -1412,6 +1440,52 @@
return $result;
}
+sub is_content_empty($;$);
+sub is_content_empty($;$)
+{
+ my $tree = shift;
+ my $do_not_ignore_index_entries = shift;
+ if (!defined($tree) or !exists($tree->{'contents'})) {
+ return 1;
+ }
+ foreach my $content (@{$tree->{'contents'}}) {
+ #print STDERR _print_current($content);
+ if ($content->{'cmdname'}) {
+ if ($content->{'type'} and $content->{'type'} eq 'index_entry_command') {
+ if ($do_not_ignore_index_entries) {
+ return 0;
+ } else {
+ next;
+ }
+ }
+ if (exists($misc_commands{$content->{'cmdname'}})) {
+ my @truc = keys(%formatted_misc_commands);
+ if ($formatted_misc_commands{$content->{'cmdname'}}) {
+ return 0;
+ } else {
+ next;
+ }
+ } elsif ($unformatted_brace_commands{$content->{'cmdname'}}
+ or $unformatted_block_commands{$content->{'cmdname'}}) {
+ next;
+ } else {
+ return 0;
+ }
+ }
+ if ($content->{'type'}) {
+ if ($content->{'type'} eq 'paragraph') {
+ return 0;
+ }
+ }
+ if ($content->{'text'} and $content->{'text'} =~ /\S/) {
+ return 0;
+ }
+ if (not is_content_empty($content, $do_not_ignore_index_entries)) {
+ return 0;
+ }
+ }
+ return 1;
+}
our %htmlxref_entries = (
'node' => [ 'node', 'section', 'chapter', 'mono' ],
Modified: trunk/tp/Texinfo/Convert/DocBook.pm
===================================================================
--- trunk/tp/Texinfo/Convert/DocBook.pm 2014-05-10 23:42:26 UTC (rev 5550)
+++ trunk/tp/Texinfo/Convert/DocBook.pm 2014-05-10 23:50:25 UTC (rev 5551)
@@ -656,6 +656,7 @@
$result .= "\n";
return $result;
}
+ # misc commands not handled especially are ignored here.
return '';
}
} elsif ($type eq 'skipline' or $type eq 'noarg') {
Modified: trunk/tp/Texinfo/Convert/Text.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Text.pm 2014-05-10 23:42:26 UTC (rev 5550)
+++ trunk/tp/Texinfo/Convert/Text.pm 2014-05-10 23:50:25 UTC (rev 5551)
@@ -508,11 +508,11 @@
} elsif ($root->{'cmdname'} ne 'node') {
$result = _convert($root->{'args'}->[0], $options);
if ($Texinfo::Common::sectioning_commands{$root->{'cmdname'}}) {
- $result = heading ($root, $result, $options->{'converter'},
- $options->{'NUMBER_SECTIONS'});
+ $result = heading($root, $result, $options->{'converter'},
+ $options->{'NUMBER_SECTIONS'});
} else {
# we always want an end of line even if is was eaten by a command
- chomp ($result);
+ chomp($result);
$result .= "\n";
}
}
Modified: trunk/tp/t/test_fill_gaps_in_sectioning.t
===================================================================
--- trunk/tp/t/test_fill_gaps_in_sectioning.t 2014-05-10 23:42:26 UTC (rev
5550)
+++ trunk/tp/t/test_fill_gaps_in_sectioning.t 2014-05-10 23:50:25 UTC (rev
5551)
@@ -64,7 +64,7 @@
if (!defined($out)) {
print STDERR " --> $name:\n$texi_result";
} else {
- is ($texi_result, $out, $name);
+ is($texi_result, $out, $name);
}
}
test_correction('@chapter chap
Added: trunk/tp/t/test_is_content_empty.t
===================================================================
--- trunk/tp/t/test_is_content_empty.t (rev 0)
+++ trunk/tp/t/test_is_content_empty.t 2014-05-10 23:50:25 UTC (rev 5551)
@@ -0,0 +1,64 @@
+use strict;
+
+use Test::More;
+use File::Spec;
+BEGIN { #plan tests => 10;
+ if (defined($ENV{'top_srcdir'})) {
+ unshift @INC, File::Spec->catdir($ENV{'top_srcdir'}, 'tp');
+ my $lib_dir = File::Spec->catdir($ENV{'top_srcdir'}, 'tp',
'maintain');
+ unshift @INC, (File::Spec->catdir($lib_dir, 'lib', 'libintl-perl',
'lib'),
+ File::Spec->catdir($lib_dir, 'lib',
'Unicode-EastAsianWidth', 'lib'),
+ File::Spec->catdir($lib_dir, 'lib', 'Text-Unidecode',
'lib'));
+ }};
+
+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::Convert::Texinfo;
+use Texinfo::Common;
+use Data::Dumper;
+
+ok(1, "modules loading");
+
+sub test_is_empty($$$;$)
+{
+ my $name = shift;
+ my $is_empty = shift;
+ my $in = shift;
+ my $do_not_ignore_index_entries = shift;
+ my $tree = parse_texi_text(undef, $in);
+ my $result = Texinfo::Common::is_content_empty($tree,
$do_not_ignore_index_entries);
+ if (not defined($is_empty)) {
+ print STDERR " --> $name: $result\n";
+ } else {
+ is($result, $is_empty, $name);
+ }
+}
+
+test_is_empty('empty', 1, '');
+test_is_empty('spaces', 1, ' ');
+test_is_empty('lines', 1, '
+
+
+ ');
+test_is_empty('text', 0, 'truc'."\n");
+test_is_empty('heading', 0, '@heading truc'."\n");
+test_is_empty('index ignored', 1, '@cindex index'."\n");
+test_is_empty('index not ignored', 0, '@cindex index'."\n", 1);
+test_is_empty('ignored misc', 1, '@defindex idx'."\n");
+test_is_empty('ignored misc then text', 0, '@alias lang=lisp
+
address@hidden
+');
+test_is_empty('@ignore', 1, '@ignore
+truc
+
address@hidden ignore
+');
+test_is_empty('block command', 0, '@itemize @bullet
address@hidden truc
address@hidden itemize
+');
+
+done_testing();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [5551] * tp/Texinfo/Common.pm(is_content_empty),,
Patrice Dumas <=