tags:

views:

95

answers:

2

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

+2  A: 

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)
Pedro Silva
Thanks, that's very helpful. One thing I'm missing: how can I control the names hyperlinks are given? currently it just shows the full URL. I want all inks to be simply displayed as 'link' in the text. Can I do that? I read about the link dictionary but didn't really get it. I don't mind altering the text files somehow to do this explicitly.
David B
almost forgot: +1. But I must admit I can't make the dictionaries work, so I;ll probably goo with MultiMarkdown.
David B
I can't make link dictionaries work either. I think any markdown solution is probably the right one. In defense of my answer, you did ask for text->html, not marked-up text->html.
Pedro Silva
+1  A: 

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.

daxim
How do I add a table in Markdown? Also, do I have to read the entire file into a string and pass it at once or do it line by line?
David B
http://search.cpan.org/perldoc?Text::MultiMarkdown
David B
Tables are not in the [Markdown syntax](http://daringfireball.net/projects/markdown/syntax), but in the [MultiMarkdown syntax](http://fletcherpenney.net/multimarkdown/users_guide/multimarkdown_syntax_guide/#tables).
daxim
see related: http://stackoverflow.com/questions/3978764
David B