#!/usr/bin/perl use strict; use warnings; use Data::Dumper qw/Dumper/; my $outfile= my $infile= $ARGV[0]; $outfile =~ s/\.org$/.pod/; my $f_in; if ($infile) { print "* Processing $infile => $outfile\n"; open $f_in , "<", "$infile" ; } else { $outfile="/tmp/test.pod"; print "* Processing __DATA__ => $outfile\n"; $f_in=\*DATA; } open my $f_out, ">", "$outfile"; my $OUT; my $r_begin_src='^\s*#\+BEGIN_SRC (\w*)\s*$'; my $r_end_src = '^\s*#\+END_SRC\s*$'; print $f_out "\n=encoding utf8\n\n"; #--- First pass while(<$f_in>) { #--- Codeblock? if ( /$r_begin_src/ .. /$r_end_src/) { s/($r_end_src|$r_begin_src)/\n/; $_=" $_"; # add indentation s#\s*Listing{(\w+)}#listing_grep($1)#gie; } else { #--- Heading? if (s/^(\*+)(\s.*)/"\n=head".length($1)."$2\n"/e ) { #--- Heading == "__DATA__" ? last if $2 =~ /^\s*__DATA__\s*$/; # stop parsing } else { #--- Textbody s/^\s+(\S)/$1/; # delete indentation s/^\s+$/\n/; # delete empty lines convert_markup(); } } $OUT.=$_; } listing_dump(); #--- Second pass $OUT =~ s#Listing{(\w+)}#listing_ref($1)#gie; #--- Output print $f_out $OUT; ##--- Process pod-file #my $do=`make.pl $outfile`; exit; # ---------------------------------------- sub convert_markup { my $in=$_; my $out; my $notPOD=0; # flipflop #--- ignore POD markups for (split /([CBIEZ]<.*?>)/,$in){ if ( $notPOD ^= 1 ) { # odd => not Pod #--- translate s#/(.+?)/#I<$1>#g; # / -> Italic s#\*(.+?)\*#B<$1>#g; # * -> Bold # s#_(.+?)_#I<$1>#g; # _ -> Underline #--- add markup DWIM s#(?)# L<$1> #g; # -> L s#([\$\%\@\&]\w+)#C<$1>#g; # -> C<$var> } $out.=$_; } $_=$out; } # ---------------------------------------- # name and refrence listings by name # "LISTING{label}" in code -> incremented number # "LISTING{label}" in text -> reference code listing # TODO: # * support org reference markup instead # like <