How to convert plain text to HTML (preferably with Perl)?

Is there a way to take a plain text file and convert it to plain HTML?

Some β€œcomplicated” things that will be great

  • identify hyperlinks.
  • Identify tab delimited tables.

UPDATE

I just found this HTML :: FromText . Check to see if it fits my needs ...

+4
source share
3 answers

Text::Markdown

Stack overflow already uses Markdown, because it is the best markup language for general text to HTML conversion. Named links are described in the help.

+3
source

Try HTML :: TextToHTML :

From the command line:

 txt2html I<arguments> 

From the scripts:

 use HTML::TextToHTML; # create a new object my $conv = new HTML::TextToHTML(); # convert a file $conv->txt2html(infile=>[$text_file], outfile=>$html_file, title=>"Wonderful Things", mail=>1, ]); # reset arguments $conv->args(infile=>[], mail=>0); # convert a string $newstring = $conv->process_chunk($mystring) 
+2
source

You can use lynx with the -dump option to achieve this:

 use File::Temp; sub html2Txt { my $html = shift; my $html_file = File::Temp->new(SUFFIX => '.html'); print $html_file $html; close $html_file; return scalar `lynx -dump $html_file 2> /dev/null`; } print html2Txt '<h1>Hi there!</h1> Testing <p>Testing</p>'; 
0
source

All Articles