[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp/Texinfo Common.pm Parser.pm Convert/...
From: |
Patrice Dumas |
Subject: |
texinfo/tp/Texinfo Common.pm Parser.pm Convert/... |
Date: |
Mon, 15 Nov 2010 00:22:37 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/11/15 00:22:37
Modified files:
tp/Texinfo : Common.pm Parser.pm
tp/Texinfo/Convert: Plaintext.pm Unicode.pm
Added files:
tp/Texinfo/Convert: UnFilled.pm
Log message:
Advance plaintext converter.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.149&r2=1.150
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Unicode.pm?cvsroot=texinfo&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/UnFilled.pm?cvsroot=texinfo&rev=1.1
Patches:
Index: Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Common.pm 13 Nov 2010 19:58:28 -0000 1.1
+++ Common.pm 15 Nov 2010 00:22:36 -0000 1.2
@@ -264,9 +264,32 @@
'deftypemethod', {'deftypeop' => 'Method'},
);
+# the type of index, f: function, v: variable, t: type
+my %index_type_def = (
+ 'f' => ['deffn', 'deftypefn', 'deftypeop', 'defop'],
+ 'v' => ['defvr', 'deftypevr', 'defcv', 'deftypecv' ],
+ 't' => ['deftp']
+);
+
+our %command_index_prefix;
+
+$command_index_prefix{'vtable'} = 'v';
+$command_index_prefix{'ftable'} = 'f';
+
+foreach my $index_type (keys %index_type_def) {
+ foreach my $def (@{$index_type_def{$index_type}}) {
+ $command_index_prefix{$def} = $index_type;
+ }
+}
+
our %def_commands;
our %def_aliases;
foreach my $def_command(keys %def_map) {
+ if (ref($def_map{$def_command}) eq 'HASH') {
+ my ($real_command) = keys (%{$def_map{$def_command}});
+ $command_index_prefix{$def_command} = $command_index_prefix{$real_command};
+ $def_aliases{$def_command} = $real_command;
+ }
$block_commands{$def_command} = 'def';
$misc_commands{$def_command.'x'} = 'line';
$def_commands{$def_command} = 1;
Index: Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -b -r1.149 -r1.150
--- Parser.pm 13 Nov 2010 19:58:28 -0000 1.149
+++ Parser.pm 15 Nov 2010 00:22:36 -0000 1.150
@@ -194,30 +194,15 @@
my %deprecated_commands = %Texinfo::Common::deprecated_commands;
my %root_commands = %Texinfo::Common::root_commands;
my @out_formats = @Texinfo::Common::out_formats;
+my %command_index_prefix = %Texinfo::Common::command_index_prefix;
-# the type of index, f: function, v: variable, t: type
-my %index_type_def = (
- 'f' => ['deffn', 'deftypefn', 'deftypeop', 'defop'],
- 'v' => ['defvr', 'deftypevr', 'defcv', 'deftypecv' ],
- 't' => ['deftp']
-);
-
-my %command_index_prefix;
-foreach my $index_type (keys %index_type_def) {
- foreach my $def (@{$index_type_def{$index_type}}) {
- $command_index_prefix{$def} = $index_type;
- }
-}
-
my %def_prepended_content;
foreach my $def_command(keys %def_map) {
# prepare what will be prepended when the def command is an alias
if (ref($def_map{$def_command}) eq 'HASH') {
my ($real_command) = keys (%{$def_map{$def_command}});
- $command_index_prefix{$def_command} = $command_index_prefix{$real_command};
- $def_aliases{$def_command} = $real_command;
my $prepended = $def_map{$def_command}->{$real_command};
if ($prepended =~ /^\{/) {
my $text = $prepended;
@@ -233,9 +218,6 @@
}
}
-$command_index_prefix{'vtable'} = 'v';
-$command_index_prefix{'ftable'} = 'f';
-
my %type_with_paragraph;
foreach my $type ('before_item', 'text_root', 'document_root',
Index: Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Convert/Plaintext.pm 13 Nov 2010 19:58:28 -0000 1.2
+++ Convert/Plaintext.pm 15 Nov 2010 00:22:36 -0000 1.3
@@ -27,6 +27,9 @@
use Texinfo::Convert::Text;
use Texinfo::Convert::Paragraph;
use Texinfo::Convert::Line;
+use Texinfo::Convert::UnFilled;
+
+use Carp qw(cluck);
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@@ -69,6 +72,14 @@
my %accent_commands = %Texinfo::Common::accent_commands;
my %misc_commands = %Texinfo::Common::misc_commands;
my %sectioning_commands = %Texinfo::Common::sectioning_commands;
+my %def_commands = %Texinfo::Common::def_commands;
+my %block_commands = %Texinfo::Common::block_commands;
+my %menu_commands = %Texinfo::Common::menu_commands;
+my %root_commands = %Texinfo::Common::root_commands;
+
+foreach my $def_command (keys(%def_commands)) {
+ $kept_misc_commands{$def_command} = 1 if ($misc_commands{$def_command});
+}
my %ignored_misc_commands;
foreach my $misc_command (keys(%misc_commands)) {
@@ -82,6 +93,24 @@
$ignored_commands{$ignored_brace_commands} = 1;
}
+# commands that leads to advancing the paragraph number. This is mostly
+#used to determine the first line, in fact.
+my %advance_paragraph_count_commands;
+foreach my $command (keys(%block_commands)) {
+ next if ($menu_commands{$command}
+ or $block_commands{$command} eq 'raw');
+ $advance_paragraph_count_commands{$command} = 1;
+}
+
+foreach my $not_advancing_para ('group', 'raggedright',
+ 'titlepage', 'copying', 'documentdescription') {
+ delete $advance_paragraph_count_commands{$not_advancing_para};
+}
+
+foreach my $advancing_para('center', 'verbatim', 'listoffloats') {
+ $advance_paragraph_count_commands{$advancing_para} = 1;
+}
+
# FIXME pass raw formats handled (or not handled)
foreach my $ignored_block_commands ('ignore', 'macro', 'rmacro') {
$ignored_commands{$ignored_block_commands} = 1;
@@ -93,6 +122,11 @@
$code_style_commands{$command} = 1;
}
+my %upper_case_commands = (
+ 'sc' => 1,
+ 'var' => 1
+);
+
my %ignored_types;
foreach my $type ('empty_line_after_command',
'empty_spaces_after_command', 'spaces_at_end',
@@ -190,6 +224,7 @@
};
$converter->{'context'} = ['_Root_context'];
$converter->{'containers'} = [];
+ $converter->{'format_context'} = [{'paragraph_count' => 0}];
return $converter;
}
@@ -203,39 +238,129 @@
return $text;
}
-sub process_text($$)
+sub process_text($$$)
{
my $self = shift;
my $command = shift;
+ my $context = shift;
my $text = $command->{'text'};
$text = uc($text) if ($self->{'upper_case'});
- if ($self->{'enable_encoding'} and $self->{'document_encoding'} eq 'utf-8') {
+ if ($self->{'enable_encoding'} and $self->{'documentencoding'} eq 'utf-8') {
return Texinfo::Convert::Unicode($self, $command);
- } elsif (!$self->{'code'} and !$self->{'context'}->[-1] eq 'preformatted') {
+ } elsif (!$context->{'code'} and !$context->{'preformatted'}) {
$text =~ s/---/\x{1F}/g;
$text =~ s/--/-/g;
$text =~ s/\x{1F}/--/g;
$text =~ s/``/"/g;
$text =~ s/\'\'/"/g;
}
+ return $text;
+}
+
+sub new_container($$)
+{
+ my $self = shift;
+ my $type = shift;
+
+
+ my $container_object;
+ if ($type eq 'line') {
+ $container_object = Texinfo::Convert::Line->new($self->{'paragraph_conf'});
+ } elsif ($type eq 'paragraph') {
+ $container_object =
Texinfo::Convert::Paragraph->new($self->{'paragraph_conf'});
+ } elsif ($type eq 'unfilled') {
+ $container_object =
Texinfo::Convert::UnFilled->new($self->{'paragraph_conf'});
+ } else {
+ die "Unknown container type $type\n";
+ }
+ my $container = {'container' => $container_object, 'upper_case' => 0,
+ 'code' => 0};
+ if (defined($self->{'preformatted'})) {
+ $container->{'preformatted'} = $self->{'preformatted'};
+ }
+ return $container;
}
sub convert_line($$)
{
my $self = shift;
my $converted = shift;
- my $line = Texinfo::Convert::Line->new($self->{'paragraph_conf'});
- push @{$self->{'containers'}}, $line;
+ my $container = $self->new_container('line');
+ push @{$self->{'containers'}}, $container;
+ my $result = $self->convert($converted);
+ $result .= $container->{'container'}->end();
+ pop @{$self->{'containers'}};
+ return $result;
+}
+
+sub convert_unfilled($$)
+{
+ my $self = shift;
+ my $converted = shift;
+ my $container = $self->new_container('unfilled');
+ $container->{'code'} = 1;
+ push @{$self->{'containers'}}, $container;
my $result = $self->convert($converted);
- $result .= $line->end();
+ $result .= $container->{'container'}->end();
pop @{$self->{'containers'}};
return $result;
}
-# code
-# sp
-# var, sc -> 'upper_case'
+sub _def_argument_content($$)
+{
+ my $self = shift;
+ my $converted = shift;
+ if ($converted->{'type'} and $converted->{'type'} eq 'bracketed') {
+ $converted = { 'contents' => $converted->{'contents'},
+ 'type' => 'bracketed_def_content' };
+ }
+ return $converted;
+}
+
+sub _definition_category($$$)
+{
+ my $current = shift;
+ my $arg_category = shift;
+ my $arg_class = shift;
+ return $arg_category->[0]
+ if (!defined($arg_class->[1]) or $arg_class->[1] !~ /\S/);
+
+ my $style =
+
$Texinfo::Common::command_index_prefix{$current->{'extra'}->{'def_command'}};
+ my $category = Texinfo::Convert::Texinfo::convert($arg_category->[0]);
+ my $class = Texinfo::Convert::Texinfo::convert($arg_class->[0]);
+ print STDERR "DEFINITION CATEGORY($style): $category $class\n";
+ if ($style eq 'f') {
+ return Texinfo::Parser::parse_texi_line (undef, "$category on $class");
+ #gdt('{category} on {class}', { 'category' => $category, 'class' => $class
});
+ } elsif ($style eq 'v') {
+ return Texinfo::Parser::parse_texi_line (undef, "$category of $class");
+ }
+ return $arg_category->[0];
+}
+
+# on top, the converter object which holds some gloal information
+#
+# context (for footntes, multitable cells):
+# 'preformatted'
+# 'max'
+#
+# format_context
+# indentation + count for prepending text
+# also paragraph count and maybe empty line count
+#
+# containers on their own stack
+# in container
+# 'upper_case'
+# 'code'
+# and (from the main context) preformatted
+#
+# paragraph number: incremented with block commands except html and such
+# and group and raggedright and menu*
+# and also center and listoffloats
+# and with paragraphs.
+
# preformatted
sub convert($$);
@@ -244,16 +369,21 @@
my $self = shift;
my $root = shift;
+ my $container_context;
+ if (@{$self->{'containers'}}) {
+ $container_context = $self->{'containers'}->[-1];
+ }
if ($self->{'debug'}) {
- print STDERR "root (@{$self->{'context'}})\n";
- print STDERR " Command: $root->{'cmdname'}\n" if ($root->{'cmdname'});
- print STDERR " Type: $root->{'type'}\n" if ($root->{'type'});
+ print STDERR "ROOT (@{$self->{'context'}})";
+ print STDERR " cmd: $root->{'cmdname'}," if ($root->{'cmdname'});
+ print STDERR " type: $root->{'type'}" if ($root->{'type'});
+ print STDERR "\n";
print STDERR " Text: $root->{'text'}\n" if (defined($root->{'text'}));
#print STDERR " Special def_command: $root->{'extra'}->{'def_command'}\n"
# if (defined($root->{'extra'}) and $root->{'extra'}->{'def_command'});
- if (@{$self->{'containers'}}) {
- print STDERR " Container:";
- $self->{'containers'}->[-1]->dump();
+ if ($container_context) {
+ print STDERR "
Container:($container_context->{'code'},$container_context->{'upper_case'},$container_context->{'preformatted'})";
+ $container_context->{'container'}->dump();
}
}
@@ -288,15 +418,17 @@
# NUMBER_FOOTNOTES SPLIT_SIZE IN_ENCODING FILLCOLUMN ENABLE_ENCODING
# OUT_ENCODING ENCODING_NAME
- return '' if (($root->{'type'} and $ignored_types{$root->{'type'}})
- or ($root->{'cmdname'} and
$ignored_commands{$root->{'cmdname'}}));
+ if (($root->{'type'} and $ignored_types{$root->{'type'}})
+ or ($root->{'cmdname'} and $ignored_commands{$root->{'cmdname'}})) {
+ print STDERR "IGNORED\n" if ($self->{'debug'});
+ return '';
+ }
my $result = '';
- my $paragraph;
- my $line;
if (defined($root->{'text'})) {
# ignore text outside of any format.
- if (ref($self->{'containers'}->[-1])) {
- $result .= $self->{'containers'}->[-1]->add_text($root->{'text'});
+ if ($container_context) {
+ $result .= $container_context->{'container'}->add_text(
+ $self->process_text($root, $container_context));
# Warn if ignored text not empty
} elsif ($root->{'text'} =~ /\S/) {
warn "BUG: ignored text not empty `$root->{'text'}'\n";
@@ -306,31 +438,34 @@
my $command = $root->{'cmdname'};
if (defined($text_no_brace_commands{$root->{'cmdname'}})) {
if ($command eq ':') {
- $self->{'containers'}->[-1]->inhibit_end_sentence();
+ $container_context->{'container'}->inhibit_end_sentence();
} elsif ($command eq '*') {
- $result .= $self->{'containers'}->[-1]->add_pending_word();
- $result .= $self->{'containers'}->[-1]->end_line();
+ $result .= $container_context->{'container'}->add_pending_word();
+ $result .= $container_context->{'container'}->end_line();
} elsif ($command eq '.' or $command eq '?' or $command eq '!') {
- $result .= $self->{'containers'}->[-1]->add_next($command, undef, 1),
+ $result .= $container_context->{'container'}->add_next($command,
undef, 1),
} elsif ($command eq ' ' or $command eq "\n" or $command eq "\t") {
- $result .=
$self->{'containers'}->[-1]->add_next($text_no_brace_commands{$root->{'cmdname'}});
+ $result .=
$container_context->{'container'}->add_next($text_no_brace_commands{$root->{'cmdname'}});
} else {
- $result .=
$self->{'containers'}->[-1]->add_text($text_no_brace_commands{$root->{'cmdname'}});
+ $result .=
$container_context->{'container'}->add_text($text_no_brace_commands{$root->{'cmdname'}});
}
+ return $result;
} elsif (defined($text_brace_no_arg_commands{$root->{'cmdname'}})) {
$command = $root->{'extra'}->{'clickstyle'}
if ($root->{'extra'}
and defined($root->{'extra'}->{'clickstyle'})
and
defined($text_brace_no_arg_commands{$root->{'extra'}->{'clickstyle'}}));
- $result .=
$self->{'containers'}->[-1]->add_text($text_brace_no_arg_commands{$command});
+ $result .=
$container_context->{'container'}->add_text($text_brace_no_arg_commands{$command});
+ return $result;
# commands with braces
} elsif ($accent_commands{$root->{'cmdname'}}) {
- $result .= $self->{'containers'}->[-1]->add_text(
+ $result .= $container_context->{'container'}->add_text(
Texinfo::Convert::Text::text_accents($root, $self->{'encoding'}));
return $result;
} elsif ($root->{'cmdname'} eq 'image') {
return $self->convert($root->{'args'}->[0]);
} elsif ($root->{'cmdname'} eq 'email') {
+ # nothing is output for email, instead the command is substituted.
my @email_contents;
if ($root->{'extra'} and $root->{'extra'}->{'brace_command_contents'}) {
@@ -348,11 +483,15 @@
}
unshift @{$self->{'current_contents'}->[-1]}, @email_contents;
}
- return;
+ return '';
} elsif ($style_map{$command}) {
- $result .=
$self->{'containers'}->[-1]->add_text($style_map{$command}->[0]);
+ $container_context->{'code'}++ if ($code_style_commands{$command});
+ $container_context->{'upper_case'}++ if ($upper_case_commands{$command});
+ $result .=
$container_context->{'container'}->add_text($style_map{$command}->[0]);
$result .= $self->convert($root->{'args'}->[0]);
- $result .=
$self->{'containers'}->[-1]->add_text($style_map{$command}->[1]);
+ $result .=
$container_context->{'container'}->add_text($style_map{$command}->[1]);
+ $container_context->{'code'}-- if ($code_style_commands{$command});
+ $container_context->{'upper_case'}-- if ($upper_case_commands{$command});
} elsif ($command eq 'footnote') {
} elsif ($command eq 'anchor') {
} elsif ($root->{'args'} and $root->{'args'}->[0]
@@ -373,6 +512,8 @@
}
} elsif ($root->{'cmdname'} eq 'node') {
# FIXME handle node
+ } elsif ($root->{'cmdname'} eq 'listoffloats') {
+ # FIXME handle listoffloats
} elsif ($root->{'extra'} and ($root->{'extra'}->{'misc_content'}
or $root->{'extra'}->{'misc_args'})) {
if ($sectioning_commands{$root->{'cmdname'}}
@@ -399,23 +540,89 @@
# FIXME do something for index entry?
}
}
+ } elsif ($def_commands{$root->{'cmdname'}}) {
+ # FIXME change indenting? Or in def_line?
+ # everything is done when in the def_line type
+ } else {
+ die "Unhandled $root->{'cmdname'}\n";
}
- } elsif ($root->{'type'} and $root->{'type'} eq 'paragraph') {
+ if ($advance_paragraph_count_commands{$root->{'cmdname'}}) {
+ $self->{'format_context'}->[-1]->{'paragraph_count'}++;
+ } elsif ($root_commands{$root->{'cmdname'}}) {
+ $self->{'format_context'}->[-1]->{'paragraph_count'} = 0;
+ }
+ }
+ my $paragraph;
+ if ($root->{'type'}) {
+ if ($root->{'type'} eq 'paragraph') {
$self->{'empty_lines_count'} = 0;
+ # FIXME indenting. First and not first paragraph.
+ # FIXME also beware of 'asis'! The space before has to be kept then.
+ # my $paragraphindent = get_conf('paragraphindent');
+ # $paragraphindent = 0 if ($paragraphindent eq 'none');
+ # if ($paragraphindent ne 'asis' and $paragraphindent and
$line_char_counter == 0 and (defined($content->{'paragraph_in_element_nr'}))
and ($info_state->{'indent_para'} or (!defined($info_state->{'indent_para'})
and ($content->{'paragraph_in_element_nr'} or (get_conf('firstparagraphindent')
eq 'insert')))))
$paragraph = Texinfo::Convert::Paragraph->new($self->{'paragraph_conf'});
- push @{$self->{'containers'}}, $paragraph;
- }
- if ($root->{'type'} and $root->{'type'} eq 'def_line') {
+ push @{$self->{'containers'}}, {'container' => $paragraph};
+ $self->{'format_context'}->[-1]->{'paragraph_count'}++;
+ } elsif ($root->{'type'} eq 'def_line') {
#print STDERR "$root->{'extra'}->{'def_command'}\n";
- foreach my $parsed_arg (@{$root->{'extra'}->{'def_args'}}) {
-
+ my @args = @{$root->{'extra'}->{'def_args'}};
+ my ($category, $name, $class, $type) = ('', '', '', '');
+ my ($parsed_category, $parsed_name, $parsed_class, $parsed_type);
+ while (@args) {
+ my $parsed_arg = shift @args;
+ if ($parsed_arg->[0] eq 'category') {
+ $parsed_category = $self->_def_argument_content($parsed_arg->[1]);
+ $category = $self->convert_unfilled($parsed_category);
+ } elsif ($parsed_arg->[0] eq 'name') {
+ $parsed_name = $self->_def_argument_content($parsed_arg->[1]);
+ $name = $self->convert_unfilled($parsed_name);
+ } elsif ($parsed_arg->[0] eq 'class') {
+ $parsed_class = $self->_def_argument_content($parsed_arg->[1]);
+ $class = $self->convert_unfilled($parsed_class);
+ } elsif ($parsed_arg->[0] eq 'type') {
+ $parsed_type = $self->_def_argument_content($parsed_arg->[1]);
+ $type = $self->convert_unfilled($parsed_type);
+ } elsif ($parsed_arg->[0] eq 'arg' or $parsed_arg->[0] eq 'argtype') {
+ unshift @args, $parsed_arg;
+ last;
+ }
+ }
+ print STDERR "DEF LINE(parsed) category `$category' name `$name' class
`$class' type `$type'\n"
+ if ($self->{'debug'});
+
+ my $parsed_definition_category = _definition_category ($root,
+ [$parsed_category,
$category],
+ [$parsed_class, $class]);
+ my $definition_category =
$self->convert_unfilled($parsed_definition_category);
+ my $type_name = '';
+ $type_name .= "$type " if ($type ne '');
+ $type_name .= $name if ($name ne '');
+
+ my $arguments = '';
+ foreach my $parsed_arg(@args) {
+ my $arg_text;
+ if ($parsed_arg->[0] eq 'spaces') {
+ $arg_text = $parsed_arg->[1]->{'text'};
+ } else {
+ $arg_text
+ =
$self->convert_unfilled($self->_def_argument_content($parsed_arg->[1]));
}
- $result = $self->convert($root->{'args'}->[0]) if ($root->{'args'});
- } elsif ($root->{'type'} and $root->{'type'} eq 'menu_entry') {
+ $arguments .= $arg_text;
+ }
+ $arguments = ' '.$arguments if ($arguments ne '');
+ print STDERR "DEF LINE definition_category `$definition_category'
arguments `$arguments'\n"
+ if ($self->{'debug'});
+ $result = " -- $definition_category: ${type_name}$arguments";
+ $result =~ s/\s*$//;
+ $result .= "\n";
+ print STDERR " --> $result" if ($self->{'debug'});
+ } elsif ($root->{'type'} eq 'menu_entry') {
foreach my $arg (@{$root->{'args'}}) {
$result .= $self->convert($arg);
}
}
+ }
if ($root->{'contents'}) {
my @contents = @{$root->{'contents'}};
push @{$self->{'current_contents'}}, address@hidden;
Index: Convert/Unicode.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Unicode.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- Convert/Unicode.pm 13 Nov 2010 21:13:16 -0000 1.6
+++ Convert/Unicode.pm 15 Nov 2010 00:22:37 -0000 1.7
@@ -558,13 +558,14 @@
return &$fallback_convert_accent($text, $command);
}
-sub unicode_text($$)
+sub unicode_text($$$)
{
my $self = shift;
my $command = shift;
+ my $context = shift;
my $text = $command->{'text'};
- if (!$self->{'code'} and !$self->{'context'}->[-1] eq 'preformatted') {
+ if (!$context->{'code'} and !$context->{'preformatted'}) {
$text =~ s/---/\x{2014}/g;
$text =~ s/--/\x{2013}/g;
$text =~ s/``/\x{201C}/g;
Index: Convert/UnFilled.pm
===================================================================
RCS file: Convert/UnFilled.pm
diff -N Convert/UnFilled.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Convert/UnFilled.pm 15 Nov 2010 00:22:37 -0000 1.1
@@ -0,0 +1,149 @@
+# UnFilled.pm: handle unfilled line of text.
+#
+# Copyright 2010 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Original author: Patrice Dumas <address@hidden>
+
+# this module has nothing Texinfo specific. It is similar with
+# Texinfo::Convert::Line, but simpler.
+
+package Texinfo::Convert::UnFilled;
+
+use 5.006;
+use strict;
+
+use Unicode::EastAsianWidth;
+
+# initialize a paragraph object.
+sub new($;$)
+{
+ my $class = shift;
+ my $conf = shift;
+ my $self = {'indent_length' => 0, 'counter' => 0, 'line_beginning' => 1,
+ 'leading_spaces' => '', 'only_spaces' => 1};
+ if (defined($conf)) {
+ foreach my $key (keys(%$conf)) {
+ if ($key eq 'text') {
+ $self->{'counter'} =
Texinfo::Convert::Unicode::string_width($conf->{$key});
+ $self->{'line_beginning'} = 0 if ($self->{'counter'});
+ } else {
+ $self->{$key} = $conf->{$key};
+ }
+ }
+ }
+ bless $self, $class;
+}
+
+# for debug
+sub dump($)
+{
+ my $self = shift;
+ my $word = 'UNDEF';
+ my $end_sentence = 'UNDEF';
+ print STDERR "unfilled ($self->{'line_beginning'},$self->{'only_spaces'})
space `$self->{'leading_spaces'}'\n";
+}
+
+# end a line.
+sub end_line($)
+{
+ my $line = shift;
+ $line->{'line_beginning'} = 1;
+ $line->{'leading_spaces'} = '';
+ $line->{'only_spaces'} = 1;
+ print STDERR "END_LINE\n" if ($line->{'debug'});
+ return "\n";
+}
+
+sub _add_text($$)
+{
+ my $line = shift;
+ my $text = shift;
+ my $result = '';
+ if ($line->{'line_beginning'}) {
+ if ($line->{'indent_length'}) {
+ $line->{'leading_spaces'} .=
+ ' ' x ($line->{'indent_length'} - $line->{'counter'});
+ print STDERR "INDENT($line->{'counter'})\n" if ($line->{'debug'});
+ }
+ $line->{'line_beginning'} = 0;
+ }
+ if ($line->{'only_spaces'}) {
+ if ($text =~ /\S/) {
+ $text = $line->{'leading_spaces'}.$text;
+ $line->{'leading_spaces'} = '';
+ $line->{'only_spaces'} = 0;
+ } elsif ($text =~ /\n/) {
+ $text = $line->end_line;
+ } else {
+ return '';
+ }
+ } else {
+ if ($text =~ /\n/) {
+ $text =~ s/\s*$//;
+ $text .= $line->end_line;
+ }
+ }
+ return $text;
+}
+
+# put a pending word and spaces in the result string.
+sub add_pending_word($)
+{
+ my $line = shift;
+ return '';
+}
+
+# end
+sub end($)
+{
+ my $line = shift;
+ return '';
+ #return $line->{'leading_spaces'};
+ #return $line->end_line();
+}
+
+# add a word and/or spaces and end of sentence.
+sub add_next($;$$$)
+{
+ my $line = shift;
+ my $word = shift;
+ my $space = shift;
+ my $end_sentence = shift;
+ my $result = '';
+
+ if (defined($word)) {
+ $result .= $line->_add_text($word);
+ }
+ if (defined($space)) {
+ $result .= $line->_add_text($space);
+ }
+ return $result;
+}
+
+sub inhibit_end_sentence($)
+{
+ my $line = shift;
+}
+
+# wrap a text.
+sub add_text($$)
+{
+ my $line = shift;
+ my $text = shift;
+ return $line->_add_text($text);
+}
+
+1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp/Texinfo Common.pm Parser.pm Convert/...,
Patrice Dumas <=