X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/19dcd50c8497eca4981f9a90cc3e014789a50f76..739554622fa1caa6bcc0474ebbdcd9db3627389d:/IkiWiki/Plugin/link.pm?ds=inline diff --git a/IkiWiki/Plugin/link.pm b/IkiWiki/Plugin/link.pm index 7d4692ef0..ef01f1107 100644 --- a/IkiWiki/Plugin/link.pm +++ b/IkiWiki/Plugin/link.pm @@ -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 { @@ -64,23 +64,27 @@ sub checkconfig () { } } -sub is_externallink ($$) { +sub is_externallink ($$;$) { my $page = shift; my $url = shift; - 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. - $url =~ s/#.*//; - return (! (bestlink($page, linkpage($url)))) + my $anchor = shift; + + if (defined $anchor) { + $url.="#".$anchor; } - return ($url =~ /$url_regexp/) + + return ($url =~ /$url_regexp|$email_regexp/) } -sub externallink ($;@) { +sub externallink ($$;$) { my $url = shift; + my $anchor = shift; my $pagetitle = shift; + if (defined $anchor) { + $url.="#".$anchor; + } + # build pagetitle if (! $pagetitle) { $pagetitle = $url; @@ -106,15 +110,15 @@ sub linkify (@) { $params{content} =~ s{(\\?)$link_regexp}{ defined $2 ? ( $1 - ? "[[$2|$3".($4 ? "#$4" : "")."]]" - : is_externallink($page, $3 . ($4 ? "#$4" : "")) - ? externallink("$3" . ($4 ? "#$4" : ""), $2) + ? "[[$2|$3".(defined $4 ? "#$4" : "")."]]" + : is_externallink($page, $3, $4) + ? externallink($3, $4, $2) : htmllink($page, $destpage, linkpage($3), anchor => $4, linktext => pagetitle($2))) : ( $1 - ? "[[$3".($4 ? "#$4" : "")."]]" - : is_externallink($page, $3 . ($4 ? "#$4" : "")) - ? externallink("$3" . ($4 ? "#$4" : "")) + ? "[[$3".(defined $4 ? "#$4" : "")."]]" + : is_externallink($page, $3, $4) + ? externallink($3, $4) : htmllink($page, $destpage, linkpage($3), anchor => $4)) }eg; @@ -128,7 +132,7 @@ sub scan (@) { my $content=$params{content}; while ($content =~ /(?