#!/usr/bin/perl -w # # t2h v0.03 --crb3 09feb01/20feb01/04mar02 # started out with fanfiction.net stream. then expanded switch-options # to allow for full pages, set up the title nicely, etc.; still have # yet to get it to tear off mail-headers. # this tool doesn't do all the pretty tabling done by the various # tools on the Win32 side (ws2html etc), it just converts from # a r.a.a.c-style text posting to something that can be fed to # ff.net, or (full-page) posted on an internal server. # # --crb3 04mar04: if given filename doen't exist, try tacking ".txt" # onto it and look for that. # $debug = 0; # get chatty, show internal results # # these are command-line switches # $para=1; # use
paragraphing? $hardln=0; # convert \n toparagraphs toggle (default) -a'AUTHOR' insert author's name\n" if($#ARGV < 0); for($nm=$b=0;$b<=$#ARGV;$b++){ if($ARGV[$b] =~ /^\-p/i){ # P: use
paragraphs $para ^= 1; }elsif($ARGV[$b] =~ /^\-h/i){ # H: keep hard linebreaks $hardln ^= 1; }elsif($ARGV[$b] =~ /^\-f/i){ # F: emit full HTML page $fullpage ^= 1; $template = $ARGV[$b]; chomp $template; $template =~ s/^\-f\=?//; if($template ne ""){ $tpt=1; # is a template filename print "using template $template... "; }else{ print "using internal template... "; } }elsif($ARGV[$b] =~ /^\-a/i){ # A: insert author's name $author = $ARGV[$b]; $author =~ s/^\-a\=?//i; print "author = $author\n" if $debug; }elsif($nm==0){ $infile = $ARGV[$b]; $nm++; print "infile = $infile\n" if $debug; }elsif($nm==1){ $outfile = $ARGV[$b]; $nm++; print "outfile = $outfile\n" if $debug; }else{ warn "Extra arg ignored: $ARGV[$b]\n"; } } print "nm=$nm\n" if $debug; if($nm<2){ $outfile = $infile; $outfile =~ s/\.txt//i; } $infile .= ".txt" unless(-e $infile); $outfile .= ".html" unless $outfile =~ /\.html?$/i; die "oops, infile and outfile are both $infile\n" if $infile eq $outfile; print "Converting $infile to $outfile"; print " full" if $fullpage; print "\n"; open(IFIL,"<$infile") or die "Can't open infile $infile\n"; open(OFIL,">$outfile") or die "Can't make outfile $outfile\n"; print OFIL "
" if $para;
$firstln=1;
while(defined($inline=
";
}else{
$inline = "
";
}
$blank=1;
}
$inline =~ s#(^|[\s,.!?"'])\_\*(\w)#$1$2#g; # _*bolditalic*_
$inline =~ s#(\w[,.!?"']*)\*\_([\s.,!?"']|$)#$1$2#g;
$inline =~ s#(^|[\s.,!?"'])\_(\w)#$1$2#g; # _italic_
$inline =~ s#(\w[,.!?"']*)\_([\s.,!?"']|$)#$1$2#g;
#
# --crb3 02dec01: special coding for title...
#
$inline =~ s#(^|[\s.,!?"'])\*\!\*(\w)#$1
| #PAYLOAD# |