]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/link.pm
In rebuilds, assume that every page has been scanned by the time the scan phase ends
[git.ikiwiki.info.git] / IkiWiki / Plugin / link.pm
index 87e06ca899b51868646346a77670835caa7deb07..1ba28eafd6d4912f16d8aa7fa5c16e01ca9f8dea 100644 (file)
@@ -7,7 +7,7 @@ use IkiWiki 3.00;
 
 my $link_regexp;
 
-my $email_regexp = qr/^.+@.+$/;
+my $email_regexp = qr/^.+@.+\..+$/;
 my $url_regexp = qr/^(?:[^:]+:\/\/|mailto:).*/i;
 
 sub import {
@@ -73,13 +73,7 @@ sub is_externallink ($$;$) {
                $url.="#".$anchor;
        }
 
-       if ($url =~ /$email_regexp/) {
-               # url looks like an email address, so we assume it
-               # is supposed to be an external link if there is no
-               # page with that name.
-               return (! (bestlink($page, linkpage($url))))
-       }
-       return ($url =~ /$url_regexp/)
+       return ($url =~ /$url_regexp|$email_regexp/)
 }
 
 sub externallink ($$;$) {
@@ -150,9 +144,9 @@ sub renamepage (@) {
        my $old=$params{oldpage};
        my $new=$params{newpage};
 
-       $params{content} =~ s{(?<!\\)$link_regexp}{
-               if (! is_externallink($page, $2, $3)) {
-                       my $linktext=$2;
+       $params{content} =~ s{(?<!\\)($link_regexp)}{
+               if (! is_externallink($page, $3, $4)) {
+                       my $linktext=$3;
                        my $link=$linktext;
                        if (bestlink($page, linkpage($linktext)) eq $old) {
                                $link=pagetitle($new, 1);
@@ -167,9 +161,12 @@ sub renamepage (@) {
                                        $link="/$link";
                                }
                        }
-                       defined $1
-                               ? ( "[[$1|$link".($3 ? "#$3" : "")."]]" )
-                               : ( "[[$link".   ($3 ? "#$3" : "")."]]" )
+                       defined $2
+                               ? ( "[[$2|$link".($4 ? "#$4" : "")."]]" )
+                               : ( "[[$link".   ($4 ? "#$4" : "")."]]" )
+               }
+               else {
+                       $1
                }
        }eg;