diff options
author | Jonas Smedegaard <dr@jones.dk> | 2011-10-14 03:23:09 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2013-10-13 00:53:27 +0200 |
commit | 24ae2a38326a771d2ce602d37bff2a3c82ac2ad5 (patch) | |
tree | 11027bec5ddfa09194ae4be1e76b678bac3c68da /IkiWiki/Plugin | |
parent | 2dbdf2509fe3f5d9604cfbcbe2d996d81257974d (diff) |
Add plugin htmlpacker to squash superfluous space in Markdown content.
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/htmlpacker.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/htmlpacker.pm b/IkiWiki/Plugin/htmlpacker.pm new file mode 100644 index 0000000..39a90b0 --- /dev/null +++ b/IkiWiki/Plugin/htmlpacker.pm @@ -0,0 +1,40 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::htmlpacker; + +# htmlpacker: HTML code cleaner +# +# Copyright 2011 Jonas Smedegaard <dr@jones.dk> +# Based on htmlbalance which is... +# Copyright 2008 Simon McVittie <http://smcv.pseudorandom.co.uk/> +# Licensed under the GNU GPL, version 2, or any later version published by the +# Free Software Foundation + +use warnings; +use strict; +use IkiWiki 3.00; + +sub import { + hook(type => "getsetup", id => "hmtlpacker", call => \&getsetup); + hook(type => "sanitize", id => "hmtlpacker", call => \&sanitize); +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => undef, + }, +} + +sub sanitize (@) { + my %params=@_; + my $ret = ''; + + eval q{use HTML::Packer}; + error $@ if $@; + my $packer = HTML::Packer->init(); + $ret = $packer->minify( \$params{content}, { html5 => $config{html5} } ); + return $ret; +} + +1 |