Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert plain text to HTML (preferably using Perl)?

Tags:

html

perl

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

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...

like image 883
David B Avatar asked Oct 19 '10 16:10

David B


People also ask

How do I make HTML text Plain?

replace(/<[^>]*>/g, '') This method is a simple and efficient way to remove the tags from the text. This method uses the string method . replace(old value,new value) which replaces the HTML tag values with the empty string.


2 Answers

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.

like image 51
daxim Avatar answered Oct 07 '22 15:10

daxim


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)
like image 30
Pedro Silva Avatar answered Oct 07 '22 14:10

Pedro Silva