summaryrefslogtreecommitdiff
path: root/IkiWiki.pm
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-02-20 03:05:47 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-02-20 03:05:47 +0000
commitfa52a730ff3b30c7d2cdd8cd5f9c8c25a0c0a2a5 (patch)
tree3a4eadd971ccd69bd4037ad3647b6cce64047833 /IkiWiki.pm
parent2ce6c23f9485d26d443fb5a1f8c5286a5e668625 (diff)
* Changed calling convention for httmllink slightly. The first three
parameters remain the same, but additional options are now passed in using named parameters. * Change plugin interface version to 1.02 to reflect this change. * Add a new anchor option to htmllink. Thanks Ben for the idea. * Support anchors in wikilinks. * Add a "more" plugin based on one contributed by Ben to allow implementing those dreaded "Read more" links in blogs.
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r--IkiWiki.pm30
1 files changed, 19 insertions, 11 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index d2fde957c..bbc857214 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -16,7 +16,7 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
bestlink htmllink readfile writefile pagetype srcfile pagename
displaytime will_render gettext
%config %links %renderedfiles %pagesources);
-our $VERSION = 1.01; # plugin interface version, next is ikiwiki version
+our $VERSION = 1.02; # plugin interface version, next is ikiwiki version
our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
@@ -30,7 +30,7 @@ sub defaultconfig () { #{{{
wiki_file_prune_regexps => [qr/\.\./, qr/^\./, qr/\/\./,
qr/\.x?html?$/, qr/\.ikiwiki-new$/,
qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//],
- wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]]+)\]\]/,
+ wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]#]+)(?:#([^\s\]]+))?\]\]/,
wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
web_commit_regexp => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/,
verbose => 0,
@@ -419,23 +419,27 @@ sub displaytime ($) { #{{{
$config{timeformat}, localtime($time)));
} #}}}
-sub htmllink ($$$;$$$) { #{{{
+sub htmllink ($$$;@) { #{{{
my $lpage=shift; # the page doing the linking
my $page=shift; # the page that will contain the link (different for inline)
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 %opts=@_;
my $bestlink;
- if (! $forcesubpage) {
+ if (! $opts{forcesubpage}) {
$bestlink=bestlink($lpage, $link);
}
else {
$bestlink="$lpage/".lc($link);
}
- $linktext=pagetitle(basename($link)) unless defined $linktext;
+ my $linktext;
+ if (defined $opts{linktext}) {
+ $linktext=$opts{linktext};
+ }
+ else {
+ $linktext=pagetitle(basename($link));
+ }
return "<span class=\"selflink\">$linktext</span>"
if length $bestlink && $page eq $bestlink;
@@ -452,10 +456,14 @@ sub htmllink ($$$;$$$) { #{{{
$bestlink=abs2rel($bestlink, dirname($page));
- if (! $noimageinline && isinlinableimage($bestlink)) {
+ if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
return "<img src=\"$bestlink\" alt=\"$linktext\" />";
}
+ if (defined $opts{anchor}) {
+ $bestlink.="#".$opts{anchor};
+ }
+
return "<a href=\"$bestlink\">$linktext</a>";
} #}}}
@@ -491,8 +499,8 @@ sub linkify ($$$) { #{{{
$content =~ s{(\\?)$config{wiki_link_regexp}}{
defined $2
- ? ( $1 ? "[[$2|$3]]" : htmllink($lpage, $page, titlepage($3), 0, 0, pagetitle($2)))
- : ( $1 ? "[[$3]]" : htmllink($lpage, $page, titlepage($3)))
+ ? ( $1 ? "[[$2|$3]]" : htmllink($lpage, $page, titlepage($3), anchor => $4, linktext => pagetitle($2)))
+ : ( $1 ? "[[$3]]" : htmllink($lpage, $page, titlepage($3), anchor => $4))
}eg;
return $content;