]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/plugins/contrib/siterel2pagerel.mdwn
web commit by http://madduck.myopenid.com/: add info on how to reconfigure existing...
[git.ikiwiki.info.git] / doc / plugins / contrib / siterel2pagerel.mdwn
1 This is a simple plugin to convert all site-relative links to page-relative links (converts /foo into ../../../foo or similar). It works as a postprocessing filter, allowing it to work on mdwn, wiki, html, rst and any other format that produces html. The code is available here:
3         #!/usr/bin/perl
4         # quick HTML siterel2pagerel link hack by Paul Wise
5         package IkiWiki::Plugin::siterel2pagerel;
7         use warnings;
8         use strict;
9         use IkiWiki 2.00;
11         sub import { #{{{
12                 hook(type => "sanitize", id => "siterel2pagerel", call => \&siterel2pagerel);
13         } # }}}
15         sub siterel2pagerel (@) { #{{{
16                 my %params=@_;
17                 my $baseurl=IkiWiki::baseurl($params{page});
18                 my $content=$params{content};
19                 $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"\/([^"]*)"/$1 href="$baseurl$2"/mig;
20                 $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"\/([^"]*)"/$1 src="$baseurl$2"/mig;
21                 # FIXME: do <script and everything else that can have URLs in it
22                 return $content;
23         } # }}}
25         1