"Fossies" - the Fresh Open Source Software Archive

Member "Grutatxt-2.20/pod2grutatxt" (13 Mar 2019, 2648 Bytes) of package /linux/www/Grutatxt-2.20.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 
    3 # pod2grutatxt - Converts POD format to Grutatxt
    4 # http://triptico.com/software/grutatxt.html
    5 #
    6 # released under the public domain
    7 
    8 use Pod::Parser;
    9 
   10 package GrutatxtParser;
   11 use base 'Pod::Parser';
   12 
   13 my $_deferred_title = 0;
   14 
   15 sub _build_header {
   16     my $title   = shift;
   17     my $char    = shift;
   18 
   19     my $s = $title;
   20     $s =~ s/./$char/g;
   21 
   22     return $title . "\n" . $s . "\n\n";
   23 }
   24 
   25 
   26 sub command {
   27     my ($parser, $command, $paragraph, $line_num) = @_;
   28 
   29     my $out_fh = $parser->output_handle();
   30     my $out = $parser->interpolate($paragraph, $line_num);
   31 
   32     if ($command =~ /^head(\d)/) {
   33         my $c = ('=', '-', '~', '~', '~')[$1];
   34         my ($t) = ($out =~ /^([^\n]+)/s);
   35 
   36         if ($t eq 'NAME') {
   37             $_deferred_title = 1;
   38             $out = '';
   39         }
   40         else {
   41             $out = _build_header($t, $c);
   42         }
   43     }
   44     elsif ($command eq 'item') {
   45         $out = ' * ' . $out;
   46     }
   47     elsif ($command eq 'over') {
   48         $out = '';
   49     }
   50     elsif ($command eq 'for') {
   51         my @w = split(/\s+/, $out);
   52         my $k = shift(@w);
   53 
   54         $out = '<<' . $k . "\n" . join(' ', @w) . "\n>>\n";
   55     }
   56     elsif ($command eq 'begin') {
   57         my @w = split(/\s+/, $out);
   58         my $k = shift(@w);
   59 
   60         $out = '<<' . $k . "\n";
   61     }
   62     elsif ($command eq 'end') {
   63         $out = ">>\n";
   64     }
   65 
   66     print $out_fh $out;
   67 }
   68 
   69 sub verbatim {
   70     my ($parser, $paragraph, $line_num) = @_;
   71     ## Format verbatim paragraph; sample actions might be:
   72     my $out_fh = $parser->output_handle();
   73     print $out_fh $paragraph;
   74 }
   75 
   76 sub textblock {
   77     my ($parser, $paragraph, $line_num) = @_;
   78     ## Translate/Format this block of text; sample actions might be:
   79     my $out_fh = $parser->output_handle();
   80     my $expansion = $parser->interpolate($paragraph, $line_num);
   81 
   82     if ($_deferred_title) {
   83         my ($t) = ($expansion =~ /^([^\n]+)/s);
   84         $expansion = _build_header($t, '=');
   85         $_deferred_title = 0;
   86     }
   87 
   88     print $out_fh $expansion;
   89 }
   90 
   91 sub interior_sequence {
   92     my ($parser, $seq_command, $seq_argument) = @_;
   93 
   94     ## Expand an interior sequence; sample actions might be:
   95     return "*$seq_argument*"     if ($seq_command eq 'B');
   96     return "`$seq_argument'"     if ($seq_command =~ /^(C|F)$/);
   97     return "_${seq_argument}_"   if ($seq_command eq 'I');
   98     return $seq_argument;
   99 }
  100 
  101 package main;
  102 
  103 ## Create a parser object and have it parse file whose name was
  104 ## given on the command-line (use STDIN if no files were given).
  105 $parser = new GrutatxtParser();
  106 $parser->parse_from_filehandle(\*STDIN)  if (@ARGV == 0);
  107 for (@ARGV) { $parser->parse_from_file($_); }
  108 
  109 exit 0;