]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/shortcut.pm
Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[ikiwiki.git] / IkiWiki / Plugin / shortcut.pm
index 7b89bf879cdf48be4421a205399cb27a07a489f8..c3e1f5446f6c98ca9f3c9c65a7a014b7c7e15c59 100644 (file)
@@ -3,7 +3,7 @@ package IkiWiki::Plugin::shortcut;
 
 use warnings;
 use strict;
-use IkiWiki;
+use IkiWiki 2.00;
 
 sub import { #{{{
        hook(type => "checkconfig", id => "shortcut", call => \&checkconfig);
@@ -13,8 +13,11 @@ sub import { #{{{
 sub checkconfig () { #{{{
        # Preprocess the shortcuts page to get all the available shortcuts
        # defined before other pages are rendered.
-       IkiWiki::preprocess("shortcuts", "shortcuts",
-               readfile(srcfile("shortcuts.mdwn")));
+       my $srcfile=eval {srcfile("shortcuts.mdwn")};
+       if (! defined $srcfile) {
+               error(gettext("shortcut plugin will not work without a shortcuts.mdwn"));
+       }
+       IkiWiki::preprocess("shortcuts", "shortcuts", readfile($srcfile));
 } # }}}
 
 sub preprocess_shortcut (@) { #{{{
@@ -54,7 +57,14 @@ sub shortcut_expand ($$@) { #{{{
        my $encoded_text=$text;
        $encoded_text=~s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
        
+       $url=~s{\%([sS])}{
+               $1 eq 's' ? $encoded_text : $text
+       }eg;
+
        $text=~s/_/ /g;
+       if (defined $params{desc}) {
+               $desc=$params{desc};
+       }
        if (defined $desc) {
                $desc=~s/\%s/$text/g;
        }
@@ -62,7 +72,6 @@ sub shortcut_expand ($$@) { #{{{
                $desc=$text;
        }
 
-       $url=~s/\%s/$encoded_text/g;
        return "<a href=\"$url\">$desc</a>";
 } #}}}