texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

texinfo/Pod-Simple-Texinfo Changes MANIFEST Mak...


From: Patrice Dumas
Subject: texinfo/Pod-Simple-Texinfo Changes MANIFEST Mak...
Date: Thu, 19 Jan 2012 20:03:13 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        12/01/19 20:03:13

Added files:
        Pod-Simple-Texinfo: Changes MANIFEST Makefile.PL README pod2texi 
        Pod-Simple-Texinfo/lib/Pod/Simple: Texinfo.pm 
        Pod-Simple-Texinfo/t: Pod-Simple-Texinfo.t 

Log message:
        Initial checking in of Pod-Simple-Texinfo files.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/Changes?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/MANIFEST?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/Makefile.PL?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/README?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/pod2texi?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/t/Pod-Simple-Texinfo.t?cvsroot=texinfo&rev=1.1

Patches:
Index: Changes
===================================================================
RCS file: Changes
diff -N Changes
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ Changes     19 Jan 2012 20:03:12 -0000      1.1
@@ -0,0 +1,6 @@
+Revision history for Perl extension Pod::Simple::Texinfo.
+
+0.01  Fri Dec 23 22:41:34 2011
+       - original version; created by h2xs 1.23 with options
+               -XA -b 5.0.0 -n Pod::Simple::Texinfo
+

Index: MANIFEST
===================================================================
RCS file: MANIFEST
diff -N MANIFEST
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ MANIFEST    19 Jan 2012 20:03:12 -0000      1.1
@@ -0,0 +1,7 @@
+Changes
+Makefile.PL
+MANIFEST
+README
+t/Pod-Simple-Texinfo.t
+lib/Pod/Simple/Texinfo.pm
+pod2texi

Index: Makefile.PL
===================================================================
RCS file: Makefile.PL
diff -N Makefile.PL
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ Makefile.PL 19 Jan 2012 20:03:12 -0000      1.1
@@ -0,0 +1,15 @@
+use 5.000;
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+    NAME              => 'Pod::Simple::Texinfo',
+    VERSION_FROM      => 'lib/Pod/Simple/Texinfo.pm', # finds $VERSION
+    EXE_FILES         => [ 'pod2texi' ],
+    PREREQ_PM         => { "Pod::Simple::PullParser" => 0,
+                           "Texinfo::Parser" => 0,
+                           "Getopt::Long" => 0 }, # e.g., Module::Name => 1.1
+    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
+      (ABSTRACT_FROM  => 'lib/Pod/Simple/Texinfo.pm', # retrieve abstract from 
module
+       AUTHOR         => 'Patrice Dumas <address@hidden>') : ()),
+);

Index: README
===================================================================
RCS file: README
diff -N README
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ README      19 Jan 2012 20:03:12 -0000      1.1
@@ -0,0 +1,31 @@
+Pod-Simple-Texinfo version 0.01
+===============================
+
+Pod::Simple based Pod formatter to render Texinfo.
+
+INSTALLATION
+
+To install this module type the following:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+DEPENDENCIES
+
+This module requires these other modules and libraries:
+
+Pod::Simple::PullParser, Texinfo::Parser.  
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2011 Patrice Dumas
+
+This library is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+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.
+

Index: pod2texi
===================================================================
RCS file: pod2texi
diff -N pod2texi
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ pod2texi    19 Jan 2012 20:03:12 -0000      1.1
@@ -0,0 +1,226 @@
+#! /usr/bin/perl -w
+
+use strict;
+use Pod::Simple::Texinfo;
+
+use Getopt::Long qw(GetOptions);
+
+Getopt::Long::Configure("gnu_getopt");
+
+{
+# A fake package to be able to use Pod::Simple::PullParser without generating
+# any output.
+package Pod::Simple::PullParserRun;
+
+use vars qw(@ISA);
address@hidden = ('Pod::Simple::PullParser');
+sub new
+{
+  return shift->SUPER::new(@_);
+}
+sub run(){};
+}
+
+my $real_command_name = $0;
+$real_command_name =~ s/.*\///;
+
+sub pod2texi_help()
+{
+  print "Usage: pod2texi [OPTION]... POD-FILE...
+
+Translate Pod to Texinfo.  If the base level is higher than 0, 
+a main manual including all the files is done otherwise all
+manuals are standalone (the default).
+
+Options:
+    --base-level=NUM        level of the head1 commands.
+    --unnumbered-sections   use unumbered sections.
+    --output=NAME           output name for the first or the main manual.
+    --top                   top for the main manual.
+    --version               display version information and exit.\n";
+}
+
+my $base_level = 0;
+my $unnumbered_sections = 0;
+my $output = undef;
+my $top = 'top';
+
+my $result_options = Getopt::Long::GetOptions (
+  'help|h' => sub { print pod2texi_help(); exit 0; },
+  'version|V' => sub {print "$real_command_name 
$Pod::Simple::Texinfo::VERSION\n\n";
+    printf __("Copyright (C) %s Patrice Dumas
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+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.\n"), '2011';
+      exit 0;},
+  'base-level=i' => \$base_level,
+  'unnumbered-sections!' => \$unnumbered_sections,
+  'output|o=s' => \$output,
+  'top=s' => \$top,
+);
+
+exit 1 if (!$result_options);
+
+my @manuals;
+my @all_manual_names;
+
+foreach my $file (@ARGV) {
+  # not really used, only the manual name is used.
+  my $parser = Pod::Simple::PullParserRun->new();
+  $parser->parse_file($file);
+  my $short_title = $parser->get_short_title();
+  if (defined($short_title) and $short_title =~ m/\S/) {
+    push @manuals, $short_title;
+    push @all_manual_names, $short_title;
+    #print STDERR "$short_title\n";
+  } else {
+    push @all_manual_names, undef;
+  }
+}
+
+my $file_nr = 0;
+my @included;
+foreach my $file (@ARGV) {
+  my $outfile;
+  my $name = shift @all_manual_names;
+  if ($base_level == 0 and !$file_nr and defined($output)) {
+    $outfile = $output;
+  } else {
+    if (defined($name)) {
+      $outfile = Pod::Simple::Texinfo::_pod_title_to_file_name($name);
+      $outfile .= '.texi';
+    } else {
+      $outfile = $file;
+      $outfile =~ s/\.(pm|pod)$/.texi/i;
+    }
+  }
+  push @included, [$name, $outfile] if ($base_level > 0);
+  my $fh;
+  if ($outfile eq '-') {
+    $fh = *STDOUT;
+  } else {
+    open (OUT, ">$outfile") or die "Open $outfile: $!\n";
+    $fh = *OUT;
+  }
+  my $new = Pod::Simple::Texinfo->new();
+  $new->output_fh($fh);
+  $new->texinfo_sectioning_base_level($base_level);
+  if ($unnumbered_sections) {
+    $new->texinfo_sectioning_style('unnumbered');
+  }
+  if ($base_level > 0 and @manuals) {
+    $new->texinfo_internal_pod_manuals(address@hidden);
+  }
+  
+  $new->parse_file($file);
+  if ($outfile ne '-') {
+    close($fh) or die "Close $outfile: $!\n";
+  }
+  $file_nr++;
+}
+
+my $STDOUT_DOCU_NAME = 'stdout';
+if ($base_level > 0) {
+  $output = '-' if (!defined($output));
+  my $fh;
+  if ($output ne '-') {
+    open (OUT, ">$output") or die "Open $output: $!\n";
+    $fh = *OUT;
+  } else {
+    $fh = *STDOUT;
+  }
+  my $outfile_name = $output;
+  $outfile_name = $STDOUT_DOCU_NAME if ($outfile_name eq '-');
+  $outfile_name =~ s/\.te?x(i|info)?$//;
+  $outfile_name .= '.info';
+  print $fh '\input texinfo'."\n";
+  print $fh '@setfilename '
+    .Pod::Simple::Texinfo::_protect_text ($outfile_name)."\n\n";
+  print $fh "address@hidden Top\n";
+  # not escaped on purpose, user may want to use @-commands
+  print $fh "address@hidden $top\n\n";
+  foreach my $include (@included) {
+    my $file = $include->[1];
+    print $fh "address@hidden ".Pod::Simple::Texinfo::_protect_text 
($file)."\n";
+  }
+  print $fh "address@hidden";
+  
+  if ($output ne '-') {
+    close($fh) or die "Close $output: $!\n";
+  }
+}
+
+if (defined($output) and $output eq '-') {
+  close (STDOUT) or die "Close stdout: $!\n";
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+pod2texi - convert Pod files to a Texinfo
+
+=head1 SYNOPSIS
+
+  pod2texi [OPTION]... POD-FILE...
+
+=head1 DESCRIPTION
+
+Translate Pod to Texinfo.  If the base level is higher than 0, 
+a main manual including all the files is done otherwise all
+manuals are standalone (the default).
+
+=head1 OPTIONS
+
+=over
+
+=item B<--base-level>=I<NUM>
+
+Sets the level of the head1 commands.  1 is for the @chapter/@unnumbered 
+level.  If set to 0, the head1 commands level is still 1, but the output 
+manual is considered to be a standalone manual.  If not 0, the pod file is 
+rendered as a fragment of a Texinfo manual.
+
+=item B<--output>=I<NAME>
+
+Name for the first manual, or the main manual if there is a main manual.
+
+=item B<--unnumbered-sections>
+
+Use unnumbered sectioning commands (@unnumbered...) instead of the default
+numbered sectioning Texinfo @-commands (@chapter, @section...).
+
+=item B<--top>=I<TOP>
+
+Name of the C<@top> element for the main manual.  May contain Texinfo code.
+
+=item B<--version>
+
+Display version information and exit.
+
+=back
+
+=head1 SEE ALSO
+
+L<Pod::Simple::Texinfo>.  The Texinfo manual.  L<perlpod>.
+
+=head1 COPYRIGHT
+
+Copyright (C) 2011 Patrice Dumas
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+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.
+
+=head1 AUTHOR
+
+Patrice Dumas E<lt>address@hidden<gt>.
+
+=cut

Index: lib/Pod/Simple/Texinfo.pm
===================================================================
RCS file: lib/Pod/Simple/Texinfo.pm
diff -N lib/Pod/Simple/Texinfo.pm
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/Pod/Simple/Texinfo.pm   19 Jan 2012 20:03:12 -0000      1.1
@@ -0,0 +1,624 @@
+# See informations on this perl module at the end of the file, in the pod
+# section.
+
+package Pod::Simple::Texinfo;
+
+require 5;
+use strict;
+
+use Carp qw(cluck);
+#use Pod::Simple::Debug (3);
+use Pod::Simple::PullParser ();
+
+use Texinfo::Convert::NodeNameNormalization qw(normalize_node);
+use Texinfo::Parser qw(parse_texi_line);
+use Texinfo::Convert::Texinfo;
+use Texinfo::Common qw(protect_comma_in_tree);
+
+use vars qw(
+  @ISA $VERSION
+);
+
address@hidden = ('Pod::Simple::PullParser');
+$VERSION = '0.01';
+
+#use UNIVERSAL ();
+
+# Allows being called from the comand line as
+# perl -w -MPod::Simple::Texinfo -e Pod::Simple::Texinfo::go thingy.pod
+sub go { Pod::Simple::Texinfo->parse_from_file(@ARGV); exit 0 }
+
+my %head_commands_level;
+foreach my $level (1 .. 4) {
+  $head_commands_level{'head'.$level} = $level;
+}
+
+my @numbered_sectioning_commands = ('part', 'chapter', 'section', 
'subsection', 
+  'subsubsection');
+my @unnumbered_sectioning_commands = ('part', 'unnumbered', 'unnumberedsec', 
+  'unnumberedsubsec', 'unnumberedsubsubsec');
+
+my @raw_formats = ('html', 'HTML', 'docbook', 'DocBook', 'texinfo',
+                       'Texinfo');
+
+# from other Pod::Simple modules.  Creates accessor subroutine.
+__PACKAGE__->_accessorize(
+  'texinfo_sectioning_base_level',
+  'texinfo_man_url_prefix',
+  'texinfo_sectioning_style',
+  'texinfo_add_upper_sectioning_command',
+  'texinfo_internal_pod_manuals',
+);
+
+my $sectioning_style = 'numbered';
+#my $sectioning_base_level = 2;
+my $sectioning_base_level = 0;
+my $man_url_prefix = 'http://man.he.net/man';
+
+sub new
+{
+  my $class = shift;
+  my $new = $class->SUPER::new(@_);
+  $new->accept_targets(@raw_formats);
+  $new->preserve_whitespace(1);
+  $new->texinfo_sectioning_base_level ($sectioning_base_level);
+  $new->texinfo_man_url_prefix ($man_url_prefix);
+  $new->texinfo_sectioning_style ($sectioning_style);
+  $new->texinfo_add_upper_sectioning_command(1);
+  return $new;
+}
+
+sub run
+{
+  my $self = shift;
+
+  # In case the caller changed the formats
+  my @formats = $self->accept_targets();
+  foreach my $format (@formats) {
+    if (lc($format) eq 'texinfo') {
+      $self->{'texinfo_raw_format_commands'}->{$format} = '';
+      $self->{'texinfo_if_format_commands'}->{':'.$format} = '';
+    } else {
+      $self->{'texinfo_raw_format_commands'}->{$format} = lc($format);
+      $self->{'texinfo_if_format_commands'}->{':'.$format} = lc($format);
+    }
+  }
+  my $base_level = $self->texinfo_sectioning_base_level;
+  $base_level = 1 if ($base_level <= 1);
+  if ($self->texinfo_sectioning_style eq 'numbered') {
+    $self->{'texinfo_sectioning_commands'} = address@hidden;
+  } else {
+    $self->{'texinfo_sectioning_commands'} = address@hidden;
+  }
+  foreach my $heading_command (keys(%head_commands_level)) {
+    my $level = $head_commands_level{$heading_command} + $base_level -1;
+    if (!defined($self->{'texinfo_sectioning_commands'}->[$level])) {
+      $self->{'texinfo_head_commands'}->{$heading_command}
+        = $self->{'texinfo_sectioning_commands'}->[-1];
+    } else {
+      $self->{'texinfo_head_commands'}->{$heading_command}
+        = $self->{'texinfo_sectioning_commands'}->[$level];
+    }
+  }
+  $self->{'texinfo_internal_pod_manuals_hash'} = {};
+  my $manuals = $self->texinfo_internal_pod_manuals();
+  if ($manuals) {
+    foreach my $manual (@$manuals) {
+       $self->{'texinfo_internal_pod_manuals_hash'}->{$manual} = 1;
+    }
+  }
+
+  if ($self->bare_output()) {
+    $self->_convert_pod();
+  } else {
+    #my $string = '';
+    #$self->output_string( \$string );
+    $self->_preamble();
+    $self->_convert_pod();
+    $self->_postamble(); 
+    #print STDERR $string;
+  }
+}
+
+my $STDIN_DOCU_NAME = 'stdin';
+sub _preamble($)
+{
+  my $self = shift;
+
+  my $fh = $self->{'output_fh'};
+
+  my $short_title = $self->get_short_title();
+  if (defined($short_title) and $short_title =~ m/\S/) {
+    $self->{'texinfo_short_title'} = $short_title;
+  }
+
+  if ($self->texinfo_sectioning_base_level == 0) {
+    #print STDERR "$fh\n";
+    print $fh '\input texinfo'."\n";
+    my $setfilename;
+    if (defined($self->{'texinfo_short_title'})) {
+      $setfilename = _pod_title_to_file_name($self->{'texinfo_short_title'});
+    } else {
+      my $source_filename = $self->source_filename();
+      if (defined($source_filename) and $source_filename ne '') {
+        if ($source_filename eq '-') {
+          $setfilename = $STDIN_DOCU_NAME;
+        } else {
+          $setfilename = $source_filename;
+          $setfilename =~ s/\.(pod|pm)$//i;
+        }
+      }
+    }
+    if (defined($setfilename) and $setfilename =~ m/\S/) {
+      $setfilename = _protect_text($setfilename);
+      $setfilename .= '.info';
+      print $fh "address@hidden $setfilename\n\n"
+    }
+
+    my $title = $self->get_title();
+    if (defined($title) and $title =~ m/\S/) {
+      print $fh "address@hidden "._protect_text($title)."\n\n";
+    }
+    print $fh "address@hidden Top\n";
+    if (defined($self->{'texinfo_short_title'})) {
+       print $fh "address@hidden 
"._protect_text($self->{'texinfo_short_title'})."\n\n";
+    }
+  } elsif (defined($self->{'texinfo_short_title'})
+           and $self->texinfo_add_upper_sectioning_command) {
+      my $level = $self->texinfo_sectioning_base_level() - 1;
+      print $fh "address@hidden>{'texinfo_sectioning_commands'}->[$level] "
+         ._protect_text($self->{'texinfo_short_title'})."\n\n";
+  }
+}
+
+
+sub _output($$$)
+{
+  my $fh = shift;
+  my $accumulated_stack = shift;
+  my $text = shift;
+
+  if (scalar(@$accumulated_stack)) {
+    $accumulated_stack->[-1] .= $text;
+  } else {
+    print $fh $text;
+  }
+}
+
+sub _protect_text($)
+{
+  my $text = shift;
+  cluck if (!defined($text));
+  $text =~ s/(address@hidden)/address@hidden/g;
+  return $text;
+}
+
+sub _pod_title_to_file_name($)
+{
+  my $name = shift;
+  $name =~ s/\s+/_/g;
+  $name =~ s/::/-/g;
+  $name =~ s/[^\w\.-]//g;
+  $name = '_' if ($name eq '');
+  return $name;
+}
+
+sub _protect_comma($) {
+  my $texinfo = shift;
+  my $tree = parse_texi_line(undef, $texinfo);
+  $tree = protect_comma_in_tree(undef, $tree);
+  return Texinfo::Convert::Texinfo::convert($tree);
+}
+
+sub _is_title($)
+{
+# Regexp from Pod::Simple::PullParser
+  my $title = shift;
+  return ($title =~ m/^(NAME | TITLE | VERSION | AUTHORS? | DESCRIPTION | 
SYNOPSIS
+             | COPYRIGHT | LICENSE | NOTES? | FUNCTIONS? | METHODS?
+             | CAVEATS? | BUGS? | SEE\ ALSO | SWITCHES | ENVIRONMENT)$/sx);
+
+}
+
+sub _section_manual_to_node_name($$$)
+{
+  my $self = shift;
+  my $manual = shift;
+  my $section = shift;
+  my $base_level = shift;
+
+  if (defined($manual) and $base_level > 0
+      and _is_title($section)) {
+    return "$manual $section";
+  } else {
+    return $section;
+  }
+}
+
+sub _prepare_anchor($$)
+{
+  my $self = shift;
+  my $texinfo_node_name = shift;
+
+  $texinfo_node_name 
+     = $self->_section_manual_to_node_name($self->{'texinfo_short_title'},
+                                          $texinfo_node_name,
+                                          
$self->texinfo_sectioning_base_level);
+
+  my $node_tree = parse_texi_line(undef, $texinfo_node_name);
+  my $normalized_base = normalize_node($node_tree);
+  my $normalized = $normalized_base;
+  my $number_appended = 0;
+  while ($self->{'texinfo_nodes'}->{$normalized}) {
+    $number_appended++;
+    $normalized = "${normalized_base}-$number_appended";
+  }
+  my $node_name;
+  if ($number_appended) {
+    $texinfo_node_name = "$texinfo_node_name $number_appended";
+    $node_tree = parse_texi_line(undef, $texinfo_node_name);
+  }
+  $node_tree = protect_comma_in_tree(undef, $node_tree);
+  $self->{'texinfo_nodes'}->{$normalized} = $node_tree;
+  return Texinfo::Convert::Texinfo::convert($node_tree);
+}
+
+# from Pod::Simple::HTML general_url_escape
+sub _url_escape($)
+{
+  my $string = shift;
+
+  $string =~ s/([^\x00-\xFF])/join '', map sprintf('%%%02X',$_), unpack 'C*', 
$1/eg;
+     # express Unicode things as urlencode(utf(orig)).
+
+  # A pretty conservative escaping, behoovey even for query components
+  #  of a URL (see RFC 2396)
+
+  $string =~ 
s/([^-_\.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/sprintf('%%%02X',ord($1))/eg;
+   # Yes, stipulate the list without a range, so that this can work right on
+   #  all charsets that this module happens to run under.
+   # Altho, hmm, what about that ord?  Presumably that won't work right
+   #  under non-ASCII charsets.  Something should be done
+   #  about that, I guess?
+
+  return $string;
+}
+
+my %tag_commands = (
+  'F' => 'file',
+  'S' => 'w',
+  'I' => 'emph',
+  'B' => 'strong', # or @b?
+  'C' => 'code'
+);
+
+my %environment_commands = (
+  'over-text' => 'table @asis',
+  'over-bullet' => 'itemize',
+  'over-number' => 'enumerate',
+  'over-block' => 'quotation',
+);
+
+my %line_commands = (
+  'item-bullet' => 'item',
+  'item-text' => 'item',
+  'item-number' => 'item',
+  'encoding' => 'documentencoding'
+);
+
+# do not appear as parsed token
+# E entity/character
+sub _convert_pod($)
+{
+  my $self = shift;
+
+  my $fh = $self->{'output_fh'};
+
+  my ($token, $type, $tagname, $top_seen);
+
+  my @accumulated_output;
+  my @format_stack;
+  while($token = $self->get_token()) {
+    my $type = $token->type();
+    #print STDERR "* type $type\n";
+    #print STDERR $token->dump()."\n";
+    if ($type eq 'start') {
+      my $tagname = $token->tagname();
+      if ($head_commands_level{$tagname} or $tagname eq 'item-text') {
+        push @accumulated_output, '';
+      } elsif ($tag_commands{$tagname}) {
+        _output($fh, address@hidden, "address@hidden");
+      } elsif ($tagname eq 'Verbatim') {
+        print $fh '@verbatim'."\n";
+        push @format_stack, 'verbatim';
+      } elsif ($environment_commands{$tagname}) {
+        print $fh "address@hidden";
+      } elsif ($tagname eq 'for') {
+        my $target = $token->attr('target');
+        push @format_stack, $target;
+        if ($self->{'texinfo_raw_format_commands'}->{$target}) {
+          print $fh 
"address@hidden>{'texinfo_raw_format_commands'}->{$target}\n";
+        } elsif ($self->{'texinfo_if_format_commands'}->{$target}) {
+          print $fh 
"address@hidden>{'texinfo_if_format_commands'}->{$target}\n";
+        }
+      } elsif ($line_commands{$tagname}) {
+        print $fh "address@hidden ";
+      } elsif ($tagname eq 'L') {
+        my $linktype = $token->attr('type');
+        my $content_implicit = $token->attr('content-implicit');
+        #print STDERR " L: $linktype";
+        my ($url_arg, $texinfo_node, $texinfo_manual);
+        if ($linktype eq 'man') {
+          # NOTE: the .'' is here to force the $token->attr to ba a real
+          # string and not an object.
+          my $replacement_arg = $token->attr('to').'';
+          # regexp from Pod::Simple::HTML resolve_man_page_link
+          # since it is very small, it is likely that copyright cannot be
+          # claimed for that part.
+          $replacement_arg =~ /^([^(]+)(?:[(](\d+)[)])?$/;
+          my $page = $1;
+          my $section = $2;
+          if (defined($page) and $page ne '') {
+            $section = 1 if (!defined($section));
+            # it is unlikely that there is a comma because of _url_escape
+            # but to be sure there is still a call to _protect_comma.
+            $url_arg 
+              = _protect_comma(_protect_text(
+                  $self->texinfo_man_url_prefix
+                  ."$section/"._url_escape($page)));
+          } else {
+            $url_arg = '';
+          }
+          $replacement_arg = _protect_text($replacement_arg);
+          _output($fh, address@hidden, "address@hidden,,$replacement_arg}");
+        } else {
+          if ($linktype eq 'url') {
+            # NOTE: the .'' is here to force the $token->attr to be a real
+            # string and not an object.
+            $url_arg = _protect_comma(_protect_text($token->attr('to').''));
+          } elsif ($linktype eq 'pod') {
+            my $manual = $token->attr('to');
+            my $section = $token->attr('section');
+            $manual .= '' if (defined($manual));
+            $section .= '' if (defined($section));
+            #print STDERR "$manual/$section\n";
+            if (defined($manual)) {
+              if (! defined($section) or $section !~ m/\S/) {
+                if ($self->{'texinfo_internal_pod_manuals_hash'}->{$manual}) {
+                  $section = 'NAME';
+                } else {
+                  $section = 'Top';
+                }
+              }
+              if ($self->{'texinfo_internal_pod_manuals_hash'}->{$manual}) {
+                $texinfo_node =
+                 $self->_section_manual_to_node_name($manual, $section, 1);
+              } else {
+                $texinfo_manual = 
_protect_text(_pod_title_to_file_name($manual));
+                $texinfo_node = $section;
+              }
+            } elsif (defined($section) and $section =~ m/\S/) {
+              $texinfo_node = $section;
+            }
+            $texinfo_node = 'Top' if (!defined($texinfo_node));
+            $texinfo_node = _protect_comma(_protect_text($texinfo_node));
+          }
+          # for pod, 'to' is the pod manual name.  Then 'section' is the 
+          # section.
+        }
+        push @accumulated_output, '';
+        push @format_stack, [$linktype, $content_implicit, $url_arg, 
+                             $texinfo_manual, $texinfo_node];
+        #if (defined($to)) {
+        #  print STDERR " | $to\n";
+        #} else { 
+        #  print STDERR "\n";
+        #}
+        #print STDERR $token->dump."\n";
+      } elsif ($tagname eq 'X') {
+        print $fh '@cindex ';
+      }
+    } elsif ($type eq 'text') {
+      my $text;
+      if (!(@format_stack) or ref($format_stack[-1]) 
+          or ($format_stack[-1] ne 'verbatim' 
+              and 
!$self->{'texinfo_raw_format_commands'}->{$format_stack[-1]})) {
+        $text = _protect_text($token->text());
+      } else {
+        $text = $token->text();
+      }
+      _output($fh, address@hidden, $text);
+      my $next_token = $self->get_token();
+      if ($next_token) {
+        if ($next_token->type() eq 'start' and $next_token->tagname() eq 'X') {
+          print $fh "\n";
+        }
+        $self->unget_token($next_token);
+      }
+    } elsif ($type eq 'end') {
+      my $tagname = $token->tagname();
+      my $result;
+      if ($head_commands_level{$tagname} or $tagname eq 'item-text') {
+        my $command_result = pop @accumulated_output;
+        my $node_name = _prepare_anchor ($self, $command_result);
+        #print $fh "address@hidden $node_name\n";
+        if ($head_commands_level{$tagname}) {
+          my $command;
+          $command 
+            = $self->{'texinfo_head_commands'}->{$tagname};
+          print $fh "address@hidden $command_result\n";
+        } else {
+          print $fh "address@hidden $command_result\n";
+        }
+        print $fh "address@hidden";
+        print $fh "\n" if ($head_commands_level{$tagname});
+      } elsif ($tagname eq 'Para') {
+        print $fh "\n\n";
+        #my $next_token = $self->get_token();
+        #if ($next_token) {
+        #  if ($next_token->type() ne 'start' 
+        #      or $next_token->tagname() ne 'Para') {
+        #    print $fh "\n";
+        #  }
+        #  $self->unget_token($next_token);
+        #}
+      } elsif ($tag_commands{$tagname}) {
+        _output($fh, address@hidden, "}");
+      } elsif ($tagname eq 'Verbatim') {
+        pop @format_stack;
+        print $fh "\n".'@end verbatim'."\n\n";
+      } elsif ($environment_commands{$tagname}) {
+        my $tag = $environment_commands{$tagname};
+        $tag =~ s/ .*//;
+        print $fh "address@hidden $tag\n\n";
+      } elsif ($tagname eq 'for') {
+        my $target = pop @format_stack;
+        if ($self->{'texinfo_raw_format_commands'}->{$target}) {
+          print $fh "address@hidden 
$self->{'texinfo_raw_format_commands'}->{$target}\n";
+        } elsif ($self->{'texinfo_if_format_commands'}->{$target}) {
+          print $fh "address@hidden 
if$self->{'texinfo_if_format_commands'}->{$target}\n";
+        }
+      } elsif ($line_commands{$tagname}) {
+        print $fh "\n";
+      } elsif ($tagname eq 'L') {
+        my $result = pop @accumulated_output;
+        my $format = pop @format_stack;
+        my ($linktype, $content_implicit, $url_arg, 
+            $texinfo_manual, $texinfo_node) = @$format;
+        if ($linktype ne 'man') {
+          my $explanation;
+          if (defined($result) and $result =~ m/\S/ and !$content_implicit) {
+            $explanation = ' '. _protect_comma($result);
+          }
+          if ($linktype eq 'url') {
+            if (defined($explanation)) {
+              _output($fh, address@hidden, 
+                       "address@hidden,$explanation}");
+            } else {
+              _output($fh, address@hidden, 
+                       "address@hidden");
+            }
+          } elsif ($linktype eq 'pod') {
+            if (defined($texinfo_manual)) {
+              $explanation = '' if (!defined($explanation));
+              _output($fh, address@hidden,
+                       "address@hidden,$explanation,, $texinfo_manual}");
+            } elsif (defined($explanation)) {
+              _output($fh, address@hidden,
+                       "address@hidden,$explanation}");
+            } else {
+              _output($fh, address@hidden,
+                       "address@hidden");
+            }
+          }
+        }
+      } elsif ($tagname eq 'X') {
+        my $next_token = $self->get_token();
+        if ($next_token) {
+          if ($next_token->type() eq 'text') {
+            print $fh "\n";
+          }
+          $self->unget_token($next_token);
+        }
+      }
+    }
+  }
+}
+
+sub _postamble($)
+{
+  my $self = shift;
+
+  my $fh = $self->{'output_fh'};
+  if ($self->texinfo_sectioning_base_level == 0) {
+    #print STDERR "$fh\n";
+    print $fh "address@hidden";
+  }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Pod::Simple::Texinfo - format Pod as Texinfo
+
+=head1 SYNOPSIS
+
+  # From the command like
+  perl -MPod::Simple::Texinfo -e Pod::Simple::Texinfo::go thingy.pod
+
+  # From perl
+  my $new = Pod::Simple::Texinfo->new;
+  $new->texinfo_sectioning_style('unnumbered');
+  my $from = shift @ARGV;
+  my $to = $from;
+  $to =~ s/\.(pod|pm)$/.texi/i;
+  $new->parse_from_file($from, $to);
+
+=head1 DESCRIPTION
+
+This class is for making a Texinfo rendering of a Pod document.
+
+This is a subclass of L<Pod::Simple::PullParser> and inherits all its
+methods (and options).
+
+It supports producing a standalone manual per Pod (the default) or 
+render the Pod as a chapter, see L</texinfo_sectioning_base_level>.
+
+=head1 METHODS
+
+=over
+
+=item texinfo_sectioning_base_level
+
+Sets the level of the head1 commands.  1 is for the @chapter/@unnumbered 
+level.  If set to 0, the head1 commands level is still 1, but the output 
+manual is considered to be a standalone manual.  If not 0, the pod file is 
+rendered as a fragment of a Texinfo manual.
+
+=item texinfo_man_url_prefix
+
+String used as a prefix for man page urls.  Default 
+is C<http://man.he.net/man>.
+
+=item texinfo_sectioning_style
+
+Default is C<numbered>, using the numbered sectioning Texinfo @-commands
+(@chapter, @section...), any other value would lead to using unnumbered
+sectioning command variants (@unnumbered...).
+
+=item texinfo_add_upper_sectioning_command
+
+If set (the default case), a sectioning command is added at the beginning 
+of the output for the whole document, using the module name, at the level
+above the level set by L<texinfo_sectioning_base_level>.  So there will be
+a C<@part> if the level is equal to 1, a C<@chapter> if the level is equal
+to 2 and so on and so forth.  If the base level is 0, a C<@top> command is 
+output instead.
+
+=back
+
+=head1 SEE ALSO
+
+L<Pod::Simple>. L<Pod::Simple::PullParser>. The Texinfo manual.
+
+=head1 COPYRIGHT
+
+Copyright (C) 2011 Patrice Dumas
+
+This library is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+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.
+
+C<_url_escape> is C<general_url_escape> from L<Pod::Simple::HTML>.
+
+=head1 AUTHOR
+
+Patrice Dumas E<lt>address@hidden<gt>.  Parts from L<Pod::Simple::HTML>.
+
+=cut

Index: t/Pod-Simple-Texinfo.t
===================================================================
RCS file: t/Pod-Simple-Texinfo.t
diff -N t/Pod-Simple-Texinfo.t
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ t/Pod-Simple-Texinfo.t      19 Jan 2012 20:03:13 -0000      1.1
@@ -0,0 +1,15 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl 
Pod-Simple-Texinfo.t'
+
+#########################
+
+# change 'tests => 1' to 'tests => last_test_to_print';
+
+use Test::More;
+BEGIN { plan tests => 1 };
+use Pod::Simple::Texinfo;
+ok(1); # If we made it this far, we're ok.
+
+#########################
+
+



reply via email to

[Prev in Thread] Current Thread [Next in Thread]