support [[linktext|pagename]] links

master
joey 2006-03-28 23:31:53 +00:00
parent d73574e19f
commit d9f1b12149
4 changed files with 11 additions and 5 deletions

View 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.

View 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]]

View File

@ -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;