Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Converting to html tags...

by Tomte (Priest)
on Mar 10, 2004 at 17:07 UTC ( [id://335518]=note: print w/replies, xml ) Need Help??


in reply to Converting to html tags...

this is based on slashcodes html-cleaning sub, any error big or small is my fault. use with caution, may produce "transitional" html ;), extracts links and uses the hostname as link-text, allows links in the form

[link-text=url]
needs URI.

sub bb2html { $introtext =~ s/<.*?>//gi; # no html allowed, no math either ;) $introtext =~ s/\n\s*\n/\n\n/gi; $introtext =~ s/\n\n\n/\n\n/gi; $introtext =~ s/&nbsp;/ /gi; $introtext =~ s/\n/<BR>/gi; $introtext =~ s/(?<=BR>)(http|https|ftp|gopher|telnet)/ $1/gi; $introtext =~ s/\s+$//gi; $introtext =~ s/^\s+//gi; $introtext .= " "; $introtext =~ s/\{/%7B/gi; $introtext =~ s/\}/%7D/gi; $introtext =~ s/\[([^A\]]{1,2})\s+.*?\]/\[$1\]/gi; $introtext =~ s/\[\/([^A\]]{1,2})\s+.*?\]/\[\/$1\]/gi; $introtext =~ s/\[([^A\]]{1,2})\]/<$1>/gi; $introtext =~ s/\[\/([^A\]]{1,2})\]/<\/$1>/gi; $introtext =~ s{\[([^=\]]+?)=(http|https|ftp|gopher|telnet)://([$ +URI::uric#]+?)\]}{ my($text, $proto, $url) = ($1, $2, $3); my $extra = ''; $extra = $1 if $url =~ s/([?!;:.,']+)$//; $extra = ')' . $extra if $url !~ /\(/ && $url =~ s/\)$//; qq[<A TARGET="_blank" HREF="$proto://$url">$text</A>$extra]; }ogie; $introtext =~ s{(?<!["=>])(http|https|ftp|gopher|telnet)://([$URI +::uric#]+)}{ my($proto, $url) = ($1, $2); my $extra = ''; my $host_capture = $url; $host_capture =~ s/([^\/]*).*/$1/i; #$host_capture = substr($host_capture,0,17) . "..." if length( +$host_capture)>20; $extra = $1 if $url =~ s/([?!;:.,']+)$//; $extra = ')' . $extra if $url !~ /\(/ && $url =~ s/\)$//; qq[<A TARGET="_blank" HREF="$proto://$url">$host_capture</A>$e +xtra]; }ogie; return $introtext; }

At least something to play with...

regards,
tomte


Hlade's Law:

If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.

Log In?
Username:
Password:

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

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

    No recent polls found