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