in reply to Text to HTML convert.

I don't have any pre-dev'd solution for you.. however may I reccomend the following (just off the top of my head)

use strict; use warnings; #Just listing a few bad chars (I think hehe) for example my %escap_chars = ( '>' => '&gt;', '<' => '&lt;}; #Text for email would either be in array or scalar I'll presume my $email_text = 'Hi this is a math email 2 + 2 = 4. and 4 > 5'; #if scalar foreach my $key (keys(%escape_chars)) { $email_text =~ s/$key/$escape_chars{$key}/g; } # if each line of email is in an array foreach my $key (keys(%escape_chars)) { s/$key/$escape_chars{$key}/g for(@email_text); }
Just as a method for dropping characters that need escaping and changing to their HTML counterpart. I believe (don't know for sure obviously) that this is something like what you would need to do. I believe there is a module that has a http link regex that you can use. Also just as a feature thought. you could test the links you find to make sure they are valid (read: not broken)links..


Grygonos

Replies are listed 'Best First'.
Re^2: Text to HTML convert.
by muntfish (Chaplain) on Oct 07, 2004 at 15:07 UTC

    You also need to escape the & (ampersand) character, as this is also a reserved char in HTML.

    I dug this code out of one of my old scripts. I'm not saying it's perfect, by any means. In particular it can treat things as URLs when they are not well formed.

    while(<F>) { s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; s!(https?://[-~@=_%;&/\+\.\?a-zA-Z0-9]+)!<a href="$1">$1</a>!g; s!([-_\+\.a-zA-Z0-9]+@[-_\+\.a-zA-Z0-9]+)!<a href="mailto:$1">$1<\ +/a>!g; # then print $_, or whatever you want to do with it }

    But I hope it helps you get started. Other monks are (as always) welcome to suggest improvements or point out flaws!

    Update: The above assumes the whole output is wrapped in  <pre> tags, otherwise original paragraph/line formatting won't be preserved.

    Update 2: Actually, the CPAN module HTML::FromText as suggested by jeffa looks like a better idea. I'll have to look into it myself...


    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&