fix encoding issues with link conversion
[ikiwiki.git] / IkiWiki / Plugin / link.pm
index e201098884b2921ecfd9842993ddb273135fbb31..2ea6aa19eebbfdb17b0a1859eb79ca511ced8504 100644 (file)
@@ -90,11 +90,13 @@ sub renamepage (@) { #{{{
        $params{content} =~ s{(?<!\\)$link_regexp}{
                my $linktext=$2;
                my $link=$linktext;
-               if (bestlink($page, $2) eq $old) {
-                       $link=$new;
-                       if ($linktext =~ m/\/*?[A-Z]/) {
-                               # preserve leading cap
-                               $link=ucfirst($link);
+               if (bestlink($page, IkiWiki::linkpage($linktext)) eq $old) {
+                       $link=IkiWiki::pagetitle($new, 1);
+                       $link=~s/ /_/g;
+                       if ($linktext =~ m/.*\/*?[A-Z]/) {
+                               # preserve leading cap of last component
+                               my @bits=split("/", $link);
+                               $link=join("/", @bits[0..$#bits-1], ucfirst($bits[$#bits]));
                        }
                        if (index($linktext, "/") == 0) {
                                # absolute link