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/&/&/g; s/</</g; s/>/>/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...
In reply to Re^2: Text to HTML convert.
by muntfish
in thread Text to HTML convert.
by SiGiN
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |