diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-07-23 18:14:20 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-07-23 18:14:20 -0400 |
commit | 4691a2ad39cce273231fddd9a589b4f8fdc1b063 (patch) | |
tree | ff28f45d29dc3864d20298941e4389bd10f7e7f0 /IkiWiki | |
parent | 96dab37a8e3acc58fb0ab5be0657c0e545e9684a (diff) |
add renamepage hooks
Implemented for regular wikilinks, with a test suite.
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Plugin/link.pm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/link.pm b/IkiWiki/Plugin/link.pm index 24579057c..51afaec9e 100644 --- a/IkiWiki/Plugin/link.pm +++ b/IkiWiki/Plugin/link.pm @@ -80,4 +80,28 @@ sub scan (@) { #{{{ } } # }}} +sub renamepage (@) { #{{{ + my %params=@_; + my $page=$params{page}; + my $old=$params{oldpage}; + my $new=$params{newpage}; + + $params{content} =~ s{(?<!\\)$link_regexp}{ + my $link=$2; + if (bestlink($page, $2) eq $old) { + if (index($2, "/") == 0) { + $link="/$new"; + } + else { + $link=$new; + } + } + defined $1 + ? ( "[[$1|$link".($3 ? "#$3" : "")."]]" ) + : ( "[[$link". ($3 ? "#$3" : "")."]]" ) + }eg; + + return $params{content}; +} #}}} + 1 |