diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-08-09 06:42:36 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-08-09 06:42:36 +0000 |
commit | 5644e171d0c25697cf338a51e28e9ce814e3ac13 (patch) | |
tree | 8a87b48d0886668cd336d5f47c5db2c07d0c3442 | |
parent | eceea9db028729d68b319f8b4e95a4ca53a35c2b (diff) |
web commit by PaulWise
-rw-r--r-- | doc/plugins/contrib/siterel2pagerel.mdwn | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/doc/plugins/contrib/siterel2pagerel.mdwn b/doc/plugins/contrib/siterel2pagerel.mdwn new file mode 100644 index 000000000..50d901417 --- /dev/null +++ b/doc/plugins/contrib/siterel2pagerel.mdwn @@ -0,0 +1,25 @@ +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: + + #!/usr/bin/perl + # quick HTML abs2rel link hack by Paul Wise + package IkiWiki::Plugin::siterel2pagerel; + + use warnings; + use strict; + use IkiWiki 2.00; + + sub import { #{{{ + hook(type => "sanitize", id => "siterel2pagerel", call => \&siterel2pagerel); + } # }}} + + sub siterel2pagerel (@) { #{{{ + my %params=@_; + my $baseurl=IkiWiki::baseurl($params{page}); + my $content=$params{content}; + $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"\/([^"]*)"/$1 href="$baseurl$2"/mig; + $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"\/([^"]*)"/$1 src="$baseurl$2"/mig; + # FIXME: do <script and everything else that can have URLs in it + return $content; + } # }}} + + 1 |