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

HTML::FromText totally wrecks cyrillic letters =/. Seems, like I'll do it rather myself

Will keep You informed

Update:

I managed to make it this way:

use HTML::FromText; use HTML::Entities; my $text=shift; my $t2h = HTML::FromText->new({ paras => 0, blockcode => 0, tables => 0, bullets => 0, numbers => 0, urls => 1, email => 1, bold => 0, underline => 0, metachars => 0, }); $text=encode_entities($text, '<>&"'); my $html=$t2h->parse($text);

Replies are listed 'Best First'.
Re^3: Text to HTML convert.
by tachyon (Chancellor) on Oct 08, 2004 at 03:06 UTC

    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