]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/htmllink-anchors.mdwn
web commit by http://id.inelegant.org/: Make htmllink understand links to specific...
[ikiwiki.git] / doc / patchqueue / htmllink-anchors.mdwn
1 Here's an attempt to make `htmllink` "do the right thing" with in-page anchors:
2
3 <pre>
4 Index: IkiWiki.pm
5 ===================================================================
6 --- IkiWiki.pm  (revision 2657)
7 +++ IkiWiki.pm  (working copy)
8 @@ -426,6 +426,8 @@
9         my $noimageinline=shift; # don't turn links into inline html images
10         my $forcesubpage=shift; # force a link to a subpage
11         my $linktext=shift; # set to force the link text to something
12 +    
13 +    my $anchor = ($link =~ s/#(.+)$// ? $1 : undef);
14  
15         my $bestlink;
16         if (! $forcesubpage) {
17 @@ -455,7 +457,10 @@
18         if (! $noimageinline && isinlinableimage($bestlink)) {
19                 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
20         }
21 -       return "<a href=\"$bestlink\">$linktext</a>";
22 +
23 +    $bestlink .= "#$anchor" if $anchor;
24 +    
25 +    return "<a href=\"$bestlink\">$linktext</a>";
26  } #}}}
27  
28  sub htmlize ($$$) { #{{{
29 </pre>