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

Something like this is probably all you need

sub get_text { my ($text, $cols) = @_; $cols ||= 80; require Text::Wrap; $Text::Wrap::columns = $cols; # tabs to 4 spaces $text =~ s/\t/ /g; # now wrap it $text = Text::Wrap::wrap('','',$text); # iterate over chunks, escaping HTML and linking $text =~ s{(\S+)} { local $_ = $1; m/^(?:http|ftp)/ ? qq!<a href="$_">!.escapeHTML($_).qq +!</a>! : m/^www\./ ? qq!<a href="http://$_">!.escapeHTML +($_).qq!</a>! : m/^[^@]+@[^@]/ ? qq!<a href="mailto:$_">!.escapeHTML +($_).qq!</a>! : escapeHTML($_); }ge; # fix whitespace (and newlines if not using pre tags) $text =~ s/( {2,})/"&nbsp;" x length $1/eg; #$text =~ s/\n/<br>\n/g; # wrap in pre tags $text = '<pre>' . $text . '</pre>'; return $text; } sub escapeHTML { my ( $escape ) = @_; return '' unless defined $escape ; $escape =~ s/&/&amp;/g; $escape =~ s/"/&quot;/g; $escape =~ s/</&lt;/g; $escape =~ s/>/&gt;/g; $escape =~ s/([^\000-\177])/'&#' . (sprintf "%3d", ord $1) . ';'/e +g; return $escape; }

cheers

tachyon