case preservation
authorJoey Hess <joey@kodama.kitenet.net>
Wed, 23 Jul 2008 22:57:27 +0000 (18:57 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Wed, 23 Jul 2008 22:57:27 +0000 (18:57 -0400)
IkiWiki/Plugin/link.pm
t/renamepage.t

index 51afaec9e7392b3ca15fe6b8c39db5d4b90d88bf..e201098884b2921ecfd9842993ddb273135fbb31 100644 (file)
@@ -11,6 +11,7 @@ sub import { #{{{
        hook(type => "checkconfig", id => "link", call => \&checkconfig);
        hook(type => "linkify", id => "link", call => \&linkify);
        hook(type => "scan", id => "link", call => \&scan);
+       hook(type => "renamepage", id => "link", call => \&renamepage);
 } # }}}
 
 sub checkconfig () { #{{{
@@ -87,13 +88,17 @@ sub renamepage (@) { #{{{
        my $new=$params{newpage};
 
        $params{content} =~ s{(?<!\\)$link_regexp}{
-               my $link=$2;
+               my $linktext=$2;
+               my $link=$linktext;
                if (bestlink($page, $2) eq $old) {
-                       if (index($2, "/") == 0) {
-                               $link="/$new";
+                       $link=$new;
+                       if ($linktext =~ m/\/*?[A-Z]/) {
+                               # preserve leading cap
+                               $link=ucfirst($link);
                        }
-                       else {
-                               $link=$new;
+                       if (index($linktext, "/") == 0) {
+                               # absolute link
+                               $link="/$link";
                        }
                }
                defined $1
index ce62bf468a0b3b498f5b01c953cba9c38ded9caf..b16ca3d23b585cfe4d3b0a7ce564f244a9c40020 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use warnings;
 use strict;
-use Test::More tests => 11;
+use Test::More tests => 14;
 use Encode;
 
 BEGIN { use_ok("IkiWiki"); }
@@ -34,6 +34,8 @@ is(try("z", "foo" => "bar", "[[xxx]]"), "[[xxx]]"); # unrelated link
 is(try("z", "foo" => "bar", "[[bar]]"), "[[bar]]"); # link already to new page
 is(try("z", "foo" => "bar", "[[foo]]"), "[[bar]]"); # basic conversion to new page name
 is(try("z", "foo" => "bar", "[[/foo]]"), "[[/bar]]"); # absolute link
+is(try("z", "foo" => "bar", "[[Foo]]"), "[[Bar]]"); # preserve case
+is(try("z", "foo" => "bar", "[[/Foo]]"), "[[/Bar]]"); # preserve case w/absolute
 is(try("z", "foo" => "bar", "[[foo]] [[xxx]]"), "[[bar]] [[xxx]]"); # 2 links, 1 converted
 is(try("z", "foo" => "bar", "[[xxx|foo]]"), "[[xxx|bar]]"); # conversion w/text
 is(try("z", "foo" => "bar", "[[foo#anchor]]"), "[[bar#anchor]]"); # with anchor