From 07c4a7b047a1f967d687afade4706412e3865a42 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 7 Jan 2017 16:58:48 -0800 Subject: [PATCH] Markdown.pl: auto linkify without '<'...'>' Do not require the surrounding '<'...'>' to automatically turn an https? or ftps? address into a real link. Additionally, recognize [RFC...] and turn those into the appropriate links. This is more in line with how other processors handle Markdown to html conversions. Signed-off-by: Kyle J. McKay --- Markdown.pl | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Markdown.pl b/Markdown.pl index d17552a..a062028 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -1288,12 +1288,12 @@ sub _EncodeBackslashEscapes { sub _DoAutoLinks { - my $text = shift; + local $_ = shift; - $text =~ s{<((https?|ftp):[^'\042>\s]+)>}{<$1>}gi; + s{<((https?|ftps?):[^'\042>\s]+)>}{<$1>}gi; # Email addresses: - $text =~ s{ + s{ < (?:mailto:)? ( @@ -1303,10 +1303,16 @@ sub _DoAutoLinks { ) > }{ - "<"._EncodeEmailAddress( _UnescapeSpecialChars($1) ).">"; + _EncodeEmailAddress(_UnescapeSpecialChars($1), "<", ">"); }egix; - return $text; + # (kjm) I don't do "x" patterns + s{(?])(?$1}sog; + s{(?RFC$1$2]}sog; + + return $_; } @@ -1326,7 +1332,9 @@ sub _EncodeEmailAddress { # mailing list: # - my $addr = shift; + my ($addr, $prefix, $suffix) = @_; + $prefix = "" unless defined($prefix); + $suffix = "" unless defined($suffix); srand; my @encode = ( @@ -1355,8 +1363,9 @@ sub _EncodeEmailAddress { $char; }gex; - $addr = qq{$addr}; - $addr =~ s{">.+?:}{">}; # strip the mailto: from the visible part + # strip the mailto: from the visible part + (my $bareaddr = $addr) =~ s/^.+?://; + $addr = qq{$prefix$bareaddr$suffix}; return $addr; }