#!/usr/bin/perl ############################################################################### # htmlizer for a text file in unicode UTF-8 # coder: tuan pham # developed: 07/31/01 (hard coded for "In the Jaws of History" # and "The Chinese Mosaic") # last updated: 12/28/02 (added -t -a) # usage: htmlizer.pl *.txt # the output will be *.html # -t="Put the title here" (in double quotes) # -a="Put the author's name here" (in double quotes) # Note: these options are recommended to use by other scripts to match the titles # and authors for each text file #-------------------------oOo-------------------------- # global vars # $input : content of the current input file $input; $TITLE=""; # text title $NAME=""; # author local($/)=undef; # lousy and lazy way to parse text main(); #-------------------------oOo-------------------------- sub main { my @A_PARA; while ( $NextFile=shift(@ARGV) ) { @A_PARA=split("=",$NextFile); if ("-t" eq @A_PARA[0]) { @A_PARA[1]=~s/\"//; # removes " $TITLE=@A_PARA[1]; } else { if ( open (TEMP,$NextFile) ) { # $input=""; # clear buffer, jfd $input=; # get the file's content make_paragraph(); make_html(); $FileName=$NextFile; $FileName=~s/\.([^\.]+)/\.html/; open(OUTFILE,"> $FileName"); print OUTFILE "$input"; close(OUTFILE); close(TEMP); } } } } #-------------------------oOo-------------------------- # parse the input text to put

tags # and   after . sub make_paragraph { # add   # temporarily, this damned line doesn't work! $input=~s/\r//g; $input=~s/(\.) ([A-Z])/$1  $2/g; # add

tags $input=~s/\n+\s+/\n

\n  /g; } #-------------------------oOo-------------------------- # adding the html header sub make_html { $header="\n". "\n". ""."\n". #""."\n". #"A Chinese Mosaic - Bette Bao Lord #- Translated to Vietnamese by Phan Le Dung (c) 1992"."\n". "$TITLE"."\n". ""."\n\n". ""."\n\n". "\n". ""."\n". ""."\n". ""."\n". "
"."\n". ""."\n\n"; $tail= "
"."\n". ""."\n". ""; $input=$header.$input.$tail; } #-------------------------oOo--------------------------