mhonarc-users

hyperlinked url modification

1998-10-12 13:08:31
I'd like to offer a minor change to the way mhonarc hyperlinks urls
detected in the body of a message.  

The way it currently hyperlinks urls includes includes often used
punctuation in the context of a sentence.  Also, query strings aren't
usually hyperlinked appropriately.  

All of the changes mentioned here only afffect the  file mhtxtplain.pl

$HUrlExp        = $Url . q%[^\s\(\)\|<>"']*[^\.;,"'\|\[\]\(\)\s<>\?\!]%;

This allows query stings such as
http://www.infoseek.com/Titles?qt=hello+world&col=WW&sv=IS&lk=noframes,
which are currently broken off at the first ampersand.  

This also removes trailing common sentence punctuation such as
commmas, periods, exclamations and question marks without them being
included in the url.  I noticecd that this was a problem with the
following example:  "Have you been to http://www.yahoo.com?";

I'm not sure what the implications are, but I did notice that when the
MIMEARG for text/plain is "keepspace" this doesn't seem to work
properly  -- the hyperlinks aren't recognized because the blank spaces
have been converted to &nbsp; .  A dirty fix for this would be...



sub preserve_space modified to replace the two &nbsp; s between A and
HREF to "real" blank spaces...

##
## BEGIN preserve_space dirty fix

sub preserve_space {
    my($str) = shift;

    1 while
    $str =~ s/^([^\t]*)(\t+)/$1 . ' ' x (length($2) * 8 - length($1) %
8)/e;
    $str =~ s/ /\&nbsp;/g;
    $str =~ s/A\&nbsp;\&nbsp;HREF/A HREF/g; # ADDED BY EMERY
    $str;
}

##
## END preserve_space dirty fix

And, modify the order of the url detection and conversion....

##
## BEGIN filter modification

sub filter {

# ...[bottom part: leading stuff omitted]...

# # Convert URLs to hyperlinks MOVED HERE by EMERY

    $data =~ s@($HUrlExp)@<A $target HREF="$1">$1</A>@gio
        unless $nourl;


    ## Check if using nonfixed font
    if ($nonfixed) {
        $data =~ s/(\r?\n)/<br>$1/g;


        if ($keepspace) {

            $data =~ s/^(.*)$/&preserve_space($1)/gem;

        }
    } else {
        $data = "<PRE>\n" . $data . "</PRE>\n";
    }

## Convert URLs to hyperlinks MOVED to above by EMERY
#    $data =~ s@($HUrlExp)@<A $target HREF="$1">$1</A>@gio
#       unless $nourl;

    ($data);
}


##
## END filter modification

==
 H.  E m e r y   F o r d            emery_ford(_at_)bigfoot(_dot_)com
 home:(301)5870957   work:(301)9796270   page:(301)7011294
 
 "I am not afraid of death, if that is what the 
  investigative apparatus of the NKVD, in glaring 
  contravention of the law, has in mind for me."  
  M. Ryutin - Nov 1, 1936 (shot by NKVD Jan 13, 1937)
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

<Prev in Thread] Current Thread [Next in Thread>