How can I convert plain text to HTML (preferably using Perl)?
Is there a way to take a plain text file and convert it to a simple HTML?
开发者_StackOverflow中文版A couple of 'sophisticated' stuff that will be great
- identify hyper-links.
- identify (tab delimited) tables.
UPDATE
I just found this HTML::FromText. Checking to see if it meets my needs...
Text::Markdown
Stack Overflow already uses Markdown because it's the best mark-up language targeted to general text to HTML conversion. Named links are explained in the editing help.
Try HTML::TextToHTML:
From the command line:
txt2html I<arguments>
From 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)
You can use lynx with -dump option to achieve that:
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>';
精彩评论