diff options
author | Joey Hess <joey@kitenet.net> | 2010-06-23 13:57:27 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-06-23 13:57:27 -0400 |
commit | 6e67219eff9ea599e9efa8a846a4c78c76c5b008 (patch) | |
tree | 18d9c28e83a0aaae2fbd21ce2f8d48e9d2af0292 /IkiWiki/Plugin | |
parent | 19dcd50c8497eca4981f9a90cc3e014789a50f76 (diff) |
simplify anchor handling
At least two bugfixes in here. First, an old bug;
\[[foo#0]] was displayed as [[foo]], losing the anchor
as the anchor text was false. Secondly, a new bug;
an email like foo#bar@baz should not check bestlink("foo@baz").
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/link.pm | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/IkiWiki/Plugin/link.pm b/IkiWiki/Plugin/link.pm index 7d4692ef0..87e06ca89 100644 --- a/IkiWiki/Plugin/link.pm +++ b/IkiWiki/Plugin/link.pm @@ -64,23 +64,33 @@ sub checkconfig () { } } -sub is_externallink ($$) { +sub is_externallink ($$;$) { my $page = shift; my $url = shift; + my $anchor = shift; + + if (defined $anchor) { + $url.="#".$anchor; + } + if ($url =~ /$email_regexp/) { # url looks like an email address, so we assume it # is supposed to be an external link if there is no # page with that name. - $url =~ s/#.*//; return (! (bestlink($page, linkpage($url)))) } return ($url =~ /$url_regexp/) } -sub externallink ($;@) { +sub externallink ($$;$) { my $url = shift; + my $anchor = shift; my $pagetitle = shift; + if (defined $anchor) { + $url.="#".$anchor; + } + # build pagetitle if (! $pagetitle) { $pagetitle = $url; @@ -106,15 +116,15 @@ sub linkify (@) { $params{content} =~ s{(\\?)$link_regexp}{ defined $2 ? ( $1 - ? "[[$2|$3".($4 ? "#$4" : "")."]]" - : is_externallink($page, $3 . ($4 ? "#$4" : "")) - ? externallink("$3" . ($4 ? "#$4" : ""), $2) + ? "[[$2|$3".(defined $4 ? "#$4" : "")."]]" + : is_externallink($page, $3, $4) + ? externallink($3, $4, $2) : htmllink($page, $destpage, linkpage($3), anchor => $4, linktext => pagetitle($2))) : ( $1 - ? "[[$3".($4 ? "#$4" : "")."]]" - : is_externallink($page, $3 . ($4 ? "#$4" : "")) - ? externallink("$3" . ($4 ? "#$4" : "")) + ? "[[$3".(defined $4 ? "#$4" : "")."]]" + : is_externallink($page, $3, $4) + ? externallink($3, $4) : htmllink($page, $destpage, linkpage($3), anchor => $4)) }eg; @@ -128,7 +138,7 @@ sub scan (@) { my $content=$params{content}; while ($content =~ /(?<!\\)$link_regexp/g) { - if (! is_externallink($page, $2 . ($3 ? "#$3" : ""))) { + if (! is_externallink($page, $2, $3)) { add_link($page, linkpage($2)); } } @@ -141,7 +151,7 @@ sub renamepage (@) { my $new=$params{newpage}; $params{content} =~ s{(?<!\\)$link_regexp}{ - if (! is_externallink($page, $2 . ($3 ? "#$3" : ""))) { + if (! is_externallink($page, $2, $3)) { my $linktext=$2; my $link=$linktext; if (bestlink($page, linkpage($linktext)) eq $old) { |