in reply to Text to HTML convert.

Well, there is always HTML::FromText. Should this be enough for you, you can always run the output through HTML::Tidy.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Text to HTML convert.
by FoxtrotUniform (Prior) on Oct 07, 2004 at 18:58 UTC
Re^2: Text to HTML convert.
by SiGiN (Initiate) on Oct 07, 2004 at 17:29 UTC

    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);

      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