Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Text to HTML convert.

by muntfish (Chaplain)
on Oct 07, 2004 at 15:07 UTC ( [id://397327]=note: print w/replies, xml ) Need Help??


in reply to Re: Text to HTML convert.
in thread Text to HTML convert.

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$&

Replies are listed 'Best First'.
Re^3: Text to HTML convert.
by jeffa (Bishop) on Oct 07, 2004 at 16:50 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://397327]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-19 10:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found