[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp texi2any.pl Texinfo/Common.pm Texinf...
From: |
Patrice Dumas |
Subject: |
texinfo/tp texi2any.pl Texinfo/Common.pm Texinf... |
Date: |
Fri, 15 Apr 2011 06:39:34 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 11/04/15 06:39:33
Modified files:
tp : texi2any.pl
tp/Texinfo : Common.pm Parser.pm
tp/Texinfo/Convert: Converter.pm HTML.pm Plaintext.pm
Log message:
Put expand_verbatiminclude in the default Converter.
Expand raw commands in HTML.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi2any.pl?cvsroot=texinfo&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.241&r2=1.242
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Converter.pm?cvsroot=texinfo&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/HTML.pm?cvsroot=texinfo&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.134&r2=1.135
Patches:
Index: texi2any.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/texi2any.pl,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- texi2any.pl 13 Apr 2011 22:49:17 -0000 1.32
+++ texi2any.pl 15 Apr 2011 06:39:32 -0000 1.33
@@ -355,6 +355,13 @@
}
}
+sub set_format($)
+{
+ my $format = shift;
+ $default_expanded_format = [$format];
+ return $format;
+}
+
sub document_warn ($) {
return if (get_conf('NO_WARN'));
my $text = shift;
@@ -487,8 +494,9 @@
if ($var eq 'DEBUGCOUNT') {
$format = 'debugcount';
} elsif ($var eq 'TEXI2HTML') {
- $format = 'html';
+ $format = set_format('html');
_set_variables_texi2html();
+ $parser_default_options->{'values'}->{'texi2html'} = 1;
} else {
# this is very wrong, but a way to avoid a spurious warning.
no warnings 'once';
@@ -533,10 +541,10 @@
'plaintext' => sub {$format = $_[0];
set_from_cmdline('SHOW_MENU', 0);
},
- 'html' => sub {$format = $_[0];},
- 'info' => sub {$format = $_[0];},
- 'docbook' => sub {$format = $_[0];},
- 'xml' => sub {$format = $_[0];},
+ 'html' => sub {$format = set_format($_[0]);},
+ 'info' => sub {$format = set_format($_[0]);},
+ 'docbook' => sub {$format = set_format($_[0]);},
+ 'xml' => sub {$format = set_format($_[0]);},
'dvi' => sub {$format = $_[0]; push @texi2dvi_args, '--'.$_[0];},
'ps' => sub {$format = $_[0]; push @texi2dvi_args, '--'.$_[0];},
'pdf' => sub {$format = $_[0]; push @texi2dvi_args, '--'.$_[0];},
Index: Texinfo/Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- Texinfo/Common.pm 13 Apr 2011 22:49:17 -0000 1.34
+++ Texinfo/Common.pm 15 Apr 2011 06:39:32 -0000 1.35
@@ -128,7 +128,7 @@
'TEXI2DVI', 'DUMP_TREE', 'MAX_MACRO_CALL_NESTING',
'PROGRAM_AND_VERSION', 'PROGRAM_HOMEPAGE', 'PROGRAM',
'AFTER_BODY_OPEN', 'EXTRA_HEAD', 'LINKS_BUTTONS', 'DO_ABOUT',
- 'PRE_BODY_CLOSE',
+ 'PRE_BODY_CLOSE', 'DEFAULT_RULE',
'CSS_FILES', 'CSS_REFS');
my %valid_options;
Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.241
retrieving revision 1.242
diff -u -b -r1.241 -r1.242
--- Texinfo/Parser.pm 13 Apr 2011 20:14:29 -0000 1.241
+++ Texinfo/Parser.pm 15 Apr 2011 06:39:33 -0000 1.242
@@ -72,7 +72,6 @@
labels_information
global_commands_information
global_informations
- expand_verbatiminclude
gdt
) ] );
@@ -4390,40 +4389,6 @@
return $args;
}
-# FIXME put this in a more suited file
-sub expand_verbatiminclude($$)
-{
- my $self = shift;
- my $current = shift;
-
- return unless ($current->{'extra'} and
defined($current->{'extra'}->{'text_arg'}));
- my $text = $current->{'extra'}->{'text_arg'};
- my $file = Texinfo::Common::locate_include_file($self, $text);
-
- my $verbatiminclude;
-
- if (defined($file)) {
- # FIXME encoding?
- if (!open(VERBINCLUDE, $file)) {
- $self->line_error (sprintf($self->__("Cannot read %s: %s"), $file, $!),
- $current->{'line_nr'});
- } else {
- $verbatiminclude = { 'cmdname' => 'verbatim',
- 'parent' => $current->{'parent'},
- 'extra' =>
- {'text_arg' => $current->{'extra'}->{'text_arg'}} };
- while (<VERBINCLUDE>) {
- push @{$verbatiminclude->{'contents'}},
- {'type' => 'raw', 'text' => $_ };
- }
- }
- } else {
- $self->line_error (sprintf($self->__("address@hidden: Cannot find %s"),
- $current->{'cmdname'}, $text), $current->{'line_nr'});
- }
- return $verbatiminclude;
-}
-
1;
__END__
# Below is stub documentation.
Index: Texinfo/Convert/Converter.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Converter.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- Texinfo/Convert/Converter.pm 13 Apr 2011 22:43:43 -0000 1.13
+++ Texinfo/Convert/Converter.pm 15 Apr 2011 06:39:33 -0000 1.14
@@ -373,6 +373,39 @@
);
}
+sub expand_verbatiminclude($$)
+{
+ my $self = shift;
+ my $current = shift;
+
+ return unless ($current->{'extra'} and
defined($current->{'extra'}->{'text_arg'}));
+ my $text = $current->{'extra'}->{'text_arg'};
+ my $file = Texinfo::Common::locate_include_file($self, $text);
+
+ my $verbatiminclude;
+
+ if (defined($file)) {
+ # FIXME encoding?
+ if (!open(VERBINCLUDE, $file)) {
+ $self->line_error (sprintf($self->__("Cannot read %s: %s"), $file, $!),
+ $current->{'line_nr'});
+ } else {
+ $verbatiminclude = { 'cmdname' => 'verbatim',
+ 'parent' => $current->{'parent'},
+ 'extra' =>
+ {'text_arg' => $current->{'extra'}->{'text_arg'}} };
+ while (<VERBINCLUDE>) {
+ push @{$verbatiminclude->{'contents'}},
+ {'type' => 'raw', 'text' => $_ };
+ }
+ }
+ } else {
+ $self->line_error (sprintf($self->__("address@hidden: Cannot find %s"),
+ $current->{'cmdname'}, $text), $current->{'line_nr'});
+ }
+ return $verbatiminclude;
+}
+
sub expand_today($)
{
my $self = shift;
Index: Texinfo/Convert/HTML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/HTML.pm,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- Texinfo/Convert/HTML.pm 14 Apr 2011 18:14:59 -0000 1.22
+++ Texinfo/Convert/HTML.pm 15 Apr 2011 06:39:33 -0000 1.23
@@ -279,6 +279,7 @@
},
'misc_elements_order' => ['Footnotes', 'Contents', 'Overview', 'About'],
'DOCTYPE' => '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
+ 'DEFAULT_RULE' => '<hr>',
'BODYTEXT' => undef,
'documentlanguage' => 'en',
'SHOW_TITLE' => 1,
@@ -424,7 +425,7 @@
$default_commands_formatting{'normal'}->{'*'} = '<br>';
-sub no_arg_commands($$$)
+sub _convert_no_arg_command($$$)
{
my $self = shift;
my $cmdname = shift;
@@ -447,10 +448,10 @@
}
foreach my $command(keys(%{$default_commands_formatting{'normal'}})) {
- $default_commands_conversion{$command} = \&no_arg_commands;
+ $default_commands_conversion{$command} = \&_convert_no_arg_command;
}
-sub convert_today($$$)
+sub _convert_today_command($$$)
{
my $self = shift;
my $cmdname = shift;
@@ -460,7 +461,7 @@
return $self->convert_tree($tree);
}
-$default_commands_conversion{'today'} = \&convert_today;
+$default_commands_conversion{'today'} = \&_convert_today_command;
# style commands
@@ -521,7 +522,7 @@
$style_commands_formatting{$context}->{$command}->{'quote'} = 1;
}
}
- $default_commands_conversion{$command} = \&style_commands;
+ $default_commands_conversion{$command} = \&_convert_style_command;
}
delete $style_commands_formatting{'preformatted'}->{'sc'}->{'attribute'};
@@ -546,7 +547,7 @@
return ($element, $class, $attributes);
}
-sub style_commands($$$$)
+sub _convert_style_command($$$$)
{
my $self = shift;
my $cmdname = shift;
@@ -576,7 +577,7 @@
return $text;
}
-sub expand_email($$$$)
+sub _convert_email_command($$$$)
{
my $self = shift;
my $cmdname = shift;
@@ -600,9 +601,9 @@
return "<a href=\"mailto:$mail\">$text</a>";
}
-$default_commands_conversion{'email'} = \&expand_email;
+$default_commands_conversion{'email'} = \&_convert_email_command;
-sub expand_uref($$$$)
+sub _convert_uref_command($$$$)
{
my $self = shift;
my $cmdname = shift;
@@ -623,10 +624,10 @@
return "<a href=\"$url\">$text</a>";
}
-$default_commands_conversion{'uref'} = \&expand_uref;
-$default_commands_conversion{'url'} = \&expand_url;
+$default_commands_conversion{'uref'} = \&_convert_uref_command;
+$default_commands_conversion{'url'} = \&_convert_uref_command;
-#sub expand_math($$$$)
+#sub _convert_math_command($$$$)
#{
# my $self = shift;
# my $cmdname = shift;
@@ -636,9 +637,9 @@
# return $args->[0]->{'normal'};
#}
-#$default_commands_conversion{'math'} = \&expand_math;
+#$default_commands_conversion{'math'} = \&_convert_math_command;
-sub accent_commands($$$$)
+sub _convert_accent_command($$$$)
{
my $self = shift;
my $cmdname = shift;
@@ -649,7 +650,7 @@
}
foreach my $command (keys(%accent_commands)) {
- $default_commands_conversion{$command} = \&accent_commands;
+ $default_commands_conversion{$command} = \&_convert_accent_command;
}
sub default_comment($$) {
@@ -686,7 +687,7 @@
return $result;
}
-sub expand_heading_commands($$$$$)
+sub _convert_heading_command($$$$$)
{
my $self = shift;
my $cmdname = shift;
@@ -722,9 +723,56 @@
}
foreach my $command (keys(%sectioning_commands), 'node') {
- $default_commands_conversion{$command} = \&expand_heading_commands;
+ $default_commands_conversion{$command} = \&_convert_heading_command;
}
+sub _convert_raw_command($$$$)
+{
+ my $self = shift;
+ my $cmdname = shift;
+ my $command = shift;
+ my $contents = shift;
+
+ if ($cmdname eq $self->{'output_format'}) {
+ chomp ($contents);
+ return $contents;
+ }
+ $self->line_warn(sprintf(__("Raw format %s is not converted"), $cmdname),
+ $command->{'line_nr'});
+ return $self->xml_protect_text($contents);
+}
+
+foreach my $command (@out_formats) {
+ $default_commands_conversion{$command} = \&_convert_raw_command;
+}
+
+sub _convert_verbatim_command($$$$)
+{
+ my $self = shift;
+ my $cmdname = shift;
+ my $command = shift;
+ my $contents = shift;
+
+ return $self->attribute_class('pre', $cmdname).'>'
+ .$self->xml_protect_text($contents) . '</pre>';
+}
+
+$default_commands_conversion{'verbatim'} = \&_convert_verbatim_command;
+
+sub _convert_verbatiminclude_command($$$$)
+{
+ my $self = shift;
+ my $cmdname = shift;
+ my $command = shift;
+ my $args = shift;
+
+ my $verbatim_include_verbatim = $self->expand_verbatiminclude($command);
+ return $self->convert_text($verbatim_include_verbatim);
+}
+
+$default_commands_conversion{'verbatiminclude'}
+ = \&_convert_verbatiminclude_command;
+
my %default_types_conversion;
#my %ignored_types;
@@ -742,7 +790,7 @@
'flushright' => 'right',
);
-sub paragraph_type($$$$)
+sub _convert_paragraph_type($$$$)
{
my $self = shift;
my $type = shift;
@@ -765,9 +813,9 @@
}
}
-$default_types_conversion{'paragraph'} = \¶graph_type;
+$default_types_conversion{'paragraph'} = \&_convert_paragraph_type;
-sub empty_line($$$) {
+sub _convert_empty_line_type($$$) {
my $self = shift;
my $type = shift;
my $command = shift;
@@ -775,10 +823,10 @@
return "\n";
}
-$default_types_conversion{'empty_line'} = \&empty_line;
-$default_types_conversion{'after_description_line'} = \&empty_line;
+$default_types_conversion{'empty_line'} = \&_convert_empty_line_type;
+$default_types_conversion{'after_description_line'} =
\&_convert_empty_line_type;
-sub bracketed($$$$) {
+sub _convert_bracketed_type($$$$) {
my $self = shift;
my $type = shift;
my $command = shift;
@@ -788,10 +836,9 @@
return '{'.$content.'}';
}
-$default_types_conversion{'bracketed'} = \&bracketed;
+$default_types_conversion{'bracketed'} = \&_convert_bracketed_type;
-
-sub process_text($$$)
+sub _convert_text($$$)
{
my $self = shift;
my $type = shift;
@@ -827,7 +874,56 @@
return $text;
}
-$default_types_conversion{'text'} = \&process_text;
+$default_types_conversion{'text'} = \&_convert_text;
+
+sub _convert_element_type($$$$)
+{
+ my $self = shift;
+ my $type = shift;
+ my $command = shift;
+ my $content = shift;
+
+ #print STDERR "GGGGGGGG $command->{'parent'}
$command->{'parent'}->{'type'}\n";
+ my $result = '';
+ $result .= $content;
+ #Â FIXME titlepage
+ if (!$command->{'element_prev'}) {
+ if (!$command->{'element_next'}) {
+ return $result.$self->get_conf('DEFAULT_RULE')."\n";
+ }
+ }
+ return $content;
+}
+
+$default_types_conversion{'element'} = \&_convert_element_type;
+
+# FIXME associate with element type (replace by _convert_element_type)?
+sub _convert_element($$)
+{
+ my $self = shift;
+ my $element = shift;
+
+ my $result = '';
+
+ #Â This may happen if there are only nodes and sections are used as elements
+ #die "BUG: no 'element_command' for $element"
+ # if (!$element->{'extra'}->{'element_command'});
+ die "BUG: no target for $element"
+ if ($element->{'extra'}->{'element_command'} and
+ !$self->{'targets'}->{$element->{'extra'}->{'element_command'}});
+ print STDERR "NEW ELEMENT
$self->{'targets'}->{$element->{'extra'}->{'element_command'}}->{'id'}\n"
+ if ($self->get_conf('DEBUG'));
+
+ $result .= $self->_convert($element);
+
+ print STDERR "END ELEMENT\n" if ($self->get_conf('DEBUG'));
+
+ #$result .= $self->_footnotes($element);
+
+ #print STDERR "AFTER FOOTNOTES\n" if ($self->{'DEBUG'});
+
+ return $result;
+}
sub _initialize($)
{
@@ -839,6 +935,11 @@
%{$self->{'css_map'}} = %css_map;
+ foreach my $format (@out_formats) {
+ $default_commands_conversion{$format} = undef
+ unless ($self->{'expanded_formats_hash'}->{$format});
+ }
+
foreach my $context (keys(%default_commands_formatting)) {
foreach my $command (keys(%{$default_commands_formatting{$context}})) {
if (exists
($Texinfo::Config::commands_formatting{$context}->{$command})) {
@@ -911,36 +1012,9 @@
'align' => ['raggedright']}];
$self->{'formats'} = [];
- return $self;
-}
-
-sub _convert_element($$)
-{
- my $self = shift;
- my $element = shift;
-
- my $result = '';
- #Â This may happen if there are only nodes and sections are used as elements
- #die "BUG: no 'element_command' for $element"
- # if (!$element->{'extra'}->{'element_command'});
- die "BUG: no target for $element"
- if ($element->{'extra'}->{'element_command'} and
- !$self->{'targets'}->{$element->{'extra'}->{'element_command'}});
- print STDERR "NEW ELEMENT
$self->{'targets'}->{$element->{'extra'}->{'element_command'}}->{'id'}\n"
- if ($self->get_conf('DEBUG'));
-
- $result .= $self->_convert($element);
-
- print STDERR "END ELEMENT\n" if ($self->get_conf('DEBUG'));
-
- #$result .= $self->_footnotes($element);
-
- #print STDERR "AFTER FOOTNOTES\n" if ($self->{'DEBUG'});
-
- return $result;
+ return $self;
}
-
# the entry point for _convert
sub convert_tree($$)
{
Index: Texinfo/Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -b -r1.134 -r1.135
--- Texinfo/Convert/Plaintext.pm 13 Apr 2011 20:14:29 -0000 1.134
+++ Texinfo/Convert/Plaintext.pm 15 Apr 2011 06:39:33 -0000 1.135
@@ -1865,7 +1865,7 @@
}
return $result;
} elsif ($root->{'cmdname'} eq 'verbatiminclude') {
- my $expansion = $self->Texinfo::Parser::expand_verbatiminclude($root);
+ my $expansion = $self->expand_verbatiminclude($root);
unshift @{$self->{'current_contents'}->[-1]}, $expansion
if ($expansion);
return '';