Photos
Blog
Projects
vanrenterghem.biz
projects
/
git.ikiwiki.info.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add t/img.t regression test also taken from version 3.20160506
[git.ikiwiki.info.git]
/
IkiWiki
/
Plugin
/
link.pm
diff --git
a/IkiWiki/Plugin/link.pm
b/IkiWiki/Plugin/link.pm
index d41965bd38b2ce12c4f59f300af3cf80fce9ac12..1ba28eafd6d4912f16d8aa7fa5c16e01ca9f8dea 100644
(file)
--- a/
IkiWiki/Plugin/link.pm
+++ b/
IkiWiki/Plugin/link.pm
@@
-7,7
+7,7
@@
use IkiWiki 3.00;
my $link_regexp;
my $link_regexp;
-my $email_regexp = qr/^
(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
+my $email_regexp = qr/^
.+@.+\..+$/;
my $url_regexp = qr/^(?:[^:]+:\/\/|mailto:).*/i;
sub import {
my $url_regexp = qr/^(?:[^:]+:\/\/|mailto:).*/i;
sub import {
@@
-64,25
+64,29
@@
sub checkconfig () {
}
}
}
}
-sub is_externallink ($$) {
+sub is_externallink ($$
;$
) {
my $page = shift;
my $url = shift;
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 $url = shift;
+ my $anchor = shift;
my $pagetitle = shift;
my $pagetitle = shift;
+ if (defined $anchor) {
+ $url.="#".$anchor;
+ }
+
# build pagetitle
# build pagetitle
- if (!
($pagetitle)
) {
+ if (!
$pagetitle
) {
$pagetitle = $url;
# use only the email address as title for mailto: urls
if ($pagetitle =~ /^mailto:.*/) {
$pagetitle = $url;
# use only the email address as title for mailto: urls
if ($pagetitle =~ /^mailto:.*/) {
@@
-90,8
+94,8
@@
sub externallink ($;@) {
}
}
}
}
- # handle email-addresses (without mailto:):
- if ($url =~ /$email_regexp/) {
+ if ($url !~ /$url_regexp/) {
+ # handle email addresses (without mailto:)
$url = "mailto:" . $url;
}
$url = "mailto:" . $url;
}
@@
-106,15
+110,15
@@
sub linkify (@) {
$params{content} =~ s{(\\?)$link_regexp}{
defined $2
? ( $1
$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
: 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;
: htmllink($page, $destpage, linkpage($3),
anchor => $4))
}eg;
@@
-128,7
+132,7
@@
sub scan (@) {
my $content=$params{content};
while ($content =~ /(?<!\\)$link_regexp/g) {
my $content=$params{content};
while ($content =~ /(?<!\\)$link_regexp/g) {
- if (! is_externallink($page, $2
. ($3 ? "#$3" : "")
)) {
+ if (! is_externallink($page, $2
, $3
)) {
add_link($page, linkpage($2));
}
}
add_link($page, linkpage($2));
}
}
@@
-140,9
+144,9
@@
sub renamepage (@) {
my $old=$params{oldpage};
my $new=$params{newpage};
my $old=$params{oldpage};
my $new=$params{newpage};
- $params{content} =~ s{(?<!\\)
$link_regexp
}{
- if (! is_externallink($page, $
2 . ($3 ? "#$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);
my $link=$linktext;
if (bestlink($page, linkpage($linktext)) eq $old) {
$link=pagetitle($new, 1);
@@
-157,9
+161,12
@@
sub renamepage (@) {
$link="/$link";
}
}
$link="/$link";
}
}
- defined $1
- ? ( "[[$1|$link".($3 ? "#$3" : "")."]]" )
- : ( "[[$link". ($3 ? "#$3" : "")."]]" )
+ defined $2
+ ? ( "[[$2|$link".($4 ? "#$4" : "")."]]" )
+ : ( "[[$link". ($4 ? "#$4" : "")."]]" )
+ }
+ else {
+ $1
}
}eg;
}
}eg;