]> sipb.mit.edu Git - ikiwiki.git/commitdiff
support [[linktext|pagename]] links
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Tue, 28 Mar 2006 23:31:53 +0000 (23:31 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Tue, 28 Mar 2006 23:31:53 +0000 (23:31 +0000)
IkiWiki/Render.pm
doc/todo/done/wikilinkfeatures.mdwn [moved from doc/todo/wikilinkfeatures.mdwn with 100% similarity]
doc/wikilink.mdwn
ikiwiki

index 5f9de8d2668b16992a9c3efedc6203b542301a1e..504edc843cc8d7e6693822659ac2477c39798d13 100644 (file)
@@ -9,7 +9,8 @@ sub linkify ($$) { #{{{
        my $page=shift;
 
        $content =~ s{(\\?)$config{wiki_link_regexp}}{
-               $1 ? "[[$2]]" : htmllink($page, $2)
+               $2 ? ( $1 ? "[[$2|$3]]" : htmllink($page, $3, 0, 0, pagetitle($2)))
+                  : ( $1 ? "[[$3]]" :    htmllink($page, $3))
        }eg;
        
        return $content;
@@ -324,7 +325,7 @@ sub findlinks ($$) { #{{{
 
        my @links;
        while ($content =~ /(?<!\\)$config{wiki_link_regexp}/g) {
-               push @links, lc($1);
+               push @links, lc($2);
        }
        # Discussion links are a special case since they're not in the text
        # of the page, but on its template.
index 4b5c5c1c08696e03557a1686dc8c28f08a1a1aee..25c7586130784126ac95b841220d64b7fcd47f8e 100644 (file)
@@ -23,3 +23,7 @@ charaters, it is possible to create page names containing other characters:
 
 Note that if the file linked to by a WikiLink looks like an image, it will
 be displayed inline on the page.
+
+It's also possible to write a WikiLink that uses something other than the
+page name as the link text. For example "\[[foo|SandBox]]" links to the
+SandBox page, but the link will appear like this: [[foo|SandBox]]
diff --git a/ikiwiki b/ikiwiki
index f801df29e8a7c206a4e6329136fb44a7c44af5b1..9e9c293544170cb61ed6a60310e7967496825098 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -19,7 +19,7 @@ sub getconfig () { #{{{
        if (! exists $ENV{WRAPPED_OPTIONS}) {
                %config=(
                        wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
-                       wiki_link_regexp => qr/\[\[([^\s\]]+)\]\]/,
+                       wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/,
                        wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]+)\]\]/,
                        wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
                        verbose => 0,
@@ -252,11 +252,12 @@ sub pagetitle ($) { #{{{
        return $page;
 } #}}}
 
-sub htmllink ($$;$$) { #{{{
+sub htmllink ($$;$$$) { #{{{
        my $page=shift;
        my $link=shift;
        my $noimageinline=shift; # don't turn links into inline html images
        my $forcesubpage=shift; # force a link to a subpage
+       my $linktext=shift; # set to force the link text to something
 
        my $bestlink;
        if (! $forcesubpage) {
@@ -266,7 +267,7 @@ sub htmllink ($$;$$) { #{{{
                $bestlink="$page/".lc($link);
        }
 
-       my $linktext=pagetitle(basename($link));
+       $linktext=pagetitle(basename($link)) unless defined $linktext;
        
        return $linktext if length $bestlink && $page eq $bestlink;