mhonarc-commits
[Top] [All Lists]

[approved] CVS: mhonarc/MHonArc/lib mhtxtplain.pl,2.45,2.46

2005-05-27 10:06:33
Update of mhonarc/MHonArc/lib
Modified Files:
	mhtxtplain.pl 
Log Message:
Bug #11761: Added link and nolink arguments to m2h_text_plain::filter.
These options can be used to deal with bug reported by specifying
nolink="mailto" to the filter.


======================================================================
FILE: mhonarc/MHonArc/lib/mhtxtplain.pl
<http://www.mhonarc.org/cgi-bin/viewcvs.cgi/*checkout*/mhonarc/MHonArc/lib/mhtxtplain.pl?rev=2.46>

<http://www.mhonarc.org/cgi-bin/viewcvs.cgi/mhonarc/MHonArc/lib/mhtxtplain.pl.diff?r1=2.45&r2=2.46&diff_format=h>
--- mhtxtplain.pl	7 May 2005 04:30:21 -0000	2.45
+++ mhtxtplain.pl	27 May 2005 06:28:33 -0000	2.46
@@ -13,5 +13,5 @@
 ##---------------------------------------------------------------------------##
 ##    MHonArc -- Internet mail-to-HTML converter
-##    Copyright (C) 1995-2002   Earl Hood, mhonarc(_at_)mhonarc(_dot_)org
+##    Copyright (C) 1995-2005   Earl Hood, mhonarc(_at_)mhonarc(_dot_)org
 ##
 ##    This program is free software; you can redistribute it and/or modify
@@ -91,5 +91,14 @@
 ##      keepspace       Preserve whitespace if nonfixed
 ##
-##      nourl           Do hyperlink URLs
+##      link="scheme1,scheme2,..."
+##                      A comma separate list of URL schemes to hyperlink.
+##                      Only URL with the given schemes will be linked.
+##
+##      nolink="scheme1,scheme2,..."
+##                      A comma separate list of URL schemes to not
+##                      hyperlink.  URLs with the given scheme will not
+##                      converted into hyperlinks.
+##
+##      nourl           Do not hyperlink URLs.
 ##
 ##      nonfixed        Use normal typeface
@@ -552,6 +561,37 @@
 
     ## Convert URLs to hyperlinks
-    $$data =~ s@($HUrlExp)@<a $target rel="nofollow" href="$1">$1</a>@gio
-        unless $nourl;
+    if (!$nourl) {
+        my $nolink = undef;
+        my $link   = undef;
+        if ($args =~ /\bnolink\s*=(\S+)/) {
+            $nolink = lc(','.$1.',');
+            $nolink =~ s/['"]//g;
+        }
+        if ($args =~ /\blink\s*=(\S+)/) {
+            $link = lc(','.$1.',');
+            $link =~ s/['"]//g;
+        }
+        $$data =~ s{
+            ($HUrlExp)
+        }{
+            if (!defined($nolink) && !defined($link)) {
+                join('', '<a ', $target, ' rel="nofollow" href="',
+                         $1, '">', $1, '</a>');
+            } else {
+                my $url_match = $1;
+                my $scheme;
+                $url_match =~ /^([^:]+)/;
+                $scheme = ',' . lc($1) . ',';
+                if ((defined($nolink) && (index($nolink, $scheme) >= $[)) ||
+                    (defined($link)   && (index($link, $scheme)   <  $[)))
+                {
+                    $url_match;
+                } else {
+                    join('', '<a ', $target, ' rel="nofollow" href="',
+                             $url_match, '">', $url_match, '</a>');
+                }
+            }
+        }gxeso;
+    }
 
     $$data = ' '  if $$data eq '';

---------------------------------------------------------------------
To sign-off this list, send email to majordomo(_at_)mhonarc(_dot_)org with the
message text UNSUBSCRIBE MHONARC-COMMITS