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);
27 if ($config{prefix_directives}) {
29 \[\[(?=[^!]) # beginning of link
31 ([^\]\|]+) # 1: link text
35 ([^\n\r\]#]+) # 2: page to link to
37 \# # '#', beginning of anchor
38 ([^\s\]]+) # 3: anchor text
46 \[\[ # beginning of link
48 ([^\]\|\n\s]+) # 1: link text
52 ([^\s\]#]+) # 2: page to link to
54 \# # '#', beginning of anchor
55 ([^\s\]]+) # 3: anchor text
65 my $page=$params{page};
66 my $destpage=$params{destpage};
68 $params{content} =~ s{(\\?)$link_regexp}{
71 ? "[[$2|$3".($4 ? "#$4" : "")."]]"
72 : htmllink($page, $destpage, linkpage($3),
73 anchor => $4, linktext => pagetitle($2)))
75 ? "[[$3".($4 ? "#$4" : "")."]]"
76 : htmllink($page, $destpage, linkpage($3),
80 return $params{content};
85 my $page=$params{page};
86 my $content=$params{content};
88 while ($content =~ /(?<!\\)$link_regexp/g) {
89 add_link($page, linkpage($2));
95 my $page=$params{page};
96 my $old=$params{oldpage};
97 my $new=$params{newpage};
99 $params{content} =~ s{(?<!\\)$link_regexp}{
102 if (bestlink($page, linkpage($linktext)) eq $old) {
103 $link=pagetitle($new, 1);
105 if ($linktext =~ m/.*\/*?[A-Z]/) {
106 # preserve leading cap of last component
107 my @bits=split("/", $link);
108 $link=join("/", @bits[0..$#bits-1], ucfirst($bits[$#bits]));
110 if (index($linktext, "/") == 0) {
116 ? ( "[[$1|$link".($3 ? "#$3" : "")."]]" )
117 : ( "[[$link". ($3 ? "#$3" : "")."]]" )
120 return $params{content};