From 81a6c5203299168384995e63a8cb1594abaf6399 Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Thu, 7 Aug 2014 16:06:03 +0400 Subject: [PATCH] Initial uri parsing support --- II/T.pm | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/II/T.pm b/II/T.pm index 895f284..47e47bf 100644 --- a/II/T.pm +++ b/II/T.pm @@ -167,13 +167,40 @@ sub pre { $post =~ s/>(.+)/>$1<\/font>/g; $post =~ s/--/—/g; $post =~ s/.?\*(.+)\*.?/ $1<\/b> /g; + + # URI's parsing + if ( $post =~ m!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?! ) { + + print "\n2:=$2=\n"; + # Images + if ( $9 !=~ m/.+\.(jpg|png|gif)/ ) { + $post + =~ s/(https?:\/\/.+)/$1<\/a>/g; + } + elsif ( $9 =~ m/.+\.((jpg|png|gif)|(JPG|PNG|GIF))/ ) { + $post + =~ s/(https?:\/\/.+\.(jpg|png|gif))/<\/a>/g; + $post + =~ s/(https?:\/\/.+\.(JPG|PNG|GIF))/<\/a>/g; + } + elsif ( $2 eq 'ii' ) { + # ii uri + $post =~ s/ii:\/\/(.+\.\d{1,4}),?.+/$1<\/a>/g; + $post =~ s/ii:\/\/(.{20})/$1<\/a>/g; + } + } + $post =~ s/^$/
\n/g; $post =~ s/(.?)\n/$1
\n/g; $post =~ s/\*(.+)/
  • $1<\/li>\n/g; - $post - =~ s/(https?:\/\/.+\.(jpg|png|gif))/<\/a>/g; - $post - =~ s/(https?:\/\/.+\.(JPG|PNG|GIF))/<\/a>/g; + + + # Url + # use Regexp::Common "URI"; + # $post =~ s( ($RE{URI}{HTTP}) ) + # ($1)gx; + + # Not are regexp parsing my $pre = 0; my $txt; @@ -192,6 +219,7 @@ sub pre { $txt .= $line; } close $fh; + return $txt; }