2 package IkiWiki::Plugin::link;
11 hook(type => "getsetup", id => "link", call => \&getsetup);
12 hook(type => "checkconfig", id => "link", call => \&checkconfig);
13 hook(type => "linkify", id => "link", call => \&linkify);
14 hook(type => "scan", id => "link", call => \&scan);
15 hook(type => "renamepage", id => "link", call => \&renamepage);
28 if ($config{prefix_directives}) {
30 \[\[(?=[^!]) # beginning of link
32 ([^\]\|]+) # 1: link text
36 ([^\n\r\]#]+) # 2: page to link to
38 \# # '#', beginning of anchor
39 ([^\s\]]+) # 3: anchor text
47 \[\[ # beginning of link
49 ([^\]\|\n\s]+) # 1: link text
53 ([^\s\]#]+) # 2: page to link to
55 \# # '#', beginning of anchor
56 ([^\s\]]+) # 3: anchor text
66 my $page=$params{page};
67 my $destpage=$params{destpage};
69 $params{content} =~ s{(\\?)$link_regexp}{
72 ? "[[$2|$3".($4 ? "#$4" : "")."]]"
73 : htmllink($page, $destpage, linkpage($3),
74 anchor => $4, linktext => pagetitle($2)))
76 ? "[[$3".($4 ? "#$4" : "")."]]"
77 : htmllink($page, $destpage, linkpage($3),
81 return $params{content};
86 my $page=$params{page};
87 my $content=$params{content};
89 while ($content =~ /(?<!\\)$link_regexp/g) {
90 add_link($page, linkpage($2));
96 my $page=$params{page};
97 my $old=$params{oldpage};
98 my $new=$params{newpage};
100 $params{content} =~ s{(?<!\\)$link_regexp}{
103 if (bestlink($page, linkpage($linktext)) eq $old) {
104 $link=pagetitle($new, 1);
106 if ($linktext =~ m/.*\/*?[A-Z]/) {
107 # preserve leading cap of last component
108 my @bits=split("/", $link);
109 $link=join("/", @bits[0..$#bits-1], ucfirst($bits[$#bits]));
111 if (index($linktext, "/") == 0) {
117 ? ( "[[$1|$link".($3 ? "#$3" : "")."]]" )
118 : ( "[[$link". ($3 ? "#$3" : "")."]]" )
121 return $params{content};